6 #include "mock_debug_print.h"
11 test_entity_invalid(void)
15 /* Invalid entity strings */
16 result
= entity_decode(NULL
);
17 g_assert_null(result
);
18 result
= entity_decode("");
19 g_assert_null(result
);
20 result
= entity_decode("foo");
21 g_assert_null(result
);
22 result
= entity_decode("&");
23 g_assert_null(result
);
24 result
= entity_decode("&;");
25 g_assert_null(result
);
26 result
= entity_decode("&#");
27 g_assert_null(result
);
28 result
= entity_decode("&#;");
29 g_assert_null(result
);
31 /* Valid entity string, but with missing semicolon */
32 result
= entity_decode("Á");
33 g_assert_null(result
);
34 result
= entity_decode("{");
35 g_assert_null(result
);
39 test_entity_toolong(void)
43 /* Largest unicode code point is 0x10ffff, let's test that,
45 result
= entity_decode("");
46 g_assert_nonnull(result
);
48 result
= entity_decode("�");
49 g_assert_null(result
);
51 /* ENTITY_MAX_LEN is 8, test 8- and 9-char entity strings
52 * for possible buffer overflows */
53 result
= entity_decode("�");
54 g_assert_null(result
);
55 result
= entity_decode("�");
56 g_assert_null(result
);
60 test_entity_unprintable(void)
62 gchar
*result
, numstr
[6]; /* "&#XX;" */
65 for (i
= 0; i
< 32; i
++) {
66 sprintf(numstr
, "&#%d;", i
);
67 result
= entity_decode(numstr
);
68 g_assert_nonnull(result
);
69 g_assert_cmpstr(result
, ==, "\xef\xbf\xbd");
75 test_entity_valid(void)
79 result
= entity_decode("Á");
80 g_assert_nonnull(result
);
82 g_printerr("result '%s'\n", result
);
83 g_assert_cmpstr(result
, ==, "Á");
86 result
= entity_decode("{");
87 g_assert_nonnull(result
);
89 g_printerr("result '%s'\n", result
);
90 g_assert_cmpstr(result
, ==, "{");
96 main(int argc
, char *argv
[])
98 g_test_init(&argc
, &argv
, NULL
);
100 g_test_add_func("/core/entity/invalid", test_entity_invalid
);
101 g_test_add_func("/core/entity/toolong", test_entity_toolong
);
102 g_test_add_func("/core/entity/unprintable", test_entity_unprintable
);
103 g_test_add_func("/core/entity/valid", test_entity_valid
);