| 1 | package plist |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "io/ioutil" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func BenchmarkXMLGenerate(b *testing.B) { |
| 10 | for i := 0; i < b.N; i++ { |
| 11 | d := newXMLPlistGenerator(ioutil.Discard) |
| 12 | d.generateDocument(plistValueTree) |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | func BenchmarkXMLParse(b *testing.B) { |
| 17 | buf := bytes.NewReader([]byte(plistValueTreeAsXML)) |
| 18 | b.ResetTimer() |
| 19 | for i := 0; i < b.N; i++ { |
| 20 | b.StartTimer() |
| 21 | d := newXMLPlistParser(buf) |
| 22 | d.parseDocument() |
| 23 | b.StopTimer() |
| 24 | buf.Seek(0, 0) |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | var InvalidXMLPlists = []string{ |
| 29 | `<plist version="1.0"><integer>0x</integer></plist>`, |
| 30 | "<plist><doct><key>helo</key><string></string></doct></plist>", |
| 31 | "<plist><dict><string>helo</string></dict></plist>", |
| 32 | "<plist><dict><key>helo</key></dict></plist>", |
| 33 | "<plist><integer>helo</integer></plist>", |
| 34 | "<plist><integer></integer></plist>", |
| 35 | "<plist><real>helo</real></plist>", |
| 36 | "<plist><data>*@&%#helo</data></plist>", |
| 37 | "<plist><date>*@&%#helo</date></plist>", |
| 38 | "<plist><date>*@&%#helo</date></plist>", |
| 39 | "<plist><integer>10</plist>", |
| 40 | "<plist><real>10</plist>", |
| 41 | "<plist><string>10</plist>", |
| 42 | "<plist><dict>10</plist>", |
| 43 | "<plist><dict><key>10</plist>", |
| 44 | "<plist>", |
| 45 | "<plist><data>", |
| 46 | "<plist><date>", |
| 47 | "<plist><array>", |
| 48 | "<plist/>", |
| 49 | "<pl", |
| 50 | "bplist00", |
| 51 | } |
| 52 | |
| 53 | func TestVariousIllegalXMLPlists(t *testing.T) { |
| 54 | for _, plist := range InvalidXMLPlists { |
| 55 | buf := bytes.NewReader([]byte(plist)) |
| 56 | d := newXMLPlistParser(buf) |
| 57 | obj, err := d.parseDocument() |
| 58 | t.Logf("Error: %v", err) |
| 59 | if obj != nil && err == nil { |
| 60 | t.Error("Expected error, received nothing.") |
| 61 | } |
| 62 | } |
| 63 | } |