X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=src%2Ftest%2Ftest-terminal-util.c;h=8cd580e71922e3593421c376b8da8503283a5dbb;hb=ca78ad1de987b800978622a22ac6c5caf628a037;hp=84b448a0957a39a62e81d0192204af54d09192bf;hpb=c665ffa9b16d910fb6660e132f19ffc4e2537590;p=thirdparty%2Fsystemd.git
diff --git a/src/test/test-terminal-util.c b/src/test/test-terminal-util.c
index 84b448a0957..8cd580e7192 100644
--- a/src/test/test-terminal-util.c
+++ b/src/test/test-terminal-util.c
@@ -1,31 +1,18 @@
-/***
- This file is part of systemd.
-
- Copyright 2010 Lennart Poettering
- Copyright 2013 Thomas H.P. Andersen
-
- systemd is free software; you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation; either version 2.1 of the License, or
- (at your option) any later version.
-
- systemd is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with systemd; If not, see .
-***/
+/* SPDX-License-Identifier: LGPL-2.1+ */
+#include
#include
#include
+#include
+#include "alloc-util.h"
#include "fd-util.h"
-#include "fileio.h"
-#include "log.h"
#include "macro.h"
+#include "path-util.h"
+#include "strv.h"
#include "terminal-util.h"
+#include "tests.h"
+#include "tmpfile-util.h"
#include "util.h"
static void test_default_term_for_tty(void) {
@@ -48,15 +35,11 @@ static void test_read_one_char(void) {
char r;
bool need_nl;
char name[] = "/tmp/test-read_one_char.XXXXXX";
- int fd;
- fd = mkostemp_safe(name, O_RDWR|O_CLOEXEC);
- assert_se(fd >= 0);
- file = fdopen(fd, "r+");
- assert_se(file);
+ assert(fmkostemp_safe(name, "r+", &file) == 0);
+
assert_se(fputs("c\n", file) >= 0);
rewind(file);
-
assert_se(read_one_char(file, &r, 1000000, &need_nl) >= 0);
assert_se(!need_nl);
assert_se(r == 'c');
@@ -72,15 +55,24 @@ static void test_read_one_char(void) {
rewind(file);
assert_se(read_one_char(file, &r, 1000000, &need_nl) < 0);
- unlink(name);
+ assert_se(unlink(name) >= 0);
+}
+
+static void test_getttyname_malloc(void) {
+ _cleanup_free_ char *ttyname = NULL;
+ _cleanup_close_ int master = -1;
+
+ assert_se((master = posix_openpt(O_RDWR|O_NOCTTY)) >= 0);
+ assert_se(getttyname_malloc(master, &ttyname) >= 0);
+ assert_se(PATH_IN_SET(ttyname, "ptmx", "pts/ptmx"));
}
int main(int argc, char *argv[]) {
- log_parse_environment();
- log_open();
+ test_setup_logging(LOG_INFO);
test_default_term_for_tty();
test_read_one_char();
+ test_getttyname_malloc();
return 0;
}