forked from fornwall/apksigner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest_test.go
87 lines (78 loc) · 2.51 KB
/
manifest_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"bytes"
"strings"
"testing"
differ "github.com/kylelemons/godebug/diff"
"github.com/kylelemons/godebug/pretty"
)
func TestParseAndWriteManifest(test *testing.T) {
cases := []struct {
comment string
serialized string
parsed Manifest
}{
{
comment: "multiline names",
serialized: strings.ReplaceAll(`Manifest-Version: 1.0
Built-By: Generated-by-ADT
Created-By: Android Gradle 3.3.2
Name: res/drawable/abc_list_selector_background_transition_holo_dark.x
ml
SHA1-Digest: x6OHiSoyMWiuIOgpmUuAh/tRnYM=
Name: res/drawable/abc_list_selector_background_transition_holo_light.
xml
SHA1-Digest: 0fvC1p6NZOpNNtjO4w0DBYRz8d0=
`, "\n", "\r\n"),
parsed: Manifest{
"": Attributes{
`Manifest-Version: 1.0`,
`Built-By: Generated-by-ADT`,
`Created-By: Android Gradle 3.3.2`,
},
"res/drawable/abc_list_selector_background_transition_holo_dark.xml": Attributes{
`SHA1-Digest: x6OHiSoyMWiuIOgpmUuAh/tRnYM=`,
},
"res/drawable/abc_list_selector_background_transition_holo_light.xml": Attributes{
`SHA1-Digest: 0fvC1p6NZOpNNtjO4w0DBYRz8d0=`,
},
},
},
}
for _, c := range cases {
parsed, err := ParseManifest(strings.NewReader(c.serialized))
if err != nil {
test.Errorf("%q: %s", c.comment, err)
} else if diff := pretty.Compare(parsed, c.parsed); diff != "" {
test.Errorf("%q: ParseManifest diff (-have +want):\n%s", c.comment, diff)
}
serialized := bytes.NewBuffer(nil)
_, err = c.parsed.WriteTo(serialized)
if err != nil {
test.Errorf("%q: %s", c.comment, err)
} else if diff := differ.Diff(serialized.String(), c.serialized); diff != "" {
test.Errorf("%q: WriteTo diff (-have +want):\n%s", c.comment, diff)
}
}
}
func TestWrap72(test *testing.T) {
input := "" +
//234567890
".bcdefgh.1.bcdefgh.2.bcdefgh.3.bcdefgh.4.bcdefgh.5.bcdefgh.6.bcdefgh.7" +
".bcdefgh.A.bcdefgh.B.bcdefgh.C.bcdefgh.D.bcdefgh.E.bcdefgh.F.bcdefgh.G" +
".bcdefgh.H.bcdefgh.I.bcdefgh.J.bcdefgh.K.bcdefgh.L.bcdefgh.M.bcdefgh\r\n" +
"hello"
want := "" +
".bcdefgh.1.bcdefgh.2.bcdefgh.3.bcdefgh.4.bcdefgh.5.bcdefgh.6.bcdefgh.7\r\n" +
" .bcdefgh.A.bcdefgh.B.bcdefgh.C.bcdefgh.D.bcdefgh.E.bcdefgh.F.bcdefgh.\r\n" +
" G.bcdefgh.H.bcdefgh.I.bcdefgh.J.bcdefgh.K.bcdefgh.L.bcdefgh.M.bcdefgh\r\n" +
"hello"
buf := bytes.NewBuffer(nil)
n, err := (&wrap72{Writer: buf}).Write([]byte(input))
if err != nil {
test.Fatal(err)
}
if diff := differ.Diff(buf.String(), want); diff != "" {
test.Errorf("written %d bytes, diff (-have +want):\n%s", n, diff)
}
}