summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2016-08-14 22:32:20 (GMT)
committer Vincent Sanders <vince@kyllikki.org>2016-08-14 22:32:20 (GMT)
commit0e5824c8e851ee6fd29868eddd3be2b738f3351e (patch)
tree5ca758b19e2636ffccb2efc77bb745fc6ad7c6fc
parenta815ad62502669e9a2b689f6f609eb03008a4ca4 (diff)
downloadnetsurf-0e5824c8e851ee6fd29868eddd3be2b738f3351e.tar.gz
netsurf-0e5824c8e851ee6fd29868eddd3be2b738f3351e.tar.bz2
add bloom filter test for adding NULL string
-rw-r--r--test/bloom.c111
1 files changed, 76 insertions, 35 deletions
diff --git a/test/bloom.c b/test/bloom.c
index 6ba3b48..0fd1b06 100644
--- a/test/bloom.c
+++ b/test/bloom.c
@@ -48,7 +48,7 @@ static struct bloom_filter *dict_bloom;
*/
static void dict_bloom_create(void)
{
- FILE *dictf;
+ FILE *dictf;
char buf[BUFSIZ];
int i;
@@ -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,9 +96,43 @@ 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;
+ FILE *dictf;
char buf[BUFSIZ];
int i;
@@ -112,9 +147,29 @@ 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;
+ FILE *dictf;
char buf[BUFSIZ];
int i;
int false_positives = 0;
@@ -135,7 +190,7 @@ START_TEST(bloom_falsepositive_test)
}
fclose(dictf);
- printf("false positive rate %d%%/%d%%\n",
+ printf("false positive rate %d%%/%d%%\n",
(false_positives * 100)/BLOOM_SIZE,
FALSE_POSITIVE_RATE);
ck_assert(false_positives < ((BLOOM_SIZE * FALSE_POSITIVE_RATE) / 100));
@@ -143,47 +198,33 @@ START_TEST(bloom_falsepositive_test)
END_TEST
-/* Suite */
-
-static Suite *bloom_suite(void)
+/**
+ * Not matching test case
+ */
+static TCase *bloom_rate_case_create(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);
+ TCase *tc;
+ tc = tcase_create("False positive rate");
- /* Matching entry tests */
- tc_match = tcase_create("Match");
-
- tcase_add_checked_fixture(tc_match,
+ tcase_add_checked_fixture(tc,
dict_bloom_create,
dict_bloom_teardown);
- tcase_add_test(tc_match, bloom_match_test);
-
- suite_add_tcase(s, tc_match);
-
+ tcase_add_test(tc, bloom_falsepositive_test);
- /* Not matching tests */
- tc_falsepositive = tcase_create("False positive rate");
+ return tc;
+}
- tcase_add_checked_fixture(tc_falsepositive,
- dict_bloom_create,
- dict_bloom_teardown);
- tcase_add_test(tc_falsepositive, bloom_falsepositive_test);
+static Suite *bloom_suite(void)
+{
+ Suite *s;
+ s = suite_create("Bloom filter");
- 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;
}