summaryrefslogtreecommitdiffstats
path: root/src/test/test-progress-bar.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-12 03:50:42 +0000
commit78e9bb837c258ac0ec7712b3d612cc2f407e731e (patch)
treef515d16b6efd858a9aeb5b0ef5d6f90bf288283d /src/test/test-progress-bar.c
parentAdding debian version 255.5-1. (diff)
downloadsystemd-78e9bb837c258ac0ec7712b3d612cc2f407e731e.tar.xz
systemd-78e9bb837c258ac0ec7712b3d612cc2f407e731e.zip
Merging upstream version 256.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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);