Line data Source code
1 : /* SPDX-License-Identifier: LGPL-2.1+ */
2 :
3 : #include "bus-internal.h"
4 : #include "bus-signature.h"
5 : #include "log.h"
6 : #include "string-util.h"
7 :
8 1 : int main(int argc, char *argv[]) {
9 : char prefix[256];
10 : int r;
11 :
12 1 : assert_se(signature_is_single("y", false));
13 1 : assert_se(signature_is_single("u", false));
14 1 : assert_se(signature_is_single("v", false));
15 1 : assert_se(signature_is_single("as", false));
16 1 : assert_se(signature_is_single("(ss)", false));
17 1 : assert_se(!signature_is_single("()", false));
18 1 : assert_se(!signature_is_single("(()()()()())", false));
19 1 : assert_se(!signature_is_single("(((())))", false));
20 1 : assert_se(signature_is_single("((((s))))", false));
21 1 : assert_se(signature_is_single("{ss}", true));
22 1 : assert_se(signature_is_single("a{ss}", false));
23 1 : assert_se(!signature_is_single("uu", false));
24 1 : assert_se(!signature_is_single("", false));
25 1 : assert_se(!signature_is_single("(", false));
26 1 : assert_se(!signature_is_single(")", false));
27 1 : assert_se(!signature_is_single("())", false));
28 1 : assert_se(!signature_is_single("((())", false));
29 1 : assert_se(!signature_is_single("{)", false));
30 1 : assert_se(!signature_is_single("{}", true));
31 1 : assert_se(!signature_is_single("{sss}", true));
32 1 : assert_se(!signature_is_single("{s}", true));
33 1 : assert_se(!signature_is_single("{ss}", false));
34 1 : assert_se(!signature_is_single("{ass}", true));
35 1 : assert_se(!signature_is_single("a}", true));
36 :
37 1 : assert_se(signature_is_pair("yy"));
38 1 : assert_se(signature_is_pair("ss"));
39 1 : assert_se(signature_is_pair("sas"));
40 1 : assert_se(signature_is_pair("sv"));
41 1 : assert_se(signature_is_pair("sa(vs)"));
42 1 : assert_se(!signature_is_pair(""));
43 1 : assert_se(!signature_is_pair("va"));
44 1 : assert_se(!signature_is_pair("sss"));
45 1 : assert_se(!signature_is_pair("{s}ss"));
46 :
47 1 : assert_se(signature_is_valid("ssa{ss}sssub", true));
48 1 : assert_se(signature_is_valid("ssa{ss}sssub", false));
49 1 : assert_se(signature_is_valid("{ss}", true));
50 1 : assert_se(!signature_is_valid("{ss}", false));
51 1 : assert_se(signature_is_valid("", true));
52 1 : assert_se(signature_is_valid("", false));
53 :
54 1 : assert_se(signature_is_valid("sssusa(uuubbba(uu)uuuu)a{u(uuuvas)}", false));
55 :
56 1 : assert_se(!signature_is_valid("a", false));
57 1 : assert_se(signature_is_valid("as", false));
58 1 : assert_se(signature_is_valid("aas", false));
59 1 : assert_se(signature_is_valid("aaas", false));
60 1 : assert_se(signature_is_valid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaad", false));
61 1 : assert_se(signature_is_valid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas", false));
62 1 : assert_se(!signature_is_valid("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaau", false));
63 :
64 1 : assert_se(signature_is_valid("((((((((((((((((((((((((((((((((s))))))))))))))))))))))))))))))))", false));
65 1 : assert_se(!signature_is_valid("((((((((((((((((((((((((((((((((()))))))))))))))))))))))))))))))))", false));
66 :
67 1 : assert_se(namespace_complex_pattern("", ""));
68 1 : assert_se(namespace_complex_pattern("foobar", "foobar"));
69 1 : assert_se(namespace_complex_pattern("foobar.waldo", "foobar.waldo"));
70 1 : assert_se(namespace_complex_pattern("foobar.", "foobar.waldo"));
71 1 : assert_se(namespace_complex_pattern("foobar.waldo", "foobar."));
72 1 : assert_se(!namespace_complex_pattern("foobar.waldo", "foobar"));
73 1 : assert_se(!namespace_complex_pattern("foobar", "foobar.waldo"));
74 1 : assert_se(!namespace_complex_pattern("", "foo"));
75 1 : assert_se(!namespace_complex_pattern("foo", ""));
76 1 : assert_se(!namespace_complex_pattern("foo.", ""));
77 :
78 1 : assert_se(path_complex_pattern("", ""));
79 1 : assert_se(!path_complex_pattern("", "/"));
80 1 : assert_se(!path_complex_pattern("/", ""));
81 1 : assert_se(path_complex_pattern("/", "/"));
82 1 : assert_se(path_complex_pattern("/foobar/", "/"));
83 1 : assert_se(!path_complex_pattern("/foobar/", "/foobar"));
84 1 : assert_se(path_complex_pattern("/foobar", "/foobar"));
85 1 : assert_se(!path_complex_pattern("/foobar", "/foobar/"));
86 1 : assert_se(!path_complex_pattern("/foobar", "/foobar/waldo"));
87 1 : assert_se(path_complex_pattern("/foobar/", "/foobar/waldo"));
88 1 : assert_se(path_complex_pattern("/foobar/waldo", "/foobar/"));
89 :
90 1 : assert_se(path_simple_pattern("/foo/", "/foo/bar/waldo"));
91 :
92 1 : assert_se(namespace_simple_pattern("", ""));
93 1 : assert_se(namespace_simple_pattern("", ".foobar"));
94 1 : assert_se(namespace_simple_pattern("foobar", "foobar"));
95 1 : assert_se(namespace_simple_pattern("foobar.waldo", "foobar.waldo"));
96 1 : assert_se(namespace_simple_pattern("foobar", "foobar.waldo"));
97 1 : assert_se(!namespace_simple_pattern("foobar.waldo", "foobar"));
98 1 : assert_se(!namespace_simple_pattern("", "foo"));
99 1 : assert_se(!namespace_simple_pattern("foo", ""));
100 1 : assert_se(namespace_simple_pattern("foo.", "foo.bar.waldo"));
101 :
102 1 : assert_se(streq(object_path_startswith("/foo/bar", "/foo"), "bar"));
103 1 : assert_se(streq(object_path_startswith("/foo", "/foo"), ""));
104 1 : assert_se(streq(object_path_startswith("/foo", "/"), "foo"));
105 1 : assert_se(streq(object_path_startswith("/", "/"), ""));
106 1 : assert_se(!object_path_startswith("/foo", "/bar"));
107 1 : assert_se(!object_path_startswith("/", "/bar"));
108 1 : assert_se(!object_path_startswith("/foo", ""));
109 :
110 1 : assert_se(object_path_is_valid("/foo/bar"));
111 1 : assert_se(object_path_is_valid("/foo"));
112 1 : assert_se(object_path_is_valid("/"));
113 1 : assert_se(object_path_is_valid("/foo5"));
114 1 : assert_se(object_path_is_valid("/foo_5"));
115 1 : assert_se(!object_path_is_valid(""));
116 1 : assert_se(!object_path_is_valid("/foo/"));
117 1 : assert_se(!object_path_is_valid("//"));
118 1 : assert_se(!object_path_is_valid("//foo"));
119 1 : assert_se(!object_path_is_valid("/foo//bar"));
120 1 : assert_se(!object_path_is_valid("/foo/aaaäöä"));
121 :
122 1 : OBJECT_PATH_FOREACH_PREFIX(prefix, "/") {
123 0 : log_info("<%s>", prefix);
124 0 : assert_not_reached("???");
125 : }
126 :
127 1 : r = 0;
128 2 : OBJECT_PATH_FOREACH_PREFIX(prefix, "/xxx") {
129 1 : log_info("<%s>", prefix);
130 1 : assert_se(streq(prefix, "/"));
131 1 : assert_se(r == 0);
132 1 : r++;
133 : }
134 1 : assert_se(r == 1);
135 :
136 1 : r = 0;
137 4 : OBJECT_PATH_FOREACH_PREFIX(prefix, "/xxx/yyy/zzz") {
138 3 : log_info("<%s>", prefix);
139 3 : assert_se(r != 0 || streq(prefix, "/xxx/yyy"));
140 3 : assert_se(r != 1 || streq(prefix, "/xxx"));
141 3 : assert_se(r != 2 || streq(prefix, "/"));
142 3 : r++;
143 : }
144 1 : assert_se(r == 3);
145 :
146 1 : return 0;
147 : }
|