blob: ee8c59719b00394ec630a83318357a20857a6654 (
plain)
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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <parserutils/utils/dict.h>
#include "testutils.h"
extern void parserutils_dict_dump(parserutils_dict *dict);
static void *myrealloc(void *ptr, size_t len, void *pw)
{
UNUSED(pw);
return realloc(ptr, len);
}
int main(int argc, char **argv)
{
parserutils_dict *dict;
uint8_t buf[256];
UNUSED(argc);
UNUSED(argv);
/* Seed buffer with printable ascii */
for (int i = 0; i < (int) sizeof(buf); i++) {
buf[i] = 97 + (int) (26.0 * (rand() / (RAND_MAX + 1.0)));
}
buf[sizeof(buf) - 1] = '\0';
dict = parserutils_dict_create(myrealloc, NULL);
assert(dict != NULL);
for (int i = 0; i < (int) sizeof(buf); i++) {
uint8_t *s = buf;
while (s - buf <= i) {
const parserutils_dict_entry *e;
parserutils_dict_insert(dict,
s, (size_t) (sizeof(buf) - i), &e);
s++;
}
}
parserutils_dict_destroy(dict);
printf("PASS\n");
return 0;
}
|