add bloom filter test for adding NULL string

This commit is contained in:
Vincent Sanders 2016-08-14 23:32:20 +01:00
parent a815ad6250
commit 0e5824c8e8

View File

@ -84,6 +84,7 @@ START_TEST(bloom_create_test)
{
struct bloom_filter *b;
b = bloom_create(BLOOM_SIZE);
ck_assert(b != NULL);
bloom_insert_str(b, "NetSurf", 7);
ck_assert(bloom_search_str(b, "NetSurf", 7));
@ -95,6 +96,40 @@ START_TEST(bloom_create_test)
}
END_TEST
/**
* insert empty string test
*/
START_TEST(bloom_insert_empty_str_test)
{
struct bloom_filter *b;
b = bloom_create(BLOOM_SIZE);
ck_assert(b != NULL);
bloom_insert_str(b, NULL, 7);
ck_assert(bloom_items(b) == 1);
bloom_destroy(b);
}
END_TEST
/**
* Basic API creation test case
*/
static TCase *bloom_api_case_create(void)
{
TCase *tc;
tc = tcase_create("Creation");
tcase_add_test(tc, bloom_create_test);
tcase_add_test(tc, bloom_insert_empty_str_test);
return tc;
}
START_TEST(bloom_match_test)
{
FILE *dictf;
@ -112,6 +147,26 @@ START_TEST(bloom_match_test)
}
END_TEST
/**
* Matching entry test case
*/
static TCase *bloom_match_case_create(void)
{
TCase *tc;
tc = tcase_create("Match");
tcase_add_checked_fixture(tc,
dict_bloom_create,
dict_bloom_teardown);
tcase_add_test(tc, bloom_match_test);
return tc;
}
START_TEST(bloom_falsepositive_test)
{
FILE *dictf;
@ -143,47 +198,33 @@ START_TEST(bloom_falsepositive_test)
END_TEST
/* Suite */
/**
* Not matching test case
*/
static TCase *bloom_rate_case_create(void)
{
TCase *tc;
tc = tcase_create("False positive rate");
tcase_add_checked_fixture(tc,
dict_bloom_create,
dict_bloom_teardown);
tcase_add_test(tc, bloom_falsepositive_test);
return tc;
}
static Suite *bloom_suite(void)
{
Suite *s;
TCase *tc_create;
TCase *tc_match;
TCase *tc_falsepositive;
s = suite_create("Bloom filter");
/* Basic API creation */
tc_create = tcase_create("Creation");
tcase_add_test(tc_create, bloom_create_test);
suite_add_tcase(s, tc_create);
/* Matching entry tests */
tc_match = tcase_create("Match");
tcase_add_checked_fixture(tc_match,
dict_bloom_create,
dict_bloom_teardown);
tcase_add_test(tc_match, bloom_match_test);
suite_add_tcase(s, tc_match);
/* Not matching tests */
tc_falsepositive = tcase_create("False positive rate");
tcase_add_checked_fixture(tc_falsepositive,
dict_bloom_create,
dict_bloom_teardown);
tcase_add_test(tc_falsepositive, bloom_falsepositive_test);
suite_add_tcase(s, tc_falsepositive);
suite_add_tcase(s, bloom_api_case_create());
suite_add_tcase(s, bloom_match_case_create());
suite_add_tcase(s, bloom_rate_case_create());
return s;
}