mirror of https://bitbucket.org/ausocean/av.git
psi/psi_test.go: improved some naming
This commit is contained in:
parent
5c4795786e
commit
1a966e8f9b
|
@ -79,7 +79,7 @@ var (
|
|||
|
||||
// standardPmtTimeLocation is a standard PMT with time and location
|
||||
// descriptors, but time and location fields zeroed out.
|
||||
standardPmtTimeLocation = PSI{
|
||||
standardPmtWithMeta = PSI{
|
||||
Pf: 0x00,
|
||||
Tid: 0x02,
|
||||
Ssi: true,
|
||||
|
@ -124,14 +124,14 @@ const (
|
|||
// GPS string for testing
|
||||
// TODO: make these realistic
|
||||
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,
|
||||
}
|
||||
|
||||
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,
|
||||
|
@ -153,7 +153,7 @@ var (
|
|||
|
||||
// Parts to construct bytes of pmt with time and bytes
|
||||
var (
|
||||
pmtTimeLocationBytesPart1 = []byte{
|
||||
pmtWithMetaHead = []byte{
|
||||
0x00, 0x02, 0xb0, 0x12, 0x00, 0x01, 0xc1, 0x00, 0x00, 0xe1, 0x00, 0xf0, 0x0a,
|
||||
TimeDescTag, // Descriptor tag for timestamp
|
||||
TimeDataSize, // Length of bytes to follow
|
||||
|
@ -161,7 +161,7 @@ var (
|
|||
LocationDescTag, // Descriptor tag for location
|
||||
LocationDataSize, // Length of bytes to follow
|
||||
}
|
||||
pmtTimeLocationBytesPart2 = []byte{
|
||||
pmtWithMetaTail = []byte{
|
||||
0x1b, 0xe1, 0x00, 0xf0, 0x00,
|
||||
}
|
||||
)
|
||||
|
@ -186,10 +186,10 @@ var (
|
|||
}
|
||||
|
||||
// Bytes representing pmt with time1 and location1
|
||||
pmtTimeLocationBytes1 = buildPmtTimeLocationBytes(locationTstStr1[:])
|
||||
pmtWithMetaTst1 = buildPmtWithMeta(locationBytes1[:])
|
||||
|
||||
// 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
|
||||
|
@ -273,7 +273,7 @@ var bytesTests = []struct {
|
|||
{
|
||||
Dt: LocationDescTag,
|
||||
Dl: LocationDataSize,
|
||||
Dd: locationTstStr1[:],
|
||||
Dd: locationBytes1[:],
|
||||
},
|
||||
},
|
||||
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
|
||||
func TestLocationGet(t *testing.T) {
|
||||
pb := standardPmtTimeLocation.Bytes()
|
||||
err := UpdateLocation(pb, string(locationTstStr1[:]))
|
||||
pb := standardPmtWithMeta.Bytes()
|
||||
err := UpdateLocation(pb, string(locationBytes1[:]))
|
||||
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)
|
||||
if err != nil {
|
||||
t.Errorf("Error for TestLocationGet LocationOf(pb): %v", err)
|
||||
}
|
||||
if g != string(locationTstStr1[:]) {
|
||||
t.Errorf(errCmp, "TestLocationGet", locationTstStr1, g)
|
||||
if g != string(locationBytes1[:]) {
|
||||
t.Errorf(errCmp, "TestLocationGet", locationBytes1, g)
|
||||
}
|
||||
}
|
||||
|
||||
// TestLocationUpdate checks to see if we can update the location string in a pmt correctly
|
||||
func TestLocationUpdate(t *testing.T) {
|
||||
cpy := make([]byte, len(pmtTimeLocationBytes1))
|
||||
copy(cpy, pmtTimeLocationBytes1)
|
||||
cpy := make([]byte, len(pmtWithMetaTst1))
|
||||
copy(cpy, pmtWithMetaTst1)
|
||||
cpy = addCrc(cpy)
|
||||
err := UpdateLocation(cpy, string(locationTstStr2[:]))
|
||||
err := UpdateLocation(cpy, string(locationBytes2[:]))
|
||||
cpy = cpy[:len(cpy)-4]
|
||||
if err != nil {
|
||||
t.Errorf("Update time returned err: %v", err)
|
||||
}
|
||||
if !bytes.Equal(pmtTimeLocationBytes2, cpy) {
|
||||
t.Errorf(errCmp, "TestLocationUpdate", pmtTimeLocationBytes2, cpy)
|
||||
if !bytes.Equal(pmtWithMetaTst2, 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
|
||||
// for pmts with time and location, as the location data field is 32 bytes, i.e. quite large
|
||||
// to type out
|
||||
func buildPmtTimeLocationBytes(tstStr []byte) []byte {
|
||||
return append(append(append(make([]byte, 0), pmtTimeLocationBytesPart1...),
|
||||
tstStr...), pmtTimeLocationBytesPart2...)
|
||||
func buildPmtWithMeta(tstStr []byte) []byte {
|
||||
dst := make([]byte, len(pmtWithMetaHead)+32+len(pmtWithMetaTail))
|
||||
copy(dst, pmtWithMetaHead)
|
||||
copy(dst[len(pmtWithMetaHead):], tstStr)
|
||||
copy(dst[len(pmtWithMetaHead)+32:], pmtWithMetaTail)
|
||||
return dst
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue