Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -42,10 +42,11 @@ OFScryptTests.m \ OFSetTests.m \ OFStringTests.m \ OFSystemInfoTests.m \ OFUTF8StringTests.m \ + OFXMLElementBuilderTests.m \ ${RUNTIME_ARC_TESTS_M} \ RuntimeTests.m \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_SUBPROCESSES} \ ADDED new_tests/OFXMLElementBuilderTests.m Index: new_tests/OFXMLElementBuilderTests.m ================================================================== --- new_tests/OFXMLElementBuilderTests.m +++ new_tests/OFXMLElementBuilderTests.m @@ -0,0 +1,70 @@ +/* + * 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 OFXMLElementBuilderTests: OTTestCase +{ + OFXMLNode *_nodes[2]; + size_t _i; +} +@end + +@implementation OFXMLElementBuilderTests +- (void)dealloc +{ + [_nodes[0] release]; + [_nodes[1] release]; + + [super dealloc]; +} + +- (void)elementBuilder: (OFXMLElementBuilder *)builder + didBuildElement: (OFXMLElement *)element +{ + OTAssertEqual(_i, 0); + _nodes[_i++] = [element retain]; +} + +- (void)elementBuilder: (OFXMLElementBuilder *)builder + didBuildOrphanNode: (OFXMLNode *)node +{ + OTAssertEqual(_i, 1); + _nodes[_i++] = [node retain]; +} + +- (void)testElementBuilder +{ + OFXMLParser *parser = [OFXMLParser parser]; + OFXMLElementBuilder *builder = [OFXMLElementBuilder builder]; + OFString *string = @"barbaz" + " " + ""; + + parser.delegate = builder; + builder.delegate = self; + + [parser parseString: string]; + OTAssertEqualObjects(_nodes[0].XMLString, string); + + [parser parseString: @""]; + OTAssertEqualObjects(_nodes[1].XMLString, @""); + + OTAssertEqual(_i, 2); +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -18,11 +18,10 @@ OFListTests.m \ OFMemoryStreamTests.m \ OFNotificationCenterTests.m \ OFStreamTests.m \ OFValueTests.m \ - OFXMLElementBuilderTests.m \ OFXMLNodeTests.m \ OFXMLParserTests.m \ TestsAppDelegate.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_SOCKETS} \ DELETED tests/OFXMLElementBuilderTests.m Index: tests/OFXMLElementBuilderTests.m ================================================================== --- tests/OFXMLElementBuilderTests.m +++ tests/OFXMLElementBuilderTests.m @@ -1,62 +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 *const module = @"OFXMLElementBuilder"; -static OFXMLNode *nodes[2]; -static size_t i = 0; - -@implementation TestsAppDelegate (OFXMLElementBuilderTests) -- (void)elementBuilder: (OFXMLElementBuilder *)builder - didBuildElement: (OFXMLElement *)element -{ - OFEnsure(i == 0); - nodes[i++] = [element retain]; -} - -- (void)elementBuilder: (OFXMLElementBuilder *)builder - didBuildOrphanNode: (OFXMLNode *)node -{ - OFEnsure(i == 1); - nodes[i++] = [node retain]; -} - -- (void)XMLElementBuilderTests -{ - void *pool = objc_autoreleasePoolPush(); - OFXMLParser *parser = [OFXMLParser parser]; - OFXMLElementBuilder *builder = [OFXMLElementBuilder builder]; - OFString *string = @"barbaz" - " " - ""; - - parser.delegate = builder; - builder.delegate = self; - - TEST(@"Building elements from parsed XML", - R([parser parseString: string]) && - nodes[0] != nil && [nodes[0].XMLString isEqual: string] && - R([parser parseString: @""]) && - nodes[1] != nil && [nodes[1].XMLString isEqual: @""] && - i == 2) - - [nodes[0] release]; - [nodes[1] release]; - objc_autoreleasePoolPop(pool); -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -105,17 +105,13 @@ @interface TestsAppDelegate (OFWindowsRegistryKeyTests) - (void)windowsRegistryKeyTests; @end -@interface TestsAppDelegate (OFXMLElementBuilderTests) -- (void)XMLElementBuilderTests; -@end - @interface TestsAppDelegate (OFXMLNodeTests) - (void)XMLNodeTests; @end @interface TestsAppDelegate (OFXMLParserTests) - (void)XMLParserTests; @end Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -387,11 +387,10 @@ [self HTTPCookieTests]; [self HTTPCookieManagerTests]; #endif [self XMLParserTests]; [self XMLNodeTests]; - [self XMLElementBuilderTests]; #ifdef OF_WINDOWS [self windowsRegistryKeyTests]; #endif