stream/mts/psi/descriptor_test.go: added comments to test funcs - as well as some todos for further testing.

This commit is contained in:
saxon 2019-01-29 22:07:06 +10:30
parent 568840f691
commit 7f8465f1ad
1 changed files with 29 additions and 0 deletions

View File

@ -127,6 +127,10 @@ var (
} }
) )
// TestHasDescriptorExists checks that PSIBytes.HasDescriptor performs as expected
// when the PSI we're interested in has the descriptor of interest. HasDescriptor
// should return the descriptor bytes.
// TODO: HasDescriptor also returns index of descriptor - we should check this.
func TestHasDescriptorExists(t *testing.T) { func TestHasDescriptorExists(t *testing.T) {
p := PSIBytes(tstPsi3.Bytes()) p := PSIBytes(tstPsi3.Bytes())
_, got := p.HasDescriptor(LocationDescTag) _, got := p.HasDescriptor(LocationDescTag)
@ -140,6 +144,10 @@ func TestHasDescriptorExists(t *testing.T) {
} }
} }
// TestHasDescriptorAbsent checks that PSIBytes.HasDescriptor performs as expected
// when the PSI does not have the descriptor of interest. HasDescriptor should
// return a nil slice and a negative index.
// TODO: check index here as well.
func TestHasDescriptorAbsent(t *testing.T) { func TestHasDescriptorAbsent(t *testing.T) {
p := PSIBytes(tstPsi3.Bytes()) p := PSIBytes(tstPsi3.Bytes())
const fakeTag = 236 const fakeTag = 236
@ -150,6 +158,10 @@ func TestHasDescriptorAbsent(t *testing.T) {
} }
} }
// TestHasDescriptorNone checks that PSIBytes.HasDescriptor behaves as expected
// when the PSI does not have any descriptors. HasDescriptor should return a nil
// slice.
// TODO: again check index here.
func TestHasDescriptorNone(t *testing.T) { func TestHasDescriptorNone(t *testing.T) {
p := PSIBytes(tstPsi2.Bytes()) p := PSIBytes(tstPsi2.Bytes())
_, got := p.HasDescriptor(LocationDescTag) _, got := p.HasDescriptor(LocationDescTag)
@ -159,6 +171,8 @@ func TestHasDescriptorNone(t *testing.T) {
} }
} }
// TestProgramInfoLen checks that PSIBytes.ProgramInfoLen correctly extracts
// the program info length from a PSI.
func TestProgramInfoLen(t *testing.T) { func TestProgramInfoLen(t *testing.T) {
p := PSIBytes(tstPsi1.Bytes()) p := PSIBytes(tstPsi1.Bytes())
got := p.ProgramInfoLen() got := p.ProgramInfoLen()
@ -168,6 +182,8 @@ func TestProgramInfoLen(t *testing.T) {
} }
} }
// TestDescriptors checks that PSIBytes.descriptors correctly returns the descriptors
// from a PSI when descriptors exist.
func TestDescriptors(t *testing.T) { func TestDescriptors(t *testing.T) {
p := PSIBytes(tstPsi1.Bytes()) p := PSIBytes(tstPsi1.Bytes())
got := p.descriptors() got := p.descriptors()
@ -181,6 +197,8 @@ func TestDescriptors(t *testing.T) {
} }
} }
// TestDescriptors checks that PSIBYtes.desriptors correctly returns nil when
// we try to get descriptors from a psi without any descriptors.
func TestDescriptorsNone(t *testing.T) { func TestDescriptorsNone(t *testing.T) {
p := PSIBytes(tstPsi2.Bytes()) p := PSIBytes(tstPsi2.Bytes())
got := p.descriptors() got := p.descriptors()
@ -190,6 +208,8 @@ func TestDescriptorsNone(t *testing.T) {
} }
} }
// TestCreateDescriptorEmpty checks that PSIBytes.createDescriptor correctly adds
// a descriptor to the descriptors list in a PSI when it has no descriptors already.
func TestCreateDescriptorEmpty(t *testing.T) { func TestCreateDescriptorEmpty(t *testing.T) {
got := PSIBytes(tstPsi2.Bytes()) got := PSIBytes(tstPsi2.Bytes())
got.createDescriptor(TimeDescTag, make([]byte, TimeDataSize)) got.createDescriptor(TimeDescTag, make([]byte, TimeDataSize))
@ -200,6 +220,9 @@ func TestCreateDescriptorEmpty(t *testing.T) {
} }
} }
// TestCreateDescriptorNotEmpty checks that PSIBytes.createDescriptor correctly adds
// a descriptor to the descriptors list in a PSI when it already has one with
// a different tag.
func TestCreateDescriptorNotEmpty(t *testing.T) { func TestCreateDescriptorNotEmpty(t *testing.T) {
got := PSIBytes(tstPsi1.Bytes()) got := PSIBytes(tstPsi1.Bytes())
got.createDescriptor(LocationDescTag, make([]byte, LocationDataSize)) got.createDescriptor(LocationDescTag, make([]byte, LocationDataSize))
@ -210,6 +233,8 @@ func TestCreateDescriptorNotEmpty(t *testing.T) {
} }
} }
// TestAddDescriptorEmpty checks that PSIBytes.AddDescriptor correctly adds a descriptor
// when there are no other descriptors present in the PSI.
func TestAddDescriptorEmpty(t *testing.T) { func TestAddDescriptorEmpty(t *testing.T) {
got := PSIBytes(tstPsi2.Bytes()) got := PSIBytes(tstPsi2.Bytes())
if err := got.AddDescriptor(TimeDescTag, make([]byte, TimeDataSize)); err != nil { if err := got.AddDescriptor(TimeDescTag, make([]byte, TimeDataSize)); err != nil {
@ -221,6 +246,8 @@ func TestAddDescriptorEmpty(t *testing.T) {
} }
} }
// TestAddDescriptorNonEmpty checks that PSIBytes.AddDescriptor correctly adds a
// descriptor when there is already a descriptor of a differing type in a PSI.
func TestAddDescriptorNonEmpty(t *testing.T) { func TestAddDescriptorNonEmpty(t *testing.T) {
got := PSIBytes(tstPsi1.Bytes()) got := PSIBytes(tstPsi1.Bytes())
if err := got.AddDescriptor(LocationDescTag, make([]byte, LocationDataSize)); err != nil { if err := got.AddDescriptor(LocationDescTag, make([]byte, LocationDataSize)); err != nil {
@ -231,3 +258,5 @@ func TestAddDescriptorNonEmpty(t *testing.T) {
t.Errorf(errNotExpectedOut, got, want) t.Errorf(errNotExpectedOut, got, want)
} }
} }
// TODO: check that we can update descriptor with AddDescriptor