]>
git.proxmox.com Git - libgit2.git/blob - tests/network/url/joinpath.c
1 #include "clar_libgit2.h"
5 static git_net_url source
, target
;
7 void test_network_url_joinpath__initialize(void)
9 memset(&source
, 0, sizeof(source
));
10 memset(&target
, 0, sizeof(target
));
13 void test_network_url_joinpath__cleanup(void)
15 git_net_url_dispose(&source
);
16 git_net_url_dispose(&target
);
19 void test_network_url_joinpath__target_paths_and_queries(void)
21 cl_git_pass(git_net_url_parse(&source
, "http://example.com/a/b"));
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
);
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
);
34 void test_network_url_joinpath__source_query_removed(void)
36 cl_git_pass(git_net_url_parse(&source
, "http://example.com/a/b?query&one&two"));
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
);
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
);
49 void test_network_url_joinpath__source_lacks_path(void)
51 cl_git_pass(git_net_url_parse(&source
, "http://example.com"));
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
94 void test_network_url_joinpath__source_is_slash(void)
96 cl_git_pass(git_net_url_parse(&source
, "http://example.com/"));
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
140 void test_network_url_joinpath__source_has_query(void)
142 cl_git_pass(git_net_url_parse(&source
, "http://example.com?query"));
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
186 void test_network_url_joinpath__empty_query_ignored(void)
188 cl_git_pass(git_net_url_parse(&source
, "http://example.com/foo"));
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
);