]>
Commit | Line | Data |
---|---|---|
288a74cc RC |
1 | /*** |
2 | This file is part of systemd. | |
3 | ||
4 | Copyright 2010 Lennart Poettering | |
5 | Copyright 2013 Thomas H.P. Andersen | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
21 | #include <stdio.h> | |
22 | #include <stdbool.h> | |
23 | ||
24 | #include "terminal-util.h" | |
25 | #include "macro.h" | |
26 | #include "util.h" | |
27 | #include "log.h" | |
3ffd4af2 | 28 | #include "fd-util.h" |
288a74cc RC |
29 | |
30 | static void test_default_term_for_tty(void) { | |
31 | puts(default_term_for_tty("/dev/tty23")); | |
32 | puts(default_term_for_tty("/dev/ttyS23")); | |
33 | puts(default_term_for_tty("/dev/tty0")); | |
34 | puts(default_term_for_tty("/dev/pty0")); | |
35 | puts(default_term_for_tty("/dev/pts/0")); | |
36 | puts(default_term_for_tty("/dev/console")); | |
37 | puts(default_term_for_tty("tty23")); | |
38 | puts(default_term_for_tty("ttyS23")); | |
39 | puts(default_term_for_tty("tty0")); | |
40 | puts(default_term_for_tty("pty0")); | |
41 | puts(default_term_for_tty("pts/0")); | |
42 | puts(default_term_for_tty("console")); | |
43 | } | |
44 | ||
45 | static void test_read_one_char(void) { | |
46 | _cleanup_fclose_ FILE *file = NULL; | |
47 | char r; | |
48 | bool need_nl; | |
49 | char name[] = "/tmp/test-read_one_char.XXXXXX"; | |
50 | int fd; | |
51 | ||
52 | fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC); | |
53 | assert_se(fd >= 0); | |
54 | file = fdopen(fd, "r+"); | |
55 | assert_se(file); | |
56 | assert_se(fputs("c\n", file) >= 0); | |
57 | rewind(file); | |
58 | ||
59 | assert_se(read_one_char(file, &r, 1000000, &need_nl) >= 0); | |
60 | assert_se(!need_nl); | |
61 | assert_se(r == 'c'); | |
62 | assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0); | |
63 | ||
64 | rewind(file); | |
65 | assert_se(fputs("foobar\n", file) >= 0); | |
66 | rewind(file); | |
67 | assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0); | |
68 | ||
69 | rewind(file); | |
70 | assert_se(fputs("\n", file) >= 0); | |
71 | rewind(file); | |
72 | assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0); | |
73 | ||
74 | unlink(name); | |
75 | } | |
76 | ||
77 | int main(int argc, char *argv[]) { | |
78 | log_parse_environment(); | |
79 | log_open(); | |
80 | ||
81 | test_default_term_for_tty(); | |
82 | test_read_one_char(); | |
83 | ||
84 | return 0; | |
85 | } |