1 #undef G_DISABLE_ASSERT
8 typedef struct _EscapeTest EscapeTest
;
12 const gchar
*original
;
13 const gchar
*expected
;
16 static EscapeTest escape_tests
[] =
28 { "&&A", "&&A" },
29 { "A&&", "A&&" },
30 { "A&&A", "A&&A" },
31 { "A&A&A", "A&A&A" },
32 { "AA", "AA" },
33 { "A
A", "A
A" }
37 escape_test (gconstpointer d
)
39 const EscapeTest
*test
= d
;
42 result
= g_markup_escape_text (test
->original
, -1);
44 g_assert_cmpstr (result
, ==, test
->expected
);
49 typedef struct _UnicharTest UnicharTest
;
57 static UnicharTest unichar_tests
[] =
79 unichar_test (gconstpointer d
)
81 const UnicharTest
*test
= d
;
84 gchar outbuf
[7], expected
[12];
86 len
= g_unichar_to_utf8 (test
->c
, outbuf
);
90 g_snprintf (expected
, 12, "&#x%x;", test
->c
);
92 strcpy (expected
, outbuf
);
95 t
.expected
= expected
;
101 test_format (const gchar
*format
,
102 const gchar
*expected
,
108 va_start (args
, expected
);
109 result
= g_markup_vprintf_escaped (format
, args
);
112 g_assert_cmpstr (result
, ==, expected
);
120 test_format ("A", "A");
121 test_format ("A%s", "A&", "&");
122 test_format ("%sA", "&A", "&");
123 test_format ("A%sA", "A&A", "&");
124 test_format ("%s%sA", "&&A", "&", "&");
125 test_format ("A%s%s", "A&&", "&", "&");
126 test_format ("A%s%sA", "A&&A", "&", "&");
127 test_format ("A%sA%sA", "A&A&A", "&", "&");
128 test_format ("%s", "<B>&", "<B>&");
129 test_format ("%c%c", "<&", '<', '&');
130 test_format (".%c.%c.", ".<.&.", '<', '&');
131 test_format ("%s", "", "");
132 test_format ("%-5s", "A ", "A");
133 test_format ("%2$s%1$s", "B.A.", "A.", "B.");
136 int main (int argc
, char **argv
)
141 g_test_init (&argc
, &argv
, NULL
);
143 for (i
= 0; i
< G_N_ELEMENTS (escape_tests
); i
++)
145 path
= g_strdup_printf ("/markup/escape-text/%d", i
);
146 g_test_add_data_func (path
, &escape_tests
[i
], escape_test
);
150 for (i
= 0; i
< G_N_ELEMENTS (unichar_tests
); i
++)
152 path
= g_strdup_printf ("/markup/escape-unichar/%d", i
);
153 g_test_add_data_func (path
, &unichar_tests
[i
], unichar_test
);
157 g_test_add_func ("/markup/format", format_test
);
159 return g_test_run ();