61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
|
/*
|
||
|
* Copyright 2014 (c) Anna Schumaker.
|
||
|
* Test the idle queue
|
||
|
*/
|
||
|
|
||
|
#include <idle.h>
|
||
|
#include <print.h>
|
||
|
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
static unsigned int test_num = 0;
|
||
|
static unsigned int 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)
|
||
|
{
|
||
|
cur++;
|
||
|
test_results(cur == expected, __LINE__);
|
||
|
}
|
||
|
|
||
|
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__);
|
||
|
return 0;
|
||
|
}
|