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;
30 /* Number of TAP tests in this file */
33 static void test_uri_parsing(void)
37 struct lttng_uri
*uri
= NULL
;
39 s_uri1
= "net://localhost";
41 size
= uri_parse(s_uri1
, &uri
);
44 uri
[0].dtype
== LTTNG_DST_IPV4
&&
45 uri
[0].utype
== LTTNG_URI_DST
&&
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
&&
54 strlen(uri
[1].subdir
) == 0 &&
55 strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0,
56 "URI set to net://localhost");
63 s_uri1
= "net://localhost:8989:4242/my/test/path";
65 size
= uri_parse(s_uri1
, &uri
);
68 uri
[0].dtype
== LTTNG_DST_IPV4
&&
69 uri
[0].utype
== LTTNG_URI_DST
&&
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
&&
77 uri
[1].port
== 4242 &&
78 strlen(uri
[1].subdir
) == 0 &&
79 strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0,
80 "URI set to net://localhost:8989:4242/my/test/path");
87 s_uri1
= "net://localhost:8989:4242";
89 size
= uri_parse(s_uri1
, &uri
);
92 uri
[0].dtype
== LTTNG_DST_IPV4
&&
93 uri
[0].utype
== LTTNG_URI_DST
&&
95 uri
[0].port
== 8989 &&
96 strlen(uri
[0].subdir
) == 0 &&
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
&&
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");
111 s_uri1
= "net6://[::1]:8989";
113 size
= uri_parse(s_uri1
, &uri
);
116 uri
[0].dtype
== LTTNG_DST_IPV6
&&
117 uri
[0].utype
== LTTNG_URI_DST
&&
119 uri
[0].port
== 8989 &&
120 strlen(uri
[0].subdir
) == 0 &&
121 strcmp(uri
[0].dst
.ipv6
, "::1") == 0 &&
122 uri
[1].dtype
== LTTNG_DST_IPV6
&&
123 uri
[1].utype
== LTTNG_URI_DST
&&
126 strlen(uri
[1].subdir
) == 0 &&
127 strcmp(uri
[1].dst
.ipv6
, "::1") == 0,
128 "URI set to net6://[::1]:8989");
135 s_uri1
= "tcp://42.42.42.42/my/test/path";
137 size
= uri_parse(s_uri1
, &uri
);
140 uri
[0].dtype
== LTTNG_DST_IPV4
&&
141 uri
[0].utype
== LTTNG_URI_DST
&&
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");
153 s_uri1
= "tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path";
155 size
= uri_parse(s_uri1
, &uri
);
158 uri
[0].dtype
== LTTNG_DST_IPV6
&&
159 uri
[0].utype
== LTTNG_URI_DST
&&
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");
171 s_uri1
= "file:///my/test/path";
173 size
= uri_parse(s_uri1
, &uri
);
176 uri
[0].dtype
== LTTNG_DST_PATH
&&
177 uri
[0].utype
== LTTNG_URI_DST
&&
180 strlen(uri
[0].subdir
) == 0 &&
181 strcmp(uri
[0].dst
.path
, "/my/test/path") == 0,
182 "URI set to file:///my/test/path");
189 /* FIXME: Noisy on stdout */
190 s_uri1
= "file/my/test/path";
191 size
= uri_parse(s_uri1
, &uri
);
192 ok(size
== -1, "Bad URI set to file/my/test/path");
195 s_uri1
= "net://:8999";
196 size
= uri_parse(s_uri1
, &uri
);
197 ok(size
== -1, "Bad URI set to net://:8999");
201 static void test_uri_cmp()
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
;
209 size1
= uri_parse(s_uri1
, &uri1
);
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);
226 size2
= uri_parse(s_uri2
, &uri2
);
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);
233 assert(strlen(uri2
[0].subdir
) == 0);
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);
242 res
= uri_compare(uri1
, uri1
);
245 "URI compare net://localhost == net://localhost");
247 res
= uri_compare(uri1
, uri2
);
250 "URI compare net://localhost != net://localhost:8989:4242");
256 int main(int argc
, char **argv
)
258 plan_tests(NUM_TESTS
);
260 diag("URI unit tests");
266 return exit_status();
This page took 0.037113 seconds and 5 git commands to generate.