mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Fix execute_xpath() to return an NSError when expression can't be evaluated; Remove previous attributes when setting attributes; Add related tests
This commit is contained in:
parent
3f994d3ee1
commit
50f447f5b8
5 changed files with 81 additions and 3 deletions
35
Tests/base/NSXMLNode/xpath.m
Normal file
35
Tests/base/NSXMLNode/xpath.m
Normal file
|
@ -0,0 +1,35 @@
|
|||
#import "ObjectTesting.h"
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSXMLElement.h>
|
||||
#import <Foundation/NSXMLDocument.h>
|
||||
#import <Foundation/NSXMLNode.h>
|
||||
#import <Foundation/NSError.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
|
||||
NSString *sourceXML = @"<parent>"
|
||||
"<chyld>buzz</chyld>"
|
||||
"<otherchyld>woody</otherchyld>"
|
||||
"<zorgtree>gollyfoo</zorgtree>"
|
||||
"<ln:loner xmlns:ln=\"http://loner.ns\">POW</ln:loner>"
|
||||
"</parent>";
|
||||
NSXMLDocument *doc = [[[NSXMLDocument alloc] initWithXMLString:sourceXML options:0 error:NULL] autorelease];
|
||||
PASS(doc != nil, "created a document from an XML string");
|
||||
|
||||
NSError *anError = nil;
|
||||
NSXMLNode *node = [[doc nodesForXPath:@"//chyld" error:&anError] lastObject];
|
||||
PASS(node != nil, "access chyld node");
|
||||
PASS(anError == nil, "no error accessing chyld node");
|
||||
PASS_EQUAL([node stringValue], @"buzz", "retrieve chyld node");
|
||||
|
||||
node = [[doc nodesForXPath:@"//ln:loner" error:&anError] lastObject];
|
||||
PASS(node == nil, "can't access ln:loner node if namespace not defined at top");
|
||||
PASS(anError != nil, "should get error when fail to access node");
|
||||
|
||||
[arp release];
|
||||
arp = nil;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue