2012-01-05 18:52:57 +00:00
|
|
|
#import "ObjectTesting.h"
|
|
|
|
#import <Foundation/NSAutoreleasePool.h>
|
|
|
|
#import <Foundation/NSXMLDocument.h>
|
2012-01-06 13:56:46 +00:00
|
|
|
#import <Foundation/NSXMLElement.h>
|
2012-01-05 18:52:57 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2012-01-06 13:56:46 +00:00
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
NSXMLDocument *node;
|
|
|
|
NSXMLElement *elem;
|
2012-01-05 18:52:57 +00:00
|
|
|
|
|
|
|
node = [NSXMLDocument alloc];
|
2012-01-05 20:46:51 +00:00
|
|
|
PASS_EXCEPTION([node initWithData: nil options: 0 error: 0],
|
2012-01-05 18:52:57 +00:00
|
|
|
NSInvalidArgumentException,
|
|
|
|
"Cannot initialise an XML document with nil data");
|
|
|
|
|
|
|
|
node = [NSXMLDocument alloc];
|
2012-01-05 20:46:51 +00:00
|
|
|
PASS_EXCEPTION([node initWithData: (NSData*)@"bad" options: 0 error: 0],
|
2012-01-05 18:52:57 +00:00
|
|
|
NSInvalidArgumentException,
|
|
|
|
"Cannot initialise an XML document with bad data class");
|
|
|
|
|
|
|
|
node = [[NSXMLDocument alloc] init];
|
2012-01-06 13:56:46 +00:00
|
|
|
test_alloc(@"NSXMLDocument");
|
|
|
|
test_NSObject(@"NSXMLDocument", [NSArray arrayWithObject: node]);
|
|
|
|
|
|
|
|
elem = [[NSXMLElement alloc] initWithName: @"elem1"];
|
|
|
|
[node addChild: elem];
|
|
|
|
PASS_EQUAL([[node children] lastObject], elem, "can add elem to doc");
|
|
|
|
[elem release];
|
|
|
|
elem = [[NSXMLElement alloc] initWithName: @"root"];
|
|
|
|
[node setRootElement: elem];
|
|
|
|
PASS_EQUAL([[node children] lastObject], elem, "can set elem as root");
|
|
|
|
PASS([[node children] count] == 1, "set root removes other children");
|
|
|
|
|
2012-01-07 07:26:18 +00:00
|
|
|
PASS_RUNS([node setRootElement: nil], "setting a nil root is ignored");
|
|
|
|
PASS_EQUAL([node rootElement], elem, "root element remains");
|
|
|
|
|
2012-01-05 18:52:57 +00:00
|
|
|
[arp release];
|
|
|
|
arp = nil;
|
|
|
|
|
2012-01-07 07:54:28 +00:00
|
|
|
[elem release];
|
2012-01-05 18:52:57 +00:00
|
|
|
[node release];
|
|
|
|
return 0;
|
|
|
|
}
|