ObjFW  Diff

Differences From Artifact [f0f6816ece]:

To Artifact [29fddc8f27]:


8
9
10
11
12
13
14

15
16
17
18
19
20
21
22
23
24













25
26
27
28
29
30
31
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import <stdio.h>
#import <stdlib.h>
#import <string.h>


#import "OFXMLFactory.h"

inline void
check_result(char *result, const char *should)
{
	if (!strcmp(result, should))
		printf("%s is expected result\n", result);
	else {
		printf("%s is NOT expected result!", result);













		exit(1);
	}

	free(result);
}

inline void







>









|
>
>
>
>
>
>
>
>
>
>
>
>
>







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
 * Q Public License 1.0, which can be found in the file LICENSE included in
 * the packaging of this file.
 */

#import <stdio.h>
#import <stdlib.h>
#import <string.h>
#import <wchar.h>

#import "OFXMLFactory.h"

inline void
check_result(char *result, const char *should)
{
	if (!strcmp(result, should))
		printf("%s is expected result\n", result);
	else {
		printf("%s is NOT expected result!\n", result);
		exit(1);
	}

	free(result);
}

inline void
check_result_wide(wchar_t *result, const wchar_t *should)
{
	if (!wcscmp(result, should))
		wprintf(L"%ls is expected result\n", result);
	else {
		wprintf(L"%ls is NOT expected result!\n", result);
		exit(1);
	}

	free(result);
}

inline void
48
49
50
51
52
53
54

























55
56
57
58
59
60
61
	strs[1] = s2;
	strs[2] = s3;
	strs[3] = NULL;

	check_result([OFXMLFactory concatAndFreeCStrings: strs],
	    "<foo>bar<test/>");
}


























inline void
test_create_stanza()
{
	check_result([OFXMLFactory createStanza: "foo"
				   withCloseTag: NO
					andData: NULL,







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
	strs[1] = s2;
	strs[2] = s3;
	strs[3] = NULL;

	check_result([OFXMLFactory concatAndFreeCStrings: strs],
	    "<foo>bar<test/>");
}

inline void
test_concat_wide()
{
	const wchar_t *c1 = L"<foo>", *c2 = L"bar", *c3 = L"<test/>";
	wchar_t *s1, *s2, *s3;
	wchar_t *strs[4];

	if ((s1 = malloc((wcslen(c1) + 1) * sizeof(wchar_t))) == NULL ||
	    (s2 = malloc((wcslen(c2) + 1) * sizeof(wchar_t))) == NULL ||
	    (s3 = malloc((wcslen(c3) + 1) * sizeof(wchar_t))) == NULL)
		exit(1);

	wcsncpy(s1, c1, wcslen(c1) + 1);
	wcsncpy(s2, c2, wcslen(c2) + 1);
	wcsncpy(s3, c3, wcslen(c3) + 1);

	strs[0] = s1;
	strs[1] = s2;
	strs[2] = s3;
	strs[3] = NULL;

	check_result_wide([OFXMLFactory concatAndFreeWideCStrings: strs],
	    L"<foo>bar<test/>");
}

inline void
test_create_stanza()
{
	check_result([OFXMLFactory createStanza: "foo"
				   withCloseTag: NO
					andData: NULL,
103
104
105
106
107
108
109
110
111























































112
113
114
115
116









117
118
119
120
121
122






123
124
125
					andData: "bar",
						 "bar", "b'az",
						 "x", "y",
						 "a", "b",
						 NULL],
	    "<foo bar='b&apos;az' x='y' a='b'>bar</foo>");
}

inline void























































test_escape()
{
	check_result([OFXMLFactory escapeCString: "<hallo> &welt'\"!&"],
	    "&lt;hallo&gt; &amp;welt&apos;&quot;!&amp;");
}










int main()
{
	test_escape();
       	test_create_stanza();
       	test_concat();







	return 0;
}









>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>





>
>
>
>
>
>
>
>
>






>
>
>
>
>
>



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
					andData: "bar",
						 "bar", "b'az",
						 "x", "y",
						 "a", "b",
						 NULL],
	    "<foo bar='b&apos;az' x='y' a='b'>bar</foo>");
}

inline void
test_create_stanza_wide()
{
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: NO
						 andData: NULL,
							  NULL],
	    L"<foo>");

	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: NO
						 andData: NULL,
							  L"bar", L"baz",
							  L"blub", L"asd",
							  NULL],
	    L"<foo bar='baz' blub='asd'>");
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: YES
						 andData: NULL,
							  NULL],
	    L"<foo/>");
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: YES
						 andData: L"bar",
							  NULL],
	    L"<foo>bar</foo>");
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: YES
						 andData: NULL,
							  L"bar", L"b&az",
							  NULL],
	    L"<foo bar='b&amp;az'/>");
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: YES
						 andData: L"bar",
							  L"bar", L"b'az",
							  NULL],
	    L"<foo bar='b&apos;az'>bar</foo>");
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: YES
						 andData: NULL,
							  L"bar", L"b&az",
							  L"x", L"asd\"",
							  NULL],
	    L"<foo bar='b&amp;az' x='asd&quot;'/>");
	check_result_wide([OFXMLFactory createWideStanza: L"foo"
					    withCloseTag: YES
						 andData: L"bar",
							  L"bar", L"b'az",
							  L"x", L"y",
							  L"a", L"b",
							  NULL],
	    L"<foo bar='b&apos;az' x='y' a='b'>bar</foo>");
}

inline void
test_escape()
{
	check_result([OFXMLFactory escapeCString: "<hallo> &welt'\"!&"],
	    "&lt;hallo&gt; &amp;welt&apos;&quot;!&amp;");
}

inline void
test_escape_wide()
{
	check_result_wide(
	    [OFXMLFactory escapeWideCString: L"<hallo> &welt'\"!&"],
	    L"&lt;hallo&gt; &amp;welt&apos;&quot;!&amp;");
}


int main()
{
	test_escape();
       	test_create_stanza();
       	test_concat();

	puts("== Now testing with wide C strings ==");

	test_escape_wide();
	test_create_stanza_wide();
	test_concat_wide();

	return 0;
}