15043
|
1 #include "tests.h"
|
|
2 #include "../util.h"
|
|
3
|
|
4 START_TEST(test_util_base16_encode)
|
|
5 {
|
|
6 assert_string_equal_free("68656c6c6f2c20776f726c642100", gaim_base16_encode("hello, world!", 14));
|
|
7 }
|
|
8 END_TEST
|
|
9
|
|
10 START_TEST(test_util_base16_decode)
|
|
11 {
|
|
12 gsize sz = 0;
|
|
13 guchar *out = gaim_base16_decode("21646c726f77202c6f6c6c656800", &sz);
|
|
14 fail_unless(sz == 14, NULL);
|
|
15 fail_unless(strcmp("!dlrow ,olleh", out) == 0, NULL);
|
|
16 g_free(out);
|
|
17 }
|
|
18 END_TEST
|
|
19
|
|
20 START_TEST(test_util_base64_encode)
|
|
21 {
|
|
22 assert_string_equal_free("Zm9ydHktdHdvAA==", gaim_base64_encode("forty-two", 10));
|
|
23 }
|
|
24 END_TEST
|
|
25
|
|
26 START_TEST(test_util_base64_decode)
|
|
27 {
|
|
28 gsize sz;
|
|
29 guchar *out = gaim_base64_decode("b3d0LXl0cm9mAA==", &sz);
|
|
30 fail_unless(sz == 10, NULL);
|
|
31 fail_unless(strcmp("owt-ytrof", out) == 0, NULL);
|
|
32 g_free(out);
|
|
33 }
|
|
34 END_TEST
|
|
35
|
|
36 START_TEST(test_util_escape_filename)
|
|
37 {
|
|
38 assert_string_equal("foo", gaim_escape_filename("foo"));
|
|
39 assert_string_equal("@oo", gaim_escape_filename("@oo"));
|
|
40 assert_string_equal("#oo", gaim_escape_filename("#oo"));
|
|
41 assert_string_equal("-oo", gaim_escape_filename("-oo"));
|
|
42 assert_string_equal("_oo", gaim_escape_filename("_oo"));
|
|
43 assert_string_equal(".oo", gaim_escape_filename(".oo"));
|
|
44 assert_string_equal("%25oo", gaim_escape_filename("%oo"));
|
|
45 assert_string_equal("%21oo", gaim_escape_filename("!oo"));
|
|
46 }
|
|
47 END_TEST
|
|
48
|
|
49 START_TEST(test_util_unescape_filename)
|
|
50 {
|
|
51 assert_string_equal("bar", gaim_unescape_filename("bar"));
|
|
52 assert_string_equal("@ar", gaim_unescape_filename("@ar"));
|
|
53 assert_string_equal("!ar", gaim_unescape_filename("!ar"));
|
|
54 assert_string_equal("!ar", gaim_unescape_filename("%21ar"));
|
|
55 assert_string_equal("%ar", gaim_unescape_filename("%25ar"));
|
|
56 }
|
|
57 END_TEST
|
|
58
|
|
59
|
|
60 START_TEST(test_util_text_strip_mnemonic)
|
|
61 {
|
|
62 assert_string_equal_free("", gaim_text_strip_mnemonic(""));
|
|
63 assert_string_equal_free("foo", gaim_text_strip_mnemonic("foo"));
|
|
64 assert_string_equal_free("foo", gaim_text_strip_mnemonic("_foo"));
|
|
65
|
|
66 }
|
|
67 END_TEST
|
|
68
|
|
69 START_TEST(test_util_email_is_valid)
|
|
70 {
|
|
71 fail_unless(gaim_email_is_valid("gaim-devel@lists.sf.net"));
|
|
72 }
|
|
73 END_TEST
|
|
74
|
|
75 Suite *
|
|
76 util_suite(void)
|
|
77 {
|
|
78 Suite *s = suite_create("Utility Functions");
|
|
79
|
|
80 TCase *tc = tcase_create("Base16");
|
|
81 tcase_add_test(tc, test_util_base16_encode);
|
|
82 tcase_add_test(tc, test_util_base16_decode);
|
|
83 suite_add_tcase(s, tc);
|
|
84
|
|
85 tc = tcase_create("Base64");
|
|
86 tcase_add_test(tc, test_util_base64_encode);
|
|
87 tcase_add_test(tc, test_util_base64_decode);
|
|
88 suite_add_tcase(s, tc);
|
|
89
|
|
90 tc = tcase_create("Filenames");
|
|
91 tcase_add_test(tc, test_util_escape_filename);
|
|
92 tcase_add_test(tc, test_util_unescape_filename);
|
|
93 suite_add_tcase(s, tc);
|
|
94
|
|
95 tc = tcase_create("Strip Mnemonic");
|
|
96 tcase_add_test(tc, test_util_text_strip_mnemonic);
|
|
97 suite_add_tcase(s, tc);
|
|
98
|
|
99 tc = tcase_create("Email");
|
|
100 tcase_add_test(tc, test_util_email_is_valid);
|
|
101 suite_add_tcase(s, tc);
|
|
102
|
|
103 return s;
|
|
104 }
|