diff --git a/internal/decoders/info_system_name_chunk_test.go b/internal/decoders/info_system_name_chunk_test.go new file mode 100644 index 0000000..618792d --- /dev/null +++ b/internal/decoders/info_system_name_chunk_test.go @@ -0,0 +1,47 @@ +package decoders + +import ( + "fmt" + "reflect" + "testing" +) + +func TestGoodInfoSystemNameChunkDecoding(t *testing.T) { + testCases := []struct { + description string + bytes []byte + expected InfoSystemNameChunk + }{ + { + description: "InfoSystemNameChunk", + bytes: []byte{ + 1, 0, 10, 0, 80, 83, 78, 32, 83, 101, 114, 118, 101, 114, + }, + expected: InfoSystemNameChunk{ + Chunk: Chunk{ + ChunkData: []byte{80, 83, 78, 32, 83, 101, 114, 118, 101, 114}, + Header: ChunkHeader{DataLen: 10, Id: 1, HasSubchunks: false}, + }, + Data: InfoSystemNameChunkData{ + SystemName: "PSN Server", + }, + }, + }, + } + + for _, testCase := range testCases { + + actual, err := DecodeInfoSystemNameChunk(testCase.bytes) + + if err != nil { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Println(err) + } + + if !reflect.DeepEqual(actual, testCase.expected) { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Printf("expected: %+v\n", testCase.expected) + fmt.Printf("actual: %+v\n", actual) + } + } +} diff --git a/internal/decoders/info_tracker_chunk_test.go b/internal/decoders/info_tracker_chunk_test.go new file mode 100644 index 0000000..ca97fa2 --- /dev/null +++ b/internal/decoders/info_tracker_chunk_test.go @@ -0,0 +1,55 @@ +package decoders + +import ( + "fmt" + "reflect" + "testing" +) + +func TestGoodInfoTrackerChunkDecoding(t *testing.T) { + testCases := []struct { + description string + bytes []byte + expected InfoTrackerChunk + }{ + { + description: "InfoTrackerChunk", + bytes: []byte{ + 1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49, + }, + expected: InfoTrackerChunk{ + Chunk: Chunk{ + ChunkData: []byte{0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49}, + Header: ChunkHeader{DataLen: 13, Id: 1, HasSubchunks: true}, + }, + Data: InfoTrackerChunkData{ + TrackerName: &InfoTrackerNameChunk{ + Chunk: Chunk{ + ChunkData: []byte{84, 114, 97, 99, 107, 101, 114, 32, 49}, + Header: ChunkHeader{DataLen: 9, Id: 0, HasSubchunks: false}, + }, + Data: InfoTrackerNameChunkData{ + TrackerName: "Tracker 1", + }, + }, + }, + }, + }, + } + + for _, testCase := range testCases { + + actual, err := DecodeInfoTrackerChunk(testCase.bytes) + + if err != nil { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Println(err) + } + + if !reflect.DeepEqual(actual, testCase.expected) { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Printf("expected: %+v\n", testCase.expected) + fmt.Printf("actual: %+v\n", actual) + } + } +} diff --git a/internal/decoders/info_tracker_list_chunk_test.go b/internal/decoders/info_tracker_list_chunk_test.go new file mode 100644 index 0000000..bb4b7fa --- /dev/null +++ b/internal/decoders/info_tracker_list_chunk_test.go @@ -0,0 +1,65 @@ +package decoders + +import ( + "fmt" + "reflect" + "testing" +) + +func TestGoodInfoTrackerListChunkDecoding(t *testing.T) { + testCases := []struct { + description string + bytes []byte + expected InfoTrackerListChunk + }{ + { + description: "InfoTrackerListChunk", + bytes: []byte{ + 2, 0, 17, 128, 1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49, + }, + expected: InfoTrackerListChunk{ + Chunk: Chunk{ + ChunkData: []byte{1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49}, + Header: ChunkHeader{DataLen: 17, Id: 2, HasSubchunks: true}, + }, + Data: InfoTrackerListChunkData{ + Trackers: []InfoTrackerChunk{ + { + Chunk: Chunk{ + ChunkData: []byte{0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49}, + Header: ChunkHeader{DataLen: 13, Id: 1, HasSubchunks: true}, + }, + Data: InfoTrackerChunkData{ + TrackerName: &InfoTrackerNameChunk{ + Chunk: Chunk{ + ChunkData: []byte{84, 114, 97, 99, 107, 101, 114, 32, 49}, + Header: ChunkHeader{DataLen: 9, Id: 0, HasSubchunks: false}, + }, + Data: InfoTrackerNameChunkData{ + TrackerName: "Tracker 1", + }, + }, + }, + }, + }, + }, + }, + }, + } + + for _, testCase := range testCases { + + actual, err := DecodeInfoTrackerListChunk(testCase.bytes) + + if err != nil { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Println(err) + } + + if !reflect.DeepEqual(actual, testCase.expected) { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Printf("expected: %+v\n", testCase.expected) + fmt.Printf("actual: %+v\n", actual) + } + } +} diff --git a/internal/decoders/info_tracker_name_chunk_test.go b/internal/decoders/info_tracker_name_chunk_test.go new file mode 100644 index 0000000..333ebb0 --- /dev/null +++ b/internal/decoders/info_tracker_name_chunk_test.go @@ -0,0 +1,47 @@ +package decoders + +import ( + "fmt" + "reflect" + "testing" +) + +func TestGoodInfoTrackerNameChunkDecoding(t *testing.T) { + testCases := []struct { + description string + bytes []byte + expected InfoTrackerNameChunk + }{ + { + description: "InfoTrackerNameChunk", + bytes: []byte{ + 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49, + }, + expected: InfoTrackerNameChunk{ + Chunk: Chunk{ + ChunkData: []byte{84, 114, 97, 99, 107, 101, 114, 32, 49}, + Header: ChunkHeader{DataLen: 9, Id: 0, HasSubchunks: false}, + }, + Data: InfoTrackerNameChunkData{ + TrackerName: "Tracker 1", + }, + }, + }, + } + + for _, testCase := range testCases { + + actual, err := DecodeInfoTrackerNameChunk(testCase.bytes) + + if err != nil { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Println(err) + } + + if !reflect.DeepEqual(actual, testCase.expected) { + t.Errorf("Test '%s' failed to decode chunk properly", testCase.description) + fmt.Printf("expected: %+v\n", testCase.expected) + fmt.Printf("actual: %+v\n", actual) + } + } +}