Kannel: Open Source WAP and SMS gateway  $Revision: 5037 $
test_dict.c File Reference
#include "gwlib/gwlib.h"

Go to the source code of this file.

Macros

#define HUGE_SIZE   200000
 

Functions

int main (void)
 

Macro Definition Documentation

#define HUGE_SIZE   200000

Definition at line 66 of file test_dict.c.

Referenced by main().

Function Documentation

int main ( void  )

Definition at line 68 of file test_dict.c.

References debug(), dict_create(), dict_destroy(), dict_get(), dict_key_count(), dict_keys(), dict_put(), error(), gwlib_init(), gwlib_shutdown(), gwlist_destroy(), gwlist_extract_first(), HUGE_SIZE, info(), octstr_compare(), octstr_create, octstr_destroy(), octstr_destroy_item(), octstr_get_cstr, uuid_generate(), UUID_STR_LEN, and uuid_unparse().

69 {
70  Dict *dict1, *dict2;
71  Octstr *key;
72  unsigned long i;
73  List *keys;
74 
75  gwlib_init();
76 
77  debug("",0,"Dict populate phase.");
80  for (i = 1; i <= HUGE_SIZE; i++) {
81  Octstr *okey, *oval;
82  uuid_t id1, id2;
83  char key[UUID_STR_LEN + 1];
84  char val[UUID_STR_LEN + 1];
85  uuid_generate(id1);
86  uuid_generate(id2);
87  uuid_unparse(id1, key);
88  uuid_unparse(id2, val);
89  okey = octstr_create(key);
90  oval = octstr_create(val);
91  dict_put(dict1, okey, oval);
92  dict_put(dict2, oval, okey);
93  }
94 
95  if (dict_key_count(dict1) == HUGE_SIZE)
96  info(0, "ok, got %d entries in dict1.", HUGE_SIZE);
97  else
98  error(0, "key count is %ld, should be %d in dict1.", dict_key_count(dict1), HUGE_SIZE);
99  if (dict_key_count(dict2) == HUGE_SIZE)
100  info(0, "ok, got %d entries in dict2.", HUGE_SIZE);
101  else
102  error(0, "key count is %ld, should be %d in dict2.", dict_key_count(dict2), HUGE_SIZE);
103 
104  debug("",0,"Dict lookup phase.");
105  keys = dict_keys(dict1);
106  while ((key = gwlist_extract_first(keys)) != NULL) {
107  Octstr *oval1, *oval2;
108  if ((oval1 = dict_get(dict1, key)) != NULL) {
109  if ((oval2 = dict_get(dict2, oval1)) != NULL) {
110  if (octstr_compare(oval2, key) != 0) {
111  error(0, "Dict cross-key check inconsistent:");
112  error(0, "dict1: key <%s>, value <%s>", octstr_get_cstr(key), octstr_get_cstr(oval1));
113  error(0, "dict2: key <%s>, value <%s>", octstr_get_cstr(oval1), octstr_get_cstr(oval2));
114  }
115  } else {
116  error(0, "dict2 key %s has NULL value.", octstr_get_cstr(key));
117  }
118  } else {
119  error(0, "dict1 key %s has NULL value.", octstr_get_cstr(key));
120  }
121  octstr_destroy(key);
122  }
123  gwlist_destroy(keys, NULL);
124 
125  dict_destroy(dict1);
126  dict_destroy(dict2);
127 
128  gwlib_shutdown();
129  return 0;
130 }
Dict * dict_create(long size_hint, void(*destroy_value)(void *))
Definition: dict.c:192
void error(int err, const char *fmt,...)
Definition: log.c:612
void info(int err, const char *fmt,...)
Definition: log.c:636
void dict_put(Dict *dict, Octstr *key, void *value)
Definition: dict.c:240
void uuid_unparse(const uuid_t uu, char *out)
Definition: gw_uuid.c:561
void uuid_generate(uuid_t out)
Definition: gw_uuid.c:392
#define HUGE_SIZE
Definition: test_dict.c:66
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
void * gwlist_extract_first(List *list)
Definition: list.c:305
void * dict_get(Dict *dict, Octstr *key)
Definition: dict.c:286
Definition: dict.c:116
long dict_key_count(Dict *dict)
Definition: dict.c:335
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:322
#define octstr_create(cstr)
Definition: octstr.h:125
void octstr_destroy_item(void *os)
Definition: octstr.c:334
#define UUID_STR_LEN
Definition: gw_uuid.h:19
void dict_destroy(Dict *dict)
Definition: dict.c:215
Definition: octstr.c:118
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:690
void gwlib_shutdown(void)
Definition: gwlib.c:94
List * dict_keys(Dict *dict)
Definition: dict.c:347
unsigned char uuid_t[16]
Definition: gw_uuid.h:32
void gwlib_init(void)
Definition: gwlib.c:78
Definition: list.c:102
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:869
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.