#include "gwlib/gwlib.h"Include dependency graph for test_dict.c:

Go to the source code of this file.
Defines | |
| #define | HUGE_SIZE 200000 |
Functions | |
| int | main (void) |
|
|
Definition at line 66 of file test_dict.c. Referenced by main(). |
|
|
Definition at line 68 of file test_dict.c. References debug(), dict_create(), dict_destroy(), dict_get(), dict_key_count(), dict_put(), error(), gw_rand(), gwlib_init(), gwlib_shutdown(), gwthread_sleep(), HUGE_SIZE, info(), octstr_create, octstr_destroy(), octstr_format(), octstr_get_cstr, octstr_imm(), uuid_generate(), UUID_STR_LEN, uuid_t, and uuid_unparse(). 00069 {
00070 Dict *dict;
00071 Octstr *foo, *bar;
00072 unsigned long i;
00073
00074 gwlib_init();
00075
00076 foo = octstr_imm("foo");
00077 bar = octstr_imm("bar");
00078
00079 debug("",0,"Dict simple test.");
00080 dict = dict_create(10, NULL);
00081 dict_put(dict, foo, bar);
00082 info(0, "foo gives %s", octstr_get_cstr(dict_get(dict, foo)));
00083 if (dict_key_count(dict) == 1)
00084 info(0, "there is but one foo.");
00085 else
00086 error(0, "key count is %ld, should be 1.", dict_key_count(dict));
00087 dict_destroy(dict);
00088
00089 debug("",0,"Dict extended/huge test.");
00090 dict = dict_create(HUGE_SIZE, (void (*)(void *))octstr_destroy);
00091 for (i = 1; i <= HUGE_SIZE; i++) {
00092 unsigned long val;
00093 Octstr *okey, *oval;
00094 uuid_t id;
00095 char key[UUID_STR_LEN + 1];
00096 uuid_generate(id);
00097 uuid_unparse(id, key);
00098 val = gw_rand();
00099 okey = octstr_create(key);
00100 oval = octstr_format("%ld", val);
00101 dict_put(dict, okey, oval);
00102 }
00103 gwthread_sleep(5); /* give hash table some time */
00104 if (dict_key_count(dict) == HUGE_SIZE)
00105 info(0, "ok, got %d entries in the dictionary.", HUGE_SIZE);
00106 else
00107 error(0, "key count is %ld, should be %d.", dict_key_count(dict), HUGE_SIZE);
00108 dict_destroy(dict);
00109
00110 gwlib_shutdown();
00111 return 0;
00112 }
|
Here is the call graph for this function:
