From 6d255425ceebd0ab394ab6873c5758146d0b1fb6 Mon Sep 17 00:00:00 2001 From: Robbie Hanson Date: Tue, 22 Nov 2011 11:42:23 -0800 Subject: [PATCH 1/3] Converted project to ARC --- KissXML/Categories/NSString+DDXML.m | 8 +- KissXML/DDXML.h | 76 +++++ KissXML/DDXMLDocument.m | 9 +- KissXML/DDXMLElement.m | 30 +- KissXML/DDXMLNode.m | 51 ++- UnitTesting/DDXMLTesting.m | 316 +++++++----------- UnitTesting/KissXML.xcodeproj/project.pbxproj | 4 + 7 files changed, 235 insertions(+), 259 deletions(-) diff --git a/KissXML/Categories/NSString+DDXML.m b/KissXML/Categories/NSString+DDXML.m index eefb2be9..c86fcec7 100644 --- a/KissXML/Categories/NSString+DDXML.m +++ b/KissXML/Categories/NSString+DDXML.m @@ -1,5 +1,8 @@ #import "NSString+DDXML.h" +#if ! __has_feature(objc_arc) +#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC). +#endif @implementation NSString (DDXML) @@ -17,12 +20,11 @@ - (NSString *)stringByTrimming - (NSString *)stringByTrimming { NSMutableString *mStr = [self mutableCopy]; - CFStringTrimWhitespace((CFMutableStringRef)mStr); + CFStringTrimWhitespace((__bridge CFMutableStringRef)mStr); NSString *result = [mStr copy]; - [mStr release]; - return [result autorelease]; + return result; } #endif diff --git a/KissXML/DDXML.h b/KissXML/DDXML.h index 9a6a6a87..20f042e2 100644 --- a/KissXML/DDXML.h +++ b/KissXML/DDXML.h @@ -21,6 +21,82 @@ #import "DDXMLDocument.h" + +#if TARGET_OS_IPHONE && 0 // Disabled by default + +// Since KissXML is a drop in replacement for NSXML, +// it may be desireable (when writing cross-platform code to be used on both Mac OS X and iOS) +// to use the NSXML prefixes instead of the DDXML prefix. +// +// This way, on Mac OS X it uses NSXML, and on iOS it uses KissXML. + +#ifndef NSXMLNode +#define NSXMLNode DDXMLNode +#endif +#ifndef NSXMLElement +#define NSXMLElement DDXMLElement +#endif +#ifndef NSXMLDocument +#define NSXMLDocument DDXMLDocument +#endif + +#ifndef NSXMLInvalidKind +#define NSXMLInvalidKind DDXMLInvalidKind +#endif +#ifndef NSXMLDocumentKind +#define NSXMLDocumentKind DDXMLDocumentKind +#endif +#ifndef NSXMLElementKind +#define NSXMLElementKind DDXMLElementKind +#endif +#ifndef NSXMLAttributeKind +#define NSXMLAttributeKind DDXMLAttributeKind +#endif +#ifndef NSXMLNamespaceKind +#define NSXMLNamespaceKind DDXMLNamespaceKind +#endif +#ifndef NSXMLProcessingInstructionKind +#define NSXMLProcessingInstructionKind DDXMLProcessingInstructionKind +#endif +#ifndef NSXMLCommentKind +#define NSXMLCommentKind DDXMLCommentKind +#endif +#ifndef NSXMLTextKind +#define NSXMLTextKind DDXMLTextKind +#endif +#ifndef NSXMLDTDKind +#define NSXMLDTDKind DDXMLDTDKind +#endif +#ifndef NSXMLEntityDeclarationKind +#define NSXMLEntityDeclarationKind DDXMLEntityDeclarationKind +#endif +#ifndef NSXMLAttributeDeclarationKind +#define NSXMLAttributeDeclarationKind DDXMLAttributeDeclarationKind +#endif +#ifndef NSXMLElementDeclarationKind +#define NSXMLElementDeclarationKind DDXMLElementDeclarationKind +#endif +#ifndef NSXMLNotationDeclarationKind +#define NSXMLNotationDeclarationKind DDXMLNotationDeclarationKind +#endif + +#ifndef NSXMLNodeOptionsNone +#define NSXMLNodeOptionsNone DDXMLNodeOptionsNone +#endif +#ifndef NSXMLNodeExpandEmptyElement +#define NSXMLNodeExpandEmptyElement DDXMLNodeExpandEmptyElement +#endif +#ifndef NSXMLNodeCompactEmptyElement +#define NSXMLNodeCompactEmptyElement DDXMLNodeCompactEmptyElement +#endif +#ifndef NSXMLNodePrettyPrint +#define NSXMLNodePrettyPrint DDXMLNodePrettyPrint +#endif + +#endif // #if TARGET_OS_IPHONE + + + // KissXML has rather straight-forward memory management: // https://github.com/robbiehanson/KissXML/wiki/MemoryManagementThreadSafety // diff --git a/KissXML/DDXMLDocument.m b/KissXML/DDXMLDocument.m index dabecbbd..a8b3458b 100644 --- a/KissXML/DDXMLDocument.m +++ b/KissXML/DDXMLDocument.m @@ -1,6 +1,10 @@ #import "DDXMLPrivate.h" #import "NSString+DDXML.h" +#if ! __has_feature(objc_arc) +#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC). +#endif + /** * Welcome to KissXML. * @@ -27,7 +31,7 @@ @implementation DDXMLDocument **/ + (id)nodeWithDocPrimitive:(xmlDocPtr)doc owner:(DDXMLNode *)owner { - return [[[DDXMLDocument alloc] initWithDocPrimitive:doc owner:owner] autorelease]; + return [[DDXMLDocument alloc] initWithDocPrimitive:doc owner:owner]; } - (id)initWithDocPrimitive:(xmlDocPtr)doc owner:(DDXMLNode *)inOwner @@ -49,7 +53,6 @@ - (id)initWithPrimitive:(xmlKindPtr)kindPtr owner:(DDXMLNode *)inOwner // Promote initializers which use proper parameter types to enable compiler to catch more mistakes. NSAssert(NO, @"Use initWithDocPrimitive:owner:"); - [self release]; return nil; } @@ -78,7 +81,6 @@ - (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)err { if (error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:0 userInfo:nil]; - [self release]; return nil; } @@ -94,7 +96,6 @@ - (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)err { if (error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:1 userInfo:nil]; - [self release]; return nil; } diff --git a/KissXML/DDXMLElement.m b/KissXML/DDXMLElement.m index a8cae781..012299fe 100644 --- a/KissXML/DDXMLElement.m +++ b/KissXML/DDXMLElement.m @@ -1,6 +1,10 @@ #import "DDXMLPrivate.h" #import "NSString+DDXML.h" +#if ! __has_feature(objc_arc) +#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC). +#endif + /** * Welcome to KissXML. * @@ -27,7 +31,7 @@ @implementation DDXMLElement **/ + (id)nodeWithElementPrimitive:(xmlNodePtr)node owner:(DDXMLNode *)owner { - return [[[DDXMLElement alloc] initWithElementPrimitive:node owner:owner] autorelease]; + return [[DDXMLElement alloc] initWithElementPrimitive:node owner:owner]; } - (id)initWithElementPrimitive:(xmlNodePtr)node owner:(DDXMLNode *)inOwner @@ -49,7 +53,6 @@ - (id)initWithPrimitive:(xmlKindPtr)kindPtr owner:(DDXMLNode *)inOwner // Promote initializers which use proper parameter types to enable compiler to catch more mistakes. NSAssert(NO, @"Use initWithElementPrimitive:owner:"); - [self release]; return nil; } @@ -60,7 +63,6 @@ - (id)initWithName:(NSString *)name xmlNodePtr node = xmlNewNode(NULL, [name xmlChar]); if (node == NULL) { - [self release]; return nil; } @@ -74,7 +76,6 @@ - (id)initWithName:(NSString *)name URI:(NSString *)URI xmlNodePtr node = xmlNewNode(NULL, [name xmlChar]); if (node == NULL) { - [self release]; return nil; } @@ -91,7 +92,6 @@ - (id)initWithName:(NSString *)name stringValue:(NSString *)string xmlNodePtr node = xmlNewNode(NULL, [name xmlChar]); if (node == NULL) { - [self release]; return nil; } @@ -106,16 +106,13 @@ - (id)initWithXMLString:(NSString *)string error:(NSError **)error DDXMLDocument *doc = [[DDXMLDocument alloc] initWithXMLString:string options:0 error:error]; if (doc == nil) { - [self release]; return nil; } DDXMLElement *result = [doc rootElement]; [result detach]; - [doc release]; - [self release]; - return [result retain]; + return result; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -326,8 +323,7 @@ - (void)addAttribute:(DDXMLNode *)attribute xmlAddChild((xmlNodePtr)genericPtr, (xmlNodePtr)attribute->genericPtr); // The attribute is now part of the xml tree heirarchy - [attribute->owner release]; - attribute->owner = [self retain]; + attribute->owner = self; } - (void)removeAttributeForName:(NSString *)name @@ -476,8 +472,7 @@ - (void)_addNamespace:(DDXMLNode *)namespace } // The namespace is now part of the xml tree heirarchy - [namespace->owner release]; - namespace->owner = [self retain]; + namespace->owner = self; if ([namespace isKindOfClass:[DDXMLNamespaceNode class]]) { @@ -710,8 +705,7 @@ - (void)addChild:(DDXMLNode *)child xmlAddChild((xmlNodePtr)genericPtr, (xmlNodePtr)child->genericPtr); // The node is now part of the xml tree heirarchy - [child->owner release]; - child->owner = [self retain]; + child->owner = self; } - (void)insertChild:(DDXMLNode *)child atIndex:(NSUInteger)index @@ -737,8 +731,7 @@ - (void)insertChild:(DDXMLNode *)child atIndex:(NSUInteger)index { xmlAddPrevSibling(childNodePtr, (xmlNodePtr)child->genericPtr); - [child->owner release]; - child->owner = [self retain]; + child->owner = self; return; } @@ -752,8 +745,7 @@ - (void)insertChild:(DDXMLNode *)child atIndex:(NSUInteger)index { xmlAddChild((xmlNodePtr)genericPtr, (xmlNodePtr)child->genericPtr); - [child->owner release]; - child->owner = [self retain]; + child->owner = self; return; } diff --git a/KissXML/DDXMLNode.m b/KissXML/DDXMLNode.m index 96848f77..b9950ec7 100644 --- a/KissXML/DDXMLNode.m +++ b/KissXML/DDXMLNode.m @@ -4,6 +4,10 @@ #import #import +#if ! __has_feature(objc_arc) +#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC). +#endif + /** * Welcome to KissXML. * @@ -76,17 +80,17 @@ + (void)initialize + (id)elementWithName:(NSString *)name { - return [[[DDXMLElement alloc] initWithName:name] autorelease]; + return [[DDXMLElement alloc] initWithName:name]; } + (id)elementWithName:(NSString *)name stringValue:(NSString *)string { - return [[[DDXMLElement alloc] initWithName:name stringValue:string] autorelease]; + return [[DDXMLElement alloc] initWithName:name stringValue:string]; } + (id)elementWithName:(NSString *)name children:(NSArray *)children attributes:(NSArray *)attributes { - DDXMLElement *result = [[[DDXMLElement alloc] initWithName:name] autorelease]; + DDXMLElement *result = [[DDXMLElement alloc] initWithName:name]; [result setChildren:children]; [result setAttributes:attributes]; @@ -95,7 +99,7 @@ + (id)elementWithName:(NSString *)name children:(NSArray *)children attributes:( + (id)elementWithName:(NSString *)name URI:(NSString *)URI { - return [[[DDXMLElement alloc] initWithName:name URI:URI] autorelease]; + return [[DDXMLElement alloc] initWithName:name URI:URI]; } + (id)attributeWithName:(NSString *)name stringValue:(NSString *)stringValue @@ -104,7 +108,7 @@ + (id)attributeWithName:(NSString *)name stringValue:(NSString *)stringValue if (attr == NULL) return nil; - return [[[DDXMLAttributeNode alloc] initWithAttrPrimitive:attr owner:nil] autorelease]; + return [[DDXMLAttributeNode alloc] initWithAttrPrimitive:attr owner:nil]; } + (id)attributeWithName:(NSString *)name URI:(NSString *)URI stringValue:(NSString *)stringValue @@ -116,7 +120,7 @@ + (id)attributeWithName:(NSString *)name URI:(NSString *)URI stringValue:(NSStri DDXMLAttributeNode *result = [[DDXMLAttributeNode alloc] initWithAttrPrimitive:attr owner:nil]; [result setURI:URI]; - return [result autorelease]; + return result; } + (id)namespaceWithName:(NSString *)name stringValue:(NSString *)stringValue @@ -128,7 +132,7 @@ + (id)namespaceWithName:(NSString *)name stringValue:(NSString *)stringValue if (ns == NULL) return nil; - return [[[DDXMLNamespaceNode alloc] initWithNsPrimitive:ns nsParent:NULL owner:nil] autorelease]; + return [[DDXMLNamespaceNode alloc] initWithNsPrimitive:ns nsParent:NULL owner:nil]; } + (id)processingInstructionWithName:(NSString *)name stringValue:(NSString *)stringValue @@ -137,7 +141,7 @@ + (id)processingInstructionWithName:(NSString *)name stringValue:(NSString *)str if (procInst == NULL) return nil; - return [[[DDXMLNode alloc] initWithPrimitive:(xmlKindPtr)procInst owner:nil] autorelease]; + return [[DDXMLNode alloc] initWithPrimitive:(xmlKindPtr)procInst owner:nil]; } + (id)commentWithStringValue:(NSString *)stringValue @@ -146,7 +150,7 @@ + (id)commentWithStringValue:(NSString *)stringValue if (comment == NULL) return nil; - return [[[DDXMLNode alloc] initWithPrimitive:(xmlKindPtr)comment owner:nil] autorelease]; + return [[DDXMLNode alloc] initWithPrimitive:(xmlKindPtr)comment owner:nil]; } + (id)textWithStringValue:(NSString *)stringValue @@ -155,7 +159,7 @@ + (id)textWithStringValue:(NSString *)stringValue if (text == NULL) return nil; - return [[[DDXMLNode alloc] initWithPrimitive:(xmlKindPtr)text owner:nil] autorelease]; + return [[DDXMLNode alloc] initWithPrimitive:(xmlKindPtr)text owner:nil]; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -194,7 +198,7 @@ + (id)nodeWithUnknownPrimitive:(xmlKindPtr)kindPtr owner:(DDXMLNode *)owner **/ + (id)nodeWithPrimitive:(xmlKindPtr)kindPtr owner:(DDXMLNode *)owner { - return [[[DDXMLNode alloc] initWithPrimitive:kindPtr owner:owner] autorelease]; + return [[DDXMLNode alloc] initWithPrimitive:kindPtr owner:owner]; } /** @@ -206,7 +210,7 @@ - (id)initWithPrimitive:(xmlKindPtr)kindPtr owner:(DDXMLNode *)inOwner if ((self = [super init])) { genericPtr = kindPtr; - owner = [inOwner retain]; + owner = inOwner; #if DDXML_DEBUG_MEMORY_ISSUES MarkBirth(genericPtr, self); @@ -229,7 +233,6 @@ - (id)init } else { - [self release]; return [[DDXMLInvalidNode alloc] init]; } } @@ -289,9 +292,6 @@ - (void)dealloc NSAssert1(NO, @"Cannot free unknown node type: %i", genericPtr->type); } } - - [owner release]; - [super dealloc]; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -643,7 +643,7 @@ - (NSArray *)children child = child->next; } - return [[result copy] autorelease]; + return [result copy]; } /** @@ -863,7 +863,6 @@ - (void)detach { [[self class] detachChild:(xmlNodePtr)node]; - [owner release]; owner = nil; } } @@ -928,7 +927,7 @@ - (NSString *)XPath node = (xmlStdPtr)node->parent; } - return [[result copy] autorelease]; + return [result copy]; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1183,11 +1182,11 @@ - (NSString *)XMLStringWithOptions:(NSUInteger)options else { NSMutableString *resTmp = [NSMutableString stringWithUTF8String:(const char *)bufferPtr->content]; - CFStringTrimWhitespace((CFMutableStringRef)resTmp); + CFStringTrimWhitespace((__bridge CFMutableStringRef)resTmp); xmlBufferFree(bufferPtr); - return [[resTmp copy] autorelease]; + return [resTmp copy]; } } @@ -2181,7 +2180,7 @@ @implementation DDXMLNamespaceNode **/ + (id)nodeWithNsPrimitive:(xmlNsPtr)ns nsParent:(xmlNodePtr)parent owner:(DDXMLNode *)owner { - return [[[DDXMLNamespaceNode alloc] initWithNsPrimitive:ns nsParent:parent owner:owner] autorelease]; + return [[DDXMLNamespaceNode alloc] initWithNsPrimitive:ns nsParent:parent owner:owner]; } /** @@ -2210,7 +2209,6 @@ - (id)initWithPrimitive:(xmlKindPtr)kindPtr owner:(DDXMLNode *)inOwner // Promote initializers which use proper parameter types to enable compiler to catch more mistakes. NSAssert(NO, @"Use initWithNsPrimitive:nsParent:owner:"); - [self release]; return nil; } @@ -2416,9 +2414,7 @@ - (void)detach { [DDXMLNode detachNamespace:(xmlNsPtr)genericPtr fromNode:nsParentPtr]; - [owner release]; owner = nil; - nsParentPtr = NULL; } } @@ -2518,7 +2514,7 @@ @implementation DDXMLAttributeNode + (id)nodeWithAttrPrimitive:(xmlAttrPtr)attr owner:(DDXMLNode *)owner { - return [[[DDXMLAttributeNode alloc] initWithAttrPrimitive:attr owner:owner] autorelease]; + return [[DDXMLAttributeNode alloc] initWithAttrPrimitive:attr owner:owner]; } - (id)initWithAttrPrimitive:(xmlAttrPtr)attr owner:(DDXMLNode *)inOwner @@ -2540,14 +2536,12 @@ - (id)initWithPrimitive:(xmlKindPtr)kindPtr owner:(DDXMLNode *)inOwner // Promote initializers which use proper parameter types to enable compiler to catch more mistakes. NSAssert(NO, @"Use initWithAttrPrimitive:nsParent:owner:"); - [self release]; return nil; } - (void)dealloc { if (attrNsPtr) xmlFreeNs(attrNsPtr); - [super dealloc]; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2669,7 +2663,6 @@ - (void)detach attr->ns = attrNsPtr; } - [owner release]; owner = nil; } } diff --git a/UnitTesting/DDXMLTesting.m b/UnitTesting/DDXMLTesting.m index f229af42..9ad2c38b 100644 --- a/UnitTesting/DDXMLTesting.m +++ b/UnitTesting/DDXMLTesting.m @@ -115,7 +115,7 @@ + (void)setUp // // See the tryCatch method below. - prevAssertionHandler = [[[[NSThread currentThread] threadDictionary] objectForKey:NSAssertionHandlerKey] retain]; + prevAssertionHandler = [[[NSThread currentThread] threadDictionary] objectForKey:NSAssertionHandlerKey]; ddAssertionHandler = [[DDAssertionHandler alloc] init]; [[[NSThread currentThread] threadDictionary] setObject:ddAssertionHandler forKey:NSAssertionHandlerKey]; @@ -130,8 +130,8 @@ + (void)tearDown else [[[NSThread currentThread] threadDictionary] removeObjectForKey:NSAssertionHandlerKey]; - [prevAssertionHandler release]; prevAssertionHandler = nil; - [ddAssertionHandler release]; ddAssertionHandler = nil; + prevAssertionHandler = nil; + ddAssertionHandler = nil; } + (NSException *)tryCatch:(void (^)())block @@ -150,10 +150,9 @@ + (NSException *)tryCatch:(void (^)())block return result; } -+ (void)testName ++ (void)testName { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *str = @"" @" yumyum" @@ -169,22 +168,19 @@ + (void)testName NSString *nsNodeName = [[nsBody childAtIndex:0] name]; NSString *ddNodeName = [[ddBody childAtIndex:0] name]; - NSAssert([nsNodeName isEqualToString:ddNodeName], @"Failed test 1"); + NSAssert([nsNodeName isEqualToString:ddNodeName], @"Failed test 1 - ns(%@) dd(%@)", nsNodeName, ddNodeName); // Test 2 - attributes NSString *nsAttrName = [[nsBody attributeForName:@"food:genre"] name]; NSString *ddAttrName = [[ddBody attributeForName:@"food:genre"] name]; - NSAssert([nsAttrName isEqualToString:ddAttrName], @"Failed test 2"); - - [pool release]; -} + NSAssert([nsAttrName isEqualToString:ddAttrName], @"Failed test 2 - ns(%@) dd(%@)", nsAttrName, ddAttrName); +}} -+ (void)testLocalName ++ (void)testLocalName { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *nsTest1 = [NSXMLNode localNameForName:@"a:quack"]; NSString *ddTest1 = [DDXMLNode localNameForName:@"a:quack"]; @@ -217,15 +213,12 @@ + (void)testLocalName NSString *nsTest6 = [nsNode localName]; NSString *ddTest6 = [ddNode localName]; - NSAssert([nsTest6 isEqualToString:ddTest6], @"Failed test 6"); - - [pool drain]; -} + NSAssert([nsTest6 isEqualToString:ddTest6], @"Failed test 6"); +}} -+ (void)testPrefixName ++ (void)testPrefixName { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *nsTest1 = [NSXMLNode prefixForName:@"a:quack"]; NSString *ddTest1 = [DDXMLNode prefixForName:@"a:quack"]; @@ -259,14 +252,11 @@ + (void)testPrefixName NSString *ddTest6 = [ddNode prefix]; NSAssert([nsTest6 isEqualToString:ddTest6], @"Failed test 6"); - - [pool drain]; -} +}} -+ (void)testDoubleAdd ++ (void)testDoubleAdd { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSXMLElement *nsRoot1 = [NSXMLElement elementWithName:@"root1"]; NSXMLElement *nsRoot2 = [NSXMLElement elementWithName:@"root2"]; @@ -378,15 +368,12 @@ + (void)testDoubleAdd NSAssert(ddDoubleAddException1 != nil, @"Failed test 4"); NSAssert(ddDoubleAddException2 != nil, @"Failed test 5"); - NSAssert(ddDoubleAddException3 != nil, @"Failed test 6"); - - [pool drain]; -} + NSAssert(ddDoubleAddException3 != nil, @"Failed test 6"); +}} -+ (void)testNsGeneral ++ (void)testNsGeneral { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSXMLNode *nsNs = [NSXMLNode namespaceWithName:@"a" stringValue:@"deusty.com"]; DDXMLNode *ddNs = [DDXMLNode namespaceWithName:@"a" stringValue:@"deusty.com"]; @@ -411,14 +398,11 @@ + (void)testNsGeneral NSString *ddTest3 = [ddNs XMLString]; NSAssert([nsTest3 isEqualToString:ddTest3], @"Failed test 3"); - - [pool drain]; -} +}} -+ (void)testNsLevel ++ (void)testNsLevel { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // // @@ -450,15 +434,12 @@ + (void)testNsLevel NSAssert([nsNs0 level] == [ddNs0 level], @"Failed test 4"); NSAssert([nsNs1 level] == [ddNs1 level], @"Failed test 5"); - NSAssert([nsNs2 level] == [ddNs2 level], @"Failed test 6"); - - [pool drain]; -} + NSAssert([nsNs2 level] == [ddNs2 level], @"Failed test 6"); +}} -+ (void)testNsURI ++ (void)testNsURI { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSXMLElement *nsNode = [NSXMLElement elementWithName:@"duck" URI:@"quack.com"]; DDXMLElement *ddNode = [DDXMLElement elementWithName:@"duck" URI:@"quack.com"]; @@ -490,15 +471,12 @@ + (void)testNsURI NSString *nsTest4 = [nsAttr URI]; NSString *ddTest4 = [ddAttr URI]; - NSAssert([nsTest4 isEqualToString:ddTest4], @"Failed test 4"); - - [pool drain]; -} + NSAssert([nsTest4 isEqualToString:ddTest4], @"Failed test 4"); +}} -+ (void)testAddAttr ++ (void)testAddAttr { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *attrName = @"artist"; @@ -589,14 +567,11 @@ + (void)testAddAttr NSAssert([nsAttrValue3 isEqualToString:attrValue3], @"Failed CHECK 6"); NSAssert([ddAttrValue3 isEqualToString:attrValue3], @"Failed test 6"); - - [pool drain]; -} +}} -+ (void)testAttrGeneral ++ (void)testAttrGeneral { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSXMLNode *nsAttr = [NSXMLNode attributeWithName:@"apple" stringValue:@"inc"]; DDXMLNode *ddAttr = [DDXMLNode attributeWithName:@"apple" stringValue:@"inc"]; @@ -620,15 +595,12 @@ + (void)testAttrGeneral NSString *nsStr3 = [nsAttr XMLString]; NSString *ddStr3 = [ddAttr XMLString]; - NSAssert([nsStr3 isEqualToString:ddStr3], @"Failed test 3"); - - [pool drain]; -} + NSAssert([nsStr3 isEqualToString:ddStr3], @"Failed test 3"); +}} -+ (void)testAttrSiblings ++ (void)testAttrSiblings { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // @@ -658,13 +630,11 @@ + (void)testAttrSiblings // Analysis: DDXML works and NSXML doesn't. I see no need to cripple DDXML because of that. - [pool drain]; -} +}} -+ (void)testAttrDocOrder ++ (void)testAttrDocOrder { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // @@ -693,13 +663,11 @@ + (void)testAttrDocOrder // Notes: Attributes play no part in the document order. - [pool drain]; -} +}} -+ (void)testAttrChildren ++ (void)testAttrChildren { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSXMLNode *nsAttr1 = [NSXMLNode attributeWithName:@"deusty" stringValue:@"designs"]; DDXMLNode *ddAttr1 = [DDXMLNode attributeWithName:@"deusty" stringValue:@"designs"]; @@ -722,13 +690,11 @@ + (void)testAttrChildren // Notes: Attributes aren't supposed to have children, although in libxml they technically do. // The child is simply a pointer to a text node, which contains the attribute value. - [pool drain]; -} +}} -+ (void)testString ++ (void)testString { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // // @@ -827,13 +793,11 @@ + (void)testString // // The DDXML version is actually more accurate, so we'll accept the difference. - [pool drain]; -} +}} -+ (void)testChildren ++ (void)testChildren { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSMutableString *xmlStr = [NSMutableString stringWithCapacity:100]; [xmlStr appendString:@""]; @@ -844,8 +808,8 @@ + (void)testChildren [xmlStr appendString:@" "]; [xmlStr appendString:@" "]; - NSXMLDocument *nsDoc = [[[NSXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil] autorelease]; - DDXMLDocument *ddDoc = [[[DDXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil] autorelease]; + NSXMLDocument *nsDoc = [[NSXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil]; + DDXMLDocument *ddDoc = [[DDXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil]; NSUInteger nsChildCount = [[nsDoc rootElement] childCount]; NSUInteger ddChildCount = [[ddDoc rootElement] childCount]; @@ -861,14 +825,11 @@ + (void)testChildren NSString *ddBeer = [[[ddDoc rootElement] childAtIndex:1] name]; NSAssert([nsBeer isEqualToString:ddBeer], @"Failed test 3"); - - [pool drain]; -} +}} -+ (void)testPreviousNextNode1 ++ (void)testPreviousNextNode1 { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // // @@ -955,15 +916,12 @@ + (void)testPreviousNextNode1 NSString *nsTest7 = [[nsNode0 previousNode] name]; NSString *ddTest7 = [[ddNode0 previousNode] name]; - NSAssert2((!nsTest7 && !ddTest7), @"Failed test 7: ns(%@) dd(%@)", nsTest7, ddTest7); - - [pool drain]; -} + NSAssert2((!nsTest7 && !ddTest7), @"Failed test 7: ns(%@) dd(%@)", nsTest7, ddTest7); +}} -+ (void)testPreviousNextNode2 ++ (void)testPreviousNextNode2 { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSMutableString *xmlStr = [NSMutableString stringWithCapacity:100]; [xmlStr appendString:@""]; @@ -981,8 +939,8 @@ + (void)testPreviousNextNode2 [xmlStr appendString:@" "]; [xmlStr appendString:@" "]; - NSXMLDocument *nsDoc = [[[NSXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil] autorelease]; - DDXMLDocument *ddDoc = [[[DDXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil] autorelease]; + NSXMLDocument *nsDoc = [[NSXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil]; + DDXMLDocument *ddDoc = [[DDXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil]; NSXMLNode *nsNode0 = [nsDoc rootElement]; // pizza DDXMLNode *ddNode0 = [ddDoc rootElement]; // pizza @@ -1036,14 +994,11 @@ + (void)testPreviousNextNode2 NSString *ddTest7 = [[ddNode0 previousNode] name]; NSAssert2((!nsTest7 && !ddTest7), @"Failed test 7: ns(%@) dd(%@)", nsTest7, ddTest7); - - [pool drain]; -} +}} -+ (void)testPrefix ++ (void)testPrefix { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // // @@ -1080,15 +1035,12 @@ + (void)testPrefix NSString *nsTest4 = [nsNode4 prefix]; NSString *ddTest4 = [ddNode4 prefix]; - NSAssert([nsTest4 isEqualToString:ddTest4], @"Failed test 4"); - - [pool drain]; -} + NSAssert([nsTest4 isEqualToString:ddTest4], @"Failed test 4"); +}} -+ (void)testURI ++ (void)testURI { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // // @@ -1211,23 +1163,20 @@ + (void)testURI NSUInteger nsTest13 = [[nsRoot elementsForLocalName:@"test" URI:@"quack.com"] count]; // Returns node5 NSUInteger ddTest13 = [[ddRoot elementsForLocalName:@"test" URI:@"quack.com"] count]; // Returns node5 - NSAssert(nsTest13 == ddTest13, @"Failed test 13"); - - [pool drain]; -} + NSAssert(nsTest13 == ddTest13, @"Failed test 13"); +}} -+ (void)testXmlns ++ (void)testXmlns { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *parseMe = @""; NSData *data = [parseMe dataUsingEncoding:NSUTF8StringEncoding]; - NSXMLDocument *nsDoc = [[[NSXMLDocument alloc] initWithData:data options:0 error:nil] autorelease]; + NSXMLDocument *nsDoc = [[NSXMLDocument alloc] initWithData:data options:0 error:nil]; NSXMLElement *nsRootElement = [nsDoc rootElement]; - DDXMLDocument *ddDoc = [[[DDXMLDocument alloc] initWithData:data options:0 error:nil] autorelease]; + DDXMLDocument *ddDoc = [[DDXMLDocument alloc] initWithData:data options:0 error:nil]; DDXMLElement *ddRootElement = [ddDoc rootElement]; // Both URI and namespaceForPrefix:@"" should return "jabber:iq:roster" @@ -1302,14 +1251,11 @@ + (void)testXmlns NSUInteger ddTest9 = [[ddNode namespaces] count]; NSAssert(nsTest9 == ddTest9, @"Failed test 9"); - - [pool drain]; -} +}} -+ (void)testCopy ++ (void)testCopy { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // // Billy @@ -1317,12 +1263,12 @@ + (void)testCopy NSString *xmlStr = @"Billy"; - NSXMLDocument *nsDoc = [[[NSXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil] autorelease]; - DDXMLDocument *ddDoc = [[[DDXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil] autorelease]; + NSXMLDocument *nsDoc = [[NSXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil]; + DDXMLDocument *ddDoc = [[DDXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil]; // Test Document copy - NSXMLDocument *nsDocCopy = [[nsDoc copy] autorelease]; + NSXMLDocument *nsDocCopy = [nsDoc copy]; [[nsDocCopy rootElement] addAttribute:[NSXMLNode attributeWithName:@"type" stringValue:@"mom"]]; NSXMLNode *nsDocAttr = [[nsDoc rootElement] attributeForName:@"type"]; @@ -1331,7 +1277,7 @@ + (void)testCopy NSAssert(nsDocAttr == nil, @"Failed CHECK 1"); NSAssert(nsDocCopyAttr != nil, @"Failed CHECK 2"); - DDXMLDocument *ddDocCopy = [[ddDoc copy] autorelease]; + DDXMLDocument *ddDocCopy = [ddDoc copy]; [[ddDocCopy rootElement] addAttribute:[DDXMLNode attributeWithName:@"type" stringValue:@"mom"]]; DDXMLNode *ddDocAttr = [[ddDoc rootElement] attributeForName:@"type"]; @@ -1343,7 +1289,7 @@ + (void)testCopy // Test Element copy NSXMLElement *nsElement = [[[nsDoc rootElement] elementsForName:@"child"] objectAtIndex:0]; - NSXMLElement *nsElementCopy = [[nsElement copy] autorelease]; + NSXMLElement *nsElementCopy = [nsElement copy]; NSAssert([nsElement parent] != nil, @"Failed CHECK 3"); NSAssert([nsElementCopy parent] == nil, @"Failed CHECK 4"); @@ -1357,7 +1303,7 @@ + (void)testCopy NSAssert(nsElementCopyAttr != nil, @"Failed CHECK 6"); DDXMLElement *ddElement = [[[ddDoc rootElement] elementsForName:@"child"] objectAtIndex:0]; - DDXMLElement *ddElementCopy = [[ddElement copy] autorelease]; + DDXMLElement *ddElementCopy = [ddElement copy]; NSAssert([nsElement parent] != nil, @"Failed test 3"); NSAssert([nsElementCopy parent] == nil, @"Failed test 4"); @@ -1373,7 +1319,7 @@ + (void)testCopy // Test Node copy NSXMLNode *nsAttr = [nsElement attributeForName:@"age"]; - NSXMLNode *nsAttrCopy = [[nsAttr copy] autorelease]; + NSXMLNode *nsAttrCopy = [nsAttr copy]; NSAssert([nsAttr parent] != nil, @"Failed CHECK 7"); NSAssert([nsAttrCopy parent] == nil, @"Failed CHECK 8"); @@ -1387,7 +1333,7 @@ + (void)testCopy NSAssert([nsAttrCopyValue isEqualToString:@"5"], @"Failed CHECK 10"); DDXMLNode *ddAttr = [ddElement attributeForName:@"age"]; - DDXMLNode *ddAttrCopy = [[ddAttr copy] autorelease]; + DDXMLNode *ddAttrCopy = [ddAttr copy]; NSAssert([ddAttr parent] != nil, @"Failed test 7"); NSAssert([ddAttrCopy parent] == nil, @"Failed test 8"); @@ -1398,15 +1344,12 @@ + (void)testCopy NSString *ddAttrCopyValue = [ddAttrCopy stringValue]; NSAssert([ddAttrValue isEqualToString:@"4"], @"Failed test 9"); - NSAssert([ddAttrCopyValue isEqualToString:@"5"], @"Failed test 10"); - - [pool drain]; -} + NSAssert([ddAttrCopyValue isEqualToString:@"5"], @"Failed test 10"); +}} -+ (void)testCData ++ (void)testCData { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // // @@ -1425,17 +1368,19 @@ + (void)testCData [xmlStr appendString:@" "]; [xmlStr appendString:@""]; - DDXMLDocument *ddDoc = [[DDXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil]; + NSError *nsErr = nil; + NSError *ddErr = nil; - [ddDoc release]; + NSXMLDocument *nsDoc = [[NSXMLDocument alloc] initWithXMLString:xmlStr options:0 error:&nsErr]; + DDXMLDocument *ddDoc = [[DDXMLDocument alloc] initWithXMLString:xmlStr options:0 error:&ddErr]; - [pool drain]; -} + NSAssert(nsDoc != nil, @"Failed CHECK 1: %@", nsErr); + NSAssert(ddDoc != nil, @"Failed test 1: %@", ddErr); +}} -+ (void)testElements ++ (void)testElements { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSMutableString *xmlStr = [NSMutableString stringWithCapacity:100]; [xmlStr appendString:@""]; @@ -1461,7 +1406,6 @@ + (void)testElements NSAssert([child isMemberOfClass:[NSXMLElement class]], @"Failed CHECK 1"); } } - [nsDoc release]; DDXMLDocument *ddDoc = [[DDXMLDocument alloc] initWithXMLString:xmlStr options:0 error:nil]; @@ -1475,15 +1419,11 @@ + (void)testElements NSAssert([child isMemberOfClass:[DDXMLElement class]], @"Failed test 1"); } } - [ddDoc release]; - - [pool drain]; -} +}} -+ (void)testXPath ++ (void)testXPath { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSMutableString *xmlStr = [NSMutableString stringWithCapacity:100]; [xmlStr appendString:@""]; @@ -1565,8 +1505,6 @@ + (void)testXPath nsNamespaceXPath, ddNamespaceXPath); } - [nsDoc release]; - [ddDoc release]; NSXMLElement *nsElement1 = [NSXMLElement elementWithName:@"duck"]; NSXMLElement *nsElement2 = [NSXMLElement elementWithName:@"quack"]; @@ -1597,13 +1535,11 @@ + (void)testXPath NSAssert2([nsAttrXPath isEqualToString:ddAttrXPath], @"Failed test 8: ns(%@) != dd(%@)", nsAttrXPath, ddAttrXPath); - [pool drain]; -} +}} -+ (void)testNodesForXPath ++ (void)testNodesForXPath { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSMutableString *xmlStr = [NSMutableString stringWithCapacity:100]; [xmlStr appendString:@""]; @@ -1663,8 +1599,6 @@ + (void)testNodesForXPath NSAssert([nsYes isEqualToString:ddYes], @"Failed test 7"); - [nsDoc release]; - [ddDoc release]; NSXMLElement *nsElement1 = [NSXMLElement elementWithName:@"duck"]; NSXMLElement *nsElement2 = [NSXMLElement elementWithName:@"quack"]; @@ -1677,15 +1611,12 @@ + (void)testNodesForXPath NSArray *nsTest4 = [nsElement1 nodesForXPath:@"quack[1]" error:nil]; NSArray *ddTest4 = [ddElement1 nodesForXPath:@"quack[1]" error:nil]; - NSAssert([nsTest4 count] == [ddTest4 count], @"Failed test 8"); - - [pool drain]; -} + NSAssert([nsTest4 count] == [ddTest4 count], @"Failed test 8"); +}} -+ (void)testNSXMLBugs ++ (void)testNSXMLBugs { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // // @@ -1710,16 +1641,11 @@ + (void)testNSXMLBugs NSAssert([ddChildren count] == 1, @"Failed test 1"); - [nsDoc release]; - [ddDoc release]; - - [pool drain]; -} +}} -+ (void)testInsertChild ++ (void)testInsertChild { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSXMLElement *nsParent = [NSXMLElement elementWithName:@"parent"]; DDXMLElement *ddParent = [DDXMLElement elementWithName:@"parent"]; @@ -1773,59 +1699,50 @@ + (void)testInsertChild }]; NSAssert(nsException != nil, @"Failed CHECK 1"); - NSAssert(ddException != nil, @"Failed test 6"); - - [pool drain]; -} + NSAssert(ddException != nil, @"Failed test 6"); +}} -+ (void)testElementSerialization ++ (void)testElementSerialization { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *str = @"chicken noodle"; NSError *err; err = nil; - NSXMLElement *nse = [[[NSXMLElement alloc] initWithXMLString:str error:&err] autorelease]; + NSXMLElement *nse = [[NSXMLElement alloc] initWithXMLString:str error:&err]; NSAssert((nse != nil) && (err == nil), @"Failed CHECK 1"); err = nil; - DDXMLElement *dde = [[[DDXMLElement alloc] initWithXMLString:str error:&err] autorelease]; + DDXMLElement *dde = [[DDXMLElement alloc] initWithXMLString:str error:&err]; NSAssert((dde != nil) && (err == nil), @"Failed test 1"); - NSAssert([[nse XMLString] isEqualToString:[dde XMLString]], @"Failed test 2"); - - [pool drain]; -} + NSAssert([[nse XMLString] isEqualToString:[dde XMLString]], @"Failed test 2"); +}} -+ (void)testAttrWithColonInName ++ (void)testAttrWithColonInName { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *str = @""; - NSXMLDocument *nsDoc = [[[NSXMLDocument alloc] initWithXMLString:str options:0 error:nil] autorelease]; - DDXMLDocument *ddDoc = [[[DDXMLDocument alloc] initWithXMLString:str options:0 error:nil] autorelease]; + NSXMLDocument *nsDoc = [[NSXMLDocument alloc] initWithXMLString:str options:0 error:nil]; + DDXMLDocument *ddDoc = [[DDXMLDocument alloc] initWithXMLString:str options:0 error:nil]; NSXMLNode *nsa = [[nsDoc rootElement] attributeForName:@"xml:pimp"]; DDXMLNode *dda = [[ddDoc rootElement] attributeForName:@"xml:pimp"]; NSAssert(nsa != nil, @"Failed CHECK 1"); - NSAssert(dda != nil, @"Failed test 1"); - - [pool drain]; -} + NSAssert(dda != nil, @"Failed test 1"); +}} -+ (void)testMemoryIssueDebugging ++ (void)testMemoryIssueDebugging { @autoreleasepool { #if DDXML_DEBUG_MEMORY_ISSUES NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; // // @@ -1893,14 +1810,12 @@ + (void)testMemoryIssueDebugging }]; NSAssert(exception4 != nil, @"Failed test 4"); - [pool drain]; #endif -} +}} -+ (void)testAttrNs ++ (void)testAttrNs { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *nsName, *ddName; NSString *nsUri, *ddUri; @@ -2070,13 +1985,11 @@ + (void)testAttrNs NSAssert([nsName isEqualToString:ddName], @"Failed test 8A"); NSAssert([nsUri isEqualToString:ddUri], @"Failed test 8B - ns(%@) dd(%@)", nsUri, ddUri); - [pool drain]; -} +}} -+ (void)testNsDetatchCopy ++ (void)testNsDetatchCopy { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *nsUri; NSString *ddUri; @@ -2107,8 +2020,8 @@ + (void)testNsDetatchCopy @""; NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding]; - NSXMLDocument *nsDoc = [[[NSXMLDocument alloc] initWithData:data options:0 error:nil] autorelease]; - DDXMLDocument *ddDoc = [[[DDXMLDocument alloc] initWithData:data options:0 error:nil] autorelease]; + NSXMLDocument *nsDoc = [[NSXMLDocument alloc] initWithData:data options:0 error:nil]; + DDXMLDocument *ddDoc = [[DDXMLDocument alloc] initWithData:data options:0 error:nil]; NSXMLElement *nsRoot = [nsDoc rootElement]; DDXMLElement *ddRoot = [ddDoc rootElement]; @@ -2127,15 +2040,12 @@ + (void)testNsDetatchCopy nsUri = [nsCow URI]; ddUri = [ddCow URI]; - NSAssert([nsUri isEqualToString:ddUri], @"Failed test 2b"); - - [pool drain]; -} + NSAssert([nsUri isEqualToString:ddUri], @"Failed test 2b"); +}} -+ (void)testInvalidNode ++ (void)testInvalidNode { @autoreleasepool { NSLog(@"Starting %@...", NSStringFromSelector(_cmd)); - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSXMLNode *nsNode = [[NSXMLNode alloc] init]; DDXMLNode *ddNode = [[DDXMLNode alloc] init]; @@ -2153,10 +2063,8 @@ + (void)testInvalidNode NSString *nsDesc = [nsNode description]; NSString *ddDesc = [ddNode description]; - NSAssert(nsDesc && [nsDesc isEqualToString:ddDesc], @"Failed test 3 - ns(%@) dd(%@)", nsDesc, ddDesc); - - [pool drain]; -} + NSAssert(nsDesc && [nsDesc isEqualToString:ddDesc], @"Failed test 3 - ns(%@) dd(%@)", nsDesc, ddDesc); +}} @end @@ -2202,7 +2110,7 @@ - (void)handleFailureInFunction:(NSString *)functionName va_list args; va_start(args, format); - NSString *reason = [[[NSString alloc] initWithFormat:format arguments:args] autorelease]; + NSString *reason = [[NSString alloc] initWithFormat:format arguments:args]; va_end(args); @@ -2234,7 +2142,7 @@ - (void)handleFailureInMethod:(SEL)selector va_list args; va_start(args, format); - NSString *reason = [[[NSString alloc] initWithFormat:format arguments:args] autorelease]; + NSString *reason = [[NSString alloc] initWithFormat:format arguments:args]; va_end(args); diff --git a/UnitTesting/KissXML.xcodeproj/project.pbxproj b/UnitTesting/KissXML.xcodeproj/project.pbxproj index 8846ed97..68e30568 100644 --- a/UnitTesting/KissXML.xcodeproj/project.pbxproj +++ b/UnitTesting/KissXML.xcodeproj/project.pbxproj @@ -282,12 +282,14 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_OBJC_ARC = YES; COPY_PHASE_STRIP = NO; GCC_DYNAMIC_NO_PIC = NO; GCC_MODEL_TUNING = G5; GCC_OPTIMIZATION_LEVEL = 0; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = KissXML_Prefix.pch; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; INFOPLIST_FILE = Info.plist; INSTALL_PATH = "$(HOME)/Applications"; PRODUCT_NAME = KissXML; @@ -298,10 +300,12 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ENABLE_OBJC_ARC = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; GCC_MODEL_TUNING = G5; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = KissXML_Prefix.pch; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; INFOPLIST_FILE = Info.plist; INSTALL_PATH = "$(HOME)/Applications"; PRODUCT_NAME = KissXML; From bcf21109e692a9af5dcbaab022280f45bbd1422e Mon Sep 17 00:00:00 2001 From: Robbie Hanson Date: Tue, 22 Nov 2011 12:05:50 -0800 Subject: [PATCH 2/3] Adding safety net for DDXML_DEBUG_MEMORY_ISSUES definition. --- KissXML/DDXML.h | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/KissXML/DDXML.h b/KissXML/DDXML.h index 20f042e2..453de447 100644 --- a/KissXML/DDXML.h +++ b/KissXML/DDXML.h @@ -31,66 +31,66 @@ // This way, on Mac OS X it uses NSXML, and on iOS it uses KissXML. #ifndef NSXMLNode -#define NSXMLNode DDXMLNode + #define NSXMLNode DDXMLNode #endif #ifndef NSXMLElement -#define NSXMLElement DDXMLElement + #define NSXMLElement DDXMLElement #endif #ifndef NSXMLDocument -#define NSXMLDocument DDXMLDocument + #define NSXMLDocument DDXMLDocument #endif #ifndef NSXMLInvalidKind -#define NSXMLInvalidKind DDXMLInvalidKind + #define NSXMLInvalidKind DDXMLInvalidKind #endif #ifndef NSXMLDocumentKind -#define NSXMLDocumentKind DDXMLDocumentKind + #define NSXMLDocumentKind DDXMLDocumentKind #endif #ifndef NSXMLElementKind -#define NSXMLElementKind DDXMLElementKind + #define NSXMLElementKind DDXMLElementKind #endif #ifndef NSXMLAttributeKind -#define NSXMLAttributeKind DDXMLAttributeKind + #define NSXMLAttributeKind DDXMLAttributeKind #endif #ifndef NSXMLNamespaceKind -#define NSXMLNamespaceKind DDXMLNamespaceKind + #define NSXMLNamespaceKind DDXMLNamespaceKind #endif #ifndef NSXMLProcessingInstructionKind -#define NSXMLProcessingInstructionKind DDXMLProcessingInstructionKind + #define NSXMLProcessingInstructionKind DDXMLProcessingInstructionKind #endif #ifndef NSXMLCommentKind -#define NSXMLCommentKind DDXMLCommentKind + #define NSXMLCommentKind DDXMLCommentKind #endif #ifndef NSXMLTextKind -#define NSXMLTextKind DDXMLTextKind + #define NSXMLTextKind DDXMLTextKind #endif #ifndef NSXMLDTDKind -#define NSXMLDTDKind DDXMLDTDKind + #define NSXMLDTDKind DDXMLDTDKind #endif #ifndef NSXMLEntityDeclarationKind -#define NSXMLEntityDeclarationKind DDXMLEntityDeclarationKind + #define NSXMLEntityDeclarationKind DDXMLEntityDeclarationKind #endif #ifndef NSXMLAttributeDeclarationKind -#define NSXMLAttributeDeclarationKind DDXMLAttributeDeclarationKind + #define NSXMLAttributeDeclarationKind DDXMLAttributeDeclarationKind #endif #ifndef NSXMLElementDeclarationKind -#define NSXMLElementDeclarationKind DDXMLElementDeclarationKind + #define NSXMLElementDeclarationKind DDXMLElementDeclarationKind #endif #ifndef NSXMLNotationDeclarationKind -#define NSXMLNotationDeclarationKind DDXMLNotationDeclarationKind + #define NSXMLNotationDeclarationKind DDXMLNotationDeclarationKind #endif #ifndef NSXMLNodeOptionsNone -#define NSXMLNodeOptionsNone DDXMLNodeOptionsNone + #define NSXMLNodeOptionsNone DDXMLNodeOptionsNone #endif #ifndef NSXMLNodeExpandEmptyElement -#define NSXMLNodeExpandEmptyElement DDXMLNodeExpandEmptyElement + #define NSXMLNodeExpandEmptyElement DDXMLNodeExpandEmptyElement #endif #ifndef NSXMLNodeCompactEmptyElement -#define NSXMLNodeCompactEmptyElement DDXMLNodeCompactEmptyElement + #define NSXMLNodeCompactEmptyElement DDXMLNodeCompactEmptyElement #endif #ifndef NSXMLNodePrettyPrint -#define NSXMLNodePrettyPrint DDXMLNodePrettyPrint + #define NSXMLNodePrettyPrint DDXMLNodePrettyPrint #endif #endif // #if TARGET_OS_IPHONE @@ -189,4 +189,8 @@ // // The debugging macro adds a significant amount of overhead, and should NOT be enabled on production builds. -#define DDXML_DEBUG_MEMORY_ISSUES 0 +#if DEBUG + #define DDXML_DEBUG_MEMORY_ISSUES 0 +#else + #define DDXML_DEBUG_MEMORY_ISSUES 0 // Don't change me! +#endif From 3ecb7c326ffb9eccf08b62c7e20bbc806550e885 Mon Sep 17 00:00:00 2001 From: Robbie Hanson Date: Tue, 22 Nov 2011 12:16:45 -0800 Subject: [PATCH 3/3] Adding ability to detach a child node without bothering to fix the namespaces. --- KissXML/DDXMLNode.m | 17 ++++++++++------- KissXML/Private/DDXMLPrivate.h | 2 ++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/KissXML/DDXMLNode.m b/KissXML/DDXMLNode.m index b9950ec7..a2cbabcd 100644 --- a/KissXML/DDXMLNode.m +++ b/KissXML/DDXMLNode.m @@ -1738,7 +1738,7 @@ + (void)removeAllNamespacesFromNode:(xmlNodePtr)node * The attribute's surrounding prev/next pointers are properly updated to remove the attribute from the attr list. * Then, if the clean flag is YES, the attribute's parent, prev, next and doc pointers are set to null. **/ -+ (void)detachAttribute:(xmlAttrPtr)attr andClean:(BOOL)flag ++ (void)detachAttribute:(xmlAttrPtr)attr andClean:(BOOL)clean { xmlNodePtr parent = attr->parent; @@ -1768,7 +1768,7 @@ + (void)detachAttribute:(xmlAttrPtr)attr andClean:(BOOL)flag } } - if (flag) + if (clean) { // Nullify pointers attr->parent = NULL; @@ -1833,7 +1833,7 @@ + (void)removeAllAttributesFromNode:(xmlNodePtr)node * The child's surrounding prev/next pointers are properly updated to remove the child from the node's children list. * Then, if the clean flag is YES, the child's parent, prev, next and doc pointers are set to null. **/ -+ (void)detachChild:(xmlNodePtr)child andClean:(BOOL)flag ++ (void)detachChild:(xmlNodePtr)child andClean:(BOOL)clean andFixNamespaces:(BOOL)fixNamespaces { xmlNodePtr parent = child->parent; @@ -1865,11 +1865,14 @@ + (void)detachChild:(xmlNodePtr)child andClean:(BOOL)flag } } - if (flag) + if (fixNamespaces) { // Fix namesapces (namespace references that now point outside tree) + // Note: This must be done before we nullify pointers so we can search up the tree. [self recursiveFixDefaultNamespacesInNode:child withNewRoot:child]; - + } + if (clean) + { // Nullify pointers child->parent = NULL; child->prev = NULL; @@ -1885,7 +1888,7 @@ + (void)detachChild:(xmlNodePtr)child andClean:(BOOL)flag **/ + (void)detachChild:(xmlNodePtr)child { - [self detachChild:child andClean:YES]; + [self detachChild:child andClean:YES andFixNamespaces:YES]; } /** @@ -1904,7 +1907,7 @@ + (void)removeChild:(xmlNodePtr)child // We perform a bit of optimization here. // No need to bother nullifying pointers since we're about to free the node anyway. - [self detachChild:child andClean:NO]; + [self detachChild:child andClean:NO andFixNamespaces:NO]; xmlFreeNode(child); } diff --git a/KissXML/Private/DDXMLPrivate.h b/KissXML/Private/DDXMLPrivate.h index 83ec935f..c374d723 100644 --- a/KissXML/Private/DDXMLPrivate.h +++ b/KissXML/Private/DDXMLPrivate.h @@ -187,10 +187,12 @@ NS_INLINE BOOL IsXmlNsPtr(void *kindPtr) + (void)removeNamespace:(xmlNsPtr)ns fromNode:(xmlNodePtr)node; + (void)removeAllNamespacesFromNode:(xmlNodePtr)node; ++ (void)detachAttribute:(xmlAttrPtr)attr andClean:(BOOL)clean; + (void)detachAttribute:(xmlAttrPtr)attr; + (void)removeAttribute:(xmlAttrPtr)attr; + (void)removeAllAttributesFromNode:(xmlNodePtr)node; ++ (void)detachChild:(xmlNodePtr)child andClean:(BOOL)clean andFixNamespaces:(BOOL)fixNamespaces; + (void)detachChild:(xmlNodePtr)child; + (void)removeChild:(xmlNodePtr)child; + (void)removeAllChildrenFromNode:(xmlNodePtr)node;