Debian Codegraph @

src/test/test-progress-bar.c

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include "format-util.h"
4 #include "pretty-print.h"
5 #include "process-util.h"
6 #include "random-util.h"
7 #include "tests.h"
8 #include "time-util.h"
9
10 #define PROGRESS_PREFIX "test:"
11
12 TEST(progress_bar) {
13
14 draw_progress_bar(PROGRESS_PREFIX, 0);
15
16 bool paused = false;
17
18 for (double d = 0; d <= 100; d += 0.5) {
19 usleep_safe(random_u64_range(20 * USEC_PER_MSEC));
20 draw_progress_barf(d, PROGRESS_PREFIX "[" PID_FMT "]", getpid_cached());
21
22 if (!paused && d >= 50) {
23 clear_progress_bar(PROGRESS_PREFIX);
24 fputs("Sleeping for 1s...", stdout);
25 fflush(stdout);
26 usleep_safe(USEC_PER_SEC);
27 paused = true;
28 }
29 }
30
31 draw_progress_barf(100, PROGRESS_PREFIX "[" PID_FMT "]", getpid_cached());
32 usleep_safe(300 * MSEC_PER_SEC);
33 clear_progress_bar(PROGRESS_PREFIX "[0123456789]" );
34 fputs("Done.\n", stdout);
35 }
36
37 DEFINE_TEST_MAIN(LOG_INFO);