ObjFW  Check-in [cb145d6634]

Overview
Comment:Forgot to hg add OFXMLParser test. Fixed.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cb145d6634b7dec26641b2a60dfd4210dde43718812f6320c4ecce9339be2b09
User & Date: js on 2009-07-17 20:11:17
Other Links: manifest | tags
Context
2009-07-19
13:04
A few new string methods. check-in: 1bbc11d7a5 user: js tags: trunk
2009-07-17
20:11
Forgot to hg add OFXMLParser test. Fixed. check-in: cb145d6634 user: js tags: trunk
17:17
Two minor changes. check-in: 5eae1c66bc user: js tags: trunk
Changes

Added tests/OFXMLParser/Makefile version [48699d3db9].



















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 version [e1028bfd04].









































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * Copyright (c) 2008 - 2009
 *   Jonathan Schleifer <js@webkeks.org>
 *
 * 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 <stdio.h>
#include <string.h>

#import "OFXMLParser.h"

@interface ParserDelegate: OFObject <OFXMLParserDelegate>
@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 = "bar<foo:bar  bar='b&amp;az'  qux=\"quux\">foo&lt;bar"
	    "<qux  >bar<baz name=''/>quxbar</xasd>";
	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;
}