Skip to content

Commit

Permalink
Adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
armon committed Feb 29, 2012
1 parent 242eb7a commit 08df6b5
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/bloomd/runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ int main(void)
tcase_add_test(tc4, test_mgr_init_destroy);
tcase_add_test(tc4, test_mgr_create_drop);
tcase_add_test(tc4, test_mgr_list);
tcase_add_test(tc4, test_mgr_list_no_filters);
tcase_add_test(tc4, test_mgr_add_check_keys);
tcase_add_test(tc4, test_mgr_check_no_keys);
tcase_add_test(tc4, test_mgr_add_check_no_filter);
tcase_add_test(tc4, test_mgr_flush_no_filter);
tcase_add_test(tc4, test_mgr_flush);
tcase_add_test(tc4, test_mgr_unmap_no_filter);
tcase_add_test(tc4, test_mgr_unmap);
tcase_add_test(tc4, test_mgr_unmap_add_keys);

srunner_run_all(sr, CK_ENV);
nf = srunner_ntests_failed(sr);
Expand Down
167 changes: 167 additions & 0 deletions tests/bloomd/test_filtmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ START_TEST(test_mgr_list)
bloom_filter_list_head *head;
res = filtmgr_list_filters(mgr, &head);
fail_unless(res == 0);
fail_unless(head->size == 2);

int has_bar1 = 0;
int has_bar2 = 0;
Expand All @@ -90,6 +91,27 @@ START_TEST(test_mgr_list)
}
END_TEST

START_TEST(test_mgr_list_no_filters)
{
bloom_config config;
int res = config_from_filename(NULL, &config);
fail_unless(res == 0);

bloom_filtmgr *mgr;
res = init_filter_manager(&config, &mgr);
fail_unless(res == 0);

bloom_filter_list_head *head;
res = filtmgr_list_filters(mgr, &head);
fail_unless(res == 0);
fail_unless(head->size == 0);

res = destroy_filter_manager(mgr);
fail_unless(res == 0);
}
END_TEST


START_TEST(test_mgr_add_check_keys)
{
bloom_config config;
Expand Down Expand Up @@ -155,3 +177,148 @@ START_TEST(test_mgr_check_no_keys)
}
END_TEST

START_TEST(test_mgr_add_check_no_filter)
{
bloom_config config;
int res = config_from_filename(NULL, &config);
fail_unless(res == 0);

bloom_filtmgr *mgr;
res = init_filter_manager(&config, &mgr);
fail_unless(res == 0);

char *keys[] = {"hey","there","person"};
char result[] = {0, 0, 0};
res = filtmgr_set_keys(mgr, "noop1", (char**)&keys, 3, (char*)&result);
fail_unless(res == -1);

for (int i=0;i<3;i++) result[i] = 0;
res = filtmgr_check_keys(mgr, "noop1", (char**)&keys, 3, (char*)&result);
fail_unless(res == -1);

res = destroy_filter_manager(mgr);
fail_unless(res == 0);
}
END_TEST

/* Flush */
START_TEST(test_mgr_flush_no_filter)
{
bloom_config config;
int res = config_from_filename(NULL, &config);
fail_unless(res == 0);

bloom_filtmgr *mgr;
res = init_filter_manager(&config, &mgr);
fail_unless(res == 0);

res = filtmgr_flush_filter(mgr, "noop1");
fail_unless(res == -1);

res = destroy_filter_manager(mgr);
fail_unless(res == 0);
}
END_TEST

START_TEST(test_mgr_flush)
{
bloom_config config;
int res = config_from_filename(NULL, &config);
fail_unless(res == 0);

bloom_filtmgr *mgr;
res = init_filter_manager(&config, &mgr);
fail_unless(res == 0);

res = filtmgr_create_filter(mgr, "zab3", NULL);
fail_unless(res == 0);

res = filtmgr_flush_filter(mgr, "zab3");
fail_unless(res == 0);

res = filtmgr_drop_filter(mgr, "zab3");
fail_unless(res == 0);

res = destroy_filter_manager(mgr);
fail_unless(res == 0);
}
END_TEST

/* Unmap */
START_TEST(test_mgr_unmap_no_filter)
{
bloom_config config;
int res = config_from_filename(NULL, &config);
fail_unless(res == 0);

bloom_filtmgr *mgr;
res = init_filter_manager(&config, &mgr);
fail_unless(res == 0);

res = filtmgr_unmap_filter(mgr, "noop2");
fail_unless(res == -1);

res = destroy_filter_manager(mgr);
fail_unless(res == 0);
}
END_TEST

START_TEST(test_mgr_unmap)
{
bloom_config config;
int res = config_from_filename(NULL, &config);
fail_unless(res == 0);

bloom_filtmgr *mgr;
res = init_filter_manager(&config, &mgr);
fail_unless(res == 0);

res = filtmgr_create_filter(mgr, "zab4", NULL);
fail_unless(res == 0);

res = filtmgr_unmap_filter(mgr, "zab4");
fail_unless(res == 0);

res = filtmgr_drop_filter(mgr, "zab4");
fail_unless(res == 0);

res = destroy_filter_manager(mgr);
fail_unless(res == 0);
}
END_TEST

START_TEST(test_mgr_unmap_add_keys)
{
bloom_config config;
int res = config_from_filename(NULL, &config);
fail_unless(res == 0);

bloom_filtmgr *mgr;
res = init_filter_manager(&config, &mgr);
fail_unless(res == 0);

res = filtmgr_create_filter(mgr, "zab5", NULL);
fail_unless(res == 0);

res = filtmgr_unmap_filter(mgr, "zab5");
fail_unless(res == 0);

// Try to add keys now
char *keys[] = {"hey","there","person"};
char result[] = {0, 0, 0};
res = filtmgr_set_keys(mgr, "zab5", (char**)&keys, 3, (char*)&result);
fail_unless(res == 0);
fail_unless(result[0]);
fail_unless(result[1]);
fail_unless(result[2]);

res = filtmgr_drop_filter(mgr, "zab5");
fail_unless(res == 0);

res = destroy_filter_manager(mgr);
fail_unless(res == 0);
}
END_TEST

/* List Cold */

0 comments on commit 08df6b5

Please sign in to comment.