ObjFW  Diff

Differences From Artifact [12fd48a9aa]:

To Artifact [ef338cc4f6]:


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







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



-
+





-
+










-
+
-
-
+
-


-
+


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

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


-
+


-
-
-
+
-
-
-
+
-




+
-
+
+
+
+


#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);
	}
/* TODO: Do not only print, but check if it's the output it should be */

inline int

	free(result);
}

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

	if ((s1 = malloc(strlen(c1) + 1)) == NULL ||
	    (s2 = malloc(strlen(c2) + 1)) == NULL ||
	    (s3 = malloc(strlen(c3) + 1)) == NULL)
		return 1;
		exit(1);

	strncpy(s1, c1, strlen(c1) + 1);
	strncpy(s2, c2, strlen(c2) + 1);
	strncpy(s3, c3, strlen(c3) + 1);

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

	puts((str = [OFXMLFactory concatAndFreeCStrings: strs]));
	check_result([OFXMLFactory concatAndFreeCStrings: strs],
	free(str);

	    "<foo>bar<test/>");
	return 0;
}

inline int
inline void
test_create_stanza()
{
	char *xml;

	xml = [OFXMLFactory createStanza: "foo"
			    withCloseTag: NO
				andCData: NULL,
					  NULL];
	puts(xml);
	check_result([OFXMLFactory createStanza: "foo"
				   withCloseTag: NO
				       andCData: NULL,
						 NULL],
	    "<foo>");
	free(xml);

	xml = [OFXMLFactory createStanza: "foo"
			    withCloseTag: NO
				andCData: NULL,
					  "bar", "baz",
					  "blub", "asd",
					  NULL];
	check_result([OFXMLFactory createStanza: "foo"
				   withCloseTag: NO
				       andCData: NULL,
						 "bar", "baz",
						 "blub", "asd",
						 NULL],
	puts(xml);
	free(xml);

	xml = [OFXMLFactory createStanza: "foo"
			    withCloseTag: YES
				andCData: NULL,
					  NULL];
	    "<foo bar='baz' blub='asd'>");
	check_result([OFXMLFactory createStanza: "foo"
				   withCloseTag: YES
				       andCData: NULL,
						 NULL],
	puts(xml);
	free(xml);

	xml = [OFXMLFactory createStanza: "foo"
			    withCloseTag: YES
				andCData: "bar",
					  NULL];
	    "<foo/>");
	check_result([OFXMLFactory createStanza: "foo"
				   withCloseTag: YES
				       andCData: "bar",
						 NULL],
	puts(xml);
	free(xml);

	xml = [OFXMLFactory createStanza: "foo"
			    withCloseTag: YES
				andCData: NULL,
					  "bar", "b&az",
					  NULL];
	    "<foo>bar</foo>");
	check_result([OFXMLFactory createStanza: "foo"
				   withCloseTag: YES
				       andCData: NULL,
						 "bar", "b&az",
						 NULL],
	puts(xml);
	free(xml);

	xml = [OFXMLFactory createStanza: "foo"
			    withCloseTag: YES
				andCData: "bar",
					  "bar", "b'az",
					  NULL];
	    "<foo bar='b&amp;az'/>");
	check_result([OFXMLFactory createStanza: "foo"
				   withCloseTag: YES
				       andCData: "bar",
						 "bar", "b'az",
						 NULL],
	puts(xml);
	free(xml);

	xml = [OFXMLFactory createStanza: "foo"
			    withCloseTag: YES
				andCData: NULL,
					  "bar", "b&az",
					  "x", "asd\"",
					  NULL];
	    "<foo bar='b&apos;az'>bar</foo>");
	check_result([OFXMLFactory createStanza: "foo"
				   withCloseTag: YES
				       andCData: NULL,
						 "bar", "b&az",
						 "x", "asd\"",
						 NULL],
	puts(xml);
	free(xml);

	xml = [OFXMLFactory createStanza: "foo"
			    withCloseTag: YES
				andCData: "bar",
					  "bar", "b'az",
					  "x", "y",
					  "a", "b",
					  NULL];
	    "<foo bar='b&amp;az' x='asd&quot;'/>");
	check_result([OFXMLFactory createStanza: "foo"
				   withCloseTag: YES
				       andCData: "bar",
						 "bar", "b'az",
						 "x", "y",
						 "a", "b",
						 NULL],
	puts(xml);
	free(xml);

	    "<foo bar='b&apos;az' x='y' a='b'>bar</foo>");
	return 0;
}

inline int
inline void
test_escape()
{
	char *tmp;

	tmp = [OFXMLFactory escapeCString: "<hallo> &welt'\"!&"];
	check_result([OFXMLFactory escapeCString: "<hallo> &welt'\"!&"],
	puts(tmp);
	free(tmp);

	    "&lt;hallo&gt; &amp;welt&apos;&quot;!&amp;");
	return 0;
}

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

	return 0;
}