talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

codeconv_test.c (1964B)


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