ADDED tests/OFXMLParser/Makefile Index: tests/OFXMLParser/Makefile ================================================================== --- tests/OFXMLParser/Makefile +++ tests/OFXMLParser/Makefile @@ -0,0 +1,25 @@ +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 + ln -s ../../src/libobjfw.so libobjfw.so.0 + ln -s ../../src/libobjfw.so libobjfw.so.0.1 + if test -f ../../src/libobjfw.dll; then \ + ln ../../src/libobjfw.dll libobjfw.dll; \ + fi + ln -s ../../src/libobjfw.dylib libobjfw.dylib + 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 ADDED tests/OFXMLParser/OFXMLParser.m Index: tests/OFXMLParser/OFXMLParser.m ================================================================== --- tests/OFXMLParser/OFXMLParser.m +++ tests/OFXMLParser/OFXMLParser.m @@ -0,0 +1,100 @@ +/* + * 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 +- (BOOL)xmlParser: (OFXMLParser*)parser + didStartTagWithName: (OFString*)name + andPrefix: (OFString*)prefix + andNamespace: (OFString*)ns + andAttributes: (OFDictionary*)attrs +{ + printf("START\nname=\"%s\"\nprefix=\"%s\"\nns=\"%s\"\n", + [name cString], [prefix cString], [ns cString]); + + if (attrs) { + OFIterator *iter = [attrs iterator]; + + for (;;) { + of_iterator_pair_t pair; + + pair = [iter nextKeyObjectPair]; + + if (pair.key == nil || pair.object == nil) + break; + + printf("ATTR: \"%s\"=\"%s\"\n", + [pair.key cString], [pair.object cString]); + } + } + + puts(""); + + return YES; +} + +- (BOOL)xmlParser: (OFXMLParser*)parser + didEndTagWithName: (OFString*)name + andPrefix: (OFString*)prefix + andNamespace: (OFString*)ns +{ + printf("END\nname=\"%s\"\nprefix=\"%s\"\nns=\"%s\"\n\n", + [name cString], [prefix cString], [ns cString]); + + return YES; +} + +- (BOOL)xmlParser: (OFXMLParser*)parser + foundString: (OFString*)string +{ + printf("STRING\n\"%s\"\n\n", [string cString]); + + return YES; +} +@end + +int +main() +{ + const char *foo = "barfoo<bar" + "barquxbar"; + 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; +}