-
Notifications
You must be signed in to change notification settings - Fork 96
/
xml_test.go
63 lines (58 loc) · 1.5 KB
/
xml_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
package plist
import (
"bytes"
"io/ioutil"
"testing"
)
func BenchmarkXMLGenerate(b *testing.B) {
for i := 0; i < b.N; i++ {
d := newXMLPlistGenerator(ioutil.Discard)
d.generateDocument(plistValueTree)
}
}
func BenchmarkXMLParse(b *testing.B) {
buf := bytes.NewReader([]byte(plistValueTreeAsXML))
b.ResetTimer()
for i := 0; i < b.N; i++ {
b.StartTimer()
d := newXMLPlistParser(buf)
d.parseDocument()
b.StopTimer()
buf.Seek(0, 0)
}
}
var InvalidXMLPlists = []string{
`<plist version="1.0"><integer>0x</integer></plist>`,
"<plist><doct><key>helo</key><string></string></doct></plist>",
"<plist><dict><string>helo</string></dict></plist>",
"<plist><dict><key>helo</key></dict></plist>",
"<plist><integer>helo</integer></plist>",
"<plist><integer></integer></plist>",
"<plist><real>helo</real></plist>",
"<plist><data>*@&%#helo</data></plist>",
"<plist><date>*@&%#helo</date></plist>",
"<plist><date>*@&%#helo</date></plist>",
"<plist><integer>10</plist>",
"<plist><real>10</plist>",
"<plist><string>10</plist>",
"<plist><dict>10</plist>",
"<plist><dict><key>10</plist>",
"<plist>",
"<plist><data>",
"<plist><date>",
"<plist><array>",
"<plist/>",
"<pl",
"bplist00",
}
func TestVariousIllegalXMLPlists(t *testing.T) {
for _, plist := range InvalidXMLPlists {
buf := bytes.NewReader([]byte(plist))
d := newXMLPlistParser(buf)
obj, err := d.parseDocument()
t.Logf("Error: %v", err)
if obj != nil && err == nil {
t.Error("Expected error, received nothing.")
}
}
}