Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix sem_init testing.
[simgrid.git] / src / xbt_sha_unit.c
1 /*******************************/
2 /* GENERATED FILE, DO NOT EDIT */
3 /*******************************/
4
5 #include <stdio.h>
6 #include "xbt.h"
7 /*******************************/
8 /* GENERATED FILE, DO NOT EDIT */
9 /*******************************/
10
11 #line 179 "xbt/xbt_sha.c" 
12 #include "xbt/hash.h"
13 #include "portable.h"           /* hexa_str */
14
15 static char *mycmp(const char *p1, const char *p2, size_t n)
16 {
17   int i;
18
19   for (i = 0; i < n; i++) {
20     if (p1[i] != p2[i]) {
21       return bprintf("Differs on %d -- Ox%x", i, p1[i]);
22     }
23   }
24   return xbt_strdup("");
25 }
26
27 static void test_sha(const char *clear, const char *hashed)
28 {
29   char hash[41];
30   xbt_sha(clear, hash);
31
32   xbt_test_add1("==== Test with '%s'", clear);
33   xbt_test_assert3(!memcmp(hash, hashed, 40), "Wrong sha: %40s!=%40s (%s)",
34                    hash, hashed, mycmp(hash, hashed, 40));
35 }
36
37
38 XBT_LOG_NEW_DEFAULT_CATEGORY(hash, "Tests of various hash functions ");
39
40
41 XBT_TEST_UNIT("sha", test_crypto_sha, "Test of the sha algorithm")
42 {
43   /* Empty string as test vector */
44   test_sha("", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
45
46   /* Some pangram as test vector */
47   test_sha("The quick brown fox jumps over the lazy dog",
48            "2fd4e1c67a2d28fced849ee1bb76e7391b93eb12");
49   test_sha("Woven silk pyjamas exchanged for blue quartz",
50            "da3aff337c810c6470db4dbf0f205c8afc31c442");
51   test_sha("Pack my box with five dozen liquor jugs",
52            "373ba8be29d4d95708bf7cd43038f4e409dcb439");
53
54 }
55 /*******************************/
56 /* GENERATED FILE, DO NOT EDIT */
57 /*******************************/
58