Skip to content

Commit

Permalink
test(chunk): increase the coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Ege <[email protected]>
  • Loading branch information
graugans committed Dec 25, 2023
1 parent ae7ff2c commit 3a6c63f
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions pkg/pcic/chunk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,83 @@ func TestRoundtrip(t *testing.T) {
"We expect the type to be the same after the round trip",
)
}

func TestHeaderSizeTooSmall(t *testing.T) {
c := pcic.NewChunk()
assert.Error(t,
c.UnmarshalBinary([]byte{
0x69, 0x00, 0x00, 0x00, /* CHUNK_TYPE */
0x30, 0x00, 0x00, 0x00, /* CHUNK_SIZE */
0x28, 0x00, 0x00, 0x00, /* HEADER_SIZE set too small */
0x02, 0x00, 0x00, 0x00, /* HEADER_VERSION */
0x00, 0x00, 0x00, 0x00, /* IMAGE_WIDTH */
0x00, 0x00, 0x00, 0x00, /* IMAGE_HEIGHT */
0x00, 0x00, 0x00, 0x00, /* DATA_FORMAT */
0x00, 0x01, 0x00, 0x00, /* TIME_STAMP */
0x00, 0x01, 0x00, 0x00, /* FRAME_COUNT */
0x00, 0x01, 0x00, 0x00, /* STATUS_CODE */
0x00, 0x01, 0x00, 0x00, /* TIME_STAMP_SEC */
0x00, 0x01, 0x00, 0x00, /* TIME_STAMP_NSEC */
}),
"An error expected, due to small header size",
)
}

func TestHeaderSizeTooBig(t *testing.T) {
c := pcic.NewChunk()
assert.Error(t,
c.UnmarshalBinary([]byte{
0x69, 0x00, 0x00, 0x00, /* CHUNK_TYPE */
0x30, 0x00, 0x00, 0x00, /* CHUNK_SIZE */
0x32, 0x00, 0x00, 0x00, /* HEADER_SIZE set too small */
0x02, 0x00, 0x00, 0x00, /* HEADER_VERSION */
0x00, 0x00, 0x00, 0x00, /* IMAGE_WIDTH */
0x00, 0x00, 0x00, 0x00, /* IMAGE_HEIGHT */
0x00, 0x00, 0x00, 0x00, /* DATA_FORMAT */
0x00, 0x01, 0x00, 0x00, /* TIME_STAMP */
0x00, 0x01, 0x00, 0x00, /* FRAME_COUNT */
0x00, 0x01, 0x00, 0x00, /* STATUS_CODE */
0x00, 0x01, 0x00, 0x00, /* TIME_STAMP_SEC */
0x00, 0x01, 0x00, 0x00, /* TIME_STAMP_NSEC */
}),
"An error expected, due to big header size",
)
}

func TestInvalidHeaderVersion(t *testing.T) {
c := pcic.NewChunk()
assert.Error(t,
c.UnmarshalBinary([]byte{
0x69, 0x00, 0x00, 0x00, /* CHUNK_TYPE */
0x30, 0x00, 0x00, 0x00, /* CHUNK_SIZE */
0x30, 0x00, 0x00, 0x00, /* HEADER_SIZE */
0x00, 0x00, 0x00, 0x00, /* HEADER_VERSION == 0 */
0x00, 0x00, 0x00, 0x00, /* IMAGE_WIDTH */
0x00, 0x00, 0x00, 0x00, /* IMAGE_HEIGHT */
0x00, 0x00, 0x00, 0x00, /* DATA_FORMAT */
0x00, 0x01, 0x00, 0x00, /* TIME_STAMP */
0x00, 0x01, 0x00, 0x00, /* FRAME_COUNT */
0x00, 0x01, 0x00, 0x00, /* STATUS_CODE */
0x00, 0x01, 0x00, 0x00, /* TIME_STAMP_SEC */
0x00, 0x01, 0x00, 0x00, /* TIME_STAMP_NSEC */
}),
"An error expected, due to wrong header version",
)
assert.Error(t,
c.UnmarshalBinary([]byte{
0x69, 0x00, 0x00, 0x00, /* CHUNK_TYPE */
0x30, 0x00, 0x00, 0x00, /* CHUNK_SIZE */
0x30, 0x00, 0x00, 0x00, /* HEADER_SIZE */
0x04, 0x00, 0x00, 0x00, /* HEADER_VERSION == 4 */
0x00, 0x00, 0x00, 0x00, /* IMAGE_WIDTH */
0x00, 0x00, 0x00, 0x00, /* IMAGE_HEIGHT */
0x00, 0x00, 0x00, 0x00, /* DATA_FORMAT */
0x00, 0x01, 0x00, 0x00, /* TIME_STAMP */
0x00, 0x01, 0x00, 0x00, /* FRAME_COUNT */
0x00, 0x01, 0x00, 0x00, /* STATUS_CODE */
0x00, 0x01, 0x00, 0x00, /* TIME_STAMP_SEC */
0x00, 0x01, 0x00, 0x00, /* TIME_STAMP_NSEC */
}),
"An error expected, due to wrong header version",
)
}

0 comments on commit 3a6c63f

Please sign in to comment.