comparison libgaim/tests/check_libgaim.c @ 15040:ba149ceb20b7

[gaim-migrate @ 17823] baby steps: 4 unit tests for libgaim to run these, you'll need check (http://check.sf.net/) 0.9.4 or later installed they run when you run 'make check' committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Sun, 26 Nov 2006 22:03:23 +0000
parents
children edd78a0c6698
comparison
equal deleted inserted replaced
15039:9a69964d8c18 15040:ba149ceb20b7
1 #include <glib.h>
2 #include <check.h>
3 #include <stdlib.h>
4 #include "../util.h"
5
6 START_TEST(test_util_base16_encode)
7 {
8 gchar *out = gaim_base16_encode("hello, world!", 14);
9 fail_unless(strcmp("68656c6c6f2c20776f726c642100", out) == 0, NULL);
10 g_free(out);
11 }
12 END_TEST
13
14 START_TEST(test_util_base16_decode)
15 {
16 gsize sz = 0;
17 guchar *out = gaim_base16_decode("21646c726f77202c6f6c6c656800", &sz);
18 fail_unless(sz == 14, NULL);
19 fail_unless(strcmp("!dlrow ,olleh", out) == 0, NULL);
20 g_free(out);
21 }
22 END_TEST
23
24 START_TEST(test_util_base64_encode)
25 {
26 gchar *out = gaim_base64_encode("forty-two", 10);
27 fail_unless(strcmp("Zm9ydHktdHdvAA==",out) == 0, NULL);
28 g_free(out);
29 }
30 END_TEST
31
32 START_TEST(test_util_base64_decode)
33 {
34 gsize sz;
35 guchar *out = gaim_base64_decode("b3d0LXl0cm9mAA==", &sz);
36 fail_unless(sz == 10, NULL);
37 fail_unless(strcmp("owt-ytrof", out) == 0, NULL);
38 g_free(out);
39 }
40 END_TEST
41
42 Suite *
43 util_suite(void)
44 {
45 Suite *s = suite_create("Utility Functions");
46
47 TCase *tc = tcase_create("Base16");
48 tcase_add_test(tc, test_util_base16_encode);
49 tcase_add_test(tc, test_util_base16_decode);
50 suite_add_tcase(s, tc);
51
52 tc = tcase_create("Base64");
53 tcase_add_test(tc, test_util_base64_encode);
54 tcase_add_test(tc, test_util_base64_decode);
55 suite_add_tcase(s, tc);
56
57 return s;
58 }
59
60 int main(void)
61 {
62 int number_failed;
63 Suite *s = util_suite ();
64 SRunner *sr = srunner_create (s);
65 srunner_run_all (sr, CK_NORMAL);
66 number_failed = srunner_ntests_failed (sr);
67 srunner_free (sr);
68 return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
69 }