mirror of
https://github.com/jwetzell/psn-go.git
synced 2026-08-08 08:53:44 +00:00
add tests for encoding info related chunks
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/psn-go/internal/decoders"
|
||||
)
|
||||
|
||||
func TestInfoSystemNameChunkEncoding(t *testing.T) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
expected []byte
|
||||
data decoders.InfoSystemNameChunkData
|
||||
}{
|
||||
{
|
||||
description: "InfoSystemNameChunk",
|
||||
expected: []byte{
|
||||
1, 0, 10, 0, 80, 83, 78, 32, 83, 101, 114, 118, 101, 114,
|
||||
},
|
||||
data: decoders.InfoSystemNameChunkData{
|
||||
SystemName: "PSN Server",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
||||
actual := EncodeInfoSystemNameChunk(testCase.data.SystemName)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/psn-go/internal/decoders"
|
||||
)
|
||||
|
||||
func TestInfoTrackerChunkEncoding(t *testing.T) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
expected []byte
|
||||
chunk decoders.InfoTrackerChunk
|
||||
}{
|
||||
{
|
||||
description: "InfoTrackerChunk",
|
||||
expected: []byte{
|
||||
1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49,
|
||||
},
|
||||
chunk: decoders.InfoTrackerChunk{
|
||||
Chunk: decoders.Chunk{
|
||||
ChunkData: []byte{0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49},
|
||||
Header: decoders.ChunkHeader{DataLen: 13, Id: 1, HasSubchunks: true},
|
||||
},
|
||||
Data: decoders.InfoTrackerChunkData{
|
||||
TrackerName: &decoders.InfoTrackerNameChunk{
|
||||
Chunk: decoders.Chunk{
|
||||
ChunkData: []byte{84, 114, 97, 99, 107, 101, 114, 32, 49},
|
||||
Header: decoders.ChunkHeader{DataLen: 9, Id: 0, HasSubchunks: false},
|
||||
},
|
||||
Data: decoders.InfoTrackerNameChunkData{
|
||||
TrackerName: "Tracker 1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
||||
actual := EncodeInfoTrackerChunk(testCase.chunk.Chunk.Header.Id, EncodeInfoTrackerNameChunk(testCase.chunk.Data.TrackerName.Data.TrackerName))
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/psn-go/internal/decoders"
|
||||
)
|
||||
|
||||
func TestInfoTrackerListChunkEncoding(t *testing.T) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
expected []byte
|
||||
chunk decoders.InfoTrackerListChunk
|
||||
}{
|
||||
{
|
||||
description: "InfoTrackerListChunk",
|
||||
expected: []byte{
|
||||
2, 0, 17, 128, 1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49,
|
||||
},
|
||||
chunk: decoders.InfoTrackerListChunk{
|
||||
Chunk: decoders.Chunk{
|
||||
ChunkData: []byte{1, 0, 13, 128, 0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49},
|
||||
Header: decoders.ChunkHeader{DataLen: 17, Id: 2, HasSubchunks: true},
|
||||
},
|
||||
Data: decoders.InfoTrackerListChunkData{
|
||||
Trackers: []decoders.InfoTrackerChunk{
|
||||
{
|
||||
Chunk: decoders.Chunk{
|
||||
ChunkData: []byte{0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49},
|
||||
Header: decoders.ChunkHeader{DataLen: 13, Id: 1, HasSubchunks: true},
|
||||
},
|
||||
Data: decoders.InfoTrackerChunkData{
|
||||
TrackerName: &decoders.InfoTrackerNameChunk{
|
||||
Chunk: decoders.Chunk{
|
||||
ChunkData: []byte{84, 114, 97, 99, 107, 101, 114, 32, 49},
|
||||
Header: decoders.ChunkHeader{DataLen: 9, Id: 0, HasSubchunks: false},
|
||||
},
|
||||
Data: decoders.InfoTrackerNameChunkData{
|
||||
TrackerName: "Tracker 1",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
||||
trackerChunks := [][]byte{}
|
||||
for _, tracker := range testCase.chunk.Data.Trackers {
|
||||
trackerChunks = append(trackerChunks, EncodeInfoTrackerChunk(tracker.Chunk.Header.Id, EncodeInfoTrackerNameChunk(tracker.Data.TrackerName.Data.TrackerName)))
|
||||
}
|
||||
|
||||
actual := EncodeInfoTrackerListChunk(trackerChunks)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package encoders
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/jwetzell/psn-go/internal/decoders"
|
||||
)
|
||||
|
||||
func TestInfoTrackerNameChunkEncoding(t *testing.T) {
|
||||
testCases := []struct {
|
||||
description string
|
||||
expected []byte
|
||||
chunk decoders.InfoTrackerNameChunkData
|
||||
}{
|
||||
{
|
||||
description: "InfoTrackerNameChunk",
|
||||
expected: []byte{
|
||||
0, 0, 9, 0, 84, 114, 97, 99, 107, 101, 114, 32, 49,
|
||||
},
|
||||
chunk: decoders.InfoTrackerNameChunkData{
|
||||
TrackerName: "Tracker 1",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, testCase := range testCases {
|
||||
|
||||
actual := EncodeInfoTrackerNameChunk(testCase.chunk.TrackerName)
|
||||
|
||||
if !reflect.DeepEqual(actual, testCase.expected) {
|
||||
t.Errorf("Test '%s' failed to encode chunk properly", testCase.description)
|
||||
fmt.Printf("expected: %v\n", testCase.expected)
|
||||
fmt.Printf("actual: %v\n", actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user