Test: CFPropertyList.propertyListFromXML.

These tests validate some basic edge cases with the parsing of XML plists.

Refs #2051.
This commit is contained in:
Alexander Ljungberg
2014-03-06 14:09:18 +00:00
parent e6acc3c336
commit 633445883e
+44
View File
@@ -25,4 +25,48 @@ var FILE = require("file"),
[self assert:[[CPDate alloc] initWithString:"2012-01-01 10:00:00 +0100"] equals:date];
}
- (void)testPropertyListFromXMLShouldHandleEmptyXMLGracefully {
var XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">",
object = CFPropertyList.propertyListFromXML(XML);
[self assert:object equals:null];
}
- (void)testPropertyListFromXMLShouldHandleEmptierXMLGracefully {
var XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>",
object = CFPropertyList.propertyListFromXML(XML);
[self assert:object equals:null];
}
- (void)testPropertyListFromXMLShouldHandleEmptiestXMLGracefully {
var XML = "",
object = CFPropertyList.propertyListFromXML(XML);
[self assert:object equals:null];
}
- (void)testPropertyListFromXMLShouldParseNiceAndCleanXML {
var XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"><plist version=\"1.0\"><dict><key>Main cib file base name</key><string>MainMenu.cib</string><key>CPBundleName</key><string>CopyAndPaste</string><key>CPBundleVersion</key><string>1.0</string><key>CPHumanReadableCopyright</key><string>Copyright \u00a9 2013, SlevenBits, Ltd. All rights reserved.</string></dict></plist>",
object = CFPropertyList.propertyListFromXML(XML);
[self assert:[object valueForKey:"Main cib file base name"] equals:"MainMenu.cib"];
[self assert:[object valueForKey:"CPBundleName"] equals:"CopyAndPaste"];
[self assert:[object valueForKey:"CPBundleVersion"] equals:"1.0"];
[self assert:[object valueForKey:"CPHumanReadableCopyright"] equals:"Copyright \u00a9 2013, SlevenBits, Ltd. All rights reserved."];
[self assert:[object count] equals:4];
}
- (void)testPropertyListFromXMLShouldIgnoreWhiteSpace{
var XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!--Some really fab XML coming here--> <!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> <!--Get ready, this will be great--> \n<plist version=\"1.0\"> \n<dict>\n\t<key>Main cib file base name</key>\n\t<string>MainMenu.cib</string>\n\t <key>CPBundleName</key>\n\t<string>CopyAndPaste</string>\n <key>CPBundleVersion</key>\n <string>1.0</string>\n <key>CPHumanReadableCopyright</key>\n <string>Copyright \u00a9 2013, SlevenBits, Ltd. All rights reserved.</string>\n</dict>\n</plist>\n",
// feed in preparsed XML to ensure we preserve whitespace for purposes of this test
object = CFPropertyList.propertyListFromXML(new window.DOMParser().parseFromString(XML, "text/xml"));
[self assert:[object valueForKey:"Main cib file base name"] equals:"MainMenu.cib"];
[self assert:[object valueForKey:"CPBundleName"] equals:"CopyAndPaste"];
[self assert:[object valueForKey:"CPBundleVersion"] equals:"1.0"];
[self assert:[object valueForKey:"CPHumanReadableCopyright"] equals:"Copyright \u00a9 2013, SlevenBits, Ltd. All rights reserved."];
[self assert:[object count] equals:4];
}
@end