mirror of
https://github.com/troglobit/libite.git
synced 2026-11-19 19:40:45 +00:00
Add unit test for progress bars
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
16ae343df2
commit
c22a6e64d9
5 files changed
+52
-56
No files matched your search
-52
@@ -114,60 +114,8 @@ void progress_simple(int percent)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef UNITTEST
|
|
||||||
#include <stdlib.h> /* atexit() */
|
|
||||||
#include <unistd.h> /* 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:
|
* Local Variables:
|
||||||
* compile-command: "make V=1 -f progress.mk"
|
|
||||||
* indent-tabs-mode: t
|
* indent-tabs-mode: t
|
||||||
* c-file-style: "linux"
|
* c-file-style: "linux"
|
||||||
* End:
|
* End:
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
OBJS =
|
|
||||||
TARGET = progress.test clean
|
|
||||||
|
|
||||||
include rules.mk
|
|
||||||
@@ -4,6 +4,7 @@ fsendfile
|
|||||||
lfile
|
lfile
|
||||||
makepath
|
makepath
|
||||||
pidfile
|
pidfile
|
||||||
|
progress
|
||||||
rsync
|
rsync
|
||||||
tempfile
|
tempfile
|
||||||
tree
|
tree
|
||||||
@@ -6,6 +6,7 @@ TESTS += fsendfile
|
|||||||
TESTS += lfile
|
TESTS += lfile
|
||||||
TESTS += makepath
|
TESTS += makepath
|
||||||
TESTS += pidfile
|
TESTS += pidfile
|
||||||
|
TESTS += progress
|
||||||
TESTS += rsync
|
TESTS += rsync
|
||||||
TESTS += tempfile
|
TESTS += tempfile
|
||||||
TESTS += tree
|
TESTS += tree
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
#include <stdlib.h> /* atexit() */
|
||||||
|
#include <unistd.h> /* 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;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user