Mercurial > pidgin.yaz
view libpurple/tests/test_util.c @ 23325:8c315f969600
Patch from Andrew Gaul that fixes another leak:
==24860== 61,150 (15,900 direct, 45,250 indirect) bytes in 124 blocks are definitely lost in loss record 294 of 317
==24860== at 0x4A07A7E: malloc (vg_replace_malloc.c:207)
==24860== by 0x331303F8A2: g_malloc (in /lib64/libglib-2.0.so.0.1600.3)
==24860== by 0x3313055397: g_slice_alloc (in /lib64/libglib-2.0.so.0.1600.3)
==24860== by 0x3BC001B0D9: gdk_color_copy (in /usr/lib64/libgdk-x11-2.0.so.0.1200.9)
==24860== by 0x3313408E2B: (within /lib64/libgobject-2.0.so.0.1600.3)
==24860== by 0x331340FC95: g_object_get_valist (in /lib64/libgobject-2.0.so.0.1600.3)
==24860== by 0x331340FF03: g_object_get (in /lib64/libgobject-2.0.so.0.1600.3)
==24860== by 0x47C1A1: tag_to_html_start (gtkimhtml.c:5023)
==24860== by 0x47C5EF: text_tag_data_new (gtkimhtml.c:5114)
==24860== by 0x47CA50: gtk_imhtml_get_markup_range (gtkimhtml.c:5198)
==24860== by 0x47CEF8: gtk_imhtml_get_markup (gtkimhtml.c:5314)
==24860== by 0x44BC3B: send_cb (gtkconv.c:548)
author | Ka-Hing Cheung <khc@hxbc.us> |
---|---|
date | Sun, 08 Jun 2008 22:18:14 +0000 |
parents | 5aacf801f6b6 |
children | ba1799f21383 |
line wrap: on
line source
#include <string.h> #include "tests.h" #include "../util.h" START_TEST(test_util_base16_encode) { assert_string_equal_free("68656c6c6f2c20776f726c642100", purple_base16_encode("hello, world!", 14)); } END_TEST START_TEST(test_util_base16_decode) { gsize sz = 0; guchar *out = purple_base16_decode("21646c726f77202c6f6c6c656800", &sz); fail_unless(sz == 14, NULL); fail_unless(strcmp("!dlrow ,olleh", out) == 0, NULL); g_free(out); } END_TEST START_TEST(test_util_base64_encode) { assert_string_equal_free("Zm9ydHktdHdvAA==", purple_base64_encode("forty-two", 10)); } END_TEST START_TEST(test_util_base64_decode) { gsize sz; guchar *out = purple_base64_decode("b3d0LXl0cm9mAA==", &sz); fail_unless(sz == 10, NULL); fail_unless(strcmp("owt-ytrof", out) == 0, NULL); g_free(out); } END_TEST START_TEST(test_util_escape_filename) { assert_string_equal("foo", purple_escape_filename("foo")); assert_string_equal("@oo", purple_escape_filename("@oo")); assert_string_equal("#oo", purple_escape_filename("#oo")); assert_string_equal("-oo", purple_escape_filename("-oo")); assert_string_equal("_oo", purple_escape_filename("_oo")); assert_string_equal(".oo", purple_escape_filename(".oo")); assert_string_equal("%25oo", purple_escape_filename("%oo")); assert_string_equal("%21oo", purple_escape_filename("!oo")); } END_TEST START_TEST(test_util_unescape_filename) { assert_string_equal("bar", purple_unescape_filename("bar")); assert_string_equal("@ar", purple_unescape_filename("@ar")); assert_string_equal("!ar", purple_unescape_filename("!ar")); assert_string_equal("!ar", purple_unescape_filename("%21ar")); assert_string_equal("%ar", purple_unescape_filename("%25ar")); } END_TEST START_TEST(test_util_text_strip_mnemonic) { assert_string_equal_free("", purple_text_strip_mnemonic("")); assert_string_equal_free("foo", purple_text_strip_mnemonic("foo")); assert_string_equal_free("foo", purple_text_strip_mnemonic("_foo")); } END_TEST START_TEST(test_util_email_is_valid) { fail_unless(purple_email_is_valid("purple-devel@lists.sf.net")); fail_if(purple_email_is_valid("purple-devel@@lists.sf.net")); fail_if(purple_email_is_valid("purple@devel@lists.sf.net")); fail_if(purple_email_is_valid("purple-devel@list..sf.net")); fail_if(purple_email_is_valid("purple-devel")); fail_if(purple_email_is_valid("purple-devel@")); fail_if(purple_email_is_valid("@lists.sf.net")); fail_if(purple_email_is_valid("")); fail_if(purple_email_is_valid("totally bogus")); } END_TEST START_TEST(test_util_str_to_time) { fail_unless(377182200 == purple_str_to_time("19811214T12:50:00", TRUE, NULL, NULL, NULL)); fail_unless(1175919261 == purple_str_to_time("20070407T04:14:21", TRUE, NULL, NULL, NULL)); } END_TEST START_TEST(test_markup_html_to_xhtml) { gchar *xhtml = NULL; gchar *plaintext = NULL; purple_markup_html_to_xhtml("<a>", &xhtml, &plaintext); fail_unless(strcmp("<a href=''></a>", xhtml) == 0, NULL); g_free(xhtml); fail_unless(strcmp("", plaintext) == 0, NULL); g_free(plaintext); } END_TEST Suite * util_suite(void) { Suite *s = suite_create("Utility Functions"); TCase *tc = tcase_create("Base16"); tcase_add_test(tc, test_util_base16_encode); tcase_add_test(tc, test_util_base16_decode); suite_add_tcase(s, tc); tc = tcase_create("Base64"); tcase_add_test(tc, test_util_base64_encode); tcase_add_test(tc, test_util_base64_decode); suite_add_tcase(s, tc); tc = tcase_create("Filenames"); tcase_add_test(tc, test_util_escape_filename); tcase_add_test(tc, test_util_unescape_filename); suite_add_tcase(s, tc); tc = tcase_create("Strip Mnemonic"); tcase_add_test(tc, test_util_text_strip_mnemonic); suite_add_tcase(s, tc); tc = tcase_create("Email"); tcase_add_test(tc, test_util_email_is_valid); suite_add_tcase(s, tc); tc = tcase_create("Time"); tcase_add_test(tc, test_util_str_to_time); suite_add_tcase(s, tc); tc = tcase_create("Markup"); tcase_add_test(tc, test_markup_html_to_xhtml); suite_add_tcase(s, tc); return s; }