1 /* Unit tests for GMarkup
2 * Copyright (C) 2013 Red Hat, Inc.
4 * This work is provided "as is"; redistribution and modification
5 * in whole or in part, in any medium, physical or electronic is
6 * permitted without restriction.
8 * This work is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * In no event shall the authors or contributors be liable for any
13 * direct, indirect, incidental, special, exemplary, or consequential
14 * damages (including, but not limited to, procurement of substitute
15 * goods or services; loss of use, data, or profits; or business
16 * interruption) however caused and on any theory of liability, whether
17 * in contract, strict liability, or tort (including negligence or
18 * otherwise) arising in any way out of the use of this software, even
19 * if advised of the possibility of such damage.
21 * Author: Matthias Clasen
31 start (GMarkupParseContext *context,
32 const gchar *element_name,
33 const gchar **attribute_names,
34 const gchar **attribute_values,
38 ParseData *data = user_data;
40 data->stack = g_slist_prepend (data->stack, g_strdup (element_name));
44 end (GMarkupParseContext *context,
45 const gchar *element_name,
49 ParseData *data = user_data;
51 const GSList *s1, *s2;
54 stack = g_markup_parse_context_get_element_stack (context);
55 for (s1 = stack, s2 = data->stack; s1 && s2; s1 = s1->next, s2 = s2->next)
56 g_assert_cmpstr (s1->data, ==, s2->data);
57 g_assert (s1 == NULL && s2 == NULL);
60 data->stack = data->stack->next;
62 g_slist_free_full (s, g_free);
65 const gchar content[] =
66 "<e1><foo><bar></bar> bla <l>fff</l></foo></e1>";
69 test_markup_stack (void)
71 GMarkupParser parser = {
78 GMarkupParseContext *context;
79 ParseData data = { NULL };
83 context = g_markup_parse_context_new (&parser, 0, &data, NULL);
84 res = g_markup_parse_context_parse (context, content, -1, &error);
86 g_assert_no_error (error);
87 g_markup_parse_context_free (context);
91 main (int argc, char *argv[])
93 g_test_init (&argc, &argv, NULL);
95 g_test_add_func ("/markup/stack", test_markup_stack);