File: xml_test.go

package info (click to toggle)
golang-github-dhowett-go-plist 0.0~git20160708.0.fec78c8-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 280 kB
  • ctags: 251
  • sloc: makefile: 2
file content (60 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download | duplicates (2)
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
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)
	}
}

func TestVariousIllegalXMLPlists(t *testing.T) {
	plists := []string{
		"<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><real>helo</real></plist>",
		"<plist><data>*@&amp;%#helo</data></plist>",
		"<plist><date>*@&amp;%#helo</date></plist>",
		"<plist><date>*@&amp;%#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>",
		"<pl",
		"bplist00",
	}

	for _, plist := range plists {
		buf := bytes.NewReader([]byte(plist))
		d := newXMLPlistParser(buf)
		_, err := d.parseDocument()
		t.Logf("Error: %v", err)
		if err == nil {
			t.Error("Expected error, received nothing.")
		}
	}
}