Fix error creation and warning
[claws.git] / src / common / tests / codeconv_test.c
blob2775f69772b2f938484043a3fc6c4fb4fd82553c
1 #include "config.h"
3 #include <glib.h>
5 #include "codeconv.h"
7 #include "mock_prefs_common_get_use_shred.h"
8 #include "mock_prefs_common_get_flush_metadata.h"
10 struct td {
11 gchar *pre; /* Input string */
12 gchar *post; /* Expected output */
15 struct td from_utf8_empty = { "", "" };
16 /* TODO: more tests */
18 struct td to_utf8_empty = { "", "" };
19 /* TODO: more tests */
21 static void
22 test_filename_from_utf8_null()
24 if (!g_test_undefined())
25 return;
27 if (g_test_subprocess()) {
28 gchar *out;
30 out = conv_filename_from_utf8(NULL);
31 g_assert_null(out);
32 return;
35 g_test_trap_subprocess(NULL, 0, 0);
36 g_test_trap_assert_stdout("*Condition*failed*");
37 g_test_trap_assert_passed();
40 static void
41 test_filename_from_utf8(gconstpointer user_data)
43 struct td *data = (struct td *)user_data;
45 if (!g_test_undefined())
46 return;
48 if (g_test_subprocess()) {
49 gchar *out;
51 out = conv_filename_from_utf8(data->pre);
52 g_assert_cmpstr(out, ==, data->post);
54 g_free(out);
55 return;
58 g_test_trap_subprocess(NULL, 0, 0);
59 g_test_trap_assert_passed();
62 static void
63 test_filename_to_utf8(gconstpointer user_data)
65 struct td *data = (struct td *)user_data;
67 if (!g_test_undefined())
68 return;
70 if (g_test_subprocess()) {
71 gchar *out;
73 out = conv_filename_to_utf8(data->pre);
74 g_assert_cmpstr(out, ==, data->post);
76 g_free(out);
77 return;
80 g_test_trap_subprocess(NULL, 0, 0);
81 g_test_trap_assert_passed();
84 int
85 main(int argc, char *argv[])
87 g_test_init(&argc, &argv, NULL);
89 g_test_add_func("/common/codeconv/filename_from_utf8/null",
90 test_filename_from_utf8_null);
91 g_test_add_data_func("/common/codeconv/filename_from_utf8/empty",
92 &from_utf8_empty,
93 test_filename_from_utf8);
95 g_test_add_func("/common/codeconv/filename_to_utf8/null",
96 test_filename_from_utf8_null);
97 g_test_add_data_func("/common/codeconv/filename_to_utf8/empty",
98 &to_utf8_empty,
99 test_filename_to_utf8);
101 /* TODO: more tests */
103 return g_test_run();