ObjFW  Diff

Differences From Artifact [c56cc9efc9]:

To Artifact [20f4783b1c]:


20
21
22
23
24
25
26
27

28
29
30
31
32
33
34
20
21
22
23
24
25
26

27
28
29
30
31
32
33
34







-
+








#import "TestsAppDelegate.h"

static OFString *module = @"OFXMLParser";
static int i = 0;

enum event_type {
	PROCESSING_INSTRUCTIONS,
	PROCESSING_INSTRUCTION,
	TAG_OPEN,
	TAG_CLOSE,
	STRING,
	CDATA,
	COMMENT
};

44
45
46
47
48
49
50
51
52



53
54
55
56


57
58
59
60
61
62
63
44
45
46
47
48
49
50


51
52
53
54
55


56
57
58
59
60
61
62
63
64







-
-
+
+
+


-
-
+
+







	OFString *msg;

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

	switch (i) {
	case 1:
		TEST(msg, type == PROCESSING_INSTRUCTIONS &&
		    [string isEqual: @"xml version='1.0'"])
		TEST(msg, type == PROCESSING_INSTRUCTION &&
		    [name isEqual: @"xml"] &&
		    [string isEqual: @"version='1.0'"])
		break;
	case 2:
		TEST(msg, type == PROCESSING_INSTRUCTIONS &&
		    [string isEqual: @"p?i"])
		TEST(msg, type == PROCESSING_INSTRUCTION &&
		    [name isEqual: @"p?i"] && string == nil)
		break;
	case 3:
		TEST(msg, type == TAG_OPEN && [name isEqual: @"root"] &&
		    prefix == nil && ns == nil && attrs.count == 0)
		break;
	case 4:
		TEST(msg, type == STRING && [string isEqual: @"\n\n "])
228
229
230
231
232
233
234
235
236



237
238
239
240


241
242
243
244

245
246
247
248
249
250
251
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







-
-
+
+
+


-
-
+
+



-
+







	case 32:
		TEST(msg, type == TAG_CLOSE && [name isEqual: @"root"] &&
		    prefix == nil && ns == nil);
		break;
	}
}

-		 (void)parser: (OFXMLParser *)parser
  foundProcessingInstructions: (OFString *)pi
-			  (void)parser: (OFXMLParser *)parser
  foundProcessingInstructionWithTarget: (OFString *)target
				  data: (OFString *)data
{
	[self	    parser: parser
	    didCreateEvent: PROCESSING_INSTRUCTIONS
		      name: nil
	    didCreateEvent: PROCESSING_INSTRUCTION
		      name: target
		    prefix: nil
		 namespace: nil
		attributes: nil
		    string: pi];
		    string: data];
}

-    (void)parser: (OFXMLParser *)parser
  didStartElement: (OFString *)name
	   prefix: (OFString *)prefix
	namespace: (OFString *)ns
       attributes: (OFArray *)attrs
367
368
369
370
371
372
373
374

375
376
377
378
379

380
381
382
383
384

385
386
387
388
389
390
369
370
371
372
373
374
375

376
377
378
379
380

381
382
383
384
385

386
387
388
389
390
391
392







-
+




-
+




-
+






	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: @"<!["])

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

	parser = [OFXMLParser parser];
	EXPECT_EXCEPTION(@"Detection of invalid XML processing instructions #2",
	EXPECT_EXCEPTION(@"Detection of invalid XML processing instruction #2",
	    OFInvalidEncodingException,
	    [parser parseString: @"<?xml encoding='UTF-7'?>"])

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

	objc_autoreleasePoolPop(pool);
}
@end