3 /* multidict_crash - A crash test for multi-level dictionnaries */
5 /* Copyright (c) 2003-2005 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
14 XBT_LOG_NEW_DEFAULT_CATEGORY(Test,"this test");
16 #define NB_ELM 10/*00*/
18 #define KEY_SIZE 6 /*512*/
22 static void str_free(void *s) {
27 int main(int argc, char *argv[]) {
29 xbt_dict_t mdict=xbt_dict_new();
31 xbt_dynar_t keys = xbt_dynar_new(sizeof(char*),str_free);
37 printf("\nGeneric multicache: CRASH test:\n");
38 printf(" Fill the struct and frees it %d times, using %d elements, depth of multicache=%d\n",NB_TEST,NB_ELM,DEPTH);
39 printf(" with %d chars long randomized keys. (a point is a test)\n",KEY_SIZE);
41 for (i=0;i<NB_TEST;i++) {
43 printf("Test %d\n",i);
45 if (i%10) printf("."); else printf("%d",i/10);
49 for (j=0;j<NB_ELM;j++) {
50 if (verbose) printf (" Add {");
52 for (l=0 ; l<DEPTH ; l++) {
53 key=xbt_malloc(KEY_SIZE);
55 for (k=0;k<KEY_SIZE-1;k++)
56 key[k]=rand() % ('z' - 'a') + 'a';
60 if (verbose) printf("%p=%s %s ",key, key,(l<DEPTH-1?";":"}"));
61 xbt_dynar_push(keys,&key);
63 if (verbose) printf("in multitree %p.\n",mdict);
65 TRYFAIL(xbt_multidict_set(mdict,keys,xbt_strdup(key),&str_free));
67 TRYFAIL(xbt_multidict_get(mdict,keys,&data));
69 xbt_assert2(data && !strcmp((char*)data,key),
70 "Retrieved value (%s) does not match the entrered one (%s)\n",
76 xbt_dict_dump(mdict,&xbt_dict_print);*/
78 xbt_dict_free(&mdict);
79 xbt_dynar_free(&keys);