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