* the COPYING file in the parent directory for full text.
*/
+#include "config.h"
+
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
bool _unused;
};
-static test_return_t init_test(void *not_used __attribute__((unused)))
+static test_return_t init_test(void *not_used)
{
hashkit_st hashk;
hashkit_st *hashk_ptr;
+ (void)not_used;
hashk_ptr= hashkit_create(&hashk);
test_true(hashk_ptr);
return TEST_SUCCESS;
}
-static test_return_t allocation_test(void *not_used __attribute__((unused)))
+static test_return_t allocation_test(void *not_used)
{
hashkit_st *hashk_ptr;
+ (void)not_used;
hashk_ptr= hashkit_create(NULL);
test_true(hashk_ptr);
return TEST_SUCCESS;
}
-static test_return_t one_at_a_time_run (hashkit_st *hashk __attribute__((unused)))
+static test_return_t one_at_a_time_run (hashkit_st *hashk)
{
uint32_t x;
const char **ptr;
+ (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
return TEST_SUCCESS;
}
-static test_return_t md5_run (hashkit_st *hashk __attribute__((unused)))
+static test_return_t md5_run (hashkit_st *hashk)
{
uint32_t x;
const char **ptr;
+ (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
return TEST_SUCCESS;
}
-static test_return_t crc_run (hashkit_st *hashk __attribute__((unused)))
+static test_return_t crc_run (hashkit_st *hashk)
{
uint32_t x;
const char **ptr;
+ (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
return TEST_SUCCESS;
}
-static test_return_t fnv1_64_run (hashkit_st *hashk __attribute__((unused)))
+static test_return_t fnv1_64_run (hashkit_st *hashk)
{
uint32_t x;
const char **ptr;
+ (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
return TEST_SUCCESS;
}
-static test_return_t fnv1a_64_run (hashkit_st *hashk __attribute__((unused)))
+static test_return_t fnv1a_64_run (hashkit_st *hashk)
{
uint32_t x;
const char **ptr;
+ (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
return TEST_SUCCESS;
}
-static test_return_t fnv1_32_run (hashkit_st *hashk __attribute__((unused)))
+static test_return_t fnv1_32_run (hashkit_st *hashk)
{
uint32_t x;
const char **ptr;
-
+ (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
return TEST_SUCCESS;
}
-static test_return_t fnv1a_32_run (hashkit_st *hashk __attribute__((unused)))
+static test_return_t fnv1a_32_run (hashkit_st *hashk)
{
uint32_t x;
const char **ptr;
+ (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
return TEST_SUCCESS;
}
-static test_return_t hsieh_run (hashkit_st *hashk __attribute__((unused)))
+static test_return_t hsieh_run (hashkit_st *hashk)
{
uint32_t x;
const char **ptr;
+ (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
return TEST_SUCCESS;
}
-static test_return_t murmur_run (hashkit_st *hashk __attribute__((unused)))
+static test_return_t murmur_run (hashkit_st *hashk)
{
-#ifdef __sparc
+ (void)hashk;
+
+#ifdef WORDS_BIGENDIAN
+ (void)murmur_values;
return TEST_SKIPPED;
#else
uint32_t 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);
}
#endif
}
-static test_return_t jenkins_run (hashkit_st *hashk __attribute__((unused)))
+static test_return_t jenkins_run (hashkit_st *hashk)
{
uint32_t x;
const char **ptr;
-
+ (void)hashk;
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
{0, 0, 0}
};
-static test_return_t hashkit_generate_value_test(hashkit_st *hashk)
+static test_return_t hashkit_digest_test(hashkit_st *hashk)
{
uint32_t value;
- value= hashkit_generate_value(hashk, "a", sizeof("a"));
+ value= hashkit_digest(hashk, "a", sizeof("a"));
return TEST_SUCCESS;
}
-static test_return_t hashkit_set_base_function_test(hashkit_st *hashk)
+static test_return_t hashkit_set_function_test(hashkit_st *hashk)
{
- for (hashkit_hash_algorithm_t algo = HASHKIT_HASH_DEFAULT; algo < HASHKIT_HASH_MAX; algo++)
+ for (hashkit_hash_algorithm_t algo = HASHKIT_HASH_DEFAULT; algo < HASHKIT_HASH_MAX; algo++)
{
hashkit_return_t rc;
uint32_t x;
const char **ptr;
uint32_t *list;
- rc= hashkit_set_base_function(hashk, algo);
+ rc= hashkit_set_function(hashk, 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_FAILURE && algo == HASHKIT_HASH_CUSTOM)
continue;
case HASHKIT_HASH_MAX:
default:
list= NULL;
- test_fail("We ended up on a non-existent hash");
+ break;
}
// Now we make sure we did set the hash correctly.
- for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
+ if (list)
{
- uint32_t hash_val;
+ for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
+ {
+ uint32_t hash_val;
- hash_val= hashkit_generate_value(hashk, *ptr, strlen(*ptr));
- test_true(list[x] == hash_val);
+ hash_val= hashkit_digest(hashk, *ptr, strlen(*ptr));
+ test_true(list[x] == hash_val);
+ }
+ }
+ else
+ {
+ return TEST_FAILURE;
}
}
return libhashkit_md5(string, string_length);
}
-static test_return_t hashkit_set_base_function_custom_test(hashkit_st *hashk)
+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_base_function_custom(hashk, hash_test_function, NULL);
+ rc= hashkit_set_custom_function(hashk, hash_test_function, NULL);
test_true(rc == HASHKIT_SUCCESS);
for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
{
uint32_t hash_val;
- hash_val= hashkit_generate_value(hashk, *ptr, strlen(*ptr));
+ hash_val= hashkit_digest(hashk, *ptr, strlen(*ptr));
test_true(md5_values[x] == hash_val);
}
return TEST_SUCCESS;
}
-static test_return_t hashkit_get_base_function_test(hashkit_st *hashk)
+static test_return_t hashkit_set_distribution_function_test(hashkit_st *hashk)
+{
+ for (hashkit_hash_algorithm_t algo = HASHKIT_HASH_DEFAULT; algo < HASHKIT_HASH_MAX; algo++)
+ {
+ hashkit_return_t rc;
+
+ rc= hashkit_set_distribution_function(hashk, algo);
+
+ /* Hsieh is disabled most of the time for patent issues */
+ if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_HSIEH)
+ continue;
+
+ if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_CUSTOM)
+ continue;
+
+ test_true(rc == HASHKIT_SUCCESS);
+ }
+
+ return TEST_SUCCESS;
+}
+
+static test_return_t hashkit_set_custom_distribution_function_test(hashkit_st *hashk)
+{
+ hashkit_return_t rc;
+
+ rc= hashkit_set_custom_distribution_function(hashk, hash_test_function, NULL);
+ test_true(rc == HASHKIT_SUCCESS);
+
+ return TEST_SUCCESS;
+}
+
+
+static test_return_t hashkit_get_function_test(hashkit_st *hashk)
{
- for (hashkit_hash_algorithm_t algo = HASHKIT_HASH_DEFAULT; algo < HASHKIT_HASH_MAX; algo++)
+ for (hashkit_hash_algorithm_t algo = HASHKIT_HASH_DEFAULT; algo < HASHKIT_HASH_MAX; algo++)
{
hashkit_return_t rc;
if (HASHKIT_HASH_CUSTOM || HASHKIT_HASH_HSIEH)
continue;
- rc= hashkit_set_base_function(hashk, algo);
+ rc= hashkit_set_function(hashk, algo);
test_true(rc == HASHKIT_SUCCESS);
- test_true(hashkit_get_base_function(hashk) == algo);
+ test_true(hashkit_get_function(hashk) == algo);
}
return TEST_SUCCESS;
}
clone= hashkit_clone(NULL, hashk);
test_true(hashkit_compare(clone, hashk));
+ hashkit_free(clone);
return TEST_SUCCESS;
}
test_st hashkit_st_functions[] ={
- {"hashkit_generate_value", 0, (test_callback_fn)hashkit_generate_value_test},
- {"hashkit_set_base_function", 0, (test_callback_fn)hashkit_set_base_function_test},
- {"hashkit_set_base_function_custom", 0, (test_callback_fn)hashkit_set_base_function_custom_test},
- {"hashkit_get_base_function", 0, (test_callback_fn)hashkit_get_base_function_test},
+ {"hashkit_digest", 0, (test_callback_fn)hashkit_digest_test},
+ {"hashkit_set_function", 0, (test_callback_fn)hashkit_set_function_test},
+ {"hashkit_set_custom_function", 0, (test_callback_fn)hashkit_set_custom_function_test},
+ {"hashkit_get_function", 0, (test_callback_fn)hashkit_get_function_test},
+ {"hashkit_set_distribution_function", 0, (test_callback_fn)hashkit_set_distribution_function_test},
+ {"hashkit_set_custom_distribution_function", 0, (test_callback_fn)hashkit_set_custom_distribution_function_test},
{"hashkit_compare", 0, (test_callback_fn)hashkit_compare_test},
{0, 0, 0}
};
-static test_return_t libhashkit_generate_value_test(hashkit_st *hashk)
+static test_return_t libhashkit_digest_test(hashkit_st *hashk)
{
uint32_t value;
(void)hashk;
- value= libhashkit_generate_value("a", sizeof("a"), HASHKIT_HASH_DEFAULT);
+ value= libhashkit_digest("a", sizeof("a"), HASHKIT_HASH_DEFAULT);
return TEST_SUCCESS;
}
test_st library_functions[] ={
- {"libhashkit_generate_value", 0, (test_callback_fn)libhashkit_generate_value_test},
+ {"libhashkit_digest", 0, (test_callback_fn)libhashkit_digest_test},
{0, 0, 0}
};