Merge branch '976-disable-assert-checks' into 'master'
[glib.git] / glib / tests / markup.c
blob71f9ff16c313eaa5d6dd8e9597860814c72a5ef7
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
24 #include "glib.h"
26 typedef struct {
27 GSList *stack;
28 } ParseData;
30 static void
31 start (GMarkupParseContext *context,
32 const gchar *element_name,
33 const gchar **attribute_names,
34 const gchar **attribute_values,
35 gpointer user_data,
36 GError **error)
38 ParseData *data = user_data;
40 data->stack = g_slist_prepend (data->stack, g_strdup (element_name));
43 static void
44 end (GMarkupParseContext *context,
45 const gchar *element_name,
46 gpointer user_data,
47 GError **error)
49 ParseData *data = user_data;
50 const GSList *stack;
51 const GSList *s1, *s2;
52 GSList *s;
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);
59 s = data->stack;
60 data->stack = data->stack->next;
61 s->next = NULL;
62 g_slist_free_full (s, g_free);
65 const gchar content[] =
66 "<e1><foo><bar></bar> bla <l>fff</l></foo></e1>";
68 static void
69 test_markup_stack (void)
71 GMarkupParser parser = {
72 start,
73 end,
74 NULL,
75 NULL,
76 NULL
78 GMarkupParseContext *context;
79 ParseData data = { NULL };
80 gboolean res;
81 GError *error = NULL;
83 context = g_markup_parse_context_new (&parser, 0, &data, NULL);
84 res = g_markup_parse_context_parse (context, content, -1, &error);
85 g_assert (res);
86 g_assert_no_error (error);
87 g_markup_parse_context_free (context);
90 int
91 main (int argc, char *argv[])
93 g_test_init (&argc, &argv, NULL);
95 g_test_add_func ("/markup/stack", test_markup_stack);
97 return g_test_run ();