4 "github.com/stretchr/testify/assert"
10 func TestFileNameWithInfo_MarshalBinary(t *testing.T) {
12 fileNameWithInfoHeader fileNameWithInfoHeader
22 name: "returns expected bytes",
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},
35 0x54, 0x45, 0x58, 0x54,
36 0x54, 0x54, 0x58, 0x54,
37 0x00, 0x43, 0x16, 0xd3,
46 for _, tt := range tests {
47 t.Run(tt.name, func(t *testing.T) {
48 f := &FileNameWithInfo{
49 fileNameWithInfoHeader: tt.fields.fileNameWithInfoHeader,
52 gotData, err := io.ReadAll(f)
53 if (err != nil) != tt.wantErr {
54 t.Errorf("MarshalBinary() error = %v, wantErr %v", err, tt.wantErr)
57 if !reflect.DeepEqual(gotData, tt.wantData) {
58 t.Errorf("MarshalBinary() gotData = %v, want %v", gotData, tt.wantData)
64 func TestFileNameWithInfo_UnmarshalBinary(t *testing.T) {
66 fileNameWithInfoHeader fileNameWithInfoHeader
76 want *FileNameWithInfo
80 name: "writes bytes into struct",
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,
92 want: &FileNameWithInfo{
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},
101 name: []byte("Audion.app.zip"),
106 for _, tt := range tests {
107 t.Run(tt.name, func(t *testing.T) {
108 f := &FileNameWithInfo{
109 fileNameWithInfoHeader: tt.fields.fileNameWithInfoHeader,
110 name: tt.fields.name,
112 if _, err := f.Write(tt.args.data); (err != nil) != tt.wantErr {
113 t.Errorf("Write() error = %v, wantErr %v", err, tt.wantErr)
115 if !assert.Equal(t, tt.want, f) {
116 t.Errorf("Read() got = %v, want %v", f, tt.want)