6 #define do_bad_test(s) do { char *r = markup_test (s); if (r == NULL) return FAILED ("Failed on test " # s); else g_free (r); } while (0)
7 #define do_ok_test(s) do { char *r = markup_test (s); if (r != NULL) return FAILED ("Could not parse valid " # s); } while (0)
10 markup_test (const char *s
)
12 GMarkupParser
*parser
= g_new0 (GMarkupParser
, 1);
13 GMarkupParseContext
*context
;
16 context
= g_markup_parse_context_new (parser
, 0, 0, 0);
18 g_markup_parse_context_parse (context
, s
, strlen (s
), &error
);
19 g_markup_parse_context_free (context
);
22 char *msg
= g_strdup (error
->message
);
33 invalid_documents (void)
35 /* These should fail */
39 do_bad_test ("<a b>");
40 do_bad_test ("<a b=>");
41 do_bad_test ("<a b=c>");
47 valid_documents (void)
49 /* These should fail */
51 do_ok_test ("<a a=\"b\">");
57 * This is a test for the kind of files that the code in mono/domain.c
58 * parses; This code comes from Mono
61 GSList
*supported_runtimes
;
62 char *required_runtime
;
63 int configuration_count
;
68 get_attribute_value (const gchar
**attribute_names
,
69 const gchar
**attribute_values
,
73 for (n
=0; attribute_names
[n
] != NULL
; n
++) {
74 if (strcmp (attribute_names
[n
], att_name
) == 0)
75 return g_strdup (attribute_values
[n
]);
81 start_element (GMarkupParseContext
*context
,
82 const gchar
*element_name
,
83 const gchar
**attribute_names
,
84 const gchar
**attribute_values
,
88 AppConfigInfo
* app_config
= (AppConfigInfo
*) user_data
;
90 if (strcmp (element_name
, "configuration") == 0) {
91 app_config
->configuration_count
++;
94 if (strcmp (element_name
, "startup") == 0) {
95 app_config
->startup_count
++;
99 if (app_config
->configuration_count
!= 1 || app_config
->startup_count
!= 1)
102 if (strcmp (element_name
, "requiredRuntime") == 0) {
103 app_config
->required_runtime
= get_attribute_value (attribute_names
, attribute_values
, "version");
104 } else if (strcmp (element_name
, "supportedRuntime") == 0) {
105 char *version
= get_attribute_value (attribute_names
, attribute_values
, "version");
106 app_config
->supported_runtimes
= g_slist_append (app_config
->supported_runtimes
, version
);
111 end_element (GMarkupParseContext
*context
,
112 const gchar
*element_name
,
116 AppConfigInfo
* app_config
= (AppConfigInfo
*) user_data
;
118 if (strcmp (element_name
, "configuration") == 0) {
119 app_config
->configuration_count
--;
120 } else if (strcmp (element_name
, "startup") == 0) {
121 app_config
->startup_count
--;
125 static const GMarkupParser
135 domain_test (char *text
)
137 AppConfigInfo
*app_config
= g_new0 (AppConfigInfo
, 1);
138 GMarkupParseContext
*context
;
140 context
= g_markup_parse_context_new (&mono_parser
, 0, app_config
, NULL
);
141 if (g_markup_parse_context_parse (context
, text
, strlen (text
), NULL
)) {
142 g_markup_parse_context_end_parse (context
, NULL
);
144 g_markup_parse_context_free (context
);
150 domain_free (AppConfigInfo
*info
)
153 if (info
->required_runtime
)
154 g_free (info
->required_runtime
);
155 for (l
= info
->supported_runtimes
; l
!= NULL
; l
= l
->next
){
158 g_slist_free (info
->supported_runtimes
);
167 info
= domain_test ("<configuration><!--hello--><startup><!--world--><requiredRuntime version=\"v1\"><!--r--></requiredRuntime></startup></configuration>");
168 if (info
->required_runtime
== NULL
)
169 return FAILED ("No required runtime section");
170 if (strcmp (info
->required_runtime
, "v1") != 0)
171 return FAILED ("Got a runtime version %s, expected v1", info
->required_runtime
);
174 info
= domain_test ("<configuration><startup><requiredRuntime version=\"v1\"/><!--comment--></configuration><!--end-->");
175 if (info
->required_runtime
== NULL
)
176 return FAILED ("No required runtime section on auto-close section");
177 if (strcmp (info
->required_runtime
, "v1") != 0)
178 return FAILED ("Got a runtime version %s, expected v1", info
->required_runtime
);
181 info
= domain_test ("<!--start--><configuration><startup><supportedRuntime version=\"v1\"/><!--middle--><supportedRuntime version=\"v2\"/></startup></configuration>");
182 if ((strcmp ((char*)info
->supported_runtimes
->data
, "v1") == 0)){
183 if (info
->supported_runtimes
->next
== NULL
)
184 return FAILED ("Expected 2 supported runtimes");
186 if ((strcmp ((char*)info
->supported_runtimes
->next
->data
, "v2") != 0))
187 return FAILED ("Expected v1, v2, got %s", info
->supported_runtimes
->next
->data
);
188 if (info
->supported_runtimes
->next
->next
!= NULL
)
189 return FAILED ("Expected v1, v2, got more");
191 return FAILED ("Expected `v1', got %s", info
->supported_runtimes
->data
);
200 return markup_test ("<configuration>\r\n <system.diagnostics>\r\n <trace autoflush=\"true\" indentsize=\"4\">\r\n <listeners>\r\n <add name=\"compilerLogListener\" type=\"System.Diagnostics.TextWriterTraceListener,System\"/> </listeners> </trace> </system.diagnostics> </configuration>");
207 return markup_test ("<?xml version=\"1.0\" encoding=\"utf-8\"?><a></a>");
211 machine_config (void)
216 if (g_file_get_contents ("../../data/net_1_1/machine.config", &data
, &size
, NULL
)){
217 return markup_test (data
);
219 printf ("Ignoring this test\n");
223 static Test markup_tests
[] = {
224 {"invalid_documents", invalid_documents
},
225 {"good_documents", valid_documents
},
226 {"mono_domain", mono_domain
},
227 {"mcs_config", mcs_config
},
228 {"xml_parse", xml_parse
},
229 {"machine_config", machine_config
},
233 DEFINE_TEST_GROUP_INIT(markup_tests_init
, markup_tests
)