/* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 * Jonathan Schleifer * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #import "OFXMLElement.h" #import "OFXMLCharacters.h" #import "OFXMLCDATA.h" #import "OFXMLComment.h" #import "OFString.h" #import "OFArray.h" #import "OFAutoreleasePool.h" #import "TestsAppDelegate.h" static OFString *module = @"OFXMLNode"; @implementation TestsAppDelegate (OFXMLNodeTests) - (void)XMLNodeTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; id nodes[4]; OFArray *a; TEST(@"+[elementWithName:]", (nodes[0] = [OFXMLElement elementWithName: @"foo"]) && [[nodes[0] XMLString] isEqual: @""]) TEST(@"+[elementWithName:stringValue:]", (nodes[1] = [OFXMLElement elementWithName: @"foo" stringValue: @"b&ar"]) && [[nodes[1] XMLString] isEqual: @"b&ar"]) TEST(@"+[elementWithName:namespace:]", (nodes[2] = [OFXMLElement elementWithName: @"foo" namespace: @"urn:objfw:test"]) && R([nodes[2] addAttributeWithName: @"test" stringValue: @"test"]) && R([nodes[2] setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]) && [[nodes[2] XMLString] isEqual: @""] && (nodes[3] = [OFXMLElement elementWithName: @"foo" namespace: @"urn:objfw:test"]) && R([nodes[3] addAttributeWithName: @"test" stringValue: @"test"]) && [[nodes[3] XMLString] isEqual: @""]) TEST(@"+[elementWithName:namespace:stringValue:]", (nodes[3] = [OFXMLElement elementWithName: @"foo" namespace: @"urn:objfw:test" stringValue: @"x"]) && R([nodes[3] setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]) && [[nodes[3] XMLString] isEqual: @"x"]) TEST(@"+[charactersWithString:]", (nodes[3] = [OFXMLCharacters charactersWithString: @""]) && [[nodes[3] XMLString] isEqual: @"<foo>"]) TEST(@"+[CDATAWithString:]", (nodes[3] = [OFXMLCDATA CDATAWithString: @""]) && [[nodes[3] XMLString] isEqual: @"]]>"]); TEST(@"+[commentWithString:]", (nodes[3] = [OFXMLComment commentWithString: @" comment "]) && [[nodes[3] XMLString] isEqual: @""]) module = @"OFXMLElement"; TEST(@"-[addAttributeWithName:stringValue:]", R([nodes[0] addAttributeWithName: @"foo" stringValue: @"b&ar"]) && [[nodes[0] XMLString] isEqual: @""] && R([nodes[1] addAttributeWithName: @"foo" stringValue: @"b&ar"]) && [[nodes[1] XMLString] isEqual: @"b&ar"]) TEST(@"-[setPrefix:forNamespace:]", R([nodes[1] setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"])) TEST(@"-[addAttributeWithName:namespace:stringValue:]", R([nodes[1] addAttributeWithName: @"foo" namespace: @"urn:objfw:test" stringValue: @"bar"]) && R([nodes[1] addAttributeWithName: @"foo" namespace: @"urn:objfw:test" stringValue: @"ignored"]) && [[nodes[1] XMLString] isEqual: @"b&ar"]) TEST(@"-[removeAttributeForName:namespace:]", R([nodes[1] removeAttributeForName: @"foo"]) && [[nodes[1] XMLString] isEqual: @"b&ar"] && R([nodes[1] removeAttributeForName: @"foo" namespace: @"urn:objfw:test"]) && [[nodes[1] XMLString] isEqual: @"b&ar"]) TEST(@"-[addChild:]", R([nodes[0] addChild: [OFXMLElement elementWithName: @"bar"]]) && [[nodes[0] XMLString] isEqual: @""] && R([nodes[2] addChild: [OFXMLElement elementWithName: @"bar" namespace: @"urn:objfw:test"]]) && [[nodes[2] XMLString] isEqual: @""]) TEST(@"+[elementWithXMLString:] and -[stringValue]", [[[OFXMLElement elementWithXMLString: @"\r\nfoo" @"bazqux"] stringValue] isEqual: @"foobarbazqux"]) TEST(@"-[elementsForName:namespace:]", (a = [nodes[2] elementsForName: @"bar" namespace: @"urn:objfw:test"]) && [a count] == 1 && [[[a firstObject] XMLString] isEqual: @""]) TEST(@"-[isEqual:]", [[OFXMLElement elementWithXMLString: @""] isEqual: [OFXMLElement elementWithXMLString: @""]] && [[OFXMLElement elementWithXMLString: @""] isEqual: [OFXMLElement elementWithXMLString: @""]]) TEST(@"-[XMLStringWithIndentation:]", [[[OFXMLElement elementWithXMLString: @"a\nb" @""] XMLStringWithIndentation: 2] isEqual: @"\n \n a\nb\n \n \n"]) [pool drain]; } @end