/* * Copyright (c) 2008-2021 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 "TestsAppDelegate.h" static OFString *module; @implementation TestsAppDelegate (OFXMLNodeTests) - (void)XMLNodeTests { void *pool = objc_autoreleasePoolPush(); id node1, node2, node3, node4; OFArray *array; module = @"OFXMLNode"; TEST(@"+[elementWithName:]", (node1 = [OFXMLElement elementWithName: @"foo"]) && [[node1 XMLString] isEqual: @""]) TEST(@"+[elementWithName:stringValue:]", (node2 = [OFXMLElement elementWithName: @"foo" stringValue: @"b&ar"]) && [[node2 XMLString] isEqual: @"b&ar"]) TEST(@"+[elementWithName:namespace:]", (node3 = [OFXMLElement elementWithName: @"foo" namespace: @"urn:objfw:test"]) && R([node3 addAttributeWithName: @"test" stringValue: @"test"]) && R([node3 setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]) && [[node3 XMLString] isEqual: @""] && (node4 = [OFXMLElement elementWithName: @"foo" namespace: @"urn:objfw:test"]) && R([node4 addAttributeWithName: @"test" stringValue: @"test"]) && [[node4 XMLString] isEqual: @""]) TEST(@"+[elementWithName:namespace:stringValue:]", (node4 = [OFXMLElement elementWithName: @"foo" namespace: @"urn:objfw:test" stringValue: @"x"]) && R([node4 setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]) && [[node4 XMLString] isEqual: @"x"]) TEST(@"+[charactersWithString:]", (node4 = [OFXMLCharacters charactersWithString: @""]) && [[node4 XMLString] isEqual: @"<foo>"]) TEST(@"+[CDATAWithString:]", (node4 = [OFXMLCDATA CDATAWithString: @""]) && [[node4 XMLString] isEqual: @"]]>"]); TEST(@"+[commentWithText:]", (node4 = [OFXMLComment commentWithText: @" comment "]) && [[node4 XMLString] isEqual: @""]) module = @"OFXMLElement"; TEST(@"-[addAttributeWithName:stringValue:]", R([node1 addAttributeWithName: @"foo" stringValue: @"b&ar"]) && [[node1 XMLString] isEqual: @""] && R([node2 addAttributeWithName: @"foo" stringValue: @"b&ar"]) && [[node2 XMLString] isEqual: @"b&ar"]) TEST(@"-[setPrefix:forNamespace:]", R([node2 setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"])) TEST(@"-[addAttributeWithName:namespace:stringValue:]", R([node2 addAttributeWithName: @"foo" namespace: @"urn:objfw:test" stringValue: @"bar"]) && R([node2 addAttributeWithName: @"foo" namespace: @"urn:objfw:test" stringValue: @"ignored"]) && [[node2 XMLString] isEqual: @"b&ar"]) TEST(@"-[removeAttributeForName:namespace:]", R([node2 removeAttributeForName: @"foo"]) && [[node2 XMLString] isEqual: @"b&ar"] && R([node2 removeAttributeForName: @"foo" namespace: @"urn:objfw:test"]) && [[node2 XMLString] isEqual: @"b&ar"]) TEST(@"-[addChild:]", R([node1 addChild: [OFXMLElement elementWithName: @"bar"]]) && [[node1 XMLString] isEqual: @""] && R([node3 addChild: [OFXMLElement elementWithName: @"bar" namespace: @"urn:objfw:test"]]) && [[node3 XMLString] isEqual: @""]) TEST(@"+[elementWithXMLString:] and -[stringValue]", [[[OFXMLElement elementWithXMLString: @"\r\nfoo" @"bazqux"] stringValue] isEqual: @"foobarbazqux"]) TEST(@"-[elementsForName:namespace:]", (array = [node3 elementsForName: @"bar" namespace: @"urn:objfw:test"]) && array.count == 1 && [[array.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"]) objc_autoreleasePoolPop(pool); } @end