ObjFW  Check-in [cd1532bb40]

Overview
Comment:Migrate OFXMLParserTests to ObjFWTest
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | objfwtest
Files: files | file ages | folders
SHA3-256: cd1532bb40d51b953d360c2c3aff8f8c0cae992bdbfc720f6c141aa7604aaa5a
User & Date: js on 2024-02-18 18:27:20
Other Links: branch diff | manifest | tags
Context
2024-02-18
18:53
Migrate OFXMLNodeTests to ObjFWTest check-in: fd477d1a54 user: js tags: objfwtest
18:27
Migrate OFXMLParserTests to ObjFWTest check-in: cd1532bb40 user: js tags: objfwtest
17:56
Migrate OFMemoryStreamTests to ObjFWTest check-in: 814d957cdc user: js tags: objfwtest
Changes

Modified new_tests/Makefile from [cd9494fed3] to [7f1203c5b5].

50
51
52
53
54
55
56

57
58
59
60
61
62
63
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64







+







       OFPropertyListTests.m			\
       OFScryptTests.m				\
       OFSetTests.m				\
       OFStringTests.m				\
       OFSystemInfoTests.m			\
       OFUTF8StringTests.m			\
       OFXMLElementBuilderTests.m		\
       OFXMLParserTests.m			\
       ${RUNTIME_ARC_TESTS_M}			\
       RuntimeTests.m				\
       ${USE_SRCS_PLUGINS}			\
       ${USE_SRCS_SOCKETS}			\
       ${USE_SRCS_SUBPROCESSES}			\
       ${USE_SRCS_THREADS}			\
       ${USE_SRCS_WINDOWS}			\

Renamed and modified tests/OFXMLParserTests.m [e9e91152cf] to new_tests/OFXMLParserTests.m [7002f67f2b].

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
191
192
193


194
195
196


197
198










199
200
201
202
203



204
205
206
207
208
209
210

211
212
213
214
215
216
217
218
219
220
221
222
223
224


225
226
227
228




229
230
231
232
233


234
235
236
237
238


239
240
241
242


243
244
245
246
247
248
249
250
251
252




253
254

255
256


257
258

259
260
261
262




263
264

265
266


267
268

269
270
271




272
273
274
275
276
277
278
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
191
192
193
194
195
196
197
198
199
200



201
202
203







204









205
206



207
208
209
210


211
212
213
214
215
216



217
218

219
220


221
222
223
224


225
226
227
228








229
230
231
232
233

234


235
236
237

238




239
240
241
242
243

244


245
246
247

248



249
250
251
252
253
254
255
256
257
258
259







-
+
+

-
-
+
+
+
+
+










-
+








-
-
-
-
-
-
-
+
+
-
-
-
-
+
+
+

-
+
-
-
-
+
+
+

-
+
-
-
-
+
+
+
+
+

-
+
-
-
+
+

-
+
-
-
-
+
+
+
+
+
+
+
+
+
+


-
-
-
+
+
+
+
+


-
-
+
-
+


+
+
-
-
+
+
+
+
+
+


-
-
+
-
-
+
-
-
-
-
-
-


+
+
+
+
+
+
-
-
+
+
+


+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+

-
+
-
-
+
+

-
+
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
+
+
+
-
-
-
+
-
-
-
-


-
-
-
+
+
+
-
-
-
-
-
-
+
-
-
-
-
-


-
-
+
-
-
+


+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+


-
-
-
+
+
-
-
-
-
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-


-
-
-
+
+
-


+
+
-
-
+
+
+
+
+
+
+
+
+
+


-
-
-
+
+
+
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-


-
-
-
+
+


-
-
+
+
+
+


-
-
-
+
+
-


-
-
+
+


-
-
+
+


-
-
-
-
-
-
-
-
+
+
+
+

-
+
-
-
+
+

-
+
-
-
-
-
+
+
+
+

-
+
-
-
+
+

-
+
-
-
-
+
+
+
+







 */

#include "config.h"

#include <stdlib.h>
#include <string.h>

#import "TestsAppDelegate.h"
#import "ObjFW.h"
#import "ObjFWTest.h"

static OFString *const module = @"OFXMLParser";
static int i = 0;
@interface OFXMLParserTests: OTTestCase <OFXMLParserDelegate>
{
	int _i;
}
@end

enum EventType {
	eventTypeProcessingInstruction,
	eventTypeTagOpen,
	eventTypeTagClose,
	eventTypeString,
	eventTypeCDATA,
	eventTypeComment
};

@implementation TestsAppDelegate (OFXMLParser)
@implementation OFXMLParserTests
-   (void)parser: (OFXMLParser *)parser
  didCreateEvent: (enum EventType)type
	    name: (OFString *)name
	  prefix: (OFString *)prefix
       namespace: (OFString *)namespace
      attributes: (OFArray *)attrs
	  string: (OFString *)string
{
	OFString *message;

	i++;
	message = [OFString stringWithFormat: @"Parsing part #%d", i];

	switch (i) {
	case 1:
	switch (_i++) {
	case 0:
		TEST(message,
		    type == eventTypeProcessingInstruction &&
		    [name isEqual: @"xml"] &&
		    [string isEqual: @"version='1.0'"])
		OTAssertEqual(type, eventTypeProcessingInstruction);
		OTAssertEqualObjects(name, @"xml");
		OTAssertEqualObjects(string, @"version='1.0'");
		break;
	case 2:
	case 1:
		TEST(message,
		    type == eventTypeProcessingInstruction &&
		    [name isEqual: @"p?i"] && string == nil)
		OTAssertEqual(type, eventTypeProcessingInstruction);
		OTAssertEqualObjects(name, @"p?i");
		OTAssertNil(string);
		break;
	case 3:
	case 2:
		TEST(message,
		    type == eventTypeTagOpen && [name isEqual: @"root"] &&
		    prefix == nil && namespace == nil && attrs.count == 0)
		OTAssertEqual(type, eventTypeTagOpen);
		OTAssertEqualObjects(name, @"root");
		OTAssertNil(prefix);
		OTAssertNil(namespace);
		OTAssertEqual(attrs.count, 0);
		break;
	case 4:
	case 3:
		TEST(message,
		    type == eventTypeString && [string isEqual: @"\n\n "])
		OTAssertEqual(type, eventTypeString);
		OTAssertEqualObjects(string, @"\n\n ");
		break;
	case 5:
	case 4:
		TEST(message,
		    type == eventTypeCDATA && [string isEqual: @"f<]]]oo]"] &&
		    parser.lineNumber == 3)
		OTAssertEqual(type, eventTypeCDATA);
		OTAssertEqualObjects(string, @"f<]]]oo]");
		OTAssertEqual(parser.lineNumber, 3);
		break;
	case 5:
		OTAssertEqual(type, eventTypeTagOpen);
		OTAssertEqualObjects(name, @"bar");
		OTAssertNil(prefix);
		OTAssertNil(namespace);
		OTAssertNil(attrs);
		break;
	case 6:
		TEST(message,
		    type == eventTypeTagOpen && [name isEqual: @"bar"] &&
		    prefix == nil && namespace == nil && attrs == nil)
		OTAssertEqual(type, eventTypeTagClose);
		OTAssertEqualObjects(name, @"bar");
		OTAssertNil(prefix);
		OTAssertNil(namespace);
		OTAssertNil(attrs);
		break;
	case 7:
		TEST(message,
		    type == eventTypeTagClose && [name isEqual: @"bar"] &&
		OTAssertEqual(type, eventTypeString);
		    prefix == nil && namespace == nil && attrs == nil)
		OTAssertEqualObjects(string, @"\n ");
		break;
	case 8:
		OTAssertEqual(type, eventTypeTagOpen);
		OTAssertEqualObjects(name, @"foobar");
		TEST(message,
		    type == eventTypeString && [string isEqual: @"\n "])
		OTAssertNil(prefix);
		OTAssertEqualObjects(namespace, @"urn:objfw:test:foobar");
		OTAssertEqualObjects(attrs, [OFArray arrayWithObject:
		    [OFXMLAttribute attributeWithName: @"xmlns"
					  stringValue: @"urn:objfw:test:"
						       @"foobar"]]);
		break;
	case 9:
		TEST(message,
		    type == eventTypeTagOpen && [name isEqual: @"foobar"] &&
		OTAssertEqual(type, eventTypeString);
		    prefix == nil &&
		    [namespace isEqual: @"urn:objfw:test:foobar"] &&
		OTAssertEqualObjects(string, @"\n  ");
		    attrs.count == 1 &&
		    /* xmlns attr */
		    [[[attrs objectAtIndex: 0] name] isEqual: @"xmlns"] &&
		    [[attrs objectAtIndex: 0] namespace] == nil &&
		    [[[attrs objectAtIndex: 0] stringValue] isEqual:
		    @"urn:objfw:test:foobar"])
		break;
	case 10:
		OTAssertEqual(type, eventTypeTagOpen);
		OTAssertEqualObjects(name, @"qux");
		OTAssertNil(prefix);
		OTAssertEqualObjects(namespace, @"urn:objfw:test:foobar");
		OTAssertEqualObjects(attrs, [OFArray arrayWithObject:
		    [OFXMLAttribute attributeWithName: @"foo"
		TEST(message,
		    type == eventTypeString && [string isEqual: @"\n  "])
					    namespace: @"http://www.w3.org/"
						       @"2000/xmlns/"
					  stringValue: @"urn:objfw:test:foo"]]);
		break;
	case 11:
		OTAssertEqual(type, eventTypeString);
		OTAssertEqualObjects(string, @"\n   ");
		TEST(message,
		    type == eventTypeTagOpen && [name isEqual: @"qux"] &&
		    prefix == nil &&
		    [namespace isEqual: @"urn:objfw:test:foobar"] &&
		    attrs.count == 1 &&
		    /* xmlns:foo attr */
		break;
	case 12:
		OTAssertEqual(type, eventTypeTagOpen);
		OTAssertEqualObjects(name, @"bla");
		OTAssertEqualObjects(prefix, @"foo");
		OTAssertEqualObjects(namespace, @"urn:objfw:test:foo");
		OTAssertEqualObjects(attrs, ([OFArray arrayWithObjects:
		    [OFXMLAttribute attributeWithName: @"bla"
		    [[[attrs objectAtIndex: 0] name] isEqual: @"foo"] &&
		    [[[attrs objectAtIndex: 0] namespace] isEqual:
		    @"http://www.w3.org/2000/xmlns/"] &&
		    [[[attrs objectAtIndex: 0] stringValue] isEqual:
		    @"urn:objfw:test:foo"])
					    namespace: @"urn:objfw:test:foo"
					  stringValue: @"bla"],
		    [OFXMLAttribute attributeWithName: @"blafoo"
					  stringValue: @"foo"], nil]));
		break;
	case 12:
	case 13:
		TEST(message,
		    type == eventTypeString && [string isEqual: @"\n   "])
		OTAssertEqual(type, eventTypeString);
		OTAssertEqualObjects(string, @"\n    ");
		break;
	case 13:
	case 14:
		TEST(message,
		    type == eventTypeTagOpen && [name isEqual: @"bla"] &&
		    [prefix isEqual: @"foo"] &&
		    [namespace isEqual: @"urn:objfw:test:foo"] &&
		    attrs.count == 2 &&
		    /* foo:bla attr */
		OTAssertEqual(type, eventTypeTagOpen);
		OTAssertEqualObjects(name, @"blup");
		OTAssertNil(prefix);
		OTAssertEqualObjects(namespace, @"urn:objfw:test:foobar");
		OTAssertEqualObjects(attrs, ([OFArray arrayWithObjects:
		    [OFXMLAttribute attributeWithName: @"qux"
		    [[[attrs objectAtIndex: 0] name] isEqual: @"bla"] &&
		    [[[attrs objectAtIndex: 0] namespace] isEqual:
		    @"urn:objfw:test:foo"] &&
		    [[[attrs objectAtIndex: 0] stringValue] isEqual: @"bla"] &&
		    /* blafoo attr */
					    namespace: @"urn:objfw:test:foo"
					  stringValue: @"asd"],
		    [OFXMLAttribute attributeWithName: @"quxqux"
		    [[[attrs objectAtIndex: 1] name] isEqual: @"blafoo"] &&
		    [[attrs objectAtIndex: 1] namespace] == nil &&
		    [[[attrs objectAtIndex: 1] stringValue] isEqual: @"foo"])
					  stringValue: @"test"], nil]));
		break;
	case 14:
		TEST(message,
		    type == eventTypeString && [string isEqual: @"\n    "])
		break;
	case 15:
		TEST(message,
		    type == eventTypeTagOpen && [name isEqual: @"blup"] &&
		    prefix == nil &&
		OTAssertEqual(type, eventTypeTagClose);
		OTAssertEqualObjects(name, @"blup");
		OTAssertNil(prefix);
		    [namespace isEqual: @"urn:objfw:test:foobar"] &&
		    attrs.count == 2 &&
		    /* foo:qux attr */
		    [[[attrs objectAtIndex: 0] name] isEqual: @"qux"] &&
		    [[[attrs objectAtIndex: 0] namespace] isEqual:
		    @"urn:objfw:test:foo"] &&
		OTAssertEqualObjects(namespace, @"urn:objfw:test:foobar");
		    [[[attrs objectAtIndex: 0] stringValue] isEqual: @"asd"] &&
		    /* quxqux attr */
		    [[[attrs objectAtIndex: 1] name] isEqual: @"quxqux"] &&
		    [[attrs objectAtIndex: 1] namespace] == nil &&
		    [[[attrs objectAtIndex: 1] stringValue] isEqual: @"test"])
		break;
	case 16:
		TEST(message,
		    type == eventTypeTagClose && [name isEqual: @"blup"] &&
		OTAssertEqual(type, eventTypeString);
		    prefix == nil &&
		    [namespace isEqual: @"urn:objfw:test:foobar"])
		OTAssertEqualObjects(string, @"\n    ");
		break;
	case 17:
		OTAssertEqual(type, eventTypeTagOpen);
		OTAssertEqualObjects(name, @"bla");
		OTAssertEqualObjects(prefix, @"bla");
		OTAssertEqualObjects(namespace, @"urn:objfw:test:bla");
		OTAssertEqualObjects(attrs, ([OFArray arrayWithObjects:
		    [OFXMLAttribute attributeWithName: @"bla"
		TEST(message,
		    type == eventTypeString && [string isEqual: @"\n    "])
					    namespace: @"http://www.w3.org/"
						       @"2000/xmlns/"
					  stringValue: @"urn:objfw:test:bla"],
		    [OFXMLAttribute attributeWithName: @"qux"
					  stringValue: @"qux"],
		    [OFXMLAttribute attributeWithName: @"foo"
					    namespace: @"urn:objfw:test:bla"
					  stringValue: @"blafoo"], nil]));
		break;
	case 18:
		TEST(message,
		    type == eventTypeTagOpen && [name isEqual: @"bla"] &&
		    [prefix isEqual: @"bla"] &&
		OTAssertEqual(type, eventTypeTagClose);
		OTAssertEqualObjects(name, @"bla");
		    [namespace isEqual: @"urn:objfw:test:bla"] &&
		    attrs.count == 3 &&
		    /* xmlns:bla attr */
		    [[[attrs objectAtIndex: 0] name] isEqual: @"bla"] &&
		OTAssertEqualObjects(prefix, @"bla");
		    [[[attrs objectAtIndex: 0] namespace] isEqual:
		    @"http://www.w3.org/2000/xmlns/"] &&
		    [[[attrs objectAtIndex: 0] stringValue] isEqual:
		    @"urn:objfw:test:bla"] &&
		OTAssertEqualObjects(namespace, @"urn:objfw:test:bla");
		    /* qux attr */
		    [[[attrs objectAtIndex: 1] name] isEqual: @"qux"] &&
		    [[attrs objectAtIndex: 1] namespace] == nil &&
		    [[[attrs objectAtIndex: 1] stringValue] isEqual: @"qux"] &&
		    /* bla:foo attr */
		    [[[attrs objectAtIndex: 2] name] isEqual: @"foo"] &&
		    [[[attrs objectAtIndex: 2] namespace] isEqual:
		    @"urn:objfw:test:bla"] &&
		    [[[attrs objectAtIndex: 2] stringValue] isEqual: @"blafoo"])
		break;
	case 19:
		TEST(message,
		    type == eventTypeTagClose && [name isEqual: @"bla"] &&
		    [prefix isEqual: @"bla"] &&
		OTAssertEqual(type, eventTypeString);
		OTAssertEqualObjects(string, @"\n    ");
		    [namespace isEqual: @"urn:objfw:test:bla"])
		break;
	case 20:
		OTAssertEqual(type, eventTypeTagOpen);
		OTAssertEqualObjects(name, @"abc");
		TEST(message,
		    type == eventTypeString && [string isEqual: @"\n    "])
		OTAssertNil(prefix);
		OTAssertEqualObjects(namespace, @"urn:objfw:test:abc");
		OTAssertEqualObjects(attrs, ([OFArray arrayWithObjects:
		    [OFXMLAttribute attributeWithName: @"xmlns"
					  stringValue: @"urn:objfw:test:abc"],
		    [OFXMLAttribute attributeWithName: @"abc"
					  stringValue: @"abc"],
		    [OFXMLAttribute attributeWithName: @"abc"
					    namespace: @"urn:objfw:test:foo"
					  stringValue: @"abc"], nil]));
		break;
	case 21:
		TEST(message,
		    type == eventTypeTagOpen && [name isEqual: @"abc"] &&
		    prefix == nil &&
		OTAssertEqual(type, eventTypeTagClose);
		OTAssertEqualObjects(name, @"abc");
		OTAssertNil(prefix);
		    [namespace isEqual: @"urn:objfw:test:abc"] &&
		    attrs.count == 3 &&
		    /* xmlns attr */
		    [[[attrs objectAtIndex: 0] name] isEqual: @"xmlns"] &&
		    [[attrs objectAtIndex: 0] namespace] == nil &&
		    [[[attrs objectAtIndex: 0] stringValue] isEqual:
		    @"urn:objfw:test:abc"] &&
		OTAssertEqualObjects(namespace, @"urn:objfw:test:abc");
		    /* abc attr */
		    [[[attrs objectAtIndex: 1] name] isEqual: @"abc"] &&
		    [[attrs objectAtIndex: 1] namespace] == nil &&
		    [[[attrs objectAtIndex: 1] stringValue] isEqual: @"abc"] &&
		    /* foo:abc attr */
		    [[[attrs objectAtIndex: 2] name] isEqual: @"abc"] &&
		    [[[attrs objectAtIndex: 2] namespace] isEqual:
		    @"urn:objfw:test:foo"] &&
		    [[[attrs objectAtIndex: 2] stringValue] isEqual: @"abc"])
		break;
	case 22:
		TEST(message,
		    type == eventTypeTagClose && [name isEqual: @"abc"] &&
		    prefix == nil && [namespace isEqual: @"urn:objfw:test:abc"])
		OTAssertEqual(type, eventTypeString);
		OTAssertEqualObjects(string, @"\n   ");
		break;
	case 23:
		TEST(message,
		    type == eventTypeString && [string isEqual: @"\n   "])
		OTAssertEqual(type, eventTypeTagClose);
		OTAssertEqualObjects(name, @"bla");
		OTAssertEqualObjects(prefix, @"foo");
		OTAssertEqualObjects(namespace, @"urn:objfw:test:foo");
		break;
	case 24:
		TEST(message,
		    type == eventTypeTagClose && [name isEqual: @"bla"] &&
		    [prefix isEqual: @"foo"] &&
		OTAssertEqual(type, eventTypeString);
		OTAssertEqualObjects(string, @"\n   ");
		    [namespace isEqual: @"urn:objfw:test:foo"])
		break;
	case 25:
		TEST(message,
		    type == eventTypeString && [string isEqual: @"\n   "])
		OTAssertEqual(type, eventTypeComment);
		OTAssertEqualObjects(string, @" commänt ");
		break;
	case 26:
		TEST(message,
		    type == eventTypeComment && [string isEqual: @" commänt "])
		OTAssertEqual(type, eventTypeString);
		OTAssertEqualObjects(string, @"\n  ");
		break;
	case 27:
		TEST(message,
		    type == eventTypeString && [string isEqual: @"\n  "])
		break;
	case 28:
		TEST(message,
		    type == eventTypeTagClose && [name isEqual: @"qux"] &&
		    prefix == nil &&
		    [namespace isEqual: @"urn:objfw:test:foobar"])
		OTAssertEqual(type, eventTypeTagClose);
		OTAssertEqualObjects(name, @"qux");
		OTAssertNil(prefix);
		OTAssertEqualObjects(namespace, @"urn:objfw:test:foobar");
		break;
	case 29:
	case 28:
		TEST(message,
		    type == eventTypeString && [string isEqual: @"\n "])
		OTAssertEqual(type, eventTypeString);
		OTAssertEqualObjects(string, @"\n ");
		break;
	case 30:
	case 29:
		TEST(message,
		    type == eventTypeTagClose && [name isEqual: @"foobar"] &&
		    prefix == nil &&
		    [namespace isEqual: @"urn:objfw:test:foobar"])
		OTAssertEqual(type, eventTypeTagClose);
		OTAssertEqualObjects(name, @"foobar");
		OTAssertNil(prefix);
		OTAssertEqualObjects(namespace, @"urn:objfw:test:foobar");
		break;
	case 31:
	case 30:
		TEST(message,
		    type == eventTypeString && [string isEqual: @"\n"])
		OTAssertEqual(type, eventTypeString);
		OTAssertEqualObjects(string, @"\n");
		break;
	case 32:
	case 31:
		TEST(message,
		    type == eventTypeTagClose && [name isEqual: @"root"] &&
		    prefix == nil && namespace == nil);
		OTAssertEqual(type, eventTypeTagClose);
		OTAssertEqualObjects(name, @"root");
		OTAssertNil(prefix);
		OTAssertNil(namespace);
		break;
	}
}

-			  (void)parser: (OFXMLParser *)parser
  foundProcessingInstructionWithTarget: (OFString *)target
				  text: (OFString *)text
353
354
355
356
357
358
359
360

361
362
363

364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381

382
383

384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399


400
401

402
403
404


405
406
407


408
409
410
411
412
413










414
415
416
417


418
419
420



421
422


423
424
425
426



427
428
429



430
431
432
334
335
336
337
338
339
340

341
342


343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360

361


362
363
364
365
366
367
368
369
370
371
372
373
374
375
376


377
378


379
380


381
382
383


384
385
386





387
388
389
390
391
392
393
394
395
396
397
398


399
400

401
402
403
404
405


406
407




408
409
410



411
412
413

414
415







-
+

-
-
+

















-
+
-
-
+














-
-
+
+
-
-
+

-
-
+
+

-
-
+
+

-
-
-
-
-
+
+
+
+
+
+
+
+
+
+


-
-
+
+
-


+
+
+
-
-
+
+
-
-
-
-
+
+
+
-
-
-
+
+
+
-


{
	if ([entity isEqual: @"foo"])
		return @"foobar";

	return nil;
}

- (void)XMLParserTests
- (void)testParser
{
	void *pool = objc_autoreleasePoolPush();
	const char *string = "\xEF\xBB\xBF<?xml version='1.0'?><?p?i?>"
	static const char *string = "\xEF\xBB\xBF<?xml version='1.0'?><?p?i?>"
	    "<!DOCTYPE foo><root>\r\r"
	    " <![CDATA[f<]]]oo]]]><bar/>\n"
	    " <foobar xmlns='urn:objfw:test:foobar'>\r\n"
	    "  <qux xmlns:foo='urn:objfw:test:foo'>\n"
	    "   <foo:bla foo:bla = '&#x62;&#x6c;&#x61;' blafoo='foo'>\n"
	    "    <blup foo:qux='asd' quxqux='test'/>\n"
	    "    <bla:bla\r\rxmlns:bla\r=\t\"urn:objfw:test:bla\" qux='qux'\r\n"
	    "     bla:foo='blafoo'/>\n"
	    "    <abc xmlns='urn:objfw:test:abc' abc='abc' foo:abc='abc'/>\n"
	    "   </foo:bla>\n"
	    "   <!-- commänt -->\n"
	    "  </qux>\n"
	    " </foobar>\n"
	    "</root>";
	OFXMLParser *parser;
	size_t j, length;

	TEST(@"+[parser]", (parser = [OFXMLParser parser]))
	parser = [OFXMLParser parser];

	TEST(@"-[setDelegate:]", (parser.delegate = self))
	parser.delegate = self;

	/* Simulate a stream where we only get chunks */
	length = strlen(string);

	for (j = 0; j < length; j+= 2) {
		if (parser.hasFinishedParsing)
			abort();

		if (j + 2 > length)
			[parser parseBuffer: string + j length: 1];
		else
			[parser parseBuffer: string + j length: 2];
	}

	TEST(@"Checking if everything was parsed",
	    i == 32 && parser.lineNumber == 18)
	OTAssertEqual(_i, 32);
	OTAssertEqual(parser.lineNumber, 18);

	TEST(@"-[hasFinishedParsing]", parser.hasFinishedParsing)
	OTAssertTrue(parser.hasFinishedParsing);

	TEST(@"Parsing whitespaces after the document",
	    R([parser parseString: @" \t\r\n "]))
	/* Parsing whitespaces after the document */
	[parser parseString: @" \t\r\n "];

	TEST(@"Parsing comments after the document",
	    R([parser parseString: @" \t<!-- foo -->\r<!--bar-->\n "]))
	/* Parsing comments after the document */
	[parser parseString: @" \t<!-- foo -->\r<!--bar-->\n "];

	EXPECT_EXCEPTION(@"Detection of junk after the document #1",
	    OFMalformedXMLException, [parser parseString: @"a"])

	EXPECT_EXCEPTION(@"Detection of junk after the document #2",
	    OFMalformedXMLException, [parser parseString: @"<!["])
	/* Detection of junk after the document */
	OTAssertThrowsSpecific([parser parseString: @"a"],
	    OFMalformedXMLException);
	OTAssertThrowsSpecific([parser parseString: @"<!["],
	    OFMalformedXMLException);
}

- (void)testDetectionOfInvalidXMLProcessingInstructions
{
	OFXMLParser *parser;

	parser = [OFXMLParser parser];
	EXPECT_EXCEPTION(@"Detection of invalid XML processing instruction #1",
	    OFMalformedXMLException,
	OTAssertThrowsSpecific([parser parseString: @"<?xml version='2.0'?>"],
	    OFMalformedXMLException);
	    [parser parseString: @"<?xml version='2.0'?>"])

	parser = [OFXMLParser parser];
	OTAssertThrowsSpecific([parser parseString: @"<x><?xml?></x>"],
	    OFMalformedXMLException);
}
	EXPECT_EXCEPTION(@"Detection of invalid XML processing instruction #2",
	    OFInvalidEncodingException,

- (void)testDetectionOfInvalidEncoding
	    [parser parseString: @"<?xml encoding='UTF-7'?>"])

	parser = [OFXMLParser parser];
	EXPECT_EXCEPTION(@"Detection of invalid XML processing instruction #3",
{
	OFXMLParser *parser = [OFXMLParser parser];

	    OFMalformedXMLException,
	    [parser parseString: @"<x><?xml?></x>"])

	OTAssertThrowsSpecific(
	    [parser parseString: @"<?xml encoding='UTF-7'?>"],
	    OFInvalidEncodingException);
	objc_autoreleasePoolPop(pool);
}
@end

Modified tests/Makefile from [48c72a53ef] to [2b37063ded].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
12
13
14
15
16
17
18

19
20
21
22
23
24
25







-







DISTCLEAN = Info.plist

PROG_NOINST = tests${PROG_SUFFIX}
STATIC_LIB_NOINST = ${TESTS_STATIC_LIB}
SRCS = OFStreamTests.m			\
       OFValueTests.m			\
       OFXMLNodeTests.m			\
       OFXMLParserTests.m		\
       TestsAppDelegate.m

IOS_USER ?= mobile
IOS_TMP ?= /tmp/objfw-test

include ../buildsys.mk

Modified tests/TestsAppDelegate.h from [91fcd8efb4] to [ba574a9222].

66
67
68
69
70
71
72
73
74
75
76
77
66
67
68
69
70
71
72












-
-
-
-
-
@interface TestsAppDelegate (OFValueTests)
- (void)valueTests;
@end

@interface TestsAppDelegate (OFXMLNodeTests)
- (void)XMLNodeTests;
@end

@interface TestsAppDelegate (OFXMLParserTests)
    <OFXMLParserDelegate, OFXMLElementBuilderDelegate>
- (void)XMLParserTests;
@end

Modified tests/TestsAppDelegate.m from [fdc6390186] to [4407e4999c].

368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
368
369
370
371
372
373
374

375
376
377
378
379
380
381







-







#if defined(OF_WII) && defined(OF_HAVE_FILES)
	[[OFFileManager defaultManager]
	    changeCurrentDirectoryPath: @"/apps/objfw-tests"];
#endif

	[self valueTests];
	[self streamTests];
	[self XMLParserTests];
	[self XMLNodeTests];

	[OFStdOut reset];

#if defined(OF_IOS)
	[OFStdOut writeFormat: @"%d tests failed!", _fails];
	[OFApplication terminateWithStatus: _fails];