blob: abc1d292dcbd413f3b6ca487efa930472a01b800 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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);
|