psi/psi_test.go: improved some naming

This commit is contained in:
saxon 2019-01-20 20:43:00 +10:30
parent 5c4795786e
commit 1a966e8f9b
1 changed files with 25 additions and 22 deletions

View File

@ -79,7 +79,7 @@ var (
// standardPmtTimeLocation is a standard PMT with time and location // standardPmtTimeLocation is a standard PMT with time and location
// descriptors, but time and location fields zeroed out. // descriptors, but time and location fields zeroed out.
standardPmtTimeLocation = PSI{ standardPmtWithMeta = PSI{
Pf: 0x00, Pf: 0x00,
Tid: 0x02, Tid: 0x02,
Ssi: true, Ssi: true,
@ -124,14 +124,14 @@ const (
// GPS string for testing // GPS string for testing
// TODO: make these realistic // TODO: make these realistic
var ( var (
locationTstStr1 = [LocationDataSize]byte{ locationBytes1 = [LocationDataSize]byte{
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
} }
locationTstStr2 = [LocationDataSize]byte{ locationBytes2 = [LocationDataSize]byte{
0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01,
@ -153,7 +153,7 @@ var (
// Parts to construct bytes of pmt with time and bytes // Parts to construct bytes of pmt with time and bytes
var ( var (
pmtTimeLocationBytesPart1 = []byte{ pmtWithMetaHead = []byte{
0x00, 0x02, 0xb0, 0x12, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x0a, 0x00, 0x02, 0xb0, 0x12, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x0a,
TimeDescTag, // Descriptor tag for timestamp TimeDescTag, // Descriptor tag for timestamp
TimeDataSize, // Length of bytes to follow TimeDataSize, // Length of bytes to follow
@ -161,7 +161,7 @@ var (
LocationDescTag, // Descriptor tag for location LocationDescTag, // Descriptor tag for location
LocationDataSize, // Length of bytes to follow LocationDataSize, // Length of bytes to follow
} }
pmtTimeLocationBytesPart2 = []byte{ pmtWithMetaTail = []byte{
0x1b, 0xe1, 0x00, 0xf0, 0x00, 0x1b, 0xe1, 0x00, 0xf0, 0x00,
} }
) )
@ -186,10 +186,10 @@ var (
} }
// Bytes representing pmt with time1 and location1 // Bytes representing pmt with time1 and location1
pmtTimeLocationBytes1 = buildPmtTimeLocationBytes(locationTstStr1[:]) pmtWithMetaTst1 = buildPmtWithMeta(locationBytes1[:])
// bytes representing pmt with with time1 and location 2 // bytes representing pmt with with time1 and location 2
pmtTimeLocationBytes2 = buildPmtTimeLocationBytes(locationTstStr2[:]) pmtWithMetaTst2 = buildPmtWithMeta(locationBytes2[:])
) )
// bytesTests contains data for testing the Bytes() funcs for the PSI data struct // bytesTests contains data for testing the Bytes() funcs for the PSI data struct
@ -273,7 +273,7 @@ var bytesTests = []struct {
{ {
Dt: LocationDescTag, Dt: LocationDescTag,
Dl: LocationDataSize, Dl: LocationDataSize,
Dd: locationTstStr1[:], Dd: locationBytes1[:],
}, },
}, },
Essd: &ESSD{ Essd: &ESSD{
@ -284,7 +284,7 @@ var bytesTests = []struct {
}, },
}, },
}, },
want: buildPmtTimeLocationBytes(locationTstStr1[:]), want: buildPmtWithMeta(locationBytes1[:]),
}, },
} }
@ -336,32 +336,32 @@ func TestTimeGet(t *testing.T) {
// TestLocationGet checks that we can correctly get location data from a pmt table // TestLocationGet checks that we can correctly get location data from a pmt table
func TestLocationGet(t *testing.T) { func TestLocationGet(t *testing.T) {
pb := standardPmtTimeLocation.Bytes() pb := standardPmtWithMeta.Bytes()
err := UpdateLocation(pb, string(locationTstStr1[:])) err := UpdateLocation(pb, string(locationBytes1[:]))
if err != nil { if err != nil {
t.Errorf("Error for TestLocationGet UpdateLocation(pb, locationTstStr1): %v", err) t.Errorf("Error for TestLocationGet UpdateLocation(pb, locationBytes1): %v", err)
} }
g, err := LocationFrom(pb) g, err := LocationFrom(pb)
if err != nil { if err != nil {
t.Errorf("Error for TestLocationGet LocationOf(pb): %v", err) t.Errorf("Error for TestLocationGet LocationOf(pb): %v", err)
} }
if g != string(locationTstStr1[:]) { if g != string(locationBytes1[:]) {
t.Errorf(errCmp, "TestLocationGet", locationTstStr1, g) t.Errorf(errCmp, "TestLocationGet", locationBytes1, g)
} }
} }
// TestLocationUpdate checks to see if we can update the location string in a pmt correctly // TestLocationUpdate checks to see if we can update the location string in a pmt correctly
func TestLocationUpdate(t *testing.T) { func TestLocationUpdate(t *testing.T) {
cpy := make([]byte, len(pmtTimeLocationBytes1)) cpy := make([]byte, len(pmtWithMetaTst1))
copy(cpy, pmtTimeLocationBytes1) copy(cpy, pmtWithMetaTst1)
cpy = addCrc(cpy) cpy = addCrc(cpy)
err := UpdateLocation(cpy, string(locationTstStr2[:])) err := UpdateLocation(cpy, string(locationBytes2[:]))
cpy = cpy[:len(cpy)-4] cpy = cpy[:len(cpy)-4]
if err != nil { if err != nil {
t.Errorf("Update time returned err: %v", err) t.Errorf("Update time returned err: %v", err)
} }
if !bytes.Equal(pmtTimeLocationBytes2, cpy) { if !bytes.Equal(pmtWithMetaTst2, cpy) {
t.Errorf(errCmp, "TestLocationUpdate", pmtTimeLocationBytes2, cpy) t.Errorf(errCmp, "TestLocationUpdate", pmtWithMetaTst2, cpy)
} }
} }
@ -377,7 +377,10 @@ func TestTrim(t *testing.T) {
// buildPmtTimeLocationBytes is a helper function to help construct the byte slices // buildPmtTimeLocationBytes is a helper function to help construct the byte slices
// for pmts with time and location, as the location data field is 32 bytes, i.e. quite large // for pmts with time and location, as the location data field is 32 bytes, i.e. quite large
// to type out // to type out
func buildPmtTimeLocationBytes(tstStr []byte) []byte { func buildPmtWithMeta(tstStr []byte) []byte {
return append(append(append(make([]byte, 0), pmtTimeLocationBytesPart1...), dst := make([]byte, len(pmtWithMetaHead)+32+len(pmtWithMetaTail))
tstStr...), pmtTimeLocationBytesPart2...) copy(dst, pmtWithMetaHead)
copy(dst[len(pmtWithMetaHead):], tstStr)
copy(dst[len(pmtWithMetaHead)+32:], pmtWithMetaTail)
return dst
} }