Update contrib.
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
25 /* This test case is dependent on the markup filr 1.gmarkup placed in the c dir.
26 Make sure that the file is present before this test case is run. Export the file
29 #undef G_DISABLE_ASSERT
36 #include "mrt2_glib2_test.h"
43 start_element_handler (GMarkupParseContext *context,
44 const gchar *element_name,
45 const gchar **attribute_names,
46 const gchar **attribute_values,
54 end_element_handler (GMarkupParseContext *context,
55 const gchar *element_name,
63 text_handler (GMarkupParseContext *context,
74 passthrough_handler (GMarkupParseContext *context,
75 const gchar *passthrough_text,
83 error_handler (GMarkupParseContext *context,
87 g_assert(FALSE && "markup_test failed");
88 g_print(" %s\n", error->message);
91 static GMarkupParser parser = {
92 start_element_handler,
100 test_in_chunks (const gchar *contents,
104 GMarkupParseContext *context;
106 int line_number,char_number;
108 context = g_markup_parse_context_new (&parser, 0, NULL, NULL);
112 int this_chunk = MIN (length - i, chunk_size);
114 if (!g_markup_parse_context_parse (context,
119 g_markup_parse_context_free (context);
124 g_assert(g_markup_parse_context_get_element(context) == NULL || !strcmp(g_markup_parse_context_get_element(context),"foobar"));
126 g_markup_parse_context_get_position(context,&line_number,&char_number);
128 g_assert(line_number == 1 && char_number == 25);
133 if (!g_markup_parse_context_end_parse (context, NULL))
135 g_markup_parse_context_free (context);
139 g_markup_parse_context_free (context);
145 test_file (const gchar *filename)
150 GMarkupParseContext *context;
153 if (!g_file_get_contents (filename,
158 g_assert(FALSE && "c:\\1.gmarkup not found");
159 fprintf (stderr, "%s\n", error->message);
160 g_error_free (error);
164 context = g_markup_parse_context_new (&parser, 0, NULL, NULL);
166 if (!g_markup_parse_context_parse (context, contents, length, NULL))
168 g_markup_parse_context_free (context);
172 if (!g_markup_parse_context_end_parse (context, NULL))
174 g_markup_parse_context_free (context);
178 g_markup_parse_context_free (context);
180 if (test_in_chunks (contents, length, 24) != 0)
186 void g_markup_printf_escaped_test()
188 const char *store = "Fortnum & Mason";
189 const char *item = "Tea";
192 output = g_markup_printf_escaped ("<purchase>"
198 g_assert(!strcmp(output,"<purchase><store>Fortnum & Mason</store><item>Tea</item></purchase>"));
208 g_log_set_handler (NULL, G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, &mrtLogHandler, NULL);
209 g_set_print_handler(mrtPrintHandler);
212 test_file ("c:\\1.gmarkup");
213 g_markup_printf_escaped_test();
216 testResultXml("markup_test");
217 #endif /* EMULATOR */