Fri, 18 May 2007 22:04:01 +0000
Added to gtkutils.c:
GtkWidget *pidgin_create_window(const char *title, guint border_width, const char *role, gboolean resizable);
| 15105 | 1 | #include <glib.h> |
| 2 | #include <check.h> | |
| 3 | #include <stdlib.h> | |
| 4 | #include <string.h> | |
| 5 | ||
| 6 | #undef HAVE_DBUS | |
| 7 | ||
|
15950
0f01bb61c5d3
Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
8 | #include "tests.h" |
|
0f01bb61c5d3
Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
9 | |
| 15105 | 10 | #include "../cipher.h" |
| 11 | #include "../signal.h" | |
| 12 | ||
| 13 | /****************************************************************************** | |
| 14 | * MD4 Tests | |
| 15 | *****************************************************************************/ | |
| 16 | #define MD4_TEST(data, digest) { \ | |
| 15884 | 17 | PurpleCipher *cipher = NULL; \ |
| 18 | PurpleCipherContext *context = NULL; \ | |
| 15105 | 19 | gchar cdigest[33]; \ |
| 20 | gboolean ret = FALSE; \ | |
| 21 | \ | |
| 15884 | 22 | cipher = purple_ciphers_find_cipher("md4"); \ |
| 23 | context = purple_cipher_context_new(cipher, NULL); \ | |
| 24 | purple_cipher_context_append(context, (guchar *)(data), strlen((data))); \ | |
| 15105 | 25 | \ |
| 15884 | 26 | ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \ |
| 15105 | 27 | NULL); \ |
| 28 | \ | |
| 29 | fail_unless(ret == TRUE, NULL); \ | |
| 30 | \ | |
| 31 | fail_unless(strcmp((digest), cdigest) == 0, NULL); \ | |
| 32 | \ | |
| 15884 | 33 | purple_cipher_context_destroy(context); \ |
| 15105 | 34 | } |
| 35 | ||
| 36 | START_TEST(test_md4_empty_string) { | |
| 37 | MD4_TEST("", "31d6cfe0d16ae931b73c59d7e0c089c0"); | |
| 38 | } | |
| 39 | END_TEST | |
| 40 | ||
| 41 | START_TEST(test_md4_a) { | |
| 42 | MD4_TEST("a", "bde52cb31de33e46245e05fbdbd6fb24"); | |
| 43 | } | |
| 44 | END_TEST | |
| 45 | ||
| 46 | START_TEST(test_md4_abc) { | |
| 47 | MD4_TEST("abc", "a448017aaf21d8525fc10ae87aa6729d"); | |
| 48 | } | |
| 49 | END_TEST | |
| 50 | ||
| 51 | START_TEST(test_md4_message_digest) { | |
| 52 | MD4_TEST("message digest", "d9130a8164549fe818874806e1c7014b"); | |
| 53 | } | |
| 54 | END_TEST | |
| 55 | ||
| 56 | START_TEST(test_md4_a_to_z) { | |
| 57 | MD4_TEST("abcdefghijklmnopqrstuvwxyz", | |
| 58 | "d79e1c308aa5bbcdeea8ed63df412da9"); | |
| 59 | } | |
| 60 | END_TEST | |
| 61 | ||
| 62 | START_TEST(test_md4_A_to_Z_a_to_z_0_to_9) { | |
| 63 | MD4_TEST("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", | |
| 64 | "043f8582f241db351ce627e153e7f0e4"); | |
| 65 | } | |
| 66 | END_TEST | |
| 67 | ||
| 68 | START_TEST(test_md4_1_to_0_8_times) { | |
| 69 | MD4_TEST("123456789012345678901234567890123456789012345678901234567890" | |
| 70 | "12345678901234567890", | |
| 71 | "e33b4ddc9c38f2199c3e7b164fcc0536"); | |
| 72 | } | |
| 73 | END_TEST | |
| 74 | ||
| 75 | ||
| 76 | /****************************************************************************** | |
| 77 | * MD5 Tests | |
| 78 | *****************************************************************************/ | |
| 79 | #define MD5_TEST(data, digest) { \ | |
| 15884 | 80 | PurpleCipher *cipher = NULL; \ |
| 81 | PurpleCipherContext *context = NULL; \ | |
| 15105 | 82 | gchar cdigest[33]; \ |
| 83 | gboolean ret = FALSE; \ | |
| 84 | \ | |
| 15884 | 85 | cipher = purple_ciphers_find_cipher("md5"); \ |
| 86 | context = purple_cipher_context_new(cipher, NULL); \ | |
| 87 | purple_cipher_context_append(context, (guchar *)(data), strlen((data))); \ | |
| 15105 | 88 | \ |
| 15884 | 89 | ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \ |
| 15105 | 90 | NULL); \ |
| 91 | \ | |
| 92 | fail_unless(ret == TRUE, NULL); \ | |
| 93 | \ | |
| 94 | fail_unless(strcmp((digest), cdigest) == 0, NULL); \ | |
| 95 | \ | |
| 15884 | 96 | purple_cipher_context_destroy(context); \ |
| 15105 | 97 | } |
| 98 | ||
| 99 | START_TEST(test_md5_empty_string) { | |
| 100 | MD5_TEST("", "d41d8cd98f00b204e9800998ecf8427e"); | |
| 101 | } | |
| 102 | END_TEST | |
| 103 | ||
| 104 | START_TEST(test_md5_a) { | |
| 105 | MD5_TEST("a", "0cc175b9c0f1b6a831c399e269772661"); | |
| 106 | } | |
| 107 | END_TEST | |
| 108 | ||
| 109 | START_TEST(test_md5_abc) { | |
| 110 | MD5_TEST("abc", "900150983cd24fb0d6963f7d28e17f72"); | |
| 111 | } | |
| 112 | END_TEST | |
| 113 | ||
| 114 | START_TEST(test_md5_message_digest) { | |
| 115 | MD5_TEST("message digest", "f96b697d7cb7938d525a2f31aaf161d0"); | |
| 116 | } | |
| 117 | END_TEST | |
| 118 | ||
| 119 | START_TEST(test_md5_a_to_z) { | |
| 120 | MD5_TEST("abcdefghijklmnopqrstuvwxyz", | |
| 121 | "c3fcd3d76192e4007dfb496cca67e13b"); | |
| 122 | } | |
| 123 | END_TEST | |
| 124 | ||
| 125 | START_TEST(test_md5_A_to_Z_a_to_z_0_to_9) { | |
| 126 | MD5_TEST("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", | |
| 127 | "d174ab98d277d9f5a5611c2c9f419d9f"); | |
| 128 | } | |
| 129 | END_TEST | |
| 130 | ||
| 131 | START_TEST(test_md5_1_to_0_8_times) { | |
| 132 | MD5_TEST("123456789012345678901234567890123456789012345678901234567890" | |
| 133 | "12345678901234567890", | |
| 134 | "57edf4a22be3c955ac49da2e2107b67a"); | |
| 135 | } | |
| 136 | END_TEST | |
| 137 | ||
| 138 | /****************************************************************************** | |
| 139 | * SHA-1 Tests | |
| 140 | *****************************************************************************/ | |
| 141 | #define SHA1_TEST(data, digest) { \ | |
| 15884 | 142 | PurpleCipher *cipher = NULL; \ |
| 143 | PurpleCipherContext *context = NULL; \ | |
| 15105 | 144 | gchar cdigest[41]; \ |
| 145 | gboolean ret = FALSE; \ | |
| 146 | \ | |
| 15884 | 147 | cipher = purple_ciphers_find_cipher("sha1"); \ |
| 148 | context = purple_cipher_context_new(cipher, NULL); \ | |
| 15105 | 149 | \ |
| 150 | if((data)) { \ | |
| 15884 | 151 | purple_cipher_context_append(context, (guchar *)(data), strlen((data))); \ |
| 15105 | 152 | } else { \ |
| 153 | gint j; \ | |
| 154 | guchar buff[1000]; \ | |
| 155 | \ | |
| 156 | memset(buff, 'a', 1000); \ | |
| 157 | \ | |
| 158 | for(j = 0; j < 1000; j++) \ | |
| 15884 | 159 | purple_cipher_context_append(context, buff, 1000); \ |
| 15105 | 160 | } \ |
| 161 | \ | |
| 15884 | 162 | ret = purple_cipher_context_digest_to_str(context, sizeof(cdigest), cdigest, \ |
| 15105 | 163 | NULL); \ |
| 164 | \ | |
| 165 | fail_unless(ret == TRUE, NULL); \ | |
| 166 | \ | |
| 167 | fail_unless(strcmp((digest), cdigest) == 0, NULL); \ | |
| 168 | \ | |
| 15884 | 169 | purple_cipher_context_destroy(context); \ |
| 15105 | 170 | } |
| 171 | ||
| 172 | START_TEST(test_sha1_a) { | |
| 173 | SHA1_TEST("a", "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8"); | |
| 174 | } | |
| 175 | END_TEST | |
| 176 | ||
| 177 | START_TEST(test_sha1_abc) { | |
| 178 | SHA1_TEST("abc", "a9993e364706816aba3e25717850c26c9cd0d89d"); | |
| 179 | } | |
| 180 | END_TEST | |
| 181 | ||
| 182 | START_TEST(test_sha1_abcd_gibberish) { | |
| 183 | SHA1_TEST("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | |
| 184 | "84983e441c3bd26ebaae4aa1f95129e5e54670f1"); | |
| 185 | } | |
| 186 | END_TEST | |
| 187 | ||
| 188 | START_TEST(test_sha1_1000_as_1000_times) { | |
| 189 | SHA1_TEST(NULL, "34aa973cd4c4daa4f61eeb2bdbad27316534016f"); | |
| 190 | } | |
| 191 | END_TEST | |
| 192 | ||
| 193 | /****************************************************************************** | |
| 194 | * Suite | |
| 195 | *****************************************************************************/ | |
| 196 | Suite * | |
| 197 | cipher_suite(void) { | |
| 198 | Suite *s = suite_create("Cipher Suite"); | |
| 199 | TCase *tc = NULL; | |
|
15950
0f01bb61c5d3
Fix compiler warnings and errors in tests resulting from using DEBUG_CFLAGS
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
15884
diff
changeset
|
200 | |
|
15106
e05ce518c3a4
[gaim-migrate @ 17828]
Gary Kramlich <grim@reaperworld.com>
parents:
15105
diff
changeset
|
201 | /* md4 tests */ |
| 15105 | 202 | tc = tcase_create("MD4"); |
| 203 | tcase_add_test(tc, test_md4_empty_string); | |
| 204 | tcase_add_test(tc, test_md4_a); | |
| 205 | tcase_add_test(tc, test_md4_abc); | |
| 206 | tcase_add_test(tc, test_md4_message_digest); | |
| 207 | tcase_add_test(tc, test_md4_a_to_z); | |
| 208 | tcase_add_test(tc, test_md4_A_to_Z_a_to_z_0_to_9); | |
| 209 | tcase_add_test(tc, test_md4_1_to_0_8_times); | |
| 210 | suite_add_tcase(s, tc); | |
| 211 | ||
| 212 | /* md5 tests */ | |
| 213 | tc = tcase_create("MD5"); | |
| 214 | tcase_add_test(tc, test_md5_empty_string); | |
| 215 | tcase_add_test(tc, test_md5_a); | |
| 216 | tcase_add_test(tc, test_md5_abc); | |
| 217 | tcase_add_test(tc, test_md5_message_digest); | |
| 218 | tcase_add_test(tc, test_md5_a_to_z); | |
| 219 | tcase_add_test(tc, test_md5_A_to_Z_a_to_z_0_to_9); | |
| 220 | tcase_add_test(tc, test_md5_1_to_0_8_times); | |
| 221 | suite_add_tcase(s, tc); | |
| 222 | ||
| 223 | /* sha1 tests */ | |
| 224 | tc = tcase_create("SHA1"); | |
| 225 | tcase_add_test(tc, test_sha1_a); | |
| 226 | tcase_add_test(tc, test_sha1_abc); | |
| 227 | tcase_add_test(tc, test_sha1_abcd_gibberish); | |
| 228 | tcase_add_test(tc, test_sha1_1000_as_1000_times); | |
| 229 | suite_add_tcase(s, tc); | |
| 230 | ||
| 231 | return s; | |
| 232 | } | |
| 233 | ||
| 234 |