1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2010 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
25 #include "specifier.h"
28 static void test_specifier_printf(void) {
31 const Specifier table[] = {
32 { 'a', specifier_string, (char*) "AAAA" },
33 { 'b', specifier_string, (char*) "BBBB" },
37 w = specifier_printf("xxx a=%a b=%b yyy", table, NULL);
42 static void test_foreach_word_quoted(void) {
45 const char test[] = "test a b c 'd' e '' '' hhh '' ''";
46 printf("<%s>\n", test);
47 FOREACH_WORD_QUOTED(w, l, test, state) {
50 assert_se(t = strndup(w, l));
56 static void test_strv_join(void) {
59 const char * const input_table_multiple[] = {
65 const char * const input_table_one[] = {
69 const char * const input_table_none[] = {
73 r = strv_join((char **)input_table_multiple, ", ");
74 assert_se(streq(r, "one, two, three"));
78 r = strv_join((char **)input_table_multiple, ";");
79 assert_se(streq(r, "one;two;three"));
83 r = strv_join((char **)input_table_multiple, NULL);
84 assert_se(streq(r, "one two three"));
88 r = strv_join((char **)input_table_one, ", ");
89 assert_se(streq(r, "one"));
93 r = strv_join((char **)input_table_none, ", ");
94 assert_se(streq(r, ""));
99 static void test_default_term_for_tty(void) {
100 printf("%s\n", default_term_for_tty("/dev/tty23"));
101 printf("%s\n", default_term_for_tty("/dev/ttyS23"));
102 printf("%s\n", default_term_for_tty("/dev/tty0"));
103 printf("%s\n", default_term_for_tty("/dev/pty0"));
104 printf("%s\n", default_term_for_tty("/dev/pts/0"));
105 printf("%s\n", default_term_for_tty("/dev/console"));
106 printf("%s\n", default_term_for_tty("tty23"));
107 printf("%s\n", default_term_for_tty("ttyS23"));
108 printf("%s\n", default_term_for_tty("tty0"));
109 printf("%s\n", default_term_for_tty("pty0"));
110 printf("%s\n", default_term_for_tty("pts/0"));
111 printf("%s\n", default_term_for_tty("console"));
114 int main(int argc, char *argv[]) {
115 test_default_term_for_tty();
116 test_foreach_word_quoted();
117 test_specifier_printf();