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