-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.c
48 lines (44 loc) · 1.46 KB
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Tests for hash.c.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <stdint.h>
#include <stdio.h>
#include <string.h>
uint64_t hash(const unsigned char *url, int len);
/*
* Test that the hash of an url has the expected value.
* Returns 1 on pass, 0 on failure.
*/
static int test(const char *url, uint64_t expected) {
uint64_t actual = hash((const unsigned char *) url, strlen(url));
printf("url=\"%s\", expected=%lu, actual=%lu, result=", url, expected, actual);
if (expected == actual) {
printf("PASS\n");
return 0;
} else {
printf("***FAIL***\n");
return 1;
}
}
int main(int argc, char *argv[]) {
int count = 0;
/*
* Test hash values were created by manually bookmarking these URLs in
* Mozilla Firefox 59.0.2 and then examining places.sqlite with sqlite3.
*/
count += test("http://example.org/", 125508604170377UL);
count += test("https://example.org/", 47358175329495UL);
count += test("https://www.reddit.com/", 47359719085711UL);
count += test("https://old.reddit.com/", 47358033120677UL);
count += test("https://en.wikipedia.org/wiki/Libert%C3%A9", 47359238090423UL);
if (count == 0) {
printf("All tests PASSED\n");
} else {
printf("Tests FAILED: %d\n", count);
}
return count;
}