Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -1,6 +1,5 @@ include ../extra.mk -SUBDIRS = OFXMLParser \ - ${OBJC_SYNC} +SUBDIRS = ${OBJC_SYNC} include ../buildsys.mk DELETED tests/OFXMLParser/Makefile Index: tests/OFXMLParser/Makefile ================================================================== --- tests/OFXMLParser/Makefile +++ tests/OFXMLParser/Makefile @@ -1,29 +0,0 @@ -PROG_NOINST = ofxmlparser${PROG_SUFFIX} -SRCS = OFXMLParser.m - -include ../../buildsys.mk -include ../../extra.mk - -CPPFLAGS += -I../../src -I../.. -LIBS := -L../../src -lobjfw ${LIBS} - -.PHONY: run - -all: run -run: ${PROG_NOINST} - rm -f libobjfw.so.0 libobjfw.so.0.1 libobjfw.dll libobjfw.dylib - if test -f ../../src/libobjfw.so; then \ - ln -s ../../src/libobjfw.so libobjfw.so.0; \ - ln -s ../../src/libobjfw.so libobjfw.so.0.1; \ - fi - if test -f ../../src/libobjfw.dll; then \ - ln ../../src/libobjfw.dll libobjfw.dll; \ - fi - if test -f ../../src/libobjfw.dylib; then \ - ln -s ../../src/libobjfw.dylib libobjfw.dylib; \ - fi - LD_LIBRARY_PATH=.$${LD_LIBRARY_PATH+:}$$LD_LIBRARY_PATH \ - DYLD_LIBRARY_PATH=.$${DYLD_LIBRARY_PATH+:}$$DYLD_LIBRARY_PATH \ - ${TEST_LAUNCHER} ./${PROG_NOINST}; EXIT=$$?; \ - rm -f libobjfw.so.0 libobjfw.so.0.1 libobjfw.dll libobjfw.dylib; \ - exit $$EXIT DELETED tests/OFXMLParser/OFXMLParser.m Index: tests/OFXMLParser/OFXMLParser.m ================================================================== --- tests/OFXMLParser/OFXMLParser.m +++ tests/OFXMLParser/OFXMLParser.m @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2008 - 2009 - * Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of libobjfw. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE included in - * the packaging of this file. - */ - -#include "config.h" - -#include -#include - -#import "OFXMLParser.h" - -@interface ParserDelegate: OFObject -@end - -@implementation ParserDelegate -- (void)xmlParser: (OFXMLParser*)parser - didStartTagWithName: (OFString*)name - prefix: (OFString*)prefix - namespace: (OFString*)ns - attributes: (OFArray*)attrs -{ - OFXMLAttribute **attrs_data; - size_t i, attrs_count; - - printf("START\nname=\"%s\"\nprefix=\"%s\"\nns=\"%s\"\n", - [name cString], [prefix cString], [ns cString]); - - attrs_data = [attrs data]; - attrs_count = [attrs count]; - - for (i = 0; i < attrs_count; i++) { - OFString *attr_name = [attrs_data[i] name]; - OFString *attr_prefix = [attrs_data[i] prefix]; - OFString *attr_ns = [attrs_data[i] namespace]; - OFString *attr_value = [attrs_data[i] stringValue]; - - printf("ATTR:\n name=\"%s\"\n", [attr_name cString]); - if (attr_prefix != nil) - printf(" prefix=\"%s\"\n", [attr_prefix cString]); - if (attr_ns != nil) - printf(" ns=\"%s\"\n", [attr_ns cString]); - printf(" value=\"%s\"\n", [attr_value cString]); - } - - puts(""); -} - -- (void)xmlParser: (OFXMLParser*)parser - didEndTagWithName: (OFString*)name - prefix: (OFString*)prefix - namespace: (OFString*)ns -{ - printf("END\nname=\"%s\"\nprefix=\"%s\"\nns=\"%s\"\n\n", - [name cString], [prefix cString], [ns cString]); -} - -- (void)xmlParser: (OFXMLParser*)parser - foundString: (OFString*)string -{ - printf("STRING\n\"%s\"\n\n", [string cString]); -} - -- (void)xmlParser: (OFXMLParser*)parser - foundComment: (OFString*)comment -{ - printf("COMMENT\n\"%s\"\n\n", [comment cString]); -} - -- (OFString*)xmlParser: (OFXMLParser*)parser - foundUnknownEntityNamed: (OFString*)entity -{ - if ([entity isEqual: @"foo"]) - return @"foobar"; - - return nil; -} -@end - -int -main() -{ - const char *foo = "bar\r\n" - "foo<barbar quxbar\r\n" - ""; - size_t len = strlen(foo); - size_t i; - OFXMLParser *parser = [OFXMLParser xmlParser]; - - [parser setDelegate: [[ParserDelegate alloc] init]]; - - /* Simulate a stream where we only get chunks */ - for (i = 0; i < len; i += 2) { - if (i + 2 > len) - [parser parseBuffer: foo + i - withSize: 1]; - else - [parser parseBuffer: foo + i - withSize: 2]; - } - /* - for (i = 0; i < len; i++) - [parser parseBuffer: foo + i - withSize: 1]; - */ - - return 0; -} Index: tests_new/Makefile ================================================================== --- tests_new/Makefile +++ tests_new/Makefile @@ -12,11 +12,12 @@ object.m \ ${PLUGIN_M} \ string.m \ tcpsocket.m \ thread.m \ - xmlelement.m + xmlelement.m \ + xmlparser.m .PHONY: run run: all rm -f libobjfw.so.0 libobjfw.so.0.1 libobjfw.dll libobjfw.dylib if test -f ../src/libobjfw.so; then \ Index: tests_new/main.m ================================================================== --- tests_new/main.m +++ tests_new/main.m @@ -30,10 +30,11 @@ #endif extern void string_tests(); extern void tcpsocket_tests(); extern void thread_tests(); extern void xmlelement_tests(); +extern void xmlparser_tests(); static int fails = 0; static void output(OFString *str, int color) @@ -104,11 +105,12 @@ dictionary_tests(); list_tests(); tcpsocket_tests(); thread_tests(); xmlelement_tests(); + xmlparser_tests(); #ifdef OF_PLUGINS plugin_tests(); #endif return fails; } ADDED tests_new/xmlparser.m Index: tests_new/xmlparser.m ================================================================== --- tests_new/xmlparser.m +++ tests_new/xmlparser.m @@ -0,0 +1,190 @@ +/* + * Copyright (c) 2008 - 2009 + * Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of libobjfw. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE included in + * the packaging of this file. + */ + +#include "config.h" + +#include + +#import "OFXMLParser.h" +#import "OFAutoreleasePool.h" +#import "OFString.h" +#import "OFExceptions.h" + +#import "main.h" + +static OFString *module = @"OFXMLParser"; +static int i = 0; + +enum event_type { + TAG_START, + TAG_END, + STRING, + COMMENT +}; + +static void +callback(enum event_type et, OFString *name, OFString *prefix, OFString *ns, + OFArray *attrs, OFString *string, OFString *comment) +{ + OFString *msg; + id *data; + size_t count; + + i++; + msg = [OFString stringWithFormat: @"Parsing part #%d", i]; + + switch (i) { + case 1: + case 5: + TEST(msg, et == STRING && [string isEqual: @"bar"]) + break; + case 2: + /* FIXME: Namespace */ + data = [attrs data]; + count = [attrs count]; + + TEST(msg, et == TAG_START && [name isEqual: @"bar"] && + [prefix isEqual: @"foo"] && ns == nil && + attrs != nil && count == 2 && + /* Attribute 1 */ + [[data[0] name] isEqual: @"bar"] && + [data[0] prefix] == nil && + [[data[0] stringValue] isEqual: @"b&az"] && + [data[0] namespace] == nil && + /* Attribute 2 */ + [[data[1] name] isEqual: @"qux"] && + [[data[1] prefix] isEqual: @"qux"] && + [[data[1] stringValue] isEqual: @" quux "] && + [data[1] namespace] == nil) + break; + case 3: + TEST(msg, et == STRING && [string isEqual: @"foo\r\n" + "foo<barbar quxbar\r\n" + ""; + size_t j, len; + + TEST(@"+[xmlParser]", (parser = [OFXMLParser xmlParser])) + + TEST(@"-[setDelegate:]", + [parser setDelegate: [[[ParserDelegate alloc] init] autorelease]]) + + /* Simulate a stream where we only get chunks */ + len = strlen(str); + + for (j = 0; j < len; j+= 2) { + if (j + 2 > len) + [parser parseBuffer: str + j + withSize: 1]; + else + [parser parseBuffer: str + j + withSize: 2]; + } + + TEST(@"Checking if everything was parsed", i == 11) + + [pool release]; +}