-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtest.c
68 lines (57 loc) · 1.23 KB
/
dtest.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
#include "dictionary.h"
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
int main(int argc, char **argv)
{
Handle dict;
Word rv;
dict = DictionaryCreate(MMStartUp(), 0);
if (!dict)
{
fprintf(stderr, "Error: DictionaryCreate() == NULL\n");
exit(1);
}
rv = DictionaryAdd(dict, "key",3,"value",5, 0);
if (!rv)
{
fprintf(stderr, "Error: DictionaryAdd() == 0\n");
DisposeHandle(dict);
exit(1);
}
rv = DictionaryContains(dict, "key",3);
if (!rv)
{
fprintf(stderr, "Error: DictionaryContains() == 0\n");
DisposeHandle(dict);
exit(1);
}
rv = DictionaryCount(dict);
if (rv != 1)
{
fprintf(stderr, "Error: DictionaryCount() != 1\n");
DisposeHandle(dict);
exit(1);
}
rv = DictionaryAdd(dict, "key2",4, "value2", 6, false);
if (!rv)
{
fprintf(stderr, "Error: DictionaryAdd() == 0\n");
DisposeHandle(dict);
exit(1);
}
{
Word cookie = 0;
DictionaryEnumerator e;
while ((cookie = DictionaryEnumerate(dict, &e, cookie)) != 0)
{
fwrite(e.key, 1, e.keySize, stdout);
fwrite(" -> ", 1, 4, stdout);
fwrite(e.value, 1, e.valueSize, stdout);
fputc('\n', stdout);
}
}
DisposeHandle(dict);
exit(0);
return 0;
}