]> git.proxmox.com Git - libgit2.git/blame - tests/network/url/joinpath.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / network / url / joinpath.c
CommitLineData
22a2d3d5
UG
1#include "clar_libgit2.h"
2#include "net.h"
3#include "netops.h"
4
5static git_net_url source, target;
6
c25aa7cd 7void test_network_url_joinpath__initialize(void)
22a2d3d5
UG
8{
9 memset(&source, 0, sizeof(source));
10 memset(&target, 0, sizeof(target));
11}
12
c25aa7cd 13void test_network_url_joinpath__cleanup(void)
22a2d3d5
UG
14{
15 git_net_url_dispose(&source);
16 git_net_url_dispose(&target);
17}
18
c25aa7cd 19void test_network_url_joinpath__target_paths_and_queries(void)
22a2d3d5
UG
20{
21 cl_git_pass(git_net_url_parse(&source, "http://example.com/a/b"));
22
23 cl_git_pass(git_net_url_joinpath(&target, &source, "/c/d"));
24 cl_assert_equal_s(target.path, "/a/b/c/d");
25 cl_assert_equal_p(target.query, NULL);
26 git_net_url_dispose(&target);
27
28 cl_git_pass(git_net_url_joinpath(&target, &source, "/c/d?foo"));
29 cl_assert_equal_s(target.path, "/a/b/c/d");
30 cl_assert_equal_s(target.query, "foo");
31 git_net_url_dispose(&target);
32}
33
c25aa7cd 34void test_network_url_joinpath__source_query_removed(void)
22a2d3d5
UG
35{
36 cl_git_pass(git_net_url_parse(&source, "http://example.com/a/b?query&one&two"));
37
38 cl_git_pass(git_net_url_joinpath(&target, &source, "/c/d"));
39 cl_assert_equal_s(target.path, "/a/b/c/d");
40 cl_assert_equal_p(target.query, NULL);
41 git_net_url_dispose(&target);
42
43 cl_git_pass(git_net_url_joinpath(&target, &source, "/c/d?foo"));
44 cl_assert_equal_s(target.path, "/a/b/c/d");
45 cl_assert_equal_s(target.query, "foo");
46 git_net_url_dispose(&target);
47}
48
c25aa7cd 49void test_network_url_joinpath__source_lacks_path(void)
22a2d3d5
UG
50{
51 cl_git_pass(git_net_url_parse(&source, "http://example.com"));
52
53 cl_git_pass(git_net_url_joinpath(&target, &source, "/"));
54 cl_assert_equal_s(target.path, "/");
55 cl_assert_equal_p(target.query, NULL);
56 git_net_url_dispose(&target);
57
58 cl_git_pass(git_net_url_joinpath(&target, &source, ""));
59 cl_assert_equal_s(target.path, "/");
60 cl_assert_equal_p(target.query, NULL);
61 git_net_url_dispose(&target);
62
63 cl_git_pass(git_net_url_joinpath(&target, &source, "asdf"));
64 cl_assert_equal_s(target.path, "/asdf");
65 cl_assert_equal_p(target.query, NULL);
66 git_net_url_dispose(&target);
67
68 cl_git_pass(git_net_url_joinpath(&target, &source, "/asdf"));
69 cl_assert_equal_s(target.path, "/asdf");
70 cl_assert_equal_p(target.query, NULL);
71 git_net_url_dispose(&target);
72
73 cl_git_pass(git_net_url_joinpath(&target, &source, "/foo/bar"));
74 cl_assert_equal_s(target.path, "/foo/bar");
75 cl_assert_equal_p(target.query, NULL);
76 git_net_url_dispose(&target);
77
78 cl_git_pass(git_net_url_joinpath(&target, &source, "asdf?hello"));
79 cl_assert_equal_s(target.path, "/asdf");
80 cl_assert_equal_s(target.query, "hello");
81 git_net_url_dispose(&target);
82
83 cl_git_pass(git_net_url_joinpath(&target, &source, "/asdf?hello"));
84 cl_assert_equal_s(target.path, "/asdf");
85 cl_assert_equal_s(target.query, "hello");
86 git_net_url_dispose(&target);
87
88 cl_git_pass(git_net_url_joinpath(&target, &source, "/foo/bar?hello"));
89 cl_assert_equal_s(target.path, "/foo/bar");
90 cl_assert_equal_s(target.query, "hello");
91 git_net_url_dispose(&target);
92}
93
c25aa7cd 94void test_network_url_joinpath__source_is_slash(void)
22a2d3d5
UG
95{
96 cl_git_pass(git_net_url_parse(&source, "http://example.com/"));
97
98 cl_git_pass(git_net_url_joinpath(&target, &source, "/"));
99 cl_assert_equal_s(target.path, "/");
100 cl_assert_equal_p(target.query, NULL);
101 git_net_url_dispose(&target);
102
103 cl_git_pass(git_net_url_joinpath(&target, &source, ""));
104 cl_assert_equal_s(target.path, "/");
105 cl_assert_equal_p(target.query, NULL);
106 git_net_url_dispose(&target);
107
108 cl_git_pass(git_net_url_joinpath(&target, &source, "asdf"));
109 cl_assert_equal_s(target.path, "/asdf");
110 cl_assert_equal_p(target.query, NULL);
111 git_net_url_dispose(&target);
112
113 cl_git_pass(git_net_url_joinpath(&target, &source, "/asdf"));
114 cl_assert_equal_s(target.path, "/asdf");
115 cl_assert_equal_p(target.query, NULL);
116 git_net_url_dispose(&target);
117
118 cl_git_pass(git_net_url_joinpath(&target, &source, "/foo/bar"));
119 cl_assert_equal_s(target.path, "/foo/bar");
120 cl_assert_equal_p(target.query, NULL);
121 git_net_url_dispose(&target);
122
123 cl_git_pass(git_net_url_joinpath(&target, &source, "asdf?hello"));
124 cl_assert_equal_s(target.path, "/asdf");
125 cl_assert_equal_s(target.query, "hello");
126 git_net_url_dispose(&target);
127
128 cl_git_pass(git_net_url_joinpath(&target, &source, "/asdf?hello"));
129 cl_assert_equal_s(target.path, "/asdf");
130 cl_assert_equal_s(target.query, "hello");
131 git_net_url_dispose(&target);
132
133 cl_git_pass(git_net_url_joinpath(&target, &source, "/foo/bar?hello"));
134 cl_assert_equal_s(target.path, "/foo/bar");
135 cl_assert_equal_s(target.query, "hello");
136 git_net_url_dispose(&target);
137}
138
139
c25aa7cd 140void test_network_url_joinpath__source_has_query(void)
22a2d3d5
UG
141{
142 cl_git_pass(git_net_url_parse(&source, "http://example.com?query"));
143
144 cl_git_pass(git_net_url_joinpath(&target, &source, "/"));
145 cl_assert_equal_s(target.path, "/");
146 cl_assert_equal_p(target.query, NULL);
147 git_net_url_dispose(&target);
148
149 cl_git_pass(git_net_url_joinpath(&target, &source, ""));
150 cl_assert_equal_s(target.path, "/");
151 cl_assert_equal_p(target.query, NULL);
152 git_net_url_dispose(&target);
153
154 cl_git_pass(git_net_url_joinpath(&target, &source, "asdf"));
155 cl_assert_equal_s(target.path, "/asdf");
156 cl_assert_equal_p(target.query, NULL);
157 git_net_url_dispose(&target);
158
159 cl_git_pass(git_net_url_joinpath(&target, &source, "/asdf"));
160 cl_assert_equal_s(target.path, "/asdf");
161 cl_assert_equal_p(target.query, NULL);
162 git_net_url_dispose(&target);
163
164 cl_git_pass(git_net_url_joinpath(&target, &source, "/foo/bar"));
165 cl_assert_equal_s(target.path, "/foo/bar");
166 cl_assert_equal_p(target.query, NULL);
167 git_net_url_dispose(&target);
168
169 cl_git_pass(git_net_url_joinpath(&target, &source, "asdf?hello"));
170 cl_assert_equal_s(target.path, "/asdf");
171 cl_assert_equal_s(target.query, "hello");
172 git_net_url_dispose(&target);
173
174 cl_git_pass(git_net_url_joinpath(&target, &source, "/asdf?hello"));
175 cl_assert_equal_s(target.path, "/asdf");
176 cl_assert_equal_s(target.query, "hello");
177 git_net_url_dispose(&target);
178
179 cl_git_pass(git_net_url_joinpath(&target, &source, "/foo/bar?hello"));
180 cl_assert_equal_s(target.path, "/foo/bar");
181 cl_assert_equal_s(target.query, "hello");
182 git_net_url_dispose(&target);
183}
184
185
c25aa7cd 186void test_network_url_joinpath__empty_query_ignored(void)
22a2d3d5
UG
187{
188 cl_git_pass(git_net_url_parse(&source, "http://example.com/foo"));
189
190 cl_git_pass(git_net_url_joinpath(&target, &source, "/bar/baz?"));
191 cl_assert_equal_s(target.path, "/foo/bar/baz");
192 cl_assert_equal_p(target.query, NULL);
193 git_net_url_dispose(&target);
194}