diff --git a/tests/Sconscript b/tests/Sconscript index 6bcda34f..f67b346c 100644 --- a/tests/Sconscript +++ b/tests/Sconscript @@ -14,8 +14,8 @@ for arg in sys.argv: src = SConscript("src/Sconscript") -tests = [ "version" , "file", "database", "index", "filter" ] -# "filter", "idle", "tag_db", +tests = [ "version" , "file", "database", "index", "filter", "idle" ] +# "tag_db", # "queue" ] #scripts = [ "playlist", "library", "deck", "audio", "gui" ] diff --git a/tests/idle b/tests/idle deleted file mode 100755 index d03b706e..00000000 --- a/tests/idle +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -# Copyright 2014 (c) Anna Schumaker - -. $(dirname $0)/_functions - -new_test "Idle Queue Test" -src/idle.run diff --git a/tests/src/idle.cpp b/tests/src/idle.cpp index 4e386cf9..8b13f4b3 100644 --- a/tests/src/idle.cpp +++ b/tests/src/idle.cpp @@ -4,57 +4,54 @@ */ #include -#include +#include "test.h" -#include +#include -static unsigned int test_num = 0; -static unsigned int cur = -1; +static float cur = -1; -void test_results(bool success, unsigned int line) -{ - print(" %u: ", test_num); - if (success) - print("Success!\n"); - else { - print("FAILED (%u) =(", line); - exit(1); - } - test_num++; -} - -void test_progress(unsigned int expected, unsigned int multiplier, - unsigned int line) -{ - unsigned int prog = (idle :: get_progress() * multiplier); - test_results(prog == expected, line); -} - -void inc_cur(unsigned int &expected) +static void inc_cur(float &expected) { cur++; - test_results(cur == expected, __LINE__); + check_equal(cur, expected); +} + +static void test_idle_queue(float n) +{ + test_equal(idle :: get_progress(), (float)1.0); + test_equal(idle :: run_task(), false); + + for (float i = 0; i < n; i++) + idle :: schedule(inc_cur, i); + test_equal(idle :: get_progress(), (float)0.0); + + test :: begin(); + for (float i = 0; i < (n - 1); i++) { + check_equal(idle :: run_task(), true); + check_equal(idle :: get_progress(), (i + 1) / n); + } + test :: success(); + + test_equal(idle :: run_task(), false); + test_equal(idle :: get_progress(), (float)1.0); +} + +static void do_test(float n) +{ + std::stringstream ss; + ss << " (n = " << n << ")"; + const std::string n_str = ss.str(); + + cur = -1; + run_test("Idle Queue Test" + n_str, test_idle_queue, n); } int main(int argc, char **argv) { - unsigned int i, num = 10; - - test_progress(num, num, __LINE__); - for (i = 0; i < num; i++) - idle :: schedule(inc_cur, i); - test_progress(0, num, __LINE__); - test_results(idle :: get_progress() == 0.0, __LINE__); - - for (i = 0; i < (num - 1); i++) { - test_results(idle :: run_task(), __LINE__); - test_progress(i + 1, num, __LINE__); - } - - test_results(idle :: run_task() == false, __LINE__); - test_progress(i + 1, num, __LINE__); - - test_results(idle :: run_task() == false, __LINE__); - test_progress(num, num, __LINE__); + do_test(10); + do_test(100); + do_test(1000); + do_test(10000); + do_test(100000); return 0; }