mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +00:00
Update testcses to cover both parsers
This commit is contained in:
parent
ca2abf51f7
commit
2b704dd9d4
2 changed files with 34 additions and 12 deletions
|
@ -5,10 +5,16 @@ int main()
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
NSXMLParser *parser;
|
NSXMLParser *parser;
|
||||||
|
Class c = NSClassFromString(@"GSSloppyXMLParser");
|
||||||
|
|
||||||
|
parser = [c new];
|
||||||
|
test_alloc(@"GSSloppyXMLParser");
|
||||||
|
test_NSObject(@"GSSloppyXMLParser", [NSArray arrayWithObject: parser]);
|
||||||
|
|
||||||
parser = [NSXMLParser new];
|
parser = [NSXMLParser new];
|
||||||
test_alloc(@"NSXMLParser");
|
test_alloc(@"NSXMLParser");
|
||||||
test_NSObject(@"NSXMLParser", [NSArray arrayWithObject: parser]);
|
test_NSObject(@"NSXMLParser", [NSArray arrayWithObject: parser]);
|
||||||
|
|
||||||
[arp release]; arp = nil;
|
[arp release]; arp = nil;
|
||||||
|
|
||||||
/* Don't release the parser ... it appears that on OSX there is a bug in
|
/* Don't release the parser ... it appears that on OSX there is a bug in
|
||||||
|
|
|
@ -267,14 +267,14 @@ testParser(NSXMLParser *parser, NSString *expect)
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
testParseData(NSData *xml, NSString *expect)
|
testParseData(NSData *xml, NSString *expect, BOOL strict)
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
NSXMLParser *parser;
|
NSXMLParser *parser;
|
||||||
Class c = NSClassFromString(@"GSSloppyXMLParser");
|
Class c = NSClassFromString(@"GSSloppyXMLParser");
|
||||||
BOOL result;
|
BOOL result;
|
||||||
|
|
||||||
c = Nil;
|
if (strict) c = Nil;
|
||||||
if (Nil == c) c = [NSXMLParser class];
|
if (Nil == c) c = [NSXMLParser class];
|
||||||
parser = [[c alloc] initWithData: xml];
|
parser = [[c alloc] initWithData: xml];
|
||||||
result = testParser(parser, expect);
|
result = testParser(parser, expect);
|
||||||
|
@ -284,29 +284,29 @@ testParseData(NSData *xml, NSString *expect)
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
testParseCString(const char *xmlBytes, NSString *expect)
|
testParseCString(const char *xmlBytes, NSString *expect, BOOL strict)
|
||||||
{
|
{
|
||||||
NSData *xml;
|
NSData *xml;
|
||||||
|
|
||||||
xml = [NSData dataWithBytes: xmlBytes length: strlen(xmlBytes)];
|
xml = [NSData dataWithBytes: xmlBytes length: strlen(xmlBytes)];
|
||||||
return testParseData(xml, expect);
|
return testParseData(xml, expect, strict);
|
||||||
}
|
}
|
||||||
|
|
||||||
static BOOL
|
static BOOL
|
||||||
testParseStream(NSInputStream *stream, NSString *expect)
|
testParseStream(NSInputStream *stream, NSString *expect, BOOL strict)
|
||||||
{
|
{
|
||||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||||
NSXMLParser *parser;
|
NSXMLParser *parser;
|
||||||
Class c = NSClassFromString(@"GSSloppyXMLParser");
|
Class c = NSClassFromString(@"GSSloppyXMLParser");
|
||||||
BOOL result;
|
BOOL result;
|
||||||
|
|
||||||
c = Nil;
|
if (strict) c = Nil;
|
||||||
if (Nil == c) c = [NSXMLParser class];
|
if (Nil == c) c = [NSXMLParser class];
|
||||||
parser = [[c alloc] initWithStream: stream];
|
parser = [[c alloc] initWithStream: stream];
|
||||||
result = testParser(parser, expect);
|
result = testParser(parser, expect);
|
||||||
|
|
||||||
[arp release];
|
[arp release];
|
||||||
return YES;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
|
@ -321,8 +321,12 @@ int main()
|
||||||
NSString *e1 =
|
NSString *e1 =
|
||||||
@"parserDidStartDocument:\nparser:didStartElement:namespaceURI:qualifiedName:attributes: test test {\n x = 1;\n}\nparser:didEndElement:namespaceURI:qualifiedName: test test\nparserDidEndDocument:\n";
|
@"parserDidStartDocument:\nparser:didStartElement:namespaceURI:qualifiedName:attributes: test test {\n x = 1;\n}\nparser:didEndElement:namespaceURI:qualifiedName: test test\nparserDidEndDocument:\n";
|
||||||
|
|
||||||
PASS((testParseCString(x1, e1)), "simple document 1")
|
PASS((testParseCString(x1, e1, YES)), "simple document 1 (strict)")
|
||||||
PASS((testParseCString(x1e, e1)), "simple document 1 without header")
|
PASS((testParseCString(x1, e1, NO)), "simple document 1 (sloppy)")
|
||||||
|
PASS((testParseCString(x1e, e1, YES)),
|
||||||
|
"simple document 1 (strict) without header")
|
||||||
|
PASS((testParseCString(x1e, e1, NO)),
|
||||||
|
"simple document 1 (sloppy) without header")
|
||||||
|
|
||||||
/* Now perform any tests using .xml and .result pairs of files in
|
/* Now perform any tests using .xml and .result pairs of files in
|
||||||
* the ParseData subdirectory.
|
* the ParseData subdirectory.
|
||||||
|
@ -341,11 +345,22 @@ int main()
|
||||||
str = [xmlPath stringByDeletingPathExtension];
|
str = [xmlPath stringByDeletingPathExtension];
|
||||||
str = [str stringByAppendingPathExtension: @"result"];
|
str = [str stringByAppendingPathExtension: @"result"];
|
||||||
xmlData = [NSData dataWithContentsOfFile: xmlPath];
|
xmlData = [NSData dataWithContentsOfFile: xmlPath];
|
||||||
|
|
||||||
result = [NSString stringWithContentsOfFile: str];
|
result = [NSString stringWithContentsOfFile: str];
|
||||||
PASS((testParseData(xmlData, result)), "parse data: %s", [xmlName UTF8String])
|
PASS((testParseData(xmlData, result, YES)),
|
||||||
|
"parse data (strict): %s", [xmlName UTF8String])
|
||||||
|
|
||||||
|
result = [NSString stringWithContentsOfFile: str];
|
||||||
|
PASS((testParseData(xmlData, result, NO)),
|
||||||
|
"parse data (sloppy): %s", [xmlName UTF8String])
|
||||||
|
|
||||||
stream = [NSInputStream inputStreamWithFileAtPath:xmlPath];
|
stream = [NSInputStream inputStreamWithFileAtPath:xmlPath];
|
||||||
PASS((testParseStream(stream, result)), "parse stream: %s", [xmlName UTF8String])
|
PASS((testParseStream(stream, result, YES)),
|
||||||
|
"parse stream (strict): %s", [xmlName UTF8String])
|
||||||
|
|
||||||
|
stream = [NSInputStream inputStreamWithFileAtPath:xmlPath];
|
||||||
|
PASS((testParseStream(stream, result, NO)),
|
||||||
|
"parse stream (sloppy): %s", [xmlName UTF8String])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,7 +380,8 @@ parserDidEndDocument:\n\
|
||||||
@"<file>&&foo;A</file>", [mgr currentDirectoryPath]];
|
@"<file>&&foo;A</file>", [mgr currentDirectoryPath]];
|
||||||
|
|
||||||
dat = [str dataUsingEncoding: NSUTF8StringEncoding];
|
dat = [str dataUsingEncoding: NSUTF8StringEncoding];
|
||||||
PASS((testParseData(dat, exp)), "external entity")
|
PASS((testParseData(dat, exp, YES)), "external entity (strict)")
|
||||||
|
PASS((testParseData(dat, exp, YES)), "external entity (sloppy)")
|
||||||
}
|
}
|
||||||
|
|
||||||
[arp release]; arp = nil;
|
[arp release]; arp = nil;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue