]> git.r.bdr.sh - rbdr/mobius/blob - hotline/news_test.go
Fix handling of refuse PM flag
[rbdr/mobius] / hotline / news_test.go
1 package hotline
2
3 import (
4 "bytes"
5 "reflect"
6 "testing"
7 )
8
9 func TestNewsCategoryListData15_MarshalBinary(t *testing.T) {
10 type fields struct {
11 Type []byte
12 Name string
13 Articles map[uint32]*NewsArtData
14 SubCats map[string]NewsCategoryListData15
15 Count []byte
16 AddSN []byte
17 DeleteSN []byte
18 GUID []byte
19 }
20 tests := []struct {
21 name string
22 fields fields
23 wantData []byte
24 wantErr bool
25 }{
26 {
27 name: "returns expected bytes when type is a bundle",
28 fields: fields{
29 Type: []byte{0x00, 0x02},
30 Articles: map[uint32]*NewsArtData{
31 uint32(1): {
32 Title: "",
33 Poster: "",
34 Data: "",
35 },
36 },
37 Name: "foo",
38 },
39 wantData: []byte{
40 0x00, 0x02,
41 0x00, 0x01,
42 0x03,
43 0x66, 0x6f, 0x6f,
44 },
45 wantErr: false,
46 },
47 {
48 name: "returns expected bytes when type is a category",
49 fields: fields{
50 Type: []byte{0x00, 0x03},
51 Articles: map[uint32]*NewsArtData{
52 uint32(1): {
53 Title: "",
54 Poster: "",
55 Data: "",
56 },
57 },
58 Name: "foo",
59 },
60 wantData: []byte{
61 0x00, 0x03,
62 0x00, 0x01,
63 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64 0x00, 0x00, 0x00, 0x01,
65 0x00, 0x00, 0x00, 0x02,
66 0x03,
67 0x66, 0x6f, 0x6f,
68 },
69 wantErr: false,
70 },
71 }
72 for _, tt := range tests {
73 t.Run(tt.name, func(t *testing.T) {
74 newscat := &NewsCategoryListData15{
75 Type: tt.fields.Type,
76 Name: tt.fields.Name,
77 Articles: tt.fields.Articles,
78 SubCats: tt.fields.SubCats,
79 Count: tt.fields.Count,
80 AddSN: tt.fields.AddSN,
81 DeleteSN: tt.fields.DeleteSN,
82 GUID: tt.fields.GUID,
83 }
84 gotData, err := newscat.MarshalBinary()
85 if bytes.Equal(newscat.Type, []byte{0, 3}) {
86 // zero out the random GUID before comparison
87 for i := 4; i < 20; i++ {
88 gotData[i] = 0
89 }
90 }
91 if (err != nil) != tt.wantErr {
92 t.Errorf("MarshalBinary() error = %v, wantErr %v", err, tt.wantErr)
93 return
94 }
95 if !reflect.DeepEqual(gotData, tt.wantData) {
96 t.Errorf("MarshalBinary() gotData = %v, want %v", gotData, tt.wantData)
97 }
98 })
99 }
100 }