3b93eae3cde8a33db0d21ea5926529ae160c24c6
[claws.git] / src / common / tests / codeconv_test.c
1 #include <glib.h>
2
3 #include "codeconv.h"
4
5 #include "mock_prefs_common_get_use_shred.h"
6
7 struct td {
8         gchar *pre; /* Input string */
9         gchar *post; /* Expected output */
10 };
11
12 struct td from_utf8_empty = { "", "" };
13 /* TODO: more tests */
14
15 struct td to_utf8_empty = { "", "" };
16 /* TODO: more tests */
17
18 static void
19 test_filename_from_utf8_null()
20 {
21         if (!g_test_undefined())
22                 return;
23
24         if (g_test_subprocess()) {
25                 gchar *out;
26
27                 out = conv_filename_from_utf8(NULL);
28                 g_assert_null(out);
29                 return;
30         }
31
32         g_test_trap_subprocess(NULL, 0, 0);
33         g_test_trap_assert_stdout("*Condition*failed*");
34         g_test_trap_assert_passed();
35 }
36
37 static void
38 test_filename_from_utf8(gconstpointer user_data)
39 {
40         struct td *data = (struct td *)user_data;
41
42         if (!g_test_undefined())
43                 return;
44
45         if (g_test_subprocess()) {
46                 gchar *out;
47
48                 out = conv_filename_from_utf8(data->pre);
49                 g_assert_cmpstr(out, ==, data->post);
50
51                 g_free(out);
52                 return;
53         }
54
55         g_test_trap_subprocess(NULL, 0, 0);
56         g_test_trap_assert_passed();
57 }
58
59 static void
60 test_filename_to_utf8(gconstpointer user_data)
61 {
62         struct td *data = (struct td *)user_data;
63
64         if (!g_test_undefined())
65                 return;
66
67         if (g_test_subprocess()) {
68                 gchar *out;
69
70                 out = conv_filename_to_utf8(data->pre);
71                 g_assert_cmpstr(out, ==, data->post);
72
73                 g_free(out);
74                 return;
75         }
76
77         g_test_trap_subprocess(NULL, 0, 0);
78         g_test_trap_assert_passed();
79 }
80
81 int
82 main(int argc, char *argv[])
83 {
84         g_test_init(&argc, &argv, NULL);
85
86         g_test_add_func("/common/codeconv/filename_from_utf8/null",
87                         test_filename_from_utf8_null);
88         g_test_add_data_func("/common/codeconv/filename_from_utf8/empty",
89                         &from_utf8_empty,
90                         test_filename_from_utf8);
91
92         g_test_add_func("/common/codeconv/filename_to_utf8/null",
93                         test_filename_from_utf8_null);
94         g_test_add_data_func("/common/codeconv/filename_to_utf8/empty",
95                         &to_utf8_empty,
96                         test_filename_to_utf8);
97
98         /* TODO: more tests */
99
100         return g_test_run();
101 }