Fix error creation and warning
[claws.git] / src / common / tests / utils_get_uri_part_test.c
blobddd9b0f394331890892fe4cb18110e3d7041f557
1 #include "config.h"
3 #include <stdio.h>
4 #include <glib.h>
6 #include "utils.h"
8 #include "mock_prefs_common_get_use_shred.h"
9 #include "mock_prefs_common_get_flush_metadata.h"
11 struct td_get_uri_part {
12 gchar *str;
13 gboolean ret;
14 guint uri_length;
17 struct td_get_uri_part td_get_uri_basic = {
18 "http://www.example.com", TRUE, 22
20 struct td_get_uri_part td_get_uri_slash = {
21 "http://www.example.com/", TRUE, 23
23 struct td_get_uri_part td_get_uri_question = {
24 "http://www.example.com/foo?", TRUE, 27
26 struct td_get_uri_part td_get_uri_parenthesis = {
27 "http://www.example.com/f(o)o", TRUE, 28
29 struct td_get_uri_part td_get_uri_brace = {
30 "http://www.example.com/f[oo", TRUE, 24
32 struct td_get_uri_part td_get_uri_umlaut = {
33 "http://www.examöple.com", TRUE, 24
35 struct td_get_uri_part td_get_uri_kanji = {
36 "http://www.漢字.com", TRUE, 21
38 struct td_get_uri_part td_get_uri_nonprintable = {
39 "http://www.exam\x01ple.com", TRUE, 15
42 #define URI "http://www.example.com"
43 static void
44 test_utils_get_uri_part_nowhitespace()
46 gboolean ret;
47 gchar *str = g_strdup("Nowhitespace"URI"nowhitespace");
48 const gchar *bp, *ep;
50 ret = get_uri_part(str, str + 12, &bp, &ep, FALSE);
52 g_assert_true(ret);
53 g_assert_true(ep == str + strlen(str));
55 g_free(str);
58 static void
59 test_utils_get_uri_part_whitespace()
61 gboolean ret;
62 gchar *str = g_strdup("Whitespace "URI" whitespace");
63 const gchar *bp, *ep;
65 ret = get_uri_part(str, str + 11, &bp, &ep, FALSE);
67 g_assert_true(ret);
68 g_assert_true(ep == bp + strlen(URI));
70 g_free(str);
72 #undef URI
74 static void
75 test_utils_get_uri_part(gconstpointer user_data)
77 const struct td_get_uri_part *data = (struct td_get_uri_part *)user_data;
78 gboolean ret;
79 const gchar *bp, *ep;
81 ret = get_uri_part(data->str, data->str, &bp, &ep, FALSE);
83 g_assert_nonnull(bp);
84 g_assert_nonnull(ep);
86 g_assert_true(ret == data->ret);
87 g_assert_true(ep >= bp);
88 g_assert_true(bp + data->uri_length == ep);
91 int
92 main(int argc, char *argv[])
94 g_test_init(&argc, &argv, NULL);
96 g_test_add_func("/common/utils/get_uri_part/nowhitespace",
97 test_utils_get_uri_part_nowhitespace);
98 g_test_add_func("/common/utils/get_uri_part/whitespace",
99 test_utils_get_uri_part_whitespace);
101 g_test_add_data_func("/common/utils/get_uri_part/basic",
102 &td_get_uri_basic,
103 test_utils_get_uri_part);
104 g_test_add_data_func("/common/utils/get_uri_part/slash",
105 &td_get_uri_slash,
106 test_utils_get_uri_part);
107 g_test_add_data_func("/common/utils/get_uri_part/question",
108 &td_get_uri_question,
109 test_utils_get_uri_part);
110 g_test_add_data_func("/common/utils/get_uri_part/parenthesis",
111 &td_get_uri_parenthesis,
112 test_utils_get_uri_part);
113 g_test_add_data_func("/common/utils/get_uri_part/brace",
114 &td_get_uri_brace,
115 test_utils_get_uri_part);
116 g_test_add_data_func("/common/utils/get_uri_part/umlaut",
117 &td_get_uri_umlaut,
118 test_utils_get_uri_part);
119 g_test_add_data_func("/common/utils/get_uri_part/kanji",
120 &td_get_uri_kanji,
121 test_utils_get_uri_part);
122 g_test_add_data_func("/common/utils/get_uri_part/nonprintable",
123 &td_get_uri_nonprintable,
124 test_utils_get_uri_part);
126 return g_test_run();