From 633445883e86a3992fb69ef1b6b8f209fef3cee2 Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Thu, 6 Mar 2014 14:09:18 +0000 Subject: [PATCH] Test: CFPropertyList.propertyListFromXML. These tests validate some basic edge cases with the parsing of XML plists. Refs #2051. --- Tests/Objective-J/CFPropertyListTest.j | 44 ++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Tests/Objective-J/CFPropertyListTest.j b/Tests/Objective-J/CFPropertyListTest.j index ad6e9c643..748732507 100644 --- a/Tests/Objective-J/CFPropertyListTest.j +++ b/Tests/Objective-J/CFPropertyListTest.j @@ -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 = "", + object = CFPropertyList.propertyListFromXML(XML); + + [self assert:object equals:null]; +} + +- (void)testPropertyListFromXMLShouldHandleEmptierXMLGracefully { + var XML = "", + 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 = "Main cib file base nameMainMenu.cibCPBundleNameCopyAndPasteCPBundleVersion1.0CPHumanReadableCopyrightCopyright \u00a9 2013, SlevenBits, Ltd. All rights reserved.", + 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 = "\n \n \n\n\tMain cib file base name\n\tMainMenu.cib\n\t CPBundleName\n\tCopyAndPaste\n CPBundleVersion\n 1.0\n CPHumanReadableCopyright\n Copyright \u00a9 2013, SlevenBits, Ltd. All rights reserved.\n\n\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