ObjFW  Check-in [4047440267]

Overview
Comment:Migration of OFXMLParser tests to new testing framework.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 404744026720978e737b2654b9ccb1f6f52a974a1444a620ac91d46d413d8103
User & Date: js on 2009-10-03 13:33:54
Other Links: manifest | tags
Context
2009-10-03
13:37
Make the @synchronized test a manual test and remove old tests. check-in: 100512818f user: js tags: trunk
13:33
Migration of OFXMLParser tests to new testing framework. check-in: 4047440267 user: js tags: trunk
13:29
Set variables to nil to prevent double-free. check-in: 7a3968b9a3 user: js tags: trunk
Changes

Modified tests/Makefile from [be948a048f] to [43656d1194].

1
2
3
4
5
6
include ../extra.mk

SUBDIRS = OFXMLParser		\
	  ${OBJC_SYNC}

include ../buildsys.mk


<
|


1
2

3
4
5
include ../extra.mk


SUBDIRS = ${OBJC_SYNC}

include ../buildsys.mk

Deleted tests/OFXMLParser/Makefile version [dba452d7c8].

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
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 version [655d941dba].

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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * 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
@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<foo:bar  bar='b&amp;az'  qux:qux=\" quux \">\r\n"
	    "foo&lt;bar<qux  >bar <baz name='' test='&foo;'/>  quxbar\r\n</qux>"
	    "</foo:bar><!-- foo bar-baz -->";
	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;
}
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<




































































































































































































































Modified tests_new/Makefile from [4beb3c855a] to [dc24c10aa3].

10
11
12
13
14
15
16
17

18
19
20
21
22
23
24
       list.m		\
       main.m		\
       object.m		\
       ${PLUGIN_M}	\
       string.m		\
       tcpsocket.m	\
       thread.m		\
       xmlelement.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 \
		ln -s ../src/libobjfw.so libobjfw.so.0; \
		ln -s ../src/libobjfw.so libobjfw.so.0.1; \







|
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
       list.m		\
       main.m		\
       object.m		\
       ${PLUGIN_M}	\
       string.m		\
       tcpsocket.m	\
       thread.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 \
		ln -s ../src/libobjfw.so libobjfw.so.0; \
		ln -s ../src/libobjfw.so libobjfw.so.0.1; \

Modified tests_new/main.m from [209c9edd89] to [04713db63e].

28
29
30
31
32
33
34

35
36
37
38
39
40
41
#ifdef OF_PLUGINS
extern void plugin_tests();
#endif
extern void string_tests();
extern void tcpsocket_tests();
extern void thread_tests();
extern void xmlelement_tests();


static int fails = 0;

static void
output(OFString *str, int color)
{
#ifdef STDOUT







>







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifdef OF_PLUGINS
extern void plugin_tests();
#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)
{
#ifdef STDOUT
102
103
104
105
106
107
108

109
110
111
112
113
114
	dataarray_tests();
	array_tests();
	dictionary_tests();
	list_tests();
	tcpsocket_tests();
	thread_tests();
	xmlelement_tests();

#ifdef OF_PLUGINS
	plugin_tests();
#endif

	return fails;
}







>






103
104
105
106
107
108
109
110
111
112
113
114
115
116
	dataarray_tests();
	array_tests();
	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 version [50ad7436fa].





























































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * 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 <string.h>

#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<bar"])
		break;
	case 4:
		TEST(msg, et == TAG_START && [name isEqual: @"qux"] &&
		    prefix == nil && ns == nil)
		break;
	case 6:
		data = [attrs data];
		count = [attrs count];

		TEST(msg, et == TAG_START && [name isEqual: @"baz"] &&
		    prefix == nil && ns == nil && attrs != nil && count == 2 &&
		    /* Attribute 1 */
		    [[data[0] name] isEqual: @"name"] &&
		    [data[0] prefix] == nil &&
		    [[data[0] stringValue] isEqual: @""] &&
		    [data[0] namespace] == nil &&
		    /* Attribute 2 */
		    [[data[1] name] isEqual: @"test"] &&
		    [data[1] prefix] == nil &&
		    [[data[1] stringValue] isEqual: @"foobar"] &&
		    [data[1] namespace] == nil)
		break;
	case 7:
		TEST(msg, et == TAG_END && [name isEqual: @"baz"] &&
		    prefix == nil && ns == nil)
		break;
	case 8:
		TEST(msg, et == STRING && [string isEqual: @"quxbar"])
		break;
	case 9:
		TEST(msg, et == TAG_END && [name isEqual: @"qux"] &&
		    prefix == nil && ns == nil)
		break;
	case 10:
		/* FIXME: Namespace */
		TEST(msg, et == TAG_END && [name isEqual: @"bar"] &&
		    [prefix isEqual: @"foo"] && ns == nil)
		break;
	case 11:
		TEST(msg, et == COMMENT && [comment isEqual: @"foo bar-baz"])
		break;
	default:
		TEST(msg, NO)
		break;
	}
}

@interface ParserDelegate: OFObject
@end

@implementation ParserDelegate
-     (void)xmlParser: (OFXMLParser*)parser
  didStartTagWithName: (OFString*)name
	       prefix: (OFString*)prefix
	    namespace: (OFString*)ns
	   attributes: (OFArray*)attrs
{
	callback(TAG_START, name, prefix, ns, attrs, nil, nil);
}

-   (void)xmlParser: (OFXMLParser*)parser
  didEndTagWithName: (OFString*)name
	     prefix: (OFString*)prefix
	  namespace: (OFString*)ns
{
	callback(TAG_END, name, prefix, ns, nil, nil, nil);
}

- (void)xmlParser: (OFXMLParser*)parser
      foundString: (OFString*)string
{
	callback(STRING, nil, nil, nil, nil, string, nil);
}

- (void)xmlParser: (OFXMLParser*)parser
     foundComment: (OFString*)comment
{
	callback(COMMENT, nil, nil, nil, nil, nil, comment);
}

-    (OFString*)xmlParser: (OFXMLParser*)parser
  foundUnknownEntityNamed: (OFString*)entity
{
	if ([entity isEqual: @"foo"])
		return @"foobar";

	return nil;
}
@end

void
xmlparser_tests()
{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFXMLParser *parser;
	const char *str = "bar<foo:bar  bar='b&amp;az'  qux:qux=\" quux \">\r\n"
	    "foo&lt;bar<qux  >bar <baz name='' test='&foo;'/>  quxbar\r\n</qux>"
	    "</foo:bar><!-- foo bar-baz -->";
	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];
}