hashkit_st *hashk_ptr;
hashk_ptr= hashkit_create(&hashk);
- test_truth(hashk_ptr);
- test_truth(hashk_ptr == &hashk);
- test_truth(hashkit_is_initialized(&hashk) == true);
- test_truth(hashkit_is_allocated(hashk_ptr) == false);
+ test_true(hashk_ptr);
+ test_true(hashk_ptr == &hashk);
+ test_true(hashkit_is_allocated(hashk_ptr) == false);
hashkit_free(hashk_ptr);
- test_truth(hashkit_is_initialized(&hashk) == false);
-
return TEST_SUCCESS;
}
hashkit_st *hashk_ptr;
hashk_ptr= hashkit_create(NULL);
- test_truth(hashk_ptr);
- test_truth(hashkit_is_allocated(hashk_ptr) == true);
- test_truth(hashkit_is_initialized(hashk_ptr) == true);
+ test_true(hashk_ptr);
+ test_true(hashkit_is_allocated(hashk_ptr) == true);
hashkit_free(hashk_ptr);
return TEST_SUCCESS;
assert(&global_hashk == hashk);
// Second we test if hashk is even valid
- test_truth(hashkit_is_initialized(hashk) == true);
/* All null? */
{
hashkit_st *hashk_ptr;
hashk_ptr= hashkit_clone(NULL, NULL);
- test_truth(hashk_ptr);
- test_truth(hashkit_is_allocated(hashk_ptr) == true);
- test_truth(hashkit_is_initialized(hashk_ptr) == true);
+ test_true(hashk_ptr);
+ test_true(hashkit_is_allocated(hashk_ptr));
hashkit_free(hashk_ptr);
}
hashk_ptr= hashkit_clone(NULL, hashk);
- test_truth(hashk_ptr);
- test_truth(hashkit_is_allocated(hashk_ptr) == true);
- test_truth(hashkit_is_initialized(hashk_ptr) == true);
-
- test_truth(hashk_ptr->distribution == hashk->distribution);
- test_truth(hashk_ptr->continuum_count == hashk->continuum_count);
- test_truth(hashk_ptr->continuum_points_count == hashk->continuum_points_count);
- test_truth(hashk_ptr->list_size == hashk->list_size);
- test_truth(hashk_ptr->context_size == hashk->context_size);
- test_truth(hashk_ptr->continuum == NULL);
- test_truth(hashk_ptr->hash_fn == hashk->hash_fn);
- test_truth(hashk_ptr->active_fn == hashk->active_fn);
- test_truth(hashk_ptr->continuum_hash_fn == hashk->continuum_hash_fn);
- test_truth(hashk_ptr->continuum_key_fn == hashk->continuum_key_fn);
- test_truth(hashk_ptr->sort_fn == hashk->sort_fn);
- test_truth(hashk_ptr->weight_fn == hashk->weight_fn);
- test_truth(hashk_ptr->list == hashk->list);
+ test_true(hashk_ptr);
+ test_true(hashkit_is_allocated(hashk_ptr));
hashkit_free(hashk_ptr);
}
hashkit_st *hash_clone;
hash_clone= hashkit_clone(&declared_clone, NULL);
- test_truth(hash_clone);
+ test_true(hash_clone);
+ test_true(hash_clone == &declared_clone);
+ test_false(hashkit_is_allocated(hash_clone));
hashkit_free(hash_clone);
}
{
hashkit_st declared_clone;
hashkit_st *hash_clone;
- memset(&declared_clone, 0 , sizeof(hashkit_st));
+
hash_clone= hashkit_clone(&declared_clone, hashk);
- test_truth(hash_clone);
+ test_true(hash_clone);
+ test_true(hash_clone == &declared_clone);
+ test_false(hashkit_is_allocated(hash_clone));
+
hashkit_free(hash_clone);
}
return TEST_SUCCESS;
}
+static test_return_t one_at_a_time_run (hashkit_st *hashk __attribute__((unused)))
+{
+ uint32_t x;
+ const char **ptr;
+
+ for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
+ {
+ uint32_t hash_val;
+
+ hash_val= hashkit_one_at_a_time(*ptr, strlen(*ptr));
+ test_true(one_at_a_time_values[x] == hash_val);
+ }
+
+ return TEST_SUCCESS;
+}
static test_return_t md5_run (hashkit_st *hashk __attribute__((unused)))
{
uint32_t hash_val;
hash_val= hashkit_md5(*ptr, strlen(*ptr));
- test_truth(md5_values[x] == hash_val);
+ test_true(md5_values[x] == hash_val);
}
return TEST_SUCCESS;
static test_return_t murmur_run (hashkit_st *hashk __attribute__((unused)))
{
+#ifdef __sparc
+ return TEST_SKIPPED;
+#else
uint32_t x;
const char **ptr;
}
return TEST_SUCCESS;
+#endif
}
static test_return_t jenkins_run (hashkit_st *hashk __attribute__((unused)))
{0, 0, 0}
};
+static test_return_t hashkit_generate_value_test(hashkit_st *hashk)
+{
+ uint32_t value;
+ value= hashkit_generate_value(hashk, "a", sizeof("a"));
+
+ return TEST_SUCCESS;
+}
+
+static test_return_t hashkit_set_base_function_test(hashkit_st *hashk)
+{
+ 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);
+
+ /* Hsieh is disabled most of the time for patent issues */
+ if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_HSIEH)
+ continue;
+
+ test_true(rc == HASHKIT_SUCCESS);
+
+ 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_MAX:
+ default:
+ list= NULL;
+ test_fail("We ended up on a non-existent hash");
+ }
+
+ // Now we make sure we did set the hash correctly.
+ 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);
+ }
+ }
+
+ return TEST_SUCCESS;
+}
+
+static test_return_t hashkit_set_base_function_custom_test(hashkit_st *hashk)
+{
+ hashkit_return_t rc;
+ uint32_t x;
+ const char **ptr;
+
+
+ rc= hashkit_set_base_function_custom(hashk, hashkit_md5, 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));
+ test_true(md5_values[x] == hash_val);
+ }
+
+ 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},
+ {0, 0, 0}
+};
+
+static test_return_t libhashkit_generate_value_test(hashkit_st *hashk)
+{
+ uint32_t value;
+
+ (void)hashk;
+
+ value= libhashkit_generate_value("a", sizeof("a"), HASHKIT_HASH_DEFAULT);
+
+ return TEST_SUCCESS;
+}
+
+test_st library_functions[] ={
+ {"libhashkit_generate_value", 0, (test_callback_fn)libhashkit_generate_value_test},
+ {0, 0, 0}
+};
+
test_st hash_tests[] ={
+ {"one_at_a_time", 0, (test_callback_fn)one_at_a_time_run },
{"md5", 0, (test_callback_fn)md5_run },
{"crc", 0, (test_callback_fn)crc_run },
{"fnv1_64", 0, (test_callback_fn)fnv1_64_run },
collection_st collection[] ={
{"allocation", 0, 0, allocation},
- {"regression", 0, 0, regression},
+ {"hashkit_st_functions", 0, 0, hashkit_st_functions},
+ {"library_functions", 0, 0, library_functions},
{"hashing", 0, 0, hash_tests},
+ {"regression", 0, 0, regression},
{0, 0, 0, 0}
};
/* Prototypes for functions we will pass to test framework */
-void *world_create(void);
+void *world_create(test_return_t *error);
test_return_t world_destroy(hashkit_st *hashk);
-void *world_create(void)
+void *world_create(test_return_t *error)
{
hashkit_st *hashk_ptr;
hashk_ptr= hashkit_create(&global_hashk);
- assert(hashk_ptr == &global_hashk);
+ if (hashk_ptr != &global_hashk)
+ {
+ *error= TEST_FAILURE;
+ return NULL;
+ }
+
+ if (hashkit_is_allocated(hashk_ptr) == true)
+ {
+ *error= TEST_FAILURE;
+ return NULL;
+ }
- // First we test if hashk is even valid
- assert(hashkit_is_initialized(hashk_ptr) == true);
- assert(hashkit_is_allocated(hashk_ptr) == false);
- assert(hashk_ptr->continuum == NULL);
+ *error= TEST_SUCCESS;
return hashk_ptr;
}
test_return_t world_destroy(hashkit_st *hashk)
{
// Did we get back what we expected?
- assert(hashkit_is_initialized(hashk) == true);
assert(hashkit_is_allocated(hashk) == false);
hashkit_free(&global_hashk);