mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
* Source/NSXMLDTD.m * Source/NSXMLDTDNode.m * Source/NSXMLElement.m * Source/NSXMLNode.m * Source/NSXMLPrivate.h: Reimplementation of all DOM classes based on libxml2. Implementation of all methods using libxml2 functions. * Tests/base/NSXMLDocument/basic.m * Tests/base/NSXMLElement/attributes.m * Tests/base/NSXMLElement/children.m * Tests/base/NSXMLNode/basic.m * Tests/base/NSXMLNode/children.m * Tests/base/NSXMLNode/kinds.m: Changes to test for new functionality. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@34789 72102866-910b-0410-8b05-ffd578937521
101 lines
3.4 KiB
Objective-C
101 lines
3.4 KiB
Objective-C
#import "ObjectTesting.h"
|
|
#import <Foundation/NSAutoreleasePool.h>
|
|
#import <Foundation/NSXMLDocument.h>
|
|
#import <Foundation/NSXMLElement.h>
|
|
|
|
int main()
|
|
{
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
NSArray *nodes = nil;
|
|
NSXMLDocument *node;
|
|
NSXMLDocument *node2;
|
|
NSXMLElement *elem;
|
|
NSString *documentXML =
|
|
@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
|
|
@"<bookstore>"
|
|
@" <book category=\"COOKING\">"
|
|
@" <title lang=\"en\">Everyday Italian</title>"
|
|
@" <author>Giada De Laurentiis</author>"
|
|
@" <year>2005</year>"
|
|
@" <price>30.00</price>"
|
|
@" </book>"
|
|
@" <book category=\"CHILDREN\">"
|
|
@" <title lang=\"en\">Harry Potter</title>"
|
|
@" <author>J K. Rowling</author>"
|
|
@" <year>2005</year>"
|
|
@" <price>29.99</price>"
|
|
@" </book>"
|
|
@" <book category=\"WEB\">"
|
|
@" <title lang=\"en\">XQuery Kick Start</title>"
|
|
@" <author>James McGovern</author>"
|
|
@" <author>Per Bothner</author>"
|
|
@" <author>Kurt Cagle</author>"
|
|
@" <author>James Linn</author>"
|
|
@" <author>Vaidyanathan Nagarajan</author>"
|
|
@" <year>2003</year>"
|
|
@" <price>49.99</price>"
|
|
@" </book>"
|
|
@" <book category=\"WEB\">"
|
|
@" <title lang=\"en\">Learning XML</title>"
|
|
@" <author>Erik T. Ray</author>"
|
|
@" <year>2003</year>"
|
|
@" <price>39.95</price>"
|
|
@" </book>"
|
|
@"</bookstore>";
|
|
|
|
node = [NSXMLDocument alloc];
|
|
PASS_EXCEPTION([node initWithData: nil options: 0 error: 0],
|
|
NSInvalidArgumentException,
|
|
"Cannot initialise an XML document with nil data");
|
|
|
|
node = [NSXMLDocument alloc];
|
|
PASS_EXCEPTION([node initWithData: (NSData*)@"bad" options: 0 error: 0],
|
|
NSInvalidArgumentException,
|
|
"Cannot initialise an XML document with bad data class");
|
|
|
|
node = [[NSXMLDocument alloc] init];
|
|
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");
|
|
|
|
PASS_RUNS([node setRootElement: nil], "setting a nil root is ignored");
|
|
PASS_EQUAL([node rootElement], elem, "root element remains");
|
|
|
|
node = [[NSXMLDocument alloc] initWithXMLString:documentXML
|
|
options:0
|
|
error:NULL];
|
|
elem = [node rootElement];
|
|
PASS(node != nil, "document was initialized from a string");
|
|
PASS_EQUAL([node rootElement], elem, "root element is correct");
|
|
PASS_EQUAL([elem name],@"bookstore", "root element is bookstore");
|
|
|
|
nodes = [node nodesForXPath:@"/bookstore/book" error:NULL];
|
|
PASS([nodes count] == 4,
|
|
"Xpath function returns the correct number of elements (4)");
|
|
elem = [nodes objectAtIndex: 0];
|
|
PASS_EQUAL([elem class],[NSXMLElement class],
|
|
"first node in Xpath result is an element");
|
|
PASS([[elem name] isEqualToString: @"book"],
|
|
"Got the correct elements from XPath query");
|
|
|
|
node2 = [[NSXMLDocument alloc] initWithXMLString:documentXML
|
|
options:0
|
|
error:NULL];
|
|
PASS([node isEqual: node2],
|
|
"Equal documents are equivalent");
|
|
|
|
[arp release];
|
|
arp = nil;
|
|
|
|
// [elem release];
|
|
// [node release];
|
|
return 0;
|
|
}
|