Migrate certificates, icons, logs to XDG dirs
[pidgin-git.git] / libpurple / tests / test_sha1.c
blob0569e009caf5fabeecaf6e8f9a24f0fdfa3b36eb
1 #include <glib.h>
3 #include <purple.h>
5 #include "ciphers/sha1hash.h"
7 static void
8 test_sha1hash(gchar *data, gchar *digest) {
9 PurpleHash *hash = NULL;
10 gchar cdigest[41];
11 gboolean ret = FALSE;
13 hash = purple_sha1_hash_new();
15 if(data) {
16 purple_hash_append(hash, (guchar *)data, strlen(data));
17 } else {
18 gint j;
19 guchar buff[1000];
21 memset(buff, 'a', 1000);
23 for(j = 0; j < 1000; j++)
24 purple_hash_append(hash, buff, 1000);
27 ret = purple_hash_digest_to_str(hash, cdigest, sizeof(cdigest));
29 g_assert(ret);
30 g_assert_cmpstr(digest, ==, cdigest);
33 static void
34 test_sha1hash_empty_string(void) {
35 test_sha1hash("",
36 "da39a3ee5e6b4b0d3255bfef95601890afd80709");
39 static void
40 test_sha1hash_a(void) {
41 test_sha1hash("a",
42 "86f7e437faa5a7fce15d1ddcb9eaeaea377667b8");
45 static void
46 test_sha1hash_abc(void) {
47 test_sha1hash("abc",
48 "a9993e364706816aba3e25717850c26c9cd0d89d");
51 static void
52 test_sha1hash_abcd_gibberish(void) {
53 test_sha1hash("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
54 "84983e441c3bd26ebaae4aa1f95129e5e54670f1");
57 static void
58 test_sha1hash_1000_as_1000_times(void) {
59 test_sha1hash(NULL,
60 "34aa973cd4c4daa4f61eeb2bdbad27316534016f");
63 gint
64 main(gint argc, gchar **argv) {
65 g_test_init(&argc, &argv, NULL);
67 g_test_add_func("/hash/sha1/empty-string",
68 test_sha1hash_empty_string);
69 g_test_add_func("/hash/sha1/a",
70 test_sha1hash_a);
71 g_test_add_func("/hash/sha1/abc",
72 test_sha1hash_abc);
73 g_test_add_func("/hash/sha1/abcd_gibberish",
74 test_sha1hash_abcd_gibberish);
75 g_test_add_func("/hash/sha1/1000 a's 1000 times",
76 test_sha1hash_1000_as_1000_times);
78 return g_test_run();