ObjFW  Diff

Differences From Artifact [60a7c83b15]:

To Artifact [878add25fb]:


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
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







-
+




-
+








-
+




-
+








-
+




-
+



-
+



-
+




-
+


-
+













-
+




-
+



-
+



-
+



-
+





-
+





{
	OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];
	OFXMLElement *elem[4];
	OFArray *a;

	TEST(@"+[elementWithName:]",
	    (elem[0] = [OFXMLElement elementWithName: @"foo"]) &&
	    [[elem[0] stringValue] isEqual: @"<foo/>"])
	    [[elem[0] XMLString] isEqual: @"<foo/>"])

	TEST(@"+[elementWithName:stringValue:]",
	    (elem[1] = [OFXMLElement elementWithName: @"foo"
					 stringValue: @"b&ar"]) &&
	    [[elem[1] stringValue] isEqual: @"<foo>b&amp;ar</foo>"])
	    [[elem[1] XMLString] isEqual: @"<foo>b&amp;ar</foo>"])

	TEST(@"+[elementWithName:namespace:]",
	    (elem[2] = [OFXMLElement elementWithName: @"foo"
					   namespace: @"urn:objfw:test"]) &&
	    R([elem[2] addAttributeWithName: @"test"
				stringValue: @"test"]) &&
	    R([elem[2] setPrefix: @"objfw-test"
		    forNamespace: @"urn:objfw:test"]) &&
	    [[elem[2] stringValue] isEqual: @"<objfw-test:foo test='test'/>"] &&
	    [[elem[2] XMLString] isEqual: @"<objfw-test:foo test='test'/>"] &&
	    (elem[3] = [OFXMLElement elementWithName: @"foo"
					   namespace: @"urn:objfw:test"]) &&
	    R([elem[3] addAttributeWithName: @"test"
				stringValue: @"test"]) &&
	    [[elem[3] stringValue] isEqual:
	    [[elem[3] XMLString] isEqual:
	    @"<foo xmlns='urn:objfw:test' test='test'/>"])

	TEST(@"+[elementWithName:namespace:stringValue:]",
	    (elem[3] = [OFXMLElement elementWithName: @"foo"
					   namespace: @"urn:objfw:test"
					 stringValue: @"x"]) &&
	    R([elem[3] setPrefix: @"objfw-test"
		    forNamespace: @"urn:objfw:test"]) &&
	    [[elem[3] stringValue] isEqual:
	    [[elem[3] XMLString] isEqual:
	    @"<objfw-test:foo>x</objfw-test:foo>"])

	TEST(@"+[elementWithCharacters:]",
	    (elem[3] = [OFXMLElement elementWithCharacters: @"<foo>"]) &&
	    [[elem[3] stringValue] isEqual: @"&lt;foo&gt;"])
	    [[elem[3] XMLString] isEqual: @"&lt;foo&gt;"])

	TEST(@"+[elementWithCDATA:]",
	    (elem[3] = [OFXMLElement elementWithCDATA: @"<foo>"]) &&
	    [[elem[3] stringValue] isEqual: @"<![CDATA[<foo>]]>"]);
	    [[elem[3] XMLString] isEqual: @"<![CDATA[<foo>]]>"]);

	TEST(@"+[elementWithComment:]",
	    (elem[3] = [OFXMLElement elementWithComment: @" comment "]) &&
	    [[elem[3] stringValue] isEqual: @"<!-- comment -->"])
	    [[elem[3] XMLString] isEqual: @"<!-- comment -->"])

	TEST(@"-[addAttributeWithName:stringValue:]",
	    R([elem[0] addAttributeWithName: @"foo"
				stringValue: @"b&ar"]) &&
	    [[elem[0] stringValue] isEqual: @"<foo foo='b&amp;ar'/>"] &&
	    [[elem[0] XMLString] isEqual: @"<foo foo='b&amp;ar'/>"] &&
	    R([elem[1] addAttributeWithName: @"foo"
				stringValue: @"b&ar"]) &&
	    [[elem[1] stringValue] isEqual:
	    [[elem[1] XMLString] isEqual:
	    @"<foo foo='b&amp;ar'>b&amp;ar</foo>"])

	TEST(@"-[setPrefix:forNamespace:]",
	    R([elem[1] setPrefix: @"objfw-test"
		    forNamespace: @"urn:objfw:test"]))

	TEST(@"-[addAttributeWithName:namespace:stringValue:]",
	    R([elem[1] addAttributeWithName: @"foo"
				  namespace: @"urn:objfw:test"
				stringValue: @"bar"]) &&
	    R([elem[1] addAttributeWithName: @"foo"
				  namespace: @"urn:objfw:test"
				stringValue: @"ignored"]) &&
	    [[elem[1] stringValue] isEqual:
	    [[elem[1] XMLString] isEqual:
	    @"<foo foo='b&amp;ar' objfw-test:foo='bar'>b&amp;ar</foo>"])

	TEST(@"-[removeAttributeForName:namespace:]",
	    R([elem[1] removeAttributeForName: @"foo"]) &&
	    [[elem[1] stringValue] isEqual:
	    [[elem[1] XMLString] isEqual:
	    @"<foo objfw-test:foo='bar'>b&amp;ar</foo>"] &&
	    R([elem[1] removeAttributeForName: @"foo"
				    namespace: @"urn:objfw:test"]) &&
	    [[elem[1] stringValue] isEqual: @"<foo>b&amp;ar</foo>"])
	    [[elem[1] XMLString] isEqual: @"<foo>b&amp;ar</foo>"])

	TEST(@"-[addChild:]",
	    R([elem[0] addChild: [OFXMLElement elementWithName: @"bar"]]) &&
	    [[elem[0] stringValue] isEqual:
	    [[elem[0] XMLString] isEqual:
	    @"<foo foo='b&amp;ar'><bar/></foo>"] &&
	    R([elem[2] addChild: [OFXMLElement elementWithName: @"bar"
		      namespace: @"urn:objfw:test"]]) &&
	    [[elem[2] stringValue] isEqual:
	    [[elem[2] XMLString] isEqual:
	    @"<objfw-test:foo test='test'><objfw-test:bar/></objfw-test:foo>"])

	TEST(@"-[elementsForName:namespace:]",
	    (a = [elem[2] elementsForName: @"bar"
				namespace: @"urn:objfw:test"]) &&
	    [a count] == 1 && [[[a firstObject] stringValue] isEqual:
	    [a count] == 1 && [[[a firstObject] XMLString] isEqual:
	    @"<bar xmlns='urn:objfw:test'/>"])

	[pool drain];
}
@end