]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
288a74cc | 2 | |
288a74cc | 3 | #include <stdbool.h> |
cf0fbc49 | 4 | #include <stdio.h> |
288a74cc | 5 | |
23b27b39 | 6 | #include "alloc-util.h" |
0d39fa9c | 7 | #include "fd-util.h" |
288a74cc | 8 | #include "macro.h" |
81f5e513 | 9 | #include "strv.h" |
0d39fa9c | 10 | #include "terminal-util.h" |
e4de7287 LP |
11 | #include "tests.h" |
12 | #include "tmpfile-util.h" | |
288a74cc | 13 | #include "util.h" |
288a74cc RC |
14 | |
15 | static void test_default_term_for_tty(void) { | |
16 | puts(default_term_for_tty("/dev/tty23")); | |
17 | puts(default_term_for_tty("/dev/ttyS23")); | |
18 | puts(default_term_for_tty("/dev/tty0")); | |
19 | puts(default_term_for_tty("/dev/pty0")); | |
20 | puts(default_term_for_tty("/dev/pts/0")); | |
21 | puts(default_term_for_tty("/dev/console")); | |
22 | puts(default_term_for_tty("tty23")); | |
23 | puts(default_term_for_tty("ttyS23")); | |
24 | puts(default_term_for_tty("tty0")); | |
25 | puts(default_term_for_tty("pty0")); | |
26 | puts(default_term_for_tty("pts/0")); | |
27 | puts(default_term_for_tty("console")); | |
28 | } | |
29 | ||
30 | static void test_read_one_char(void) { | |
31 | _cleanup_fclose_ FILE *file = NULL; | |
32 | char r; | |
33 | bool need_nl; | |
34 | char name[] = "/tmp/test-read_one_char.XXXXXX"; | |
288a74cc | 35 | |
d8351049 ZJS |
36 | assert(fmkostemp_safe(name, "r+", &file) == 0); |
37 | ||
288a74cc RC |
38 | assert_se(fputs("c\n", file) >= 0); |
39 | rewind(file); | |
288a74cc RC |
40 | assert_se(read_one_char(file, &r, 1000000, &need_nl) >= 0); |
41 | assert_se(!need_nl); | |
42 | assert_se(r == 'c'); | |
43 | assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0); | |
44 | ||
45 | rewind(file); | |
46 | assert_se(fputs("foobar\n", file) >= 0); | |
47 | rewind(file); | |
48 | assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0); | |
49 | ||
50 | rewind(file); | |
51 | assert_se(fputs("\n", file) >= 0); | |
52 | rewind(file); | |
53 | assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0); | |
54 | ||
55 | unlink(name); | |
56 | } | |
57 | ||
58 | int main(int argc, char *argv[]) { | |
294bf0c3 | 59 | test_setup_logging(LOG_INFO); |
288a74cc RC |
60 | |
61 | test_default_term_for_tty(); | |
62 | test_read_one_char(); | |
cb91deaf | 63 | |
288a74cc RC |
64 | return 0; |
65 | } |