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