summaryrefslogtreecommitdiffstats
path: root/src/test/test-progress-bar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/test-progress-bar.c')
-rw-r--r--src/test/test-progress-bar.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/test/test-progress-bar.c b/src/test/test-progress-bar.c
new file mode 100644
index 0000000..b47adf0
--- /dev/null
+++ b/src/test/test-progress-bar.c
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "pretty-print.h"
+#include "random-util.h"
+#include "tests.h"
+
+#define PROGRESS_PREFIX "test: "
+
+TEST(progress_bar) {
+
+ draw_progress_bar(PROGRESS_PREFIX, 0);
+
+ bool paused = false;
+
+ for (double d = 0; d <= 100; d += 0.5) {
+ usleep_safe(random_u64_range(20 * USEC_PER_MSEC));
+ draw_progress_bar(PROGRESS_PREFIX, d);
+
+ if (!paused && d >= 50) {
+ clear_progress_bar(PROGRESS_PREFIX);
+ fputs("Sleeping for 1s...", stdout);
+ fflush(stdout);
+ usleep_safe(USEC_PER_SEC);
+ paused = true;
+ }
+ }
+
+ draw_progress_bar(PROGRESS_PREFIX, 100);
+ usleep_safe(300 * MSEC_PER_SEC);
+ clear_progress_bar(PROGRESS_PREFIX);
+ fputs("Done.\n", stdout);
+}
+
+DEFINE_TEST_MAIN(LOG_INFO);