2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
4 * SPDX-License-Identifier: GPL-2.0-only
13 #include <common/uri.h>
16 int lttng_opt_quiet
= 1;
17 int lttng_opt_verbose
= 3;
20 /* Number of TAP tests in this file */
23 static void test_uri_parsing(void)
27 struct lttng_uri
*uri
= NULL
;
29 s_uri1
= "net://localhost";
31 size
= uri_parse(s_uri1
, &uri
);
34 uri
[0].dtype
== LTTNG_DST_IPV4
&&
35 uri
[0].utype
== LTTNG_URI_DST
&&
38 strlen(uri
[0].subdir
) == 0 &&
39 strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0 &&
40 uri
[1].dtype
== LTTNG_DST_IPV4
&&
41 uri
[1].utype
== LTTNG_URI_DST
&&
44 strlen(uri
[1].subdir
) == 0 &&
45 strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0,
46 "URI set to net://localhost");
53 s_uri1
= "net://localhost:8989:4242/my/test/path";
55 size
= uri_parse(s_uri1
, &uri
);
58 uri
[0].dtype
== LTTNG_DST_IPV4
&&
59 uri
[0].utype
== LTTNG_URI_DST
&&
61 uri
[0].port
== 8989 &&
62 strcmp(uri
[0].subdir
, "my/test/path") == 0 &&
63 strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0 &&
64 uri
[1].dtype
== LTTNG_DST_IPV4
&&
65 uri
[1].utype
== LTTNG_URI_DST
&&
67 uri
[1].port
== 4242 &&
68 strlen(uri
[1].subdir
) == 0 &&
69 strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0,
70 "URI set to net://localhost:8989:4242/my/test/path");
77 s_uri1
= "net://localhost:8989:4242";
79 size
= uri_parse(s_uri1
, &uri
);
82 uri
[0].dtype
== LTTNG_DST_IPV4
&&
83 uri
[0].utype
== LTTNG_URI_DST
&&
85 uri
[0].port
== 8989 &&
86 strlen(uri
[0].subdir
) == 0 &&
87 strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0 &&
88 uri
[1].dtype
== LTTNG_DST_IPV4
&&
89 uri
[1].utype
== LTTNG_URI_DST
&&
91 uri
[1].port
== 4242 &&
92 strlen(uri
[1].subdir
) == 0 &&
93 strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0,
94 "URI set to net://localhost:8989:4242");
101 s_uri1
= "net6://[::1]:8989";
103 size
= uri_parse(s_uri1
, &uri
);
106 uri
[0].dtype
== LTTNG_DST_IPV6
&&
107 uri
[0].utype
== LTTNG_URI_DST
&&
109 uri
[0].port
== 8989 &&
110 strlen(uri
[0].subdir
) == 0 &&
111 strcmp(uri
[0].dst
.ipv6
, "::1") == 0 &&
112 uri
[1].dtype
== LTTNG_DST_IPV6
&&
113 uri
[1].utype
== LTTNG_URI_DST
&&
116 strlen(uri
[1].subdir
) == 0 &&
117 strcmp(uri
[1].dst
.ipv6
, "::1") == 0,
118 "URI set to net6://[::1]:8989");
125 s_uri1
= "tcp://42.42.42.42/my/test/path";
127 size
= uri_parse(s_uri1
, &uri
);
130 uri
[0].dtype
== LTTNG_DST_IPV4
&&
131 uri
[0].utype
== LTTNG_URI_DST
&&
134 strcmp(uri
[0].subdir
, "my/test/path") == 0 &&
135 strcmp(uri
[0].dst
.ipv4
, "42.42.42.42") == 0,
136 "URI set to tcp://42.42.42.42/my/test/path");
143 s_uri1
= "tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path";
145 size
= uri_parse(s_uri1
, &uri
);
148 uri
[0].dtype
== LTTNG_DST_IPV6
&&
149 uri
[0].utype
== LTTNG_URI_DST
&&
152 strcmp(uri
[0].subdir
, "my/test/path") == 0 &&
153 strcmp(uri
[0].dst
.ipv6
, "fe80::f66d:4ff:fe53:d220") == 0,
154 "URI set to tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path");
161 s_uri1
= "file:///my/test/path";
163 size
= uri_parse(s_uri1
, &uri
);
166 uri
[0].dtype
== LTTNG_DST_PATH
&&
167 uri
[0].utype
== LTTNG_URI_DST
&&
170 strlen(uri
[0].subdir
) == 0 &&
171 strcmp(uri
[0].dst
.path
, "/my/test/path") == 0,
172 "URI set to file:///my/test/path");
179 /* FIXME: Noisy on stdout */
180 s_uri1
= "file/my/test/path";
181 size
= uri_parse(s_uri1
, &uri
);
182 ok(size
== -1, "Bad URI set to file/my/test/path");
185 s_uri1
= "net://:8999";
186 size
= uri_parse(s_uri1
, &uri
);
187 ok(size
== -1, "Bad URI set to net://:8999");
191 static void test_uri_cmp(void)
193 struct lttng_uri
*uri1
, *uri2
;
194 const char *s_uri1
= "net://localhost";
195 const char *s_uri2
= "net://localhost:8989:4242";
196 ssize_t size1
, size2
;
199 size1
= uri_parse(s_uri1
, &uri1
);
203 assert(uri1
[0].dtype
== LTTNG_DST_IPV4
);
204 assert(uri1
[0].utype
== LTTNG_URI_DST
);
205 assert(uri1
[0].stype
== 0);
206 assert(uri1
[0].port
== 0);
207 assert(strlen(uri1
[0].subdir
) == 0);
208 assert(strcmp(uri1
[0].dst
.ipv4
, "127.0.0.1") == 0);
209 assert(uri1
[1].dtype
== LTTNG_DST_IPV4
);
210 assert(uri1
[1].utype
== LTTNG_URI_DST
);
211 assert(uri1
[1].stype
== 0);
212 assert(uri1
[1].port
== 0);
213 assert(strlen(uri1
[1].subdir
) == 0);
214 assert(strcmp(uri1
[1].dst
.ipv4
, "127.0.0.1") == 0);
216 size2
= uri_parse(s_uri2
, &uri2
);
219 assert(uri2
[0].dtype
== LTTNG_DST_IPV4
);
220 assert(uri2
[0].utype
== LTTNG_URI_DST
);
221 assert(uri2
[0].stype
== 0);
222 assert(uri2
[0].port
== 8989);
223 assert(strlen(uri2
[0].subdir
) == 0);
224 assert(strcmp(uri2
[0].dst
.ipv4
, "127.0.0.1") == 0);
225 assert(uri2
[1].dtype
== LTTNG_DST_IPV4
);
226 assert(uri2
[1].utype
== LTTNG_URI_DST
);
227 assert(uri2
[1].stype
== 0);
228 assert(uri2
[1].port
== 4242);
229 assert(strlen(uri2
[1].subdir
) == 0);
230 assert(strcmp(uri2
[1].dst
.ipv4
, "127.0.0.1") == 0);
232 res
= uri_compare(uri1
, uri1
);
235 "URI compare net://localhost == net://localhost");
237 res
= uri_compare(uri1
, uri2
);
240 "URI compare net://localhost != net://localhost:8989:4242");
246 int main(int argc
, char **argv
)
248 plan_tests(NUM_TESTS
);
250 diag("URI unit tests");
256 return exit_status();
This page took 0.03537 seconds and 4 git commands to generate.