From 583bb5d84b4aa1cfaf50ad366d337a282990f7ab Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Thu, 27 Aug 2015 08:11:59 -0400 Subject: [PATCH] tests/core: Update filter test to new framework Signed-off-by: Anna Schumaker --- tests/core/Sconscript | 2 +- tests/core/filter.cpp | 30 +++++++++++------------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/tests/core/Sconscript b/tests/core/Sconscript index 2908eceb..872f5558 100644 --- a/tests/core/Sconscript +++ b/tests/core/Sconscript @@ -17,9 +17,9 @@ res += [ CoreTest("string", "string.cpp") ] res += [ CoreTest("file", "file.cpp") ] res += [ CoreTest("database", "database.cpp") ] res += [ CoreTest("index", "index.cpp") ] +res += [ CoreTest("filter", "filter.cpp") ] Return("res") -#test( "filter" ) #test( "idle" ) # #test( "tags/generic" ) diff --git a/tests/core/filter.cpp b/tests/core/filter.cpp index 645a865d..a5cf4c4b 100644 --- a/tests/core/filter.cpp +++ b/tests/core/filter.cpp @@ -4,7 +4,7 @@ */ #include -#include +#include "test.h" static void do_test_add(const std::string &text, const std::string &lc) { @@ -12,7 +12,7 @@ static void do_test_add(const std::string &text, const std::string &lc) test_equal(filter :: add(text, i++), lc); } -static void test_add() +static void test_addition() { do_test_add("It's dangerous to go alone! Take this...", "its dangerous to go alone take this"); @@ -43,26 +43,20 @@ static void test_add() } -static std::set::iterator IT; -static unsigned int *IDS = NULL; - -static unsigned int _do_test_search_compare(unsigned int i) -{ - return (*IT++ == IDS[i]) ? LOOP_PASSED : LOOP_FAILED; -} - static void do_test_search(const std::string &text, unsigned int len, unsigned int *ids) { int init_values[] = { 1, 2, 3, 4, 5 }; std::set res(init_values, init_values + 5); + std::set::iterator it; filter :: search(text, res); test_equal(res.size(), (size_t)len); - IDS = ids; - IT = res.begin(); - test_for_each(0, len, 1, _do_test_search_compare); + it = res.begin(); + for (unsigned int i = 0; i < len; i++) + test_loop_equal(*it++, ids[i], i); + test_loop_passed(); } static void test_search() @@ -88,9 +82,7 @@ static void test_search() do_test_search("d", 3, res6); } -int main(int argc, char **argv) -{ - test :: run("Filter Add Test", test_add); - test :: run("Filter Search Test", test_search); - return 0; -} +DECLARE_UNIT_TESTS( + UNIT_TEST("Filter Addition", test_addition), + UNIT_TEST("Filter Search", test_search), +);