From c22a6e64d92c1804ff93d40b8d726b7da0061f75 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Mon, 6 Jun 2016 17:38:09 +0200 Subject: [PATCH] Add unit test for progress bars Signed-off-by: Joachim Nilsson --- progress.c | 52 ----------------------------------------------- progress.mk | 4 ---- tests/.gitignore | 1 + tests/Makefile.am | 1 + tests/progress.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 52 insertions(+), 56 deletions(-) delete mode 100644 progress.mk create mode 100644 tests/progress.c diff --git a/progress.c b/progress.c index a2f5563..dbe53bf 100644 --- a/progress.c +++ b/progress.c @@ -114,60 +114,8 @@ void progress_simple(int percent) } } -#ifdef UNITTEST -#include /* atexit() */ -#include /* usleep() */ - -#define MAX_WIDTH 80 -#define msleep(msec) usleep(msec * 1000) - -static void bye(void) -{ - showcursor(); -} - -static void testit(int fn, int percent) -{ - if (fn) - progress(percent, MAX_WIDTH); - else - progress_simple(percent); -} - -static void test(int fn) -{ - int i, percent, block = 0, num = 85; - - while (block < num) { - percent = block * 100 / num; - for (i = 0; i < 10; i++) { - testit(fn, percent); - msleep(5); - } - block++; - msleep(10); - } - testit(fn, 100); -} - -int main(void) -{ - atexit(bye); - hidecursor(); - - printf("\nAdvanced:\n"); - test(1); - printf("\nSimple:\n"); - test(0); - printf("\n"); - - return 0; -} -#endif /* UNITTEST */ - /** * Local Variables: - * compile-command: "make V=1 -f progress.mk" * indent-tabs-mode: t * c-file-style: "linux" * End: diff --git a/progress.mk b/progress.mk deleted file mode 100644 index f0e0332..0000000 --- a/progress.mk +++ /dev/null @@ -1,4 +0,0 @@ -OBJS = -TARGET = progress.test clean - -include rules.mk diff --git a/tests/.gitignore b/tests/.gitignore index 8f11a2f..ac26258 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -4,6 +4,7 @@ fsendfile lfile makepath pidfile +progress rsync tempfile tree diff --git a/tests/Makefile.am b/tests/Makefile.am index f19fbe0..e804c68 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -6,6 +6,7 @@ TESTS += fsendfile TESTS += lfile TESTS += makepath TESTS += pidfile +TESTS += progress TESTS += rsync TESTS += tempfile TESTS += tree diff --git a/tests/progress.c b/tests/progress.c new file mode 100644 index 0000000..82795be --- /dev/null +++ b/tests/progress.c @@ -0,0 +1,50 @@ +#include /* atexit() */ +#include /* usleep() */ +#include "conio.h" +#include "check.h" + +#define MAX_WIDTH 80 +#define msleep(msec) usleep(msec * 1000) + +static void bye(void) +{ + showcursor(); +} + +static void testit(int fn, int percent) +{ + if (fn) + progress(percent, MAX_WIDTH); + else + progress_simple(percent); +} + +static void run_test(int fn) +{ + int i, percent, block = 0, num = 85; + + while (block < num) { + percent = block * 100 / num; + for (i = 0; i < 10; i++) { + testit(fn, percent); + msleep(1); + } + block++; + msleep(1); + } + testit(fn, 100); +} + +int main(void) +{ + atexit(bye); + hidecursor(); + + printf("\nAdvanced:\n"); + run_test(1); + printf("\nSimple:\n"); + run_test(0); + printf("\n"); + + return 0; +}