Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -52,10 +52,11 @@ OFSetTests.m \ OFStringTests.m \ OFSystemInfoTests.m \ OFUTF8StringTests.m \ OFXMLElementBuilderTests.m \ + OFXMLNodeTests.m \ OFXMLParserTests.m \ ${RUNTIME_ARC_TESTS_M} \ RuntimeTests.m \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ADDED new_tests/OFXMLNodeTests.m Index: new_tests/OFXMLNodeTests.m ================================================================== --- new_tests/OFXMLNodeTests.m +++ new_tests/OFXMLNodeTests.m @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2008-2024 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 "ObjFW.h" +#import "ObjFWTest.h" + +@interface OFXMLNodeTests: OTTestCase +@end + +@implementation OFXMLNodeTests +- (void)testElementWithName +{ + OTAssertEqualObjects( + [[OFXMLElement elementWithName: @"foo"] XMLString], + @""); +} + +- (void)testElementWithNameStringValue +{ + OTAssertEqualObjects( + [[OFXMLElement elementWithName: @"foo" + stringValue: @"b&ar"] XMLString], + @"b&ar"); +} + +- (void)testElementWithNameNamespace +{ + OFXMLElement *element; + + element = [OFXMLElement elementWithName: @"foo" + namespace: @"urn:objfw:test"]; + [element addAttributeWithName: @"test" stringValue: @"test"]; + [element setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]; + OTAssertEqualObjects(element.XMLString, + @""); + + element = [OFXMLElement elementWithName: @"foo" + namespace: @"urn:objfw:test"]; + [element addAttributeWithName: @"test" stringValue: @"test"]; + OTAssertEqualObjects(element.XMLString, + @""); +} + +- (void)testElementWithNameNamespaceStringValue +{ + OFXMLElement *element = [OFXMLElement elementWithName: @"foo" + namespace: @"urn:objfw:test" + stringValue: @"x"]; + [element setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]; + OTAssertEqualObjects(element.XMLString, + @"x"); +} + +- (void)testElementWithXMLStringAndStringValue +{ + OTAssertEqualObjects([[OFXMLElement elementWithXMLString: + @"\r\nfoo" + @"bazqux"] stringValue], + @"foobarbazqux"); +} + +- (void)testCharactersWithString +{ + OTAssertEqualObjects( + [[OFXMLCharacters charactersWithString: @""] XMLString], + @"<foo>"); +} + +- (void)testCDATAWithString +{ + OTAssertEqualObjects( + [[OFXMLCDATA CDATAWithString: @""] XMLString], + @"]]>"); +} + +- (void)testCommentWithText +{ + OTAssertEqualObjects( + [[OFXMLComment commentWithText: @" comment "] XMLString], + @""); +} + +- (void)testIsEqual +{ + OTAssertEqualObjects( + [OFXMLElement elementWithXMLString: @""], + [OFXMLElement elementWithXMLString: @""]); + + OTAssertEqualObjects( + [OFXMLElement elementWithXMLString: @""], + [OFXMLElement elementWithXMLString: @""]); + + OTAssertNotEqualObjects( + [OFXMLElement elementWithXMLString: @""], + [OFXMLElement elementWithXMLString: @""]); +} + +- (void)testHash +{ + OTAssertEqual( + [[OFXMLElement elementWithXMLString: @""] hash], + [[OFXMLElement elementWithXMLString: @""] + hash]); + + OTAssertEqual( + [[OFXMLElement elementWithXMLString: @""] hash], + [[OFXMLElement elementWithXMLString: @""] hash]); + + OTAssertNotEqual( + [[OFXMLElement elementWithXMLString: @""] hash], + [[OFXMLElement elementWithXMLString: @""] hash]); +} + +- (void)testAddAttributeWithNameStringValue +{ + OFXMLElement *element = [OFXMLElement elementWithName: @"foo" + stringValue: @"b&ar"]; + + [element setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]; + [element addAttributeWithName: @"foo" + stringValue: @"b&ar"]; + [element addAttributeWithName: @"foo" + namespace: @"urn:objfw:test" + stringValue: @"bar"]; + + OTAssertEqualObjects(element.XMLString, + @"b&ar"); +} + +- (void)testRemoveAttributeForNameNamespace +{ + OFXMLElement *element = [OFXMLElement elementWithName: @"foo" + stringValue: @"b&ar"]; + + [element setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]; + [element addAttributeWithName: @"foo" + stringValue: @"b&ar"]; + [element addAttributeWithName: @"foo" + namespace: @"urn:objfw:test" + stringValue: @"bar"]; + + [element removeAttributeForName: @"foo"]; + OTAssertEqualObjects(element.XMLString, + @"b&ar"); + + [element removeAttributeForName: @"foo" namespace: @"urn:objfw:test"]; + OTAssertEqualObjects(element.XMLString, @"b&ar"); +} + +- (void)testAddChild +{ + OFXMLElement *element; + + element = [OFXMLElement elementWithName: @"foo"]; + [element addAttributeWithName: @"foo" stringValue: @"b&ar"]; + [element addChild: [OFXMLElement elementWithName: @"bar"]]; + OTAssertEqualObjects(element.XMLString, + @""); + + element = [OFXMLElement elementWithName: @"foo" + namespace: @"urn:objfw:test"]; + [element setPrefix: @"objfw-test" forNamespace: @"urn:objfw:test"]; + [element addAttributeWithName: @"test" stringValue: @"test"]; + [element addChild: [OFXMLElement elementWithName: @"bar" + namespace: @"urn:objfw:test"]]; + OTAssertEqualObjects(element.XMLString, + @""); +} + +- (void)testElementsForNameNamespace +{ + OFXMLElement *element = [OFXMLElement elementWithName: @"foo"]; + OFXMLElement *bar; + + [element addChild: [OFXMLElement elementWithName: @"foo"]]; + bar = [OFXMLElement elementWithName: @"bar" + namespace: @"urn:objfw:test"]; + [element addChild: bar]; + + OTAssertEqualObjects([element elementsForName: @"bar" + namespace: @"urn:objfw:test"], + [OFArray arrayWithObject: bar]); +} + +- (void)testXMLStringWithIndentation +{ + OTAssertEqualObjects([[OFXMLElement + elementWithXMLString: @"a\nb"] + XMLStringWithIndentation: 2], + @"\n \n a\nb\n \n \n"); +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -13,11 +13,10 @@ PROG_NOINST = tests${PROG_SUFFIX} STATIC_LIB_NOINST = ${TESTS_STATIC_LIB} SRCS = OFStreamTests.m \ OFValueTests.m \ - OFXMLNodeTests.m \ TestsAppDelegate.m IOS_USER ?= mobile IOS_TMP ?= /tmp/objfw-test DELETED tests/OFXMLNodeTests.m Index: tests/OFXMLNodeTests.m ================================================================== --- tests/OFXMLNodeTests.m +++ tests/OFXMLNodeTests.m @@ -1,137 +0,0 @@ -/* - * Copyright (c) 2008-2024 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 Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -64,9 +64,5 @@ @end @interface TestsAppDelegate (OFValueTests) - (void)valueTests; @end - -@interface TestsAppDelegate (OFXMLNodeTests) -- (void)XMLNodeTests; -@end Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -370,11 +370,10 @@ changeCurrentDirectoryPath: @"/apps/objfw-tests"]; #endif [self valueTests]; [self streamTests]; - [self XMLNodeTests]; [OFStdOut reset]; #if defined(OF_IOS) [OFStdOut writeFormat: @"%d tests failed!", _fails];