* Source/NSXMLElement.m (-addAttribute:): Raise correct exception.

* Tests/base/NSXMLNode/children.m: Add test cases for attributes.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34879 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2012-03-05 09:41:40 +00:00
parent b2e4fadd62
commit 391c16f630
3 changed files with 26 additions and 10 deletions

View file

@ -1,3 +1,8 @@
2012-03-05 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSXMLElement.m (-addAttribute:): Raise correct exception.
* Tests/base/NSXMLNode/children.m: Add test cases for attributes.
2012-03-05 Eric Wasylishen <ewasylishen@gmail.com> 2012-03-05 Eric Wasylishen <ewasylishen@gmail.com>
* Tests/base/NSString/locale.m: Expand test of compare: * Tests/base/NSString/locale.m: Expand test of compare:

View file

@ -155,7 +155,7 @@ GS_PRIVATE_INTERNAL(NSXMLElement)
if (nil != [attribute parent]) if (nil != [attribute parent])
{ {
[NSException raise: @"NSInvalidArgumentException" [NSException raise: NSInternalInconsistencyException
format: @"Tried to add attribute to multiple parents."]; format: @"Tried to add attribute to multiple parents."];
} }

View file

@ -11,23 +11,34 @@ int main()
NS_DURING NS_DURING
{ {
NSXMLElement *node = [[NSXMLElement alloc] initWithKind: NSXMLElementKind]; NSXMLElement *node = [[NSXMLElement alloc] initWithKind: NSXMLElementKind];
NSXMLDocument *docA = [[NSXMLDocument alloc] initWithRootElement: node]; NSXMLDocument *docA = nil;
NSXMLDocument *docB = nil; NSXMLDocument *docB = nil;
NSXMLNode *attr; NSXMLNode *attr;
[node setName: @"name"];
attr = [NSXMLNode attributeWithName: @"key" stringValue: @"value"];
[node addAttribute: attr];
PASS(node == [attr parent], "Attr parent is set to node");
PASS_EXCEPTION([node addAttribute: attr], NSInternalInconsistencyException, "Cannot add attribute twice");
[node release];
PASS(nil == [attr parent], "Attr parent is set to nil");
node = [[NSXMLElement alloc] initWithKind: NSXMLElementKind];
[node setName: @"name"];
[node addAttribute: attr];
docA = [[NSXMLDocument alloc] initWithRootElement: node];
PASS(docA == [node parent], "Parent is set to docA");
// NSLog(@"Here..."); // NSLog(@"Here...");
[node detach]; [node detach];
PASS(docB = [[NSXMLDocument alloc] initWithRootElement: node], "Detached children can be reattached."); PASS((docB = [[NSXMLDocument alloc] initWithRootElement: node]), "Detached children can be reattached.");
[docA release]; [docA release];
// NSLog(@"Here... again"); // NSLog(@"Here... again");
PASS(docB == [node parent], "Parent is set to docB"); PASS(docB == [node parent], "Parent is set to docB");
[node setName: @"name"];
attr = [NSXMLNode attributeWithName: @"key" stringValue: @"value"];
[node addAttribute: attr];
PASS(node == [attr parent], "Attr parent is set to node");
[docB release]; [docB release];
PASS(nil == [node parent], "Parent is set to nil"); PASS(nil == [node parent], "Parent is set to nil");
docA = [[NSXMLDocument alloc] initWithRootElement: node]; docA = [[NSXMLDocument alloc] initWithRootElement: node];
@ -35,12 +46,12 @@ int main()
PASS_EXCEPTION(docB = [[NSXMLDocument alloc] initWithRootElement: node], NSInternalInconsistencyException, "Reusing a child throws an exception"); PASS_EXCEPTION(docB = [[NSXMLDocument alloc] initWithRootElement: node], NSInternalInconsistencyException, "Reusing a child throws an exception");
// NSLog(@"Last time"); // NSLog(@"Last time");
//[node release]; [node release];
//[docA release]; //[docA release];
} }
NS_HANDLER NS_HANDLER
{ {
PASS (NO, "NSXML child handling working."); // I don't think this is valid... commenting out for now. PASS (0 == 1, "NSXML child handling working."); // I don't think this is valid... commenting out for now.
} }
NS_ENDHANDLER NS_ENDHANDLER
END_SET("NSXMLNode - handling children") END_SET("NSXMLNode - handling children")