915e7d1adc74f7ff25d6717bb6624b5b79218f94
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.
26 #include <sys/types.h>
28 #include <common/sessiond-comm/sessiond-comm.h>
29 #include <common/uri.h>
33 /* This path will NEVER be created in this test */
34 #define PATH1 "tmp/.test-junk-lttng"
36 #define RANDOM_STRING_LEN 16
39 int lttng_opt_quiet
= 1;
40 int lttng_opt_verbose
= 3;
43 * Test string URI and if uri_parse works well.
49 struct lttng_uri
*uri
;
51 fprintf(stdout
, "Testing URIs...\n");
53 s_uri1
= "net://localhost";
54 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
55 size
= uri_parse(s_uri1
, &uri
);
57 assert(uri
[0].dtype
== LTTNG_DST_IPV4
);
58 assert(uri
[0].utype
== LTTNG_URI_DST
);
59 assert(uri
[0].stype
== 0);
60 assert(uri
[0].port
== 0);
61 assert(strlen(uri
[0].subdir
) == 0);
62 assert(strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0);
64 assert(uri
[1].dtype
== LTTNG_DST_IPV4
);
65 assert(uri
[1].utype
== LTTNG_URI_DST
);
66 assert(uri
[1].stype
== 0);
67 assert(uri
[1].port
== 0);
68 assert(strlen(uri
[1].subdir
) == 0);
69 assert(strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0);
72 s_uri1
= "net://localhost:8989:4242/my/test/path";
73 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
74 size
= uri_parse(s_uri1
, &uri
);
76 assert(uri
[0].dtype
== LTTNG_DST_IPV4
);
77 assert(uri
[0].utype
== LTTNG_URI_DST
);
78 assert(uri
[0].stype
== 0);
79 assert(uri
[0].port
== 8989);
80 assert(strcmp(uri
[0].subdir
, "my/test/path") == 0);
81 assert(strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0);
83 assert(uri
[1].dtype
== LTTNG_DST_IPV4
);
84 assert(uri
[1].utype
== LTTNG_URI_DST
);
85 assert(uri
[1].stype
== 0);
86 assert(uri
[1].port
== 4242);
87 assert(strcmp(uri
[0].subdir
, "my/test/path") == 0);
88 assert(strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0);
91 s_uri1
= "net://localhost:8989:4242";
92 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
93 size
= uri_parse(s_uri1
, &uri
);
95 assert(uri
[0].dtype
== LTTNG_DST_IPV4
);
96 assert(uri
[0].utype
== LTTNG_URI_DST
);
97 assert(uri
[0].stype
== 0);
98 assert(uri
[0].port
== 8989);
99 assert(strlen(uri
[1].subdir
) == 0);
100 assert(strcmp(uri
[0].dst
.ipv4
, "127.0.0.1") == 0);
102 assert(uri
[1].dtype
== LTTNG_DST_IPV4
);
103 assert(uri
[1].utype
== LTTNG_URI_DST
);
104 assert(uri
[1].stype
== 0);
105 assert(uri
[1].port
== 4242);
106 assert(strlen(uri
[1].subdir
) == 0);
107 assert(strcmp(uri
[1].dst
.ipv4
, "127.0.0.1") == 0);
110 s_uri1
= "net6://localhost:8989";
111 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
112 size
= uri_parse(s_uri1
, &uri
);
114 assert(uri
[0].dtype
== LTTNG_DST_IPV6
);
115 assert(uri
[0].utype
== LTTNG_URI_DST
);
116 assert(uri
[0].stype
== 0);
117 assert(uri
[0].port
== 8989);
118 assert(strlen(uri
[1].subdir
) == 0);
119 assert(strcmp(uri
[0].dst
.ipv6
, "::1") == 0);
121 assert(uri
[1].dtype
== LTTNG_DST_IPV6
);
122 assert(uri
[1].utype
== LTTNG_URI_DST
);
123 assert(uri
[1].stype
== 0);
124 assert(uri
[1].port
== 0);
125 assert(strlen(uri
[1].subdir
) == 0);
126 assert(strcmp(uri
[0].dst
.ipv6
, "::1") == 0);
129 s_uri1
= "tcp://42.42.42.42/my/test/path";
130 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
131 size
= uri_parse(s_uri1
, &uri
);
133 assert(uri
[0].dtype
== LTTNG_DST_IPV4
);
134 assert(uri
[0].utype
== LTTNG_URI_DST
);
135 assert(uri
[0].stype
== 0);
136 assert(uri
[0].port
== 0);
137 assert(strcmp(uri
[0].subdir
, "my/test/path") == 0);
138 assert(strcmp(uri
[0].dst
.ipv4
, "42.42.42.42") == 0);
141 s_uri1
= "tcp6://[fe80::f66d:4ff:fe53:d220]/my/test/path";
142 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
143 size
= uri_parse(s_uri1
, &uri
);
145 assert(uri
[0].dtype
== LTTNG_DST_IPV6
);
146 assert(uri
[0].utype
== LTTNG_URI_DST
);
147 assert(uri
[0].stype
== 0);
148 assert(uri
[0].port
== 0);
149 assert(strcmp(uri
[0].subdir
, "my/test/path") == 0);
150 assert(strcmp(uri
[0].dst
.ipv6
, "fe80::f66d:4ff:fe53:d220") == 0);
153 s_uri1
= "file:///my/test/path";
154 fprintf(stdout
, " [+] URI set to %s ", s_uri1
);
155 size
= uri_parse(s_uri1
, &uri
);
157 assert(uri
[0].dtype
== LTTNG_DST_PATH
);
158 assert(uri
[0].utype
== LTTNG_URI_DST
);
159 assert(uri
[0].stype
== 0);
160 assert(uri
[0].port
== 0);
161 assert(strlen(uri
[1].subdir
) == 0);
162 assert(strcmp(uri
[0].dst
.path
, "/my/test/path") == 0);
165 s_uri1
= "file/my/test/path";
166 fprintf(stdout
, " [+] Bad URI set to %s ", s_uri1
);
167 size
= uri_parse(s_uri1
, &uri
);
171 s_uri1
= "net://:8999";
172 fprintf(stdout
, " [+] Bad URI set to %s ", s_uri1
);
173 size
= uri_parse(s_uri1
, &uri
);
180 int main(int argc
, char **argv
)
186 printf("\nStreaming unit tests\n-----------\n");
This page took 0.089102 seconds and 4 git commands to generate.