| File: | .build-ci/../shared/test/test-progress-util.c |
| Warning: | line 26, column 2 Null pointer passed to 1st parameter expecting 'nonnull' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | // SPDX-License-Identifier: LGPL-2.1-or-later | |||
| 2 | /* | |||
| 3 | * This file is part of nvme-cli. | |||
| 4 | */ | |||
| 5 | #include <stdbool.h> | |||
| 6 | #include <stdio.h> | |||
| 7 | #include <stdlib.h> | |||
| 8 | #include <string.h> | |||
| 9 | ||||
| 10 | #include <progress-util.h> | |||
| 11 | ||||
| 12 | static bool_Bool check_bool(const char *name, bool_Bool got) | |||
| 13 | { | |||
| 14 | printf(" - %s [%s]\n", name, got ? "PASS" : "FAIL"); | |||
| 15 | return got; | |||
| 16 | } | |||
| 17 | ||||
| 18 | static char *capture(void (*fn)(FILE *stream)) | |||
| 19 | { | |||
| 20 | static char buf[512]; | |||
| 21 | FILE *stream = tmpfile(); | |||
| 22 | size_t n; | |||
| 23 | ||||
| 24 | memset(buf, 0, sizeof(buf)); | |||
| 25 | fn(stream); | |||
| 26 | rewind(stream); | |||
| ||||
| 27 | n = fread(buf, 1, sizeof(buf) - 1, stream); | |||
| 28 | buf[n] = '\0'; | |||
| 29 | fclose(stream); | |||
| 30 | ||||
| 31 | return buf; | |||
| 32 | } | |||
| 33 | ||||
| 34 | static void run_zero(FILE *stream) | |||
| 35 | { | |||
| 36 | shr_spinner("Task", 0.0, stream); | |||
| 37 | } | |||
| 38 | ||||
| 39 | static void run_half(FILE *stream) | |||
| 40 | { | |||
| 41 | shr_spinner("Task", 0.5, stream); | |||
| 42 | } | |||
| 43 | ||||
| 44 | static void run_full(FILE *stream) | |||
| 45 | { | |||
| 46 | shr_spinner("Task", 1.0, stream); | |||
| 47 | } | |||
| 48 | ||||
| 49 | static void run_clamped(FILE *stream) | |||
| 50 | { | |||
| 51 | shr_spinner("Task", 5.0, stream); | |||
| 52 | } | |||
| 53 | ||||
| 54 | int main(void) | |||
| 55 | { | |||
| 56 | bool_Bool pass = true1; | |||
| 57 | char *out; | |||
| 58 | ||||
| 59 | printf("test_spinner:\n"); | |||
| 60 | ||||
| 61 | out = capture(run_zero); | |||
| ||||
| 62 | pass &= check_bool("0% output contains the label", strstr(out, "Task")_Generic (0 ? (out) : (void *) 1, const void *: (const char * ) (strstr (out, "Task")), default: strstr (out, "Task")) != NULL((void*)0)); | |||
| 63 | pass &= check_bool("0% output shows 0%", strstr(out, "0%")_Generic (0 ? (out) : (void *) 1, const void *: (const char * ) (strstr (out, "0%")), default: strstr (out, "0%")) != NULL((void*)0)); | |||
| 64 | ||||
| 65 | out = capture(run_half); | |||
| 66 | pass &= check_bool("50% output shows 50%", strstr(out, "50%")_Generic (0 ? (out) : (void *) 1, const void *: (const char * ) (strstr (out, "50%")), default: strstr (out, "50%")) != NULL((void*)0)); | |||
| 67 | ||||
| 68 | out = capture(run_full); | |||
| 69 | pass &= check_bool("100% output shows 100%", strstr(out, "100%")_Generic (0 ? (out) : (void *) 1, const void *: (const char * ) (strstr (out, "100%")), default: strstr (out, "100%")) != NULL((void*)0)); | |||
| 70 | ||||
| 71 | out = capture(run_clamped); | |||
| 72 | pass &= check_bool("percent > 1.0 is clamped to 100%", strstr(out, "100%")_Generic (0 ? (out) : (void *) 1, const void *: (const char * ) (strstr (out, "100%")), default: strstr (out, "100%")) != NULL((void*)0)); | |||
| 73 | ||||
| 74 | fflush(stdoutstdout); | |||
| 75 | exit(pass ? EXIT_SUCCESS0 : EXIT_FAILURE1); | |||
| 76 | } |