*
*/
-#include "config.h"
+#include <mem_config.h>
+#include <libtest/test.hpp>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+using namespace libtest;
-#include <libhashkit/hashkit.h>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
-#include <libtest/test.h>
+#include <libhashkit-1.0/hashkit.h>
+#include <libhashkit/is.h>
-#include "hash_results.h"
+#include "tests/hash_results.h"
static hashkit_st global_hashk;
bool _unused;
};
-static test_return_t init_test(void *not_used)
+static test_return_t init_test(void *)
{
hashkit_st hashk;
hashkit_st *hashk_ptr;
- (void)not_used;
hashk_ptr= hashkit_create(&hashk);
test_true(hashk_ptr);
test_true(hashk_ptr == &hashk);
- test_true(hashkit_is_allocated(hashk_ptr) == false);
+ test_false(hashkit_is_allocated(hashk_ptr));
hashkit_free(hashk_ptr);
return TEST_SUCCESS;
}
-static test_return_t allocation_test(void *not_used)
+static test_return_t allocation_test(void *)
{
hashkit_st *hashk_ptr;
- (void)not_used;
hashk_ptr= hashkit_create(NULL);
test_true(hashk_ptr);
- test_true(hashkit_is_allocated(hashk_ptr) == true);
+ test_true(hashkit_is_allocated(hashk_ptr));
hashkit_free(hashk_ptr);
return TEST_SUCCESS;
static test_return_t clone_test(hashkit_st *hashk)
{
// First we make sure that the testing system is giving us what we expect.
- assert(&global_hashk == hashk);
+ test_true(&global_hashk == hashk);
// Second we test if hashk is even valid
return TEST_SUCCESS;
}
-static test_return_t one_at_a_time_run (hashkit_st *hashk)
+static test_return_t one_at_a_time_run (hashkit_st *)
{
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_one_at_a_time(*ptr, strlen(*ptr));
- test_true(one_at_a_time_values[x] == hash_val);
+ test_compare(one_at_a_time_values[x],
+ libhashkit_one_at_a_time(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t md5_run (hashkit_st *hashk)
+static test_return_t md5_run (hashkit_st *)
{
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_md5(*ptr, strlen(*ptr));
- test_true(md5_values[x] == hash_val);
+ test_compare(md5_values[x],
+ libhashkit_md5(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t crc_run (hashkit_st *hashk)
+static test_return_t crc_run (hashkit_st *)
{
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_crc32(*ptr, strlen(*ptr));
- assert(crc_values[x] == hash_val);
+ test_compare(crc_values[x],
+ libhashkit_crc32(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t fnv1_64_run (hashkit_st *hashk)
+static test_return_t fnv1_64_run (hashkit_st *)
{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1_64));
+
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_fnv1_64(*ptr, strlen(*ptr));
- assert(fnv1_64_values[x] == hash_val);
+ test_compare(fnv1_64_values[x],
+ libhashkit_fnv1_64(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t fnv1a_64_run (hashkit_st *hashk)
+static test_return_t fnv1a_64_run (hashkit_st *)
{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_FNV1A_64));
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_fnv1a_64(*ptr, strlen(*ptr));
- assert(fnv1a_64_values[x] == hash_val);
+ test_compare(fnv1a_64_values[x],
+ libhashkit_fnv1a_64(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t fnv1_32_run (hashkit_st *hashk)
+static test_return_t fnv1_32_run (hashkit_st *)
{
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_fnv1_32(*ptr, strlen(*ptr));
- assert(fnv1_32_values[x] == hash_val);
+ test_compare(fnv1_32_values[x],
+ libhashkit_fnv1_32(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t fnv1a_32_run (hashkit_st *hashk)
+static test_return_t fnv1a_32_run (hashkit_st *)
{
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_fnv1a_32(*ptr, strlen(*ptr));
- assert(fnv1a_32_values[x] == hash_val);
+ test_compare(fnv1a_32_values[x],
+ libhashkit_fnv1a_32(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
}
-static test_return_t hsieh_run (hashkit_st *hashk)
+static test_return_t hsieh_run (hashkit_st *)
{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_HSIEH));
+
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
+ test_compare(hsieh_values[x],
+ libhashkit_hsieh(*ptr, strlen(*ptr)));
+ }
+
+ return TEST_SUCCESS;
+}
+
+static test_return_t murmur3_TEST(hashkit_st *)
+{
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_MURMUR3));
-#ifdef HAVE_HSIEH_HASH
- hash_val= libhashkit_hsieh(*ptr, strlen(*ptr));
+#ifdef WORDS_BIGENDIAN
+ (void)murmur3_values;
+ return TEST_SKIPPED;
#else
- hash_val= 1;
-#endif
- assert(hsieh_values[x] == hash_val);
+ uint32_t x;
+ const char **ptr;
+
+ for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
+ {
+ test_compare(murmur3_values[x],
+ libhashkit_murmur3(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
+#endif
}
-static test_return_t murmur_run (hashkit_st *hashk)
+static test_return_t murmur_run (hashkit_st *)
{
- (void)hashk;
+ test_skip(true, libhashkit_has_algorithm(HASHKIT_HASH_MURMUR));
#ifdef WORDS_BIGENDIAN
(void)murmur_values;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
-#ifdef HAVE_MURMUR_HASH
- hash_val= libhashkit_murmur(*ptr, strlen(*ptr));
-#else
- hash_val= 1;
-#endif
- assert(murmur_values[x] == hash_val);
+ test_compare(murmur_values[x],
+ libhashkit_murmur(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
#endif
}
-static test_return_t jenkins_run (hashkit_st *hashk)
+static test_return_t jenkins_run (hashkit_st *)
{
uint32_t x;
const char **ptr;
- (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= libhashkit_jenkins(*ptr, strlen(*ptr));
- assert(jenkins_values[x] == hash_val);
+ test_compare(jenkins_values[x],
+ libhashkit_jenkins(*ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
static test_return_t hashkit_digest_test(hashkit_st *hashk)
{
- uint32_t value;
- value= hashkit_digest(hashk, "a", sizeof("a"));
+ test_true(hashkit_digest(hashk, "a", sizeof("a")));
return TEST_SUCCESS;
}
const char **ptr;
uint32_t *list;
- hashkit_return_t rc= hashkit_set_function(hashk, static_cast<hashkit_hash_algorithm_t>(algo));
+ test_skip(true, libhashkit_has_algorithm(static_cast<hashkit_hash_algorithm_t>(algo)));
- /* Hsieh is disabled most of the time for patent issues */
-#ifndef HAVE_HSIEH_HASH
- if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_HSIEH)
- continue;
-#endif
-
-#ifndef HAVE_MURMUR_HASH
- if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_MURMUR)
- continue;
-#endif
-
- if (rc == HASHKIT_INVALID_ARGUMENT && algo == HASHKIT_HASH_CUSTOM)
- continue;
+ hashkit_return_t rc= hashkit_set_function(hashk, static_cast<hashkit_hash_algorithm_t>(algo));
- test_true_got(rc == HASHKIT_SUCCESS, hashkit_strerror(NULL, rc));
+ test_compare_got(HASHKIT_SUCCESS, rc, hashkit_strerror(NULL, rc));
switch (algo)
{
case HASHKIT_HASH_DEFAULT:
list= one_at_a_time_values;
break;
+
case HASHKIT_HASH_MD5:
list= md5_values;
break;
+
case HASHKIT_HASH_CRC:
list= crc_values;
break;
+
case HASHKIT_HASH_FNV1_64:
list= fnv1_64_values;
break;
+
case HASHKIT_HASH_FNV1A_64:
list= fnv1a_64_values;
break;
+
case HASHKIT_HASH_FNV1_32:
list= fnv1_32_values;
break;
+
case HASHKIT_HASH_FNV1A_32:
list= fnv1a_32_values;
break;
+
case HASHKIT_HASH_HSIEH:
list= hsieh_values;
break;
+
case HASHKIT_HASH_MURMUR:
list= murmur_values;
break;
+
case HASHKIT_HASH_JENKINS:
list= jenkins_values;
break;
+
case HASHKIT_HASH_CUSTOM:
case HASHKIT_HASH_MAX:
default:
{
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= hashkit_digest(hashk, *ptr, strlen(*ptr));
- test_true(list[x] == hash_val);
+ test_compare(list[x],
+ hashkit_digest(hashk, *ptr, strlen(*ptr)));
}
}
else
return TEST_SUCCESS;
}
-static uint32_t hash_test_function(const char *string, size_t string_length, void *context)
+static uint32_t hash_test_function(const char *string, size_t string_length, void *)
{
- (void)context;
return libhashkit_md5(string, string_length);
}
static test_return_t hashkit_set_custom_function_test(hashkit_st *hashk)
{
- hashkit_return_t rc;
uint32_t x;
const char **ptr;
- rc= hashkit_set_custom_function(hashk, hash_test_function, NULL);
- test_true(rc == HASHKIT_SUCCESS);
+ test_compare(HASHKIT_SUCCESS,
+ hashkit_set_custom_function(hashk, hash_test_function, NULL));
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
- uint32_t hash_val;
-
- hash_val= hashkit_digest(hashk, *ptr, strlen(*ptr));
- test_true(md5_values[x] == hash_val);
+ test_compare(md5_values[x],
+ hashkit_digest(hashk, *ptr, strlen(*ptr)));
}
return TEST_SUCCESS;
hashkit_return_t rc= hashkit_set_distribution_function(hashk, static_cast<hashkit_hash_algorithm_t>(algo));
/* Hsieh is disabled most of the time for patent issues */
- if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_HSIEH)
- continue;
-
- if (rc == HASHKIT_INVALID_ARGUMENT && algo == HASHKIT_HASH_CUSTOM)
+ if (rc == HASHKIT_INVALID_ARGUMENT)
continue;
- test_true(rc == HASHKIT_SUCCESS);
+ test_compare(HASHKIT_SUCCESS, rc);
}
return TEST_SUCCESS;
static test_return_t hashkit_set_custom_distribution_function_test(hashkit_st *hashk)
{
- hashkit_return_t rc= hashkit_set_custom_distribution_function(hashk, hash_test_function, NULL);
- test_true(rc == HASHKIT_SUCCESS);
+ test_compare(HASHKIT_SUCCESS,
+ hashkit_set_custom_distribution_function(hashk, hash_test_function, NULL));
return TEST_SUCCESS;
}
for (int algo= int(HASHKIT_HASH_DEFAULT); algo < int(HASHKIT_HASH_MAX); algo++)
{
- if (HASHKIT_HASH_CUSTOM or HASHKIT_HASH_HSIEH)
+ if (HASHKIT_HASH_CUSTOM)
+ {
continue;
+ }
+ test_skip(true, libhashkit_has_algorithm(static_cast<hashkit_hash_algorithm_t>(algo)));
- hashkit_return_t rc= hashkit_set_function(hashk, static_cast<hashkit_hash_algorithm_t>(algo));
- test_true(rc == HASHKIT_SUCCESS);
+ test_compare(HASHKIT_SUCCESS,
+ hashkit_set_function(hashk, static_cast<hashkit_hash_algorithm_t>(algo)));
- test_true(hashkit_get_function(hashk) == algo);
+ test_compare(hashkit_get_function(hashk), algo);
}
return TEST_SUCCESS;
}
{0, 0, 0}
};
-static test_return_t libhashkit_digest_test(hashkit_st *hashk)
+static test_return_t libhashkit_digest_test(hashkit_st *)
{
-
- (void)hashk;
-
- uint32_t value= libhashkit_digest("a", sizeof("a"), HASHKIT_HASH_DEFAULT);
- test_true(value);
+ test_true(libhashkit_digest("a", sizeof("a"), HASHKIT_HASH_DEFAULT));
return TEST_SUCCESS;
}
{"fnv1a_32", 0, (test_callback_fn*)fnv1a_32_run },
{"hsieh", 0, (test_callback_fn*)hsieh_run },
{"murmur", 0, (test_callback_fn*)murmur_run },
+ {"murmur3", 0, (test_callback_fn*)murmur3_TEST },
{"jenkis", 0, (test_callback_fn*)jenkins_run },
{0, 0, (test_callback_fn*)0}
};
{0, 0, 0, 0}
};
-/* Prototypes for functions we will pass to test framework */
-void *world_create(test_return_t *error);
-test_return_t world_destroy(hashkit_st *hashk);
-
-void *world_create(test_return_t *error)
+static void *world_create(libtest::server_startup_st&, test_return_t& error)
{
hashkit_st *hashk_ptr= hashkit_create(&global_hashk);
if (hashk_ptr != &global_hashk)
{
- *error= TEST_FAILURE;
+ error= TEST_FAILURE;
return NULL;
}
if (hashkit_is_allocated(hashk_ptr) == true)
{
- *error= TEST_FAILURE;
+ error= TEST_FAILURE;
return NULL;
}
- *error= TEST_SUCCESS;
-
return hashk_ptr;
}
-test_return_t world_destroy(hashkit_st *hashk)
+static bool world_destroy(void *object)
{
+ hashkit_st *hashk= (hashkit_st *)object;
// Did we get back what we expected?
- assert(hashkit_is_allocated(hashk) == false);
+ test_true(hashkit_is_allocated(hashk) == false);
hashkit_free(&global_hashk);
return TEST_SUCCESS;
}
-void get_world(world_st *world)
+void get_world(libtest::Framework* world)
{
- world->collections= collection;
- world->create= (test_callback_create_fn*)world_create;
- world->destroy= (test_callback_fn*)world_destroy;
+ world->collections(collection);
+ world->create(world_create);
+ world->destroy(world_destroy);
}