-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtest.c
75 lines (64 loc) · 1.58 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
* CacheHash Copyright 2014 Regents of the University of Michigan
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*/
#include <string.h>
#include "cachehash.h"
#include <assert.h>
#include <stdio.h>
cachehash *ch = NULL;
void testCreation(void)
{
ch = cachehash_init(5, NULL);
assert(ch);
cachehash_free(ch, NULL);
}
void testPut(void)
{
ch = cachehash_init(5, NULL);
char *key = "test-key";
char *value = "test-value";
cachehash_put(ch, key, strlen(key), value);
cachehash_debug_dump(ch);
key = "test-key-2";
value = "test-value-2";
cachehash_put(ch, key, strlen(key), value);
cachehash_debug_dump(ch);
}
void testPutAndHas(void)
{
ch = cachehash_init(5, NULL);
char *key = "test-key";
char *value = "test-value";
cachehash_put(ch, key, strlen(key), value);
cachehash_debug_dump(ch);
printf("value of has is %s\n", cachehash_has(ch, key, strlen(key)));
assert(cachehash_has(ch, key, strlen(key)) == value);
cachehash_free(ch, NULL);
}
void evict_cb(void *arg)
{
(void) arg;
}
void testEvict(void)
{
ch = cachehash_init(5, NULL);
char *key = "test-key";
char *value = "test-value";
cachehash_put(ch, key, strlen(key), value);
cachehash_debug_dump(ch);
printf("value of has is %s\n", cachehash_has(ch, key, strlen(key)));
assert(cachehash_has(ch, key, strlen(key)) == value);
cachehash_free(ch, NULL);
}
int main(void)
{
testCreation();
printf("--\n");
testPut();
printf("--\n");
testPutAndHas();
}