]> git.r.bdr.sh - rbdr/mobius/blame - hotline/file_name_with_info_test.go
Update goreleaser config
[rbdr/mobius] / hotline / file_name_with_info_test.go
CommitLineData
43ecc0f4
JH
1package hotline
2
3import (
4 "github.com/stretchr/testify/assert"
b129b7cb 5 "io"
72dd37f1 6 "reflect"
43ecc0f4
JH
7 "testing"
8)
9
72dd37f1 10func TestFileNameWithInfo_MarshalBinary(t *testing.T) {
43ecc0f4 11 type fields struct {
72dd37f1
JH
12 fileNameWithInfoHeader fileNameWithInfoHeader
13 name []byte
14 }
15 tests := []struct {
16 name string
17 fields fields
18 wantData []byte
19 wantErr bool
20 }{
21 {
22 name: "returns expected bytes",
23 fields: fields{
24 fileNameWithInfoHeader: fileNameWithInfoHeader{
25 Type: [4]byte{0x54, 0x45, 0x58, 0x54}, // TEXT
26 Creator: [4]byte{0x54, 0x54, 0x58, 0x54}, // TTXT
27 FileSize: [4]byte{0x00, 0x43, 0x16, 0xd3}, // File Size
28 RSVD: [4]byte{0, 0, 0, 0},
29 NameScript: [2]byte{0, 0},
30 NameSize: [2]byte{0x00, 0x03},
31 },
32 name: []byte("foo"),
33 },
34 wantData: []byte{
35 0x54, 0x45, 0x58, 0x54,
36 0x54, 0x54, 0x58, 0x54,
37 0x00, 0x43, 0x16, 0xd3,
38 0, 0, 0, 0,
39 0, 0,
40 0x00, 0x03,
41 0x66, 0x6f, 0x6f,
42 },
43 wantErr: false,
44 },
45 }
46 for _, tt := range tests {
47 t.Run(tt.name, func(t *testing.T) {
48 f := &FileNameWithInfo{
49 fileNameWithInfoHeader: tt.fields.fileNameWithInfoHeader,
50 name: tt.fields.name,
51 }
b129b7cb 52 gotData, err := io.ReadAll(f)
72dd37f1
JH
53 if (err != nil) != tt.wantErr {
54 t.Errorf("MarshalBinary() error = %v, wantErr %v", err, tt.wantErr)
55 return
56 }
57 if !reflect.DeepEqual(gotData, tt.wantData) {
58 t.Errorf("MarshalBinary() gotData = %v, want %v", gotData, tt.wantData)
59 }
60 })
61 }
62}
63
64func TestFileNameWithInfo_UnmarshalBinary(t *testing.T) {
65 type fields struct {
66 fileNameWithInfoHeader fileNameWithInfoHeader
67 name []byte
43ecc0f4
JH
68 }
69 type args struct {
72dd37f1 70 data []byte
43ecc0f4
JH
71 }
72 tests := []struct {
73 name string
74 fields fields
75 args args
8fc43f8e 76 want *FileNameWithInfo
43ecc0f4
JH
77 wantErr bool
78 }{
79 {
72dd37f1 80 name: "writes bytes into struct",
43ecc0f4 81 args: args{
72dd37f1 82 data: []byte{
43ecc0f4
JH
83 0x54, 0x45, 0x58, 0x54, // TEXT
84 0x54, 0x54, 0x58, 0x54, // TTXT
85 0x00, 0x43, 0x16, 0xd3, // File Size
86 0x00, 0x00, 0x00, 0x00, // RSVD
87 0x00, 0x00, // NameScript
88 0x00, 0x0e, // Name Size
89 0x41, 0x75, 0x64, 0x69, 0x6f, 0x6e, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x7a, 0x69, 0x70,
90 },
91 },
92 want: &FileNameWithInfo{
72dd37f1
JH
93 fileNameWithInfoHeader: fileNameWithInfoHeader{
94 Type: [4]byte{0x54, 0x45, 0x58, 0x54}, // TEXT
95 Creator: [4]byte{0x54, 0x54, 0x58, 0x54}, // TTXT
96 FileSize: [4]byte{0x00, 0x43, 0x16, 0xd3}, // File Size
97 RSVD: [4]byte{0, 0, 0, 0},
98 NameScript: [2]byte{0, 0},
99 NameSize: [2]byte{0x00, 0x0e},
100 },
101 name: []byte("Audion.app.zip"),
43ecc0f4 102 },
43ecc0f4
JH
103 wantErr: false,
104 },
105 }
106 for _, tt := range tests {
107 t.Run(tt.name, func(t *testing.T) {
108 f := &FileNameWithInfo{
72dd37f1
JH
109 fileNameWithInfoHeader: tt.fields.fileNameWithInfoHeader,
110 name: tt.fields.name,
43ecc0f4 111 }
b129b7cb 112 if _, err := f.Write(tt.args.data); (err != nil) != tt.wantErr {
8fc43f8e 113 t.Errorf("Write() error = %v, wantErr %v", err, tt.wantErr)
43ecc0f4
JH
114 }
115 if !assert.Equal(t, tt.want, f) {
116 t.Errorf("Read() got = %v, want %v", f, tt.want)
43ecc0f4
JH
117 }
118 })
119 }
8fc43f8e 120}