]>
Commit | Line | Data |
---|---|---|
43ecc0f4 JH |
1 | package hotline |
2 | ||
3 | import ( | |
4 | "github.com/stretchr/testify/assert" | |
5 | "testing" | |
6 | ) | |
7 | ||
8 | func TestFileNameWithInfo_Read(t *testing.T) { | |
9 | type fields struct { | |
10 | Type []byte | |
11 | Creator []byte | |
12 | FileSize []byte | |
13 | NameScript []byte | |
14 | NameSize []byte | |
15 | Name []byte | |
16 | } | |
17 | type args struct { | |
18 | p []byte | |
19 | } | |
20 | tests := []struct { | |
21 | name string | |
22 | fields fields | |
23 | args args | |
24 | want *FileNameWithInfo | |
25 | wantN int | |
26 | wantErr bool | |
27 | }{ | |
28 | { | |
29 | name: "reads bytes into struct", | |
30 | fields: fields{}, | |
31 | args: args{ | |
32 | p: []byte{ | |
33 | 0x54, 0x45, 0x58, 0x54, // TEXT | |
34 | 0x54, 0x54, 0x58, 0x54, // TTXT | |
35 | 0x00, 0x43, 0x16, 0xd3, // File Size | |
36 | 0x00, 0x00, 0x00, 0x00, // RSVD | |
37 | 0x00, 0x00, // NameScript | |
38 | 0x00, 0x0e, // Name Size | |
39 | 0x41, 0x75, 0x64, 0x69, 0x6f, 0x6e, 0x2e, 0x61, 0x70, 0x70, 0x2e, 0x7a, 0x69, 0x70, | |
40 | }, | |
41 | }, | |
42 | want: &FileNameWithInfo{ | |
43 | Type: []byte("TEXT"), | |
44 | Creator: []byte("TTXT"), | |
45 | FileSize: []byte{0x00, 0x43, 0x16, 0xd3}, | |
46 | RSVD: []byte{0, 0, 0, 0}, | |
47 | NameScript: []byte{0, 0}, | |
48 | NameSize: []byte{0x00, 0x0e}, | |
49 | Name: []byte("Audion.app.zip"), | |
50 | }, | |
51 | wantN: 34, | |
52 | wantErr: false, | |
53 | }, | |
54 | } | |
55 | for _, tt := range tests { | |
56 | t.Run(tt.name, func(t *testing.T) { | |
57 | f := &FileNameWithInfo{ | |
58 | Type: tt.fields.Type, | |
59 | Creator: tt.fields.Creator, | |
60 | FileSize: tt.fields.FileSize, | |
61 | NameScript: tt.fields.NameScript, | |
62 | NameSize: tt.fields.NameSize, | |
63 | Name: tt.fields.Name, | |
64 | } | |
65 | gotN, err := f.Read(tt.args.p) | |
66 | if (err != nil) != tt.wantErr { | |
67 | t.Errorf("Read() error = %v, wantErr %v", err, tt.wantErr) | |
68 | return | |
69 | } | |
70 | if gotN != tt.wantN { | |
71 | t.Errorf("Read() gotN = %v, want %v", gotN, tt.wantN) | |
72 | } | |
73 | if !assert.Equal(t, tt.want, f) { | |
74 | t.Errorf("Read() got = %v, want %v", f, tt.want) | |
75 | ||
76 | } | |
77 | }) | |
78 | } | |
79 | } |