annotate libgaim/tests/test_util.c @ 15358:7c41ecf41614

[gaim-migrate @ 18151] Revert GtkIMHtml hacks that tried to fix gtkimhtml bugs, replace it with heuristic workaround. If you receive a message with more than 100 HTML tags strip all formatting before displaying it. Hopefully nobody has any legitimate uses for 100 HTML tags in a message. I guess we'll see in beta6... which I think we're good for now. I think that post-2.0.0 we'll wind up replacing GtkIMHtml with a legitimate HTML widget and do the Adium/Kopete "chat theme" thing. An HTML widget should be able to handle formatting more efficiently than GtkTextView. committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Thu, 18 Jan 2007 02:35:14 +0000
parents edd78a0c6698
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15042
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 #include "tests.h"
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 #include "../util.h"
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
4 START_TEST(test_util_base16_encode)
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 {
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
6 assert_string_equal_free("68656c6c6f2c20776f726c642100", gaim_base16_encode("hello, world!", 14));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
7 }
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
8 END_TEST
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 START_TEST(test_util_base16_decode)
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 {
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 gsize sz = 0;
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 guchar *out = gaim_base16_decode("21646c726f77202c6f6c6c656800", &sz);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 fail_unless(sz == 14, NULL);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 fail_unless(strcmp("!dlrow ,olleh", out) == 0, NULL);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 g_free(out);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 }
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 END_TEST
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 START_TEST(test_util_base64_encode)
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 {
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
22 assert_string_equal_free("Zm9ydHktdHdvAA==", gaim_base64_encode("forty-two", 10));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 }
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
24 END_TEST
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
25
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
26 START_TEST(test_util_base64_decode)
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27 {
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
28 gsize sz;
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
29 guchar *out = gaim_base64_decode("b3d0LXl0cm9mAA==", &sz);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30 fail_unless(sz == 10, NULL);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31 fail_unless(strcmp("owt-ytrof", out) == 0, NULL);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
32 g_free(out);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 }
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34 END_TEST
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36 START_TEST(test_util_escape_filename)
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37 {
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 assert_string_equal("foo", gaim_escape_filename("foo"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 assert_string_equal("@oo", gaim_escape_filename("@oo"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40 assert_string_equal("#oo", gaim_escape_filename("#oo"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
41 assert_string_equal("-oo", gaim_escape_filename("-oo"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42 assert_string_equal("_oo", gaim_escape_filename("_oo"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43 assert_string_equal(".oo", gaim_escape_filename(".oo"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
44 assert_string_equal("%25oo", gaim_escape_filename("%oo"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
45 assert_string_equal("%21oo", gaim_escape_filename("!oo"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
46 }
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
47 END_TEST
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
48
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
49 START_TEST(test_util_unescape_filename)
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
50 {
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51 assert_string_equal("bar", gaim_unescape_filename("bar"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52 assert_string_equal("@ar", gaim_unescape_filename("@ar"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53 assert_string_equal("!ar", gaim_unescape_filename("!ar"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54 assert_string_equal("!ar", gaim_unescape_filename("%21ar"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 assert_string_equal("%ar", gaim_unescape_filename("%25ar"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
56 }
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
57 END_TEST
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
58
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
59
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
60 START_TEST(test_util_text_strip_mnemonic)
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
61 {
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
62 assert_string_equal_free("", gaim_text_strip_mnemonic(""));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
63 assert_string_equal_free("foo", gaim_text_strip_mnemonic("foo"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
64 assert_string_equal_free("foo", gaim_text_strip_mnemonic("_foo"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
65
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
66 }
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67 END_TEST
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
69 START_TEST(test_util_email_is_valid)
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
70 {
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
71 fail_unless(gaim_email_is_valid("gaim-devel@lists.sf.net"));
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72 }
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
73 END_TEST
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
74
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
75 Suite *
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
76 util_suite(void)
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
77 {
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
78 Suite *s = suite_create("Utility Functions");
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
79
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
80 TCase *tc = tcase_create("Base16");
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
81 tcase_add_test(tc, test_util_base16_encode);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
82 tcase_add_test(tc, test_util_base16_decode);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
83 suite_add_tcase(s, tc);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
84
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
85 tc = tcase_create("Base64");
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
86 tcase_add_test(tc, test_util_base64_encode);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
87 tcase_add_test(tc, test_util_base64_decode);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
88 suite_add_tcase(s, tc);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
89
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
90 tc = tcase_create("Filenames");
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
91 tcase_add_test(tc, test_util_escape_filename);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
92 tcase_add_test(tc, test_util_unescape_filename);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
93 suite_add_tcase(s, tc);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
94
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
95 tc = tcase_create("Strip Mnemonic");
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
96 tcase_add_test(tc, test_util_text_strip_mnemonic);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
97 suite_add_tcase(s, tc);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
98
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
99 tc = tcase_create("Email");
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
100 tcase_add_test(tc, test_util_email_is_valid);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
101 suite_add_tcase(s, tc);
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
102
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
103 return s;
edd78a0c6698 [gaim-migrate @ 17825]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
104 }