]> git.saurik.com Git - apple/libc.git/blob - tests/os_simple_hash.c
Libc-1439.100.3.tar.gz
[apple/libc.git] / tests / os_simple_hash.c
1 #include <darwintest.h>
2 #include <stdlib.h>
3 #include <os/stdlib.h>
4
5 T_DECL(os_simple_hash, "sanity check of os_simple_hash",
6 T_META_ALL_VALID_ARCHS(true))
7 {
8 const char * string =
9 "We made the buttons on the screen look so good you'll want to lick them.";
10 uint64_t hashval = os_simple_hash_string(string);
11 T_EXPECT_NE(hashval, 0ULL, "usually should get a non-0 hash value");
12
13 char buf[1024];
14 arc4random_buf(buf, sizeof(buf));
15 hashval = os_simple_hash(buf, sizeof(buf));
16 T_EXPECT_NE(hashval, 0ULL, "usually should get a non-0 hash value");
17 }
18
19 T_DECL(os_simple_hash_seeds, "os_simple_hash different seeds give different hashes",
20 T_META_ALL_VALID_ARCHS(true))
21 {
22 const char * string =
23 "We made the buttons on the screen look so good you'll want to lick them.";
24
25 uint64_t hashval0 = os_simple_hash_string_with_seed(string, 0x0);
26 T_EXPECT_NE(hashval0, 0ULL, "usually should get a non-0 hash value");
27 uint64_t hashval1 = os_simple_hash_string_with_seed(string, 0x1);
28 T_EXPECT_NE(hashval1, 0ULL, "usually should get a non-0 hash value");
29 uint64_t hashvalF = os_simple_hash_string_with_seed(string, 0xF);
30 T_EXPECT_NE(hashvalF, 0ULL, "usually should get a non-0 hash value");
31 uint64_t hashvalFoo = os_simple_hash_string_with_seed(string, 0xF0000000);
32 T_EXPECT_NE(hashvalFoo, 0ULL, "usually should get a non-0 hash value");
33
34 T_EXPECT_NE(hashval0, hashval1, NULL);
35 T_EXPECT_NE(hashval0, hashvalF, NULL);
36 T_EXPECT_NE(hashval0, hashvalFoo, NULL);
37 T_EXPECT_NE(hashval1, hashvalF, NULL);
38 T_EXPECT_NE(hashval1, hashvalFoo, NULL);
39 T_EXPECT_NE(hashvalF, hashvalFoo, NULL);
40 }