ef852c03b5ba218a02bbc2574f78c75601bef9a3
2 * Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
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.
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
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.
23 #include <common/uri.h>
26 int lttng_opt_quiet
= 1;
27 int lttng_opt_verbose
= 3;
29 /* Number of TAP tests in this file */
32 void test_uri_parsing(void)
36 struct lttng_uri
*uri
= NULL
;
38 s_uri1
= "net://localhost";
40 size
= uri_parse(s_uri1
, &uri
);
43 uri
[0].dtype
== LTTNG_DST_IPV4
&&
44 uri
[0].utype
== LTTNG_URI_DST
&&
47 strlen(uri
[0].subdir
) == 0 &&
48 strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0 &&
49 uri
[1].dtype
== LTTNG_DST_IPV4
&&
50 uri
[1].utype
== LTTNG_URI_DST
&&
53 strlen(uri
[1].subdir
) == 0 &&
54 strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0,
55 "URI set to net://localhost");
62 s_uri1
= "net://localhost:8989:4242/my/test/path";
64 size
= uri_parse(s_uri1
, &uri
);
67 uri
[0].dtype
== LTTNG_DST_IPV4
&&
68 uri
[0].utype
== LTTNG_URI_DST
&&
70 uri
[0].port
== 8989 &&
71 strcmp(uri
[0].subdir
, "my/test/path") == 0 &&
72 strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0 &&
73 uri
[1].dtype
== LTTNG_DST_IPV4
&&
74 uri
[1].utype
== LTTNG_URI_DST
&&
76 uri
[1].port
== 4242 &&
77 strcmp(uri
[0].subdir
, "my/test/path") == 0 &&
78 strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0,
79 "URI set to net://localhost:8989:4242/my/test/path");
86 s_uri1
= "net://localhost:8989:4242";
88 size
= uri_parse(s_uri1
, &uri
);
91 uri
[0].dtype
== LTTNG_DST_IPV4
&&
92 uri
[0].utype
== LTTNG_URI_DST
&&
94 uri
[0].port
== 8989 &&
95 strlen(uri
[1].subdir
) == 0 &&
96 strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0 &&
97 uri
[1].dtype
== LTTNG_DST_IPV4
&&
98 uri
[1].utype
== LTTNG_URI_DST
&&
100 uri
[1].port
== 4242 &&
101 strlen(uri
[1].subdir
) == 0 &&
102 strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0,
103 "URI set to net://localhost:8989:4242");
110 s_uri1
= "net6://localhost:8989";
112 size
= uri_parse(s_uri1
, &uri
);
115 uri
[0].dtype
== LTTNG_DST_IPV6
&&
116 uri
[0].utype
== LTTNG_URI_DST
&&
118 uri
[0].port
== 8989 &&
119 strlen(uri
[1].subdir
) == 0 &&
120 strcmp(uri
[0].dst
.ipv6
, "::1") == 0 &&
121 uri
[1].dtype
== LTTNG_DST_IPV6
&&
122 uri
[1].utype
== LTTNG_URI_DST
&&
125 strlen(uri
[1].subdir
) == 0 &&
126 strcmp(uri
[0].dst
.ipv6
, "::1") == 0,
127 "URI set to net6://localhost:8989");
134 s_uri1
= "tcp://42.42.42.42/my/test/path";
136 size
= uri_parse(s_uri1
, &uri
);
139 uri
[0].dtype
== LTTNG_DST_IPV4
&&
140 uri
[0].utype
== LTTNG_URI_DST
&&
143 strcmp(uri
[0].subdir
, "my/test/path") == 0 &&
144 strcmp(uri
[0].dst
.ipv4
, "42.42.42.42") == 0,
145 "URI set to tcp://42.42.42.42/my/test/path");
152 s_uri1
= "tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path";
154 size
= uri_parse(s_uri1
, &uri
);
157 uri
[0].dtype
== LTTNG_DST_IPV6
&&
158 uri
[0].utype
== LTTNG_URI_DST
&&
161 strcmp(uri
[0].subdir
, "my/test/path") == 0 &&
162 strcmp(uri
[0].dst
.ipv6
, "fe80::f66d:4ff:fe53:d220") == 0,
163 "URI set to tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path");
170 s_uri1
= "file:///my/test/path";
172 size
= uri_parse(s_uri1
, &uri
);
175 uri
[0].dtype
== LTTNG_DST_PATH
&&
176 uri
[0].utype
== LTTNG_URI_DST
&&
179 strlen(uri
[0].subdir
) == 0 &&
180 strcmp(uri
[0].dst
.path
, "/my/test/path") == 0,
181 "URI set to file:///my/test/path");
188 /* FIXME: Noisy on stdout */
189 s_uri1
= "file/my/test/path";
190 size
= uri_parse(s_uri1
, &uri
);
191 ok(size
== -1, "Bad URI set to file/my/test/path");
194 s_uri1
= "net://:8999";
195 size
= uri_parse(s_uri1
, &uri
);
196 ok(size
== -1, "Bad URI set to net://:8999");
202 struct lttng_uri
*uri1
, *uri2
;
203 const char *s_uri1
= "net://localhost";
204 const char *s_uri2
= "net://localhost:8989:4242";
205 ssize_t size1
, size2
;
208 size1
= uri_parse(s_uri1
, &uri1
);
212 assert(uri1
[0].dtype
== LTTNG_DST_IPV4
);
213 assert(uri1
[0].utype
== LTTNG_URI_DST
);
214 assert(uri1
[0].stype
== 0);
215 assert(uri1
[0].port
== 0);
216 assert(strlen(uri1
[0].subdir
) == 0);
217 assert(strcmp(uri1
[0].dst
.ipv4
, "127.0.0.1") == 0);
218 assert(uri1
[1].dtype
== LTTNG_DST_IPV4
);
219 assert(uri1
[1].utype
== LTTNG_URI_DST
);
220 assert(uri1
[1].stype
== 0);
221 assert(uri1
[1].port
== 0);
222 assert(strlen(uri1
[1].subdir
) == 0);
223 assert(strcmp(uri1
[1].dst
.ipv4
, "127.0.0.1") == 0);
225 size2
= uri_parse(s_uri2
, &uri2
);
228 assert(uri2
[0].dtype
== LTTNG_DST_IPV4
);
229 assert(uri2
[0].utype
== LTTNG_URI_DST
);
230 assert(uri2
[0].stype
== 0);
231 assert(uri2
[0].port
== 8989);
232 assert(strlen(uri2
[1].subdir
) == 0);
233 assert(strcmp(uri2
[0].dst
.ipv4
, "127.0.0.1") == 0);
234 assert(uri2
[1].dtype
== LTTNG_DST_IPV4
);
235 assert(uri2
[1].utype
== LTTNG_URI_DST
);
236 assert(uri2
[1].stype
== 0);
237 assert(uri2
[1].port
== 4242);
238 assert(strlen(uri2
[1].subdir
) == 0);
239 assert(strcmp(uri2
[1].dst
.ipv4
, "127.0.0.1") == 0);
241 res
= uri_compare(uri1
, uri1
);
244 "URI compare net://localhost == net://localhost");
246 res
= uri_compare(uri1
, uri2
);
249 "URI compare net://localhost != net://localhost:8989:4242");
255 int main(int argc
, char **argv
)
257 plan_tests(NUM_TESTS
);
259 diag("URI unit tests");
265 return exit_status();
This page took 0.051226 seconds and 4 git commands to generate.