]>
Commit | Line | Data |
---|---|---|
52ad194e | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
663996b3 MS |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2013 Lennart Poettering | |
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 | ||
663996b3 | 21 | #include "bus-internal.h" |
db2df898 MP |
22 | #include "bus-signature.h" |
23 | #include "log.h" | |
24 | #include "string-util.h" | |
663996b3 MS |
25 | |
26 | int main(int argc, char *argv[]) { | |
60f067b4 JS |
27 | char prefix[256]; |
28 | int r; | |
29 | ||
30 | assert_se(signature_is_single("y", false)); | |
31 | assert_se(signature_is_single("u", false)); | |
32 | assert_se(signature_is_single("v", false)); | |
33 | assert_se(signature_is_single("as", false)); | |
34 | assert_se(signature_is_single("(ss)", false)); | |
35 | assert_se(signature_is_single("()", false)); | |
36 | assert_se(signature_is_single("(()()()()())", false)); | |
37 | assert_se(signature_is_single("(((())))", false)); | |
38 | assert_se(signature_is_single("((((s))))", false)); | |
39 | assert_se(signature_is_single("{ss}", true)); | |
40 | assert_se(signature_is_single("a{ss}", false)); | |
41 | assert_se(!signature_is_single("uu", false)); | |
42 | assert_se(!signature_is_single("", false)); | |
43 | assert_se(!signature_is_single("(", false)); | |
44 | assert_se(!signature_is_single(")", false)); | |
45 | assert_se(!signature_is_single("())", false)); | |
46 | assert_se(!signature_is_single("((())", false)); | |
47 | assert_se(!signature_is_single("{)", false)); | |
48 | assert_se(!signature_is_single("{}", true)); | |
49 | assert_se(!signature_is_single("{sss}", true)); | |
50 | assert_se(!signature_is_single("{s}", true)); | |
51 | assert_se(!signature_is_single("{ss}", false)); | |
52 | assert_se(!signature_is_single("{ass}", true)); | |
53 | assert_se(!signature_is_single("a}", true)); | |
663996b3 MS |
54 | |
55 | assert_se(signature_is_pair("yy")); | |
56 | assert_se(signature_is_pair("ss")); | |
57 | assert_se(signature_is_pair("sas")); | |
58 | assert_se(signature_is_pair("sv")); | |
59 | assert_se(signature_is_pair("sa(vs)")); | |
60 | assert_se(!signature_is_pair("")); | |
61 | assert_se(!signature_is_pair("va")); | |
62 | assert_se(!signature_is_pair("sss")); | |
63 | assert_se(!signature_is_pair("{s}ss")); | |
64 | ||
65 | assert_se(signature_is_valid("ssa{ss}sssub", true)); | |
66 | assert_se(signature_is_valid("ssa{ss}sssub", false)); | |
67 | assert_se(signature_is_valid("{ss}", true)); | |
68 | assert_se(!signature_is_valid("{ss}", false)); | |
69 | assert_se(signature_is_valid("", true)); | |
70 | assert_se(signature_is_valid("", false)); | |
71 | ||
72 | assert_se(signature_is_valid("sssusa(uuubbba(uu)uuuu)a{u(uuuvas)}", false)); | |
73 | ||
74 | assert_se(!signature_is_valid("a", false)); | |
75 | assert_se(signature_is_valid("as", false)); | |
76 | assert_se(signature_is_valid("aas", false)); | |
77 | assert_se(signature_is_valid("aaas", false)); | |
78 | assert_se(signature_is_valid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaad", false)); | |
79 | assert_se(signature_is_valid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas", false)); | |
80 | assert_se(!signature_is_valid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaau", false)); | |
81 | ||
82 | assert_se(signature_is_valid("(((((((((((((((((((((((((((((((())))))))))))))))))))))))))))))))", false)); | |
83 | assert_se(!signature_is_valid("((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))", false)); | |
84 | ||
85 | assert_se(namespace_complex_pattern("", "")); | |
86 | assert_se(namespace_complex_pattern("foobar", "foobar")); | |
87 | assert_se(namespace_complex_pattern("foobar.waldo", "foobar.waldo")); | |
88 | assert_se(namespace_complex_pattern("foobar.", "foobar.waldo")); | |
89 | assert_se(namespace_complex_pattern("foobar.waldo", "foobar.")); | |
90 | assert_se(!namespace_complex_pattern("foobar.waldo", "foobar")); | |
91 | assert_se(!namespace_complex_pattern("foobar", "foobar.waldo")); | |
92 | assert_se(!namespace_complex_pattern("", "foo")); | |
93 | assert_se(!namespace_complex_pattern("foo", "")); | |
94 | assert_se(!namespace_complex_pattern("foo.", "")); | |
95 | ||
96 | assert_se(path_complex_pattern("", "")); | |
86f210e9 MP |
97 | assert_se(!path_complex_pattern("", "/")); |
98 | assert_se(!path_complex_pattern("/", "")); | |
663996b3 MS |
99 | assert_se(path_complex_pattern("/", "/")); |
100 | assert_se(path_complex_pattern("/foobar/", "/")); | |
86f210e9 | 101 | assert_se(!path_complex_pattern("/foobar/", "/foobar")); |
663996b3 | 102 | assert_se(path_complex_pattern("/foobar", "/foobar")); |
86f210e9 | 103 | assert_se(!path_complex_pattern("/foobar", "/foobar/")); |
663996b3 MS |
104 | assert_se(!path_complex_pattern("/foobar", "/foobar/waldo")); |
105 | assert_se(path_complex_pattern("/foobar/", "/foobar/waldo")); | |
86f210e9 MP |
106 | assert_se(path_complex_pattern("/foobar/waldo", "/foobar/")); |
107 | ||
108 | assert_se(path_simple_pattern("/foo/", "/foo/bar/waldo")); | |
663996b3 MS |
109 | |
110 | assert_se(namespace_simple_pattern("", "")); | |
86f210e9 | 111 | assert_se(namespace_simple_pattern("", ".foobar")); |
663996b3 MS |
112 | assert_se(namespace_simple_pattern("foobar", "foobar")); |
113 | assert_se(namespace_simple_pattern("foobar.waldo", "foobar.waldo")); | |
114 | assert_se(namespace_simple_pattern("foobar", "foobar.waldo")); | |
115 | assert_se(!namespace_simple_pattern("foobar.waldo", "foobar")); | |
116 | assert_se(!namespace_simple_pattern("", "foo")); | |
117 | assert_se(!namespace_simple_pattern("foo", "")); | |
86f210e9 | 118 | assert_se(namespace_simple_pattern("foo.", "foo.bar.waldo")); |
663996b3 | 119 | |
60f067b4 JS |
120 | assert_se(streq(object_path_startswith("/foo/bar", "/foo"), "bar")); |
121 | assert_se(streq(object_path_startswith("/foo", "/foo"), "")); | |
122 | assert_se(streq(object_path_startswith("/foo", "/"), "foo")); | |
123 | assert_se(streq(object_path_startswith("/", "/"), "")); | |
124 | assert_se(!object_path_startswith("/foo", "/bar")); | |
125 | assert_se(!object_path_startswith("/", "/bar")); | |
126 | assert_se(!object_path_startswith("/foo", "")); | |
127 | ||
128 | assert_se(object_path_is_valid("/foo/bar")); | |
129 | assert_se(object_path_is_valid("/foo")); | |
130 | assert_se(object_path_is_valid("/")); | |
131 | assert_se(object_path_is_valid("/foo5")); | |
132 | assert_se(object_path_is_valid("/foo_5")); | |
133 | assert_se(!object_path_is_valid("")); | |
134 | assert_se(!object_path_is_valid("/foo/")); | |
135 | assert_se(!object_path_is_valid("//")); | |
136 | assert_se(!object_path_is_valid("//foo")); | |
137 | assert_se(!object_path_is_valid("/foo//bar")); | |
138 | assert_se(!object_path_is_valid("/foo/aaaäöä")); | |
139 | ||
140 | OBJECT_PATH_FOREACH_PREFIX(prefix, "/") { | |
141 | log_info("<%s>", prefix); | |
142 | assert_not_reached("???"); | |
143 | } | |
144 | ||
145 | r = 0; | |
146 | OBJECT_PATH_FOREACH_PREFIX(prefix, "/xxx") { | |
147 | log_info("<%s>", prefix); | |
148 | assert_se(streq(prefix, "/")); | |
149 | assert_se(r == 0); | |
150 | r++; | |
151 | } | |
152 | assert_se(r == 1); | |
153 | ||
154 | r = 0; | |
155 | OBJECT_PATH_FOREACH_PREFIX(prefix, "/xxx/yyy/zzz") { | |
156 | log_info("<%s>", prefix); | |
157 | assert_se(r != 0 || streq(prefix, "/xxx/yyy")); | |
158 | assert_se(r != 1 || streq(prefix, "/xxx")); | |
159 | assert_se(r != 2 || streq(prefix, "/")); | |
160 | r++; | |
161 | } | |
162 | assert_se(r == 3); | |
163 | ||
663996b3 MS |
164 | return 0; |
165 | } |