Debian Codegraph @

x7875_test.go

raw symbols SCIP
1 package zipextra
2
3 import (
4 "encoding/hex"
5 "math"
6 "math/big"
7 "testing"
8 )
9
10 func TestInfoZIPNewUnix(t *testing.T) {
11 tests := []struct {
12 version uint8
13 uid *big.Int
14 gid *big.Int
15 raw string
16 }{
17 // normal ids
18 {1, big.NewInt(0), big.NewInt(0), "75780b000104000000000400000000"},
19 {1, big.NewInt(1), big.NewInt(1), "75780b000104010000000401000000"},
20 {1, big.NewInt(255), big.NewInt(255), "75780b000104ff00000004ff000000"},
21 {1, big.NewInt(1000), big.NewInt(1000), "75780b000104e803000004e8030000"},
22
23 // unusual
24 {1, big.NewInt(math.MaxInt32), big.NewInt(math.MaxInt32), "75780b000104ffffff7f04ffffff7f"},
25 {1, big.NewInt(math.MaxInt64), big.NewInt(math.MaxInt64), "757813000108ffffffffffffff7f08ffffffffffffff7f"},
26 {1, new(big.Int).SetBytes([]byte{0x0a, 0x0b}), big.NewInt(math.MaxInt64), "75780f0001040b0a000008ffffffffffffff7f"},
27 }
28
29 for _, test := range tests {
30 // encode
31 raw := NewInfoZIPNewUnix(test.uid, test.gid).Encode()
32 if test.raw != hex.EncodeToString(raw) {
33 t.Errorf("expected %s, got %s", test.raw, hex.EncodeToString(raw))
34 }
35
36 // decode
37 unix, err := testHeader(t, raw, ExtraFieldUnixN).InfoZIPNewUnix()
38 if err != nil {
39 t.Fatal(err)
40 }
41
42 if test.raw != hex.EncodeToString(unix.Encode()) {
43 t.Errorf("expected %s, got %s", test.raw, hex.EncodeToString(unix.Encode()))
44 }
45 if test.uid.String() != unix.Uid.String() {
46 t.Errorf("expected uid %s, got %s", test.uid.String(), unix.Uid.String())
47 }
48 if test.gid.String() != unix.Gid.String() {
49 t.Errorf("expected gid %s, got %s", test.gid.String(), unix.Gid.String())
50 }
51 }
52 }