/* dict_usage - A test of normal usage of a dictionnary */
-/* Authors: Martin Quinson */
-/* Copyright (C) 2003 the OURAGAN project. */
+/* Copyright (c) 2003,2004 Martin Quinson. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
- under the terms of the license (GNU LGPL) which comes with this package. */
+ * under the terms of the license (GNU LGPL) which comes with this package. */
#include <stdio.h>
-#include <assert.h>
-#include <gras.h>
+#include "gras.h"
XBT_LOG_EXTERNAL_CATEGORY(dict);
XBT_LOG_NEW_DEFAULT_CATEGORY(test,"Logging specific to this test");
errcode=xbt_dict_get(head,key,&data);
- printf(" - Search %s. Found %s\n",key,data?(char*)data:"(null)");fflush(stdout);
+ printf(" - Search %s. Found %s\n",key,data?(char*)data:"NULL");fflush(stdout);
+ if (!data)
+ return errcode;
if (strcmp((char*)data,key))
return mismatch_error;
return errcode;
xbt_dict_foreach(head,cursor,key,data) {
printf(" - Seen: %s->%s\n",key,data);
- xbt_assert2(!strcmp(key,data),
+ xbt_assert2(!data || !strcmp(key,data),
"Key(%s) != value(%s). Abording\n",key,data);
}
return no_error;
fill(&head);
+ /* xbt_dict_dump(head,(void (*)(void*))&printf);*/
+ printf(" - Test that it works with NULL data\n");
+ printf(" - Store NULL under 'null'\n");fflush(stdout);
+ xbt_dict_set(head,"null",NULL,NULL);
+ TRYFAIL(search(head,"null"));
+ /* xbt_dict_dump(head,(void (*)(void*))&printf); */
+ printf(" Check whether I see it while traversing\n");fflush(stdout);
+ {
+ xbt_dict_cursor_t cursor=NULL;
+ char *key;
+ int found=0;
+
+ xbt_dict_foreach(head,cursor,key,data) {
+ printf(" - Seen: %s->%s\n",key,data);fflush(stdout);
+ if (!strcmp(key,"null"))
+ found = 1;
+ }
+ xbt_assert0(found,"the key 'null', associated to NULL is not found");
+ }
+
printf(" - Change some values\n");
printf(" - Change 123 to 'Changed 123'\n");
xbt_dict_set(head,"123",strdup("Changed 123"),&free);
printf(" - Retrive values\n");
TRYFAIL(xbt_dict_get(head,"123",(void**)&data));
- assert(data);
+ xbt_assert(data);
TRYFAIL(strcmp("123",data));
TRYEXPECT(xbt_dict_get(head,"Can't be found",(void**)&data),mismatch_error);