From 9d351731c3e302fdf9f9201bbeda74c2d9e1302e Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Tue, 28 Apr 2015 14:39:33 +0200 Subject: [PATCH] [xbt] Add unit test got xbt_dict with arbitrary (not a NULL temrinated string) key --- src/xbt/dict.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/xbt/dict.c b/src/xbt/dict.c index 9d2ba31844..7259a19e03 100644 --- a/src/xbt/dict.c +++ b/src/xbt/dict.c @@ -1172,4 +1172,27 @@ XBT_TEST_UNIT("crash", test_dict_crash, "Crash test") xbt_dict_free(&head); } +XBT_TEST_UNIT("ext", test_dict_int, "Test dictionnary with int keys") +{ + xbt_dict_t dict = xbt_dict_new(); + int count = 500; + + xbt_test_add("Insert elements"); + int i; + for (i = 0; i < count; ++i) + xbt_dict_set_ext(dict, (char*) &i, sizeof(i), (void*) (intptr_t) i, NULL); + xbt_test_assert(xbt_dict_size(dict) == count, + "Bad number of elements in the dictionnary"); + + xbt_test_add("Check elements"); + for (i = 0; i < count; ++i) { + int res = (int) (intptr_t) xbt_dict_get_ext(dict, (char*) &i, sizeof(i)); + xbt_test_assert(xbt_dict_size(dict) == count, + "Unexpected value at index %i, expected %i but was %i", i, i, res); + } + + xbt_test_add("Free the array"); + xbt_dict_free(&dict); +} + #endif /* SIMGRID_TEST */ -- 2.20.1