2011-02-16 08:21:17 +00:00
|
|
|
#import <Foundation/Foundation.h>
|
2011-02-24 12:11:11 +00:00
|
|
|
#import "Testing.h"
|
2011-02-24 12:09:11 +00:00
|
|
|
#if defined(GNUSTEP_BASE_LIBRARY) && (GS_USE_LIBXML == 1)
|
2018-01-11 16:39:21 +00:00
|
|
|
#import <Foundation/NSFileManager.h>
|
2011-02-16 08:21:17 +00:00
|
|
|
#import <GNUstepBase/GSXML.h>
|
|
|
|
#import "ObjectTesting.h"
|
|
|
|
int main()
|
|
|
|
{
|
2024-11-15 13:00:56 +00:00
|
|
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
|
|
|
NSFileManager *mgr;
|
|
|
|
GSXMLParser *parser;
|
|
|
|
GSXMLDocument *doc;
|
|
|
|
GSXMLNamespace *namespace;
|
|
|
|
NSMutableArray *iparams;
|
|
|
|
NSMutableArray *oparams;
|
|
|
|
GSXMLNode *node;
|
|
|
|
GSXMLRPC *rpc;
|
|
|
|
NSString *str;
|
|
|
|
NSString *testPath;
|
|
|
|
NSString *absolutePath;
|
|
|
|
NSData *dat;
|
2011-02-16 08:21:17 +00:00
|
|
|
|
2024-11-15 13:00:56 +00:00
|
|
|
TEST_FOR_CLASS(@"GSXMLDocument", AUTORELEASE([GSXMLDocument alloc]),
|
2011-02-16 08:21:17 +00:00
|
|
|
"GSXMLDocument +alloc returns a GSXMLDocument");
|
|
|
|
|
2024-11-15 13:00:56 +00:00
|
|
|
TEST_FOR_CLASS(@"GSXMLDocument", [GSXMLDocument documentWithVersion: @"1.0"],
|
2011-02-16 08:21:17 +00:00
|
|
|
"GSXMLDocument +documentWithVersion: returns a GSXMLDocument");
|
|
|
|
|
2024-11-15 13:00:56 +00:00
|
|
|
TEST_FOR_CLASS(@"GSXMLNode", AUTORELEASE([GSXMLNode alloc]),
|
2011-02-16 08:21:17 +00:00
|
|
|
"GSXMLNode +alloc returns a GSXMLNode");
|
|
|
|
|
2024-11-15 13:00:56 +00:00
|
|
|
TEST_FOR_CLASS(@"GSXMLRPC", AUTORELEASE([GSXMLRPC alloc]),
|
2011-02-16 08:21:17 +00:00
|
|
|
"GSXMLRPC +alloc returns a GSXMLRPC instance");
|
|
|
|
|
|
|
|
NS_DURING
|
|
|
|
node = [GSXMLNode new];
|
|
|
|
PASS(node == nil, "GSXMLNode +new returns nil");
|
|
|
|
NS_HANDLER
|
|
|
|
PASS(node == nil, "GSXMLNode +new returns nil");
|
|
|
|
NS_ENDHANDLER
|
|
|
|
|
2024-11-15 13:00:56 +00:00
|
|
|
TEST_FOR_CLASS(@"GSXMLNamespace", AUTORELEASE([GSXMLNamespace alloc]),
|
2011-02-16 08:21:17 +00:00
|
|
|
"GSXMLNamespace +alloc returns a GSXMLNamespace");
|
|
|
|
|
|
|
|
|
|
|
|
NS_DURING
|
|
|
|
namespace = [GSXMLNamespace new];
|
|
|
|
PASS(namespace == nil, "GSXMLNamespace +new returns nil");
|
|
|
|
NS_HANDLER
|
|
|
|
PASS(namespace == nil, "GSXMLNamespace +new returns nil");
|
|
|
|
NS_ENDHANDLER
|
|
|
|
|
|
|
|
doc = [GSXMLDocument documentWithVersion: @"1.0"];
|
|
|
|
node = [doc makeNodeWithNamespace: nil name: @"nicola" content: nil];
|
|
|
|
PASS (node != nil,"Can create a document node");
|
|
|
|
|
|
|
|
[doc setRoot: node];
|
|
|
|
PASS([[doc root] isEqual: node],"Can set document node as root node");
|
|
|
|
|
|
|
|
[doc makeNodeWithNamespace: nil name: @"nicola" content: nil];
|
|
|
|
[node makeChildWithNamespace: nil
|
|
|
|
name: @"paragraph"
|
|
|
|
content: @"Hi this is some text"];
|
|
|
|
[node makeChildWithNamespace: nil
|
|
|
|
name: @"paragraph"
|
|
|
|
content: @"Hi this is even some more text"];
|
|
|
|
[doc setRoot: node];
|
|
|
|
PASS([[doc root] isEqual: node],
|
|
|
|
"Can set a document node (with children) as root node");
|
|
|
|
|
|
|
|
namespace = [node makeNamespaceHref: @"http: //www.gnustep.org"
|
|
|
|
prefix: @"gnustep"];
|
|
|
|
PASS(namespace != nil,"Can create a node namespace");
|
|
|
|
|
|
|
|
node = [doc makeNodeWithNamespace: namespace name: @"nicola" content: nil];
|
|
|
|
PASS([[node namespace] isEqual: namespace],
|
|
|
|
"Can create a node with a namespace");
|
|
|
|
|
|
|
|
node = [doc makeNodeWithNamespace: namespace name: @"another" content: nil];
|
|
|
|
PASS([[node namespace] isEqual: namespace],
|
|
|
|
"Can create a node with same namespace as another node");
|
|
|
|
|
|
|
|
PASS([[namespace prefix] isEqual: @"gnustep"],
|
|
|
|
"A namespace remembers its prefix");
|
|
|
|
|
|
|
|
|
2024-11-15 13:00:56 +00:00
|
|
|
rpc = AUTORELEASE([(GSXMLRPC*)[GSXMLRPC alloc]
|
|
|
|
initWithURL: @"http://localhost/"]);
|
2011-02-16 08:21:17 +00:00
|
|
|
PASS(rpc != nil, "Can initialise an RPC instance");
|
|
|
|
|
|
|
|
iparams = [NSMutableArray array];
|
|
|
|
oparams = [NSMutableArray array];
|
|
|
|
|
|
|
|
dat = [rpc buildMethod: @"method" params: nil];
|
|
|
|
PASS(dat != nil, "Can build an empty method call (nil params)");
|
|
|
|
str = [rpc parseMethod: dat params: oparams];
|
|
|
|
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
|
|
|
|
"Can parse an empty method call (nil params)");
|
|
|
|
|
|
|
|
dat = [rpc buildMethod: @"method" params: iparams];
|
|
|
|
PASS(dat != nil, "Can build an empty method call");
|
|
|
|
str = [rpc parseMethod: dat params: oparams];
|
|
|
|
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
|
|
|
|
"Can parse an empty method call");
|
|
|
|
|
|
|
|
[iparams addObject: @"a string"];
|
|
|
|
dat = [rpc buildMethod: @"method" params: iparams];
|
|
|
|
PASS(dat != nil, "Can build a method call with a string");
|
|
|
|
str = [rpc parseMethod: dat params: oparams];
|
|
|
|
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
|
|
|
|
"Can parse a method call with a string");
|
|
|
|
|
|
|
|
[rpc setCompact: YES];
|
|
|
|
str = [rpc buildMethodCall: @"method" params: iparams];
|
|
|
|
[rpc setCompact: NO];
|
|
|
|
str = [str stringByReplacingString: @"<string>" withString: @""];
|
|
|
|
str = [str stringByReplacingString: @"</string>" withString: @""];
|
|
|
|
str = [rpc parseMethod: [str dataUsingEncoding: NSUTF8StringEncoding]
|
|
|
|
params: oparams];
|
|
|
|
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
|
|
|
|
"Can parse a method call with a string without the <string> element");
|
|
|
|
|
|
|
|
[iparams addObject: [NSNumber numberWithInt: 4]];
|
|
|
|
dat = [rpc buildMethod: @"method" params: iparams];
|
|
|
|
PASS(dat != nil, "Can build a method call with an integer");
|
|
|
|
str = [rpc parseMethod: dat params: oparams];
|
|
|
|
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
|
|
|
|
"Can parse a method call with an integer");
|
|
|
|
|
|
|
|
[iparams addObject: [NSNumber numberWithFloat: 4.5]];
|
|
|
|
dat = [rpc buildMethod: @"method" params: iparams];
|
|
|
|
PASS(dat != nil, "Can build a method call with a float");
|
|
|
|
str = [rpc parseMethod: dat params: oparams];
|
|
|
|
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
|
|
|
|
"Can parse a method call with a float");
|
|
|
|
|
|
|
|
[iparams addObject: [NSData dataWithBytes: "1234" length: 4]];
|
|
|
|
dat = [rpc buildMethod: @"method" params: iparams];
|
|
|
|
PASS(dat != nil, "Can build a method call with binary data");
|
|
|
|
str = [rpc parseMethod: dat params: oparams];
|
|
|
|
PASS([str isEqual: @"method"] && [iparams isEqual: oparams],
|
|
|
|
"Can parse a method call with binary data");
|
|
|
|
|
2013-03-16 17:40:56 +00:00
|
|
|
[rpc setTimeZone: [NSTimeZone systemTimeZone]];
|
2011-02-16 08:21:17 +00:00
|
|
|
[iparams addObject: [NSDate date]];
|
|
|
|
dat = [rpc buildMethod: @"method" params: iparams];
|
|
|
|
PASS(dat != nil, "Can build a method call with a date");
|
|
|
|
str = [rpc parseMethod: dat params: oparams];
|
|
|
|
PASS([str isEqual: @"method"]
|
|
|
|
&& [[iparams description] isEqual: [oparams description]],
|
|
|
|
"Can parse a method call with a date");
|
|
|
|
|
2018-01-11 16:39:21 +00:00
|
|
|
mgr = [NSFileManager defaultManager];
|
2022-08-10 15:15:16 +00:00
|
|
|
testPath = [[mgr currentDirectoryPath]
|
|
|
|
stringByAppendingPathComponent: @"GNUmakefile"];
|
|
|
|
absolutePath = [[NSURL fileURLWithPath: testPath] absoluteString];
|
2018-01-11 16:39:21 +00:00
|
|
|
|
|
|
|
str = [NSString stringWithFormat:
|
|
|
|
@"<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
|
|
|
|
@"<!DOCTYPE foo [\n"
|
2022-08-10 15:15:16 +00:00
|
|
|
@"<!ENTITY foo SYSTEM \"%@\">\n"
|
2018-01-11 16:39:21 +00:00
|
|
|
@"]>\n"
|
2022-08-10 15:15:16 +00:00
|
|
|
@"<file>&&foo;A</file>", absolutePath];
|
2018-01-11 16:39:21 +00:00
|
|
|
|
|
|
|
parser = [GSXMLParser parserWithData:
|
|
|
|
[str dataUsingEncoding: NSUTF8StringEncoding]];
|
|
|
|
[parser substituteEntities: YES];
|
|
|
|
[parser parse];
|
|
|
|
PASS_EQUAL([[[parser document] root] content], @"&A",
|
|
|
|
"external entity is ignored")
|
2011-02-16 08:21:17 +00:00
|
|
|
|
2018-01-14 12:30:13 +00:00
|
|
|
parser = [GSXMLParser parserWithData:
|
|
|
|
[str dataUsingEncoding: NSUTF8StringEncoding]];
|
|
|
|
[parser substituteEntities: YES];
|
|
|
|
[parser resolveEntities: YES];
|
|
|
|
[parser parse];
|
|
|
|
str = [[[parser document] root] content];
|
|
|
|
PASS([str rangeOfString: @"MAKEFILES"].length > 0,
|
|
|
|
"external entity is resolved")
|
|
|
|
|
|
|
|
str = @"<!DOCTYPE plist PUBLIC \"-//GNUstep//DTD plist 0.9//EN\""
|
|
|
|
@" \"http://www.gnustep.org/plist-0_9.xml\">\n"
|
|
|
|
@"<plist></plist>";
|
|
|
|
parser = [GSXMLParser parserWithData:
|
|
|
|
[str dataUsingEncoding: NSUTF8StringEncoding]];
|
|
|
|
[parser substituteEntities: YES];
|
|
|
|
[parser resolveEntities: YES];
|
|
|
|
[parser doValidityChecking: YES];
|
|
|
|
PASS([parser parse] == NO, "empty plist is not valid")
|
|
|
|
|
|
|
|
str = @"<!DOCTYPE plist PUBLIC \"-//GNUstep//DTD plist 0.9//EN\""
|
|
|
|
@" \"http://www.gnustep.org/plist-0_9.xml\">\n"
|
|
|
|
@"<plist><string>xxx</string></plist>";
|
|
|
|
parser = [GSXMLParser parserWithData:
|
|
|
|
[str dataUsingEncoding: NSUTF8StringEncoding]];
|
|
|
|
[parser substituteEntities: YES];
|
|
|
|
[parser resolveEntities: YES];
|
|
|
|
[parser doValidityChecking: YES];
|
|
|
|
PASS([parser parse] == YES, "plist containing string is valid")
|
|
|
|
|
|
|
|
PASS_EQUAL([[[[[parser document] root] firstChild] firstChild] content],
|
|
|
|
@"xxx", "root/plist/string is parsed")
|
|
|
|
|
2011-02-16 08:21:17 +00:00
|
|
|
[arp release]; arp = nil;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
int main(int argc,char **argv)
|
|
|
|
{
|
2011-02-24 18:53:31 +00:00
|
|
|
START_SET("GSXML")
|
|
|
|
SKIP("GSXML support unavailable");
|
|
|
|
END_SET("GSXML")
|
2011-02-16 08:21:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|