tests: make functions static in test_uri.c
[lttng-tools.git] / tests / unit / test_uri.c
CommitLineData
de9a8b41
DG
1/*
2 * Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by as
6 * published by the Free Software Foundation; only version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 51
15 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
de9a8b41 18#include <assert.h>
de9a8b41 19#include <string.h>
de9a8b41 20
c291fb24 21#include <tap/tap.h>
de9a8b41 22
c291fb24 23#include <common/uri.h>
de9a8b41 24
ad7c9c18 25/* For error.h */
de9a8b41 26int lttng_opt_quiet = 1;
a4b92340 27int lttng_opt_verbose = 3;
c7e35b03 28int lttng_opt_mi;
de9a8b41 29
c291fb24
CB
30/* Number of TAP tests in this file */
31#define NUM_TESTS 11
32
8fa8ae59 33static void test_uri_parsing(void)
de9a8b41
DG
34{
35 ssize_t size;
36 const char *s_uri1;
c291fb24 37 struct lttng_uri *uri = NULL;
de9a8b41
DG
38
39 s_uri1 = "net://localhost";
c291fb24 40
de9a8b41 41 size = uri_parse(s_uri1, &uri);
c291fb24
CB
42
43 ok(size == 2 &&
44 uri[0].dtype == LTTNG_DST_IPV4 &&
45 uri[0].utype == LTTNG_URI_DST &&
46 uri[0].stype == 0 &&
47 uri[0].port == 0 &&
48 strlen(uri[0].subdir) == 0 &&
49 strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0 &&
50 uri[1].dtype == LTTNG_DST_IPV4 &&
51 uri[1].utype == LTTNG_URI_DST &&
52 uri[1].stype == 0 &&
53 uri[1].port == 0 &&
54 strlen(uri[1].subdir) == 0 &&
55 strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0,
56 "URI set to net://localhost");
57
58 if (uri) {
59 uri_free(uri);
60 uri = NULL;
61 }
de9a8b41
DG
62
63 s_uri1 = "net://localhost:8989:4242/my/test/path";
c291fb24 64
de9a8b41 65 size = uri_parse(s_uri1, &uri);
c291fb24
CB
66
67 ok(size == 2 &&
68 uri[0].dtype == LTTNG_DST_IPV4 &&
69 uri[0].utype == LTTNG_URI_DST &&
70 uri[0].stype == 0 &&
71 uri[0].port == 8989 &&
72 strcmp(uri[0].subdir, "my/test/path") == 0 &&
73 strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0 &&
74 uri[1].dtype == LTTNG_DST_IPV4 &&
75 uri[1].utype == LTTNG_URI_DST &&
76 uri[1].stype == 0 &&
77 uri[1].port == 4242 &&
ee059b98 78 strlen(uri[1].subdir) == 0 &&
c291fb24
CB
79 strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0,
80 "URI set to net://localhost:8989:4242/my/test/path");
81
82 if (uri) {
83 uri_free(uri);
84 uri = NULL;
85 }
de9a8b41
DG
86
87 s_uri1 = "net://localhost:8989:4242";
c291fb24 88
de9a8b41 89 size = uri_parse(s_uri1, &uri);
c291fb24
CB
90
91 ok(size == 2 &&
92 uri[0].dtype == LTTNG_DST_IPV4 &&
93 uri[0].utype == LTTNG_URI_DST &&
94 uri[0].stype == 0 &&
95 uri[0].port == 8989 &&
ee059b98 96 strlen(uri[0].subdir) == 0 &&
c291fb24
CB
97 strcmp(uri[0].dst.ipv4, "127.0.0.1") == 0 &&
98 uri[1].dtype == LTTNG_DST_IPV4 &&
99 uri[1].utype == LTTNG_URI_DST &&
100 uri[1].stype == 0 &&
101 uri[1].port == 4242 &&
102 strlen(uri[1].subdir) == 0 &&
103 strcmp(uri[1].dst.ipv4, "127.0.0.1") == 0,
104 "URI set to net://localhost:8989:4242");
105
106 if (uri) {
107 uri_free(uri);
108 uri = NULL;
109 }
de9a8b41 110
5d7ba9b6 111 s_uri1 = "net6://[::1]:8989";
c291fb24 112
de9a8b41 113 size = uri_parse(s_uri1, &uri);
c291fb24
CB
114
115 ok(size == 2 &&
116 uri[0].dtype == LTTNG_DST_IPV6 &&
117 uri[0].utype == LTTNG_URI_DST &&
118 uri[0].stype == 0 &&
119 uri[0].port == 8989 &&
ee059b98 120 strlen(uri[0].subdir) == 0 &&
c291fb24
CB
121 strcmp(uri[0].dst.ipv6, "::1") == 0 &&
122 uri[1].dtype == LTTNG_DST_IPV6 &&
123 uri[1].utype == LTTNG_URI_DST &&
124 uri[1].stype == 0 &&
125 uri[1].port == 0 &&
126 strlen(uri[1].subdir) == 0 &&
ee059b98 127 strcmp(uri[1].dst.ipv6, "::1") == 0,
5d7ba9b6 128 "URI set to net6://[::1]:8989");
c291fb24
CB
129
130 if (uri) {
131 uri_free(uri);
132 uri = NULL;
133 }
de9a8b41
DG
134
135 s_uri1 = "tcp://42.42.42.42/my/test/path";
c291fb24 136
de9a8b41 137 size = uri_parse(s_uri1, &uri);
c291fb24
CB
138
139 ok(size == 1 &&
140 uri[0].dtype == LTTNG_DST_IPV4 &&
141 uri[0].utype == LTTNG_URI_DST &&
142 uri[0].stype == 0 &&
143 uri[0].port == 0 &&
144 strcmp(uri[0].subdir, "my/test/path") == 0 &&
145 strcmp(uri[0].dst.ipv4, "42.42.42.42") == 0,
146 "URI set to tcp://42.42.42.42/my/test/path");
147
148 if (uri) {
149 uri_free(uri);
150 uri = NULL;
151 }
de9a8b41 152
a4b92340 153 s_uri1 = "tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path";
c291fb24 154
de9a8b41 155 size = uri_parse(s_uri1, &uri);
c291fb24
CB
156
157 ok(size == 1 &&
158 uri[0].dtype == LTTNG_DST_IPV6 &&
159 uri[0].utype == LTTNG_URI_DST &&
160 uri[0].stype == 0 &&
161 uri[0].port == 0 &&
162 strcmp(uri[0].subdir, "my/test/path") == 0 &&
163 strcmp(uri[0].dst.ipv6, "fe80::f66d:4ff:fe53:d220") == 0,
164 "URI set to tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path");
165
166 if (uri) {
167 uri_free(uri);
168 uri = NULL;
169 }
de9a8b41
DG
170
171 s_uri1 = "file:///my/test/path";
c291fb24 172
de9a8b41 173 size = uri_parse(s_uri1, &uri);
de9a8b41 174
c291fb24
CB
175 ok(size == 1 &&
176 uri[0].dtype == LTTNG_DST_PATH &&
177 uri[0].utype == LTTNG_URI_DST &&
178 uri[0].stype == 0 &&
179 uri[0].port == 0 &&
180 strlen(uri[0].subdir) == 0 &&
181 strcmp(uri[0].dst.path, "/my/test/path") == 0,
182 "URI set to file:///my/test/path");
183
184 if (uri) {
185 uri_free(uri);
186 uri = NULL;
187 }
188
189 /* FIXME: Noisy on stdout */
de9a8b41 190 s_uri1 = "file/my/test/path";
de9a8b41 191 size = uri_parse(s_uri1, &uri);
c291fb24 192 ok(size == -1, "Bad URI set to file/my/test/path");
2e67d81d 193 assert(!uri);
de9a8b41
DG
194
195 s_uri1 = "net://:8999";
de9a8b41 196 size = uri_parse(s_uri1, &uri);
c291fb24 197 ok(size == -1, "Bad URI set to net://:8999");
2e67d81d 198 assert(!uri);
3cb37009 199}
de9a8b41 200
8fa8ae59 201static void test_uri_cmp()
3cb37009
CB
202{
203 struct lttng_uri *uri1, *uri2;
204 const char *s_uri1 = "net://localhost";
205 const char *s_uri2 = "net://localhost:8989:4242";
206 ssize_t size1, size2;
207 int res;
208
209 size1 = uri_parse(s_uri1, &uri1);
210
211 /* Sanity checks */
212 assert(size1 == 2);
213 assert(uri1[0].dtype == LTTNG_DST_IPV4);
214 assert(uri1[0].utype == LTTNG_URI_DST);
215 assert(uri1[0].stype == 0);
216 assert(uri1[0].port == 0);
217 assert(strlen(uri1[0].subdir) == 0);
218 assert(strcmp(uri1[0].dst.ipv4, "127.0.0.1") == 0);
219 assert(uri1[1].dtype == LTTNG_DST_IPV4);
220 assert(uri1[1].utype == LTTNG_URI_DST);
221 assert(uri1[1].stype == 0);
222 assert(uri1[1].port == 0);
223 assert(strlen(uri1[1].subdir) == 0);
224 assert(strcmp(uri1[1].dst.ipv4, "127.0.0.1") == 0);
225
226 size2 = uri_parse(s_uri2, &uri2);
227
228 assert(size2 == 2);
229 assert(uri2[0].dtype == LTTNG_DST_IPV4);
230 assert(uri2[0].utype == LTTNG_URI_DST);
231 assert(uri2[0].stype == 0);
232 assert(uri2[0].port == 8989);
ee059b98 233 assert(strlen(uri2[0].subdir) == 0);
3cb37009
CB
234 assert(strcmp(uri2[0].dst.ipv4, "127.0.0.1") == 0);
235 assert(uri2[1].dtype == LTTNG_DST_IPV4);
236 assert(uri2[1].utype == LTTNG_URI_DST);
237 assert(uri2[1].stype == 0);
238 assert(uri2[1].port == 4242);
239 assert(strlen(uri2[1].subdir) == 0);
240 assert(strcmp(uri2[1].dst.ipv4, "127.0.0.1") == 0);
241
3cb37009 242 res = uri_compare(uri1, uri1);
c291fb24
CB
243
244 ok(res == 0,
245 "URI compare net://localhost == net://localhost");
3cb37009
CB
246
247 res = uri_compare(uri1, uri2);
c291fb24
CB
248
249 ok(res != 0,
250 "URI compare net://localhost != net://localhost:8989:4242");
3cb37009
CB
251
252 uri_free(uri1);
253 uri_free(uri2);
de9a8b41
DG
254}
255
256int main(int argc, char **argv)
257{
c291fb24 258 plan_tests(NUM_TESTS);
de9a8b41 259
e3bef725
CB
260 diag("URI unit tests");
261
3cb37009 262 test_uri_parsing();
c291fb24 263
3cb37009 264 test_uri_cmp();
de9a8b41 265
c291fb24 266 return exit_status();
de9a8b41 267}
This page took 0.068188 seconds and 5 git commands to generate.