Skip to content
Snippets Groups Projects
Commit 01526fb2 authored by Roman Tsisyk's avatar Roman Tsisyk
Browse files

Update mhash unit test

parent d4640dd1
No related merge requests found
add_executable(rlist rlist.c test.c) add_executable(rlist rlist.c test.c)
add_executable(queue queue.c) add_executable(queue queue.c)
#add_executable(mhash mhash.c) add_executable(mhash mhash.c)
add_executable(rope_basic rope_basic.c ${CMAKE_SOURCE_DIR}/src/rope.c) add_executable(rope_basic rope_basic.c ${CMAKE_SOURCE_DIR}/src/rope.c)
add_executable(rope_avl rope_avl.c ${CMAKE_SOURCE_DIR}/src/rope.c) add_executable(rope_avl rope_avl.c ${CMAKE_SOURCE_DIR}/src/rope.c)
add_executable(rope_stress rope_stress.c ${CMAKE_SOURCE_DIR}/src/rope.c) add_executable(rope_stress rope_stress.c ${CMAKE_SOURCE_DIR}/src/rope.c)
...@@ -9,7 +9,7 @@ add_executable(objc_finally objc_finally.m) ...@@ -9,7 +9,7 @@ add_executable(objc_finally objc_finally.m)
add_executable(objc_catchcxx objc_catchcxx.m) add_executable(objc_catchcxx objc_catchcxx.m)
add_dependencies(objc_finally build_bundled_libs) add_dependencies(objc_finally build_bundled_libs)
add_dependencies(objc_catchcxx build_bundled_libs) add_dependencies(objc_catchcxx build_bundled_libs)
#set_target_properties(mhash PROPERTIES COMPILE_FLAGS "-std=c99") set_target_properties(mhash PROPERTIES COMPILE_FLAGS "-std=c99")
target_link_libraries(objc_finally ${LIBOBJC_LIB} -lm -pthread) target_link_libraries(objc_finally ${LIBOBJC_LIB} -lm -pthread)
target_link_libraries(objc_catchcxx ${LIBOBJC_LIB} ${LUAJIT_LIB} -lm -pthread) target_link_libraries(objc_catchcxx ${LIBOBJC_LIB} ${LUAJIT_LIB} -lm -pthread)
if (TARGET_OS_LINUX OR TARGET_OS_DEBIAN_FREEBSD) if (TARGET_OS_LINUX OR TARGET_OS_DEBIAN_FREEBSD)
......
...@@ -5,18 +5,27 @@ ...@@ -5,18 +5,27 @@
#define MH_SOURCE 1 #define MH_SOURCE 1
#define mh_name _i32 #define mh_name _i32
#define mh_key_t int32_t struct mh_i32_node_t {
#define mh_val_t int32_t int32_t key;
#define mh_hash(a) (a) int32_t val;
#define mh_eq(a, b) ((a) == (b)) };
#define mh_node_t struct mh_i32_node_t
#define mh_hash_arg_t void *
#define mh_hash(a, arg) (a->key)
#define mh_eq_arg_t void *
#define mh_eq(a, b, arg) ((a->key) == (b->key))
#include "mhash.h" #include "mhash.h"
#define mh_name _i32_collision #define mh_name _i32_collision
#define mh_key_t int32_t struct mh_i32_collision_node_t {
#define mh_val_t int32_t int32_t key;
#define mh_hash(a) 42 int32_t val;
#define mh_eq(a, b) ((a) == (b)) };
#define mh_node_t struct mh_i32_collision_node_t
#define mh_hash_arg_t void *
#define mh_hash(a, arg) 42
#define mh_eq_arg_t void *
#define mh_eq(a, b, arg) ((a->key) == (b->key))
#include "mhash.h" #include "mhash.h"
...@@ -30,9 +39,19 @@ static void mhash_int32_id_test() ...@@ -30,9 +39,19 @@ static void mhash_int32_id_test()
#define init() ({ mh_i32_init(); }) #define init() ({ mh_i32_init(); })
#define clear(x) ({ mh_i32_clear((x)); }) #define clear(x) ({ mh_i32_clear((x)); })
#define destroy(x) ({ mh_i32_destroy((x)); }) #define destroy(x) ({ mh_i32_destroy((x)); })
#define get(x) ({ mh_i32_get(h, (x)); }) #define get(x) ({ \
#define put(x) ({ mh_i32_put(h, (x), 0, &ret); }) const struct mh_i32_node_t _node = { .key = (x) }; \
#define del(x) ({ mh_i32_del(h, (x)); }) mh_i32_get(h, &_node, NULL, NULL); \
})
#define put(x) ({ \
const struct mh_i32_node_t _node = { .key = (x) }; \
mh_i32_put(h, &_node, NULL, NULL, &ret); \
})
#define key(k) (mh_i32_node(h, k)->key)
#define val(k) (mh_i32_node(h, k)->val)
#define del(k) ({ \
mh_i32_del(h, k, NULL, NULL); \
})
#include "mhash_body.c" #include "mhash_body.c"
footer(); footer();
...@@ -45,11 +64,21 @@ static void mhash_int32_collision_test() ...@@ -45,11 +64,21 @@ static void mhash_int32_collision_test()
int ret, k; int ret, k;
struct mh_i32_collision_t *h; struct mh_i32_collision_t *h;
#define init() ({ mh_i32_collision_init(); }) #define init() ({ mh_i32_collision_init(); })
#define clear(x) ({ mh_i32_collision_clear((x)); }) #define clear(x) ({ mh_i32_collision_clear((x)); })
#define destroy(x) ({ mh_i32_collision_destroy((x)); }) #define destroy(x) ({ mh_i32_collision_destroy((x)); })
#define get(x) ({ mh_i32_collision_get(h, (x)); }) #define get(x) ({ \
#define put(x) ({ mh_i32_collision_put(h, (x), 0, &ret); }) const struct mh_i32_collision_node_t _node = { .key = (x) }; \
#define del(x) ({ mh_i32_collision_del(h, (x)); }) mh_i32_collision_get(h, &_node, NULL, NULL); \
})
#define put(x) ({ \
const struct mh_i32_collision_node_t _node = { .key = (x) }; \
mh_i32_collision_put(h, &_node, NULL, NULL, &ret); \
})
#define key(k) (mh_i32_collision_node(h, k)->key)
#define val(k) (mh_i32_collision_node(h, k)->val)
#define del(k) ({ \
mh_i32_collision_del(h, k, NULL, NULL); \
})
#include "mhash_body.c" #include "mhash_body.c"
footer(); footer();
......
#define set(x) ({ \ #define set(x) ({ \
k = put(x); \ k = put(x); \
mh_value(h, k) = (x) << 1; \ val(k) = (x) << 1; \
}) })
#define rm(x) ({ \
k = get(x); \ #define rm(x) ({ \
del(k); \ mh_int_t k = get(x); \
}) del(k); \
})
#define tst(x) ({ \ #define tst(x) ({ \
k = get(x); \ mh_int_t k = get((x)); \
fail_unless(k != mh_end(h)); \ fail_unless(k != mh_end(h)); \
fail_unless(mh_value(h, k) == (x) << 1);\ fail_unless(val(k) == ((x) << 1)); \
}) })
#define clr(x) fail_unless(get(x) == mh_end(h)) #define clr(x) fail_unless(get(x) == mh_end(h))
#define usd(x) fail_unless(get(x) != mh_end(h)) #define usd(x) fail_unless(get(x) != mh_end(h))
...@@ -174,3 +176,5 @@ destroy(h); ...@@ -174,3 +176,5 @@ destroy(h);
#undef get #undef get
#undef put #undef put
#undef del #undef del
#undef key
#undef val
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment