|
| 1 | +unit network; |
| 2 | + |
| 3 | +interface |
| 4 | + |
| 5 | +uses |
| 6 | + TestFramework, SysUtils, Windows, Classes, |
| 7 | + uTestsFromLibGit2, uGitForDelphi, uClar; |
| 8 | + |
| 9 | +type |
| 10 | + Test_network_remotes = class(TClarTest) |
| 11 | + private |
| 12 | + _remote: Pgit_remote; |
| 13 | + _repo: Pgit_repository; |
| 14 | + _refspec: Pgit_refspec; |
| 15 | + protected |
| 16 | + procedure SetUp; override; |
| 17 | + procedure TearDown; override; |
| 18 | + published |
| 19 | + procedure test_network_remotes__parsing; |
| 20 | + procedure test_network_remotes__refspec_parsing; |
| 21 | + procedure test_network_remotes__fnmatch; |
| 22 | + procedure test_network_remotes__transform; |
| 23 | + procedure test_network_remotes__transform_r; |
| 24 | + end; |
| 25 | + |
| 26 | + Test_network_remotelocal = class(TClarTest) |
| 27 | + private |
| 28 | + repo: Pgit_repository; |
| 29 | + file_path_buf: AnsiString; |
| 30 | + remote: Pgit_remote; |
| 31 | + procedure build_local_file_url(var out_: AnsiString; fixture: PAnsiChar); |
| 32 | + procedure connect_to_local_repository(local_repository: PAnsiChar); |
| 33 | + protected |
| 34 | + procedure SetUp; override; |
| 35 | + procedure TearDown; override; |
| 36 | + published |
| 37 | + procedure test_network_remotelocal__retrieve_advertised_references; |
| 38 | + procedure test_network_remotelocal__retrieve_advertised_references_from_spaced_repository; |
| 39 | + end; |
| 40 | + |
| 41 | + Test_network_createremotethenload = class(TClarTest) |
| 42 | + private |
| 43 | + _remote: Pgit_remote; |
| 44 | + _repo: Pgit_repository; |
| 45 | + _config: Pgit_config; |
| 46 | + url: AnsiString; |
| 47 | + protected |
| 48 | + procedure SetUp; override; |
| 49 | + procedure TearDown; override; |
| 50 | + published |
| 51 | + procedure test_network_createremotethenload__parsing; |
| 52 | + end; |
| 53 | + |
| 54 | +implementation |
| 55 | + |
| 56 | +{ Test_network_remotes } |
| 57 | + |
| 58 | +procedure Test_network_remotes.SetUp; |
| 59 | +begin |
| 60 | + inherited; |
| 61 | + cl_fixture_sandbox('testrepo.git'); |
| 62 | + |
| 63 | + cl_git_pass(git_repository_open(_repo, 'testrepo.git')); |
| 64 | + cl_git_pass(git_remote_load(_remote, _repo, 'test')); |
| 65 | + |
| 66 | + _refspec := git_remote_fetchspec(_remote); |
| 67 | + cl_assert(_refspec <> nil); |
| 68 | +end; |
| 69 | + |
| 70 | +procedure Test_network_remotes.TearDown; |
| 71 | +begin |
| 72 | + inherited; |
| 73 | + git_remote_free(_remote); |
| 74 | + git_repository_free(_repo); |
| 75 | + cl_fixture_cleanup('testrepo.git'); |
| 76 | +end; |
| 77 | + |
| 78 | +procedure Test_network_remotes.test_network_remotes__fnmatch; |
| 79 | +begin |
| 80 | + CheckTrue(true); // can't check members of opaque type |
| 81 | +end; |
| 82 | + |
| 83 | +procedure Test_network_remotes.test_network_remotes__parsing; |
| 84 | +begin |
| 85 | + cl_assert(StrComp(git_remote_name(_remote), 'test') = 0); |
| 86 | + cl_assert(StrComp(git_remote_url(_remote), 'git://github.com/libgit2/libgit2') = 0); |
| 87 | +end; |
| 88 | + |
| 89 | +procedure Test_network_remotes.test_network_remotes__refspec_parsing; |
| 90 | +// function git_refspec_src(const refspec: Pgit_refspec): PAnsiChar; |
| 91 | +// begin |
| 92 | +// if refspec = nil then Result := nil |
| 93 | +// else Result := refspec.src; |
| 94 | +// end; |
| 95 | +// |
| 96 | +// function git_refspec_dst(const refspec: Pgit_refspec): PAnsiChar; |
| 97 | +// begin |
| 98 | +// if refspec = nil then Result := nil |
| 99 | +// else Result := refspec.dst; |
| 100 | +// end; |
| 101 | +begin |
| 102 | + CheckTrue(true); // can't check members of opaque type |
| 103 | +// cl_assert(StrComp(git_refspec_src(_refspec), 'refs/heads/*') = 0); |
| 104 | +// cl_assert(StrComp(git_refspec_dst(_refspec), 'refs/remotes/test/*') = 0); |
| 105 | +end; |
| 106 | + |
| 107 | +procedure Test_network_remotes.test_network_remotes__transform; |
| 108 | +begin |
| 109 | +// char ref[1024]; |
| 110 | +// |
| 111 | +// memset(ref, 0x0, sizeof(ref)); |
| 112 | +// cl_git_pass(git_refspec_transform(ref, sizeof(ref), _refspec, "refs/heads/master")); |
| 113 | +// cl_assert(!strcmp(ref, "refs/remotes/test/master")); |
| 114 | + CheckTrue(true); // can't check members of opaque type |
| 115 | +end; |
| 116 | + |
| 117 | +procedure Test_network_remotes.test_network_remotes__transform_r; |
| 118 | +begin |
| 119 | +// git_buf buf = GIT_BUF_INIT; |
| 120 | +// |
| 121 | +// cl_git_pass(git_refspec_transform_r(&buf, _refspec, "refs/heads/master")); |
| 122 | +// cl_assert(!strcmp(git_buf_cstr(&buf), "refs/remotes/test/master")); |
| 123 | +// git_buf_free(&buf); |
| 124 | + CheckTrue(true); // can't check members of an opaque type |
| 125 | +end; |
| 126 | + |
| 127 | +{ Test_network_remotelocal } |
| 128 | + |
| 129 | +procedure Test_network_remotelocal.build_local_file_url(var out_: AnsiString; fixture: PAnsiChar); |
| 130 | +var |
| 131 | + path_buf: String; |
| 132 | +begin |
| 133 | + path_buf := String(fixture); |
| 134 | + path_buf := 'file:///' + StringReplace(path_buf, ' ', '%20', [rfReplaceAll]); |
| 135 | + |
| 136 | + out_ := PAnsiChar(AnsiString(path_buf)); |
| 137 | +end; |
| 138 | + |
| 139 | +procedure Test_network_remotelocal.connect_to_local_repository(local_repository: PAnsiChar); |
| 140 | +begin |
| 141 | + build_local_file_url(file_path_buf, local_repository); |
| 142 | + |
| 143 | + cl_git_pass(git_remote_new(remote, repo, PAnsiChar(file_path_buf), nil)); |
| 144 | + cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH)); |
| 145 | +end; |
| 146 | + |
| 147 | +procedure Test_network_remotelocal.SetUp; |
| 148 | +begin |
| 149 | + inherited; |
| 150 | + cl_git_pass(git_repository_init(repo, 'remotelocal/', 0)); |
| 151 | + cl_assert(repo <> nil); |
| 152 | +end; |
| 153 | + |
| 154 | +procedure Test_network_remotelocal.TearDown; |
| 155 | +begin |
| 156 | + inherited; |
| 157 | + git_remote_free(remote); |
| 158 | + git_repository_free(repo); |
| 159 | + cl_fixture_cleanup('remotelocal'); |
| 160 | +end; |
| 161 | + |
| 162 | +function count_ref__cb(head: Pgit_remote_head; payload: PByte): Integer; stdcall; |
| 163 | +var |
| 164 | + count: PInt; |
| 165 | +begin |
| 166 | + count := PInt(payload); |
| 167 | + |
| 168 | +// (void)head; |
| 169 | + count^ := count^ + 1; |
| 170 | + |
| 171 | + Result := GIT_SUCCESS; |
| 172 | +end; |
| 173 | + |
| 174 | +procedure Test_network_remotelocal.test_network_remotelocal__retrieve_advertised_references; |
| 175 | +var |
| 176 | + how_many_refs: Integer; |
| 177 | +begin |
| 178 | + how_many_refs := 0; |
| 179 | + |
| 180 | + connect_to_local_repository(cl_fixture('testrepo.git')); |
| 181 | + |
| 182 | + cl_git_pass(git_remote_ls(remote, @count_ref__cb, @how_many_refs)); |
| 183 | + |
| 184 | + cl_assert(how_many_refs = 12); //* 1 HEAD + 9 refs + 2 peeled tags */ |
| 185 | +end; |
| 186 | + |
| 187 | +procedure Test_network_remotelocal.test_network_remotelocal__retrieve_advertised_references_from_spaced_repository; |
| 188 | +var |
| 189 | + how_many_refs: Integer; |
| 190 | +begin |
| 191 | + how_many_refs := 0; |
| 192 | + |
| 193 | + cl_fixture_sandbox('testrepo.git'); |
| 194 | + cl_git_pass(p_rename('testrepo.git', 'spaced testrepo.git')); |
| 195 | + |
| 196 | + connect_to_local_repository('spaced testrepo.git'); |
| 197 | + |
| 198 | + cl_git_pass(git_remote_ls(remote, @count_ref__cb, @how_many_refs)); |
| 199 | + |
| 200 | + cl_assert(how_many_refs = 12); //* 1 HEAD */ |
| 201 | + |
| 202 | + cl_fixture_cleanup('spaced testrepo.git'); |
| 203 | +end; |
| 204 | + |
| 205 | +{ Test_network_createremotethenload } |
| 206 | + |
| 207 | +procedure Test_network_createremotethenload.SetUp; |
| 208 | +begin |
| 209 | + inherited; |
| 210 | + |
| 211 | + url := 'http://github.com/libgit2/libgit2.git'; |
| 212 | + |
| 213 | + cl_fixture_sandbox('testrepo.git'); |
| 214 | + |
| 215 | + cl_git_pass(git_repository_open(_repo, 'testrepo.git')); |
| 216 | + |
| 217 | + cl_git_pass(git_repository_config(_config, _repo)); |
| 218 | + cl_git_pass(git_config_set_string(_config, 'remote.origin.fetch', '+refs/heads/*:refs/remotes/origin/*')); |
| 219 | + cl_git_pass(git_config_set_string(_config, 'remote.origin.url', PAnsiChar(url))); |
| 220 | + git_config_free(_config); |
| 221 | + |
| 222 | + cl_git_pass(git_remote_load(_remote, _repo, 'origin')); |
| 223 | +end; |
| 224 | + |
| 225 | +procedure Test_network_createremotethenload.TearDown; |
| 226 | +begin |
| 227 | + inherited; |
| 228 | + git_remote_free(_remote); |
| 229 | + git_repository_free(_repo); |
| 230 | + cl_fixture_cleanup('testrepo.git'); |
| 231 | +end; |
| 232 | + |
| 233 | +procedure Test_network_createremotethenload.test_network_createremotethenload__parsing; |
| 234 | +begin |
| 235 | + cl_assert(StrComp(git_remote_name(_remote), 'origin') = 0); |
| 236 | + cl_assert(StrComp(git_remote_url(_remote), PAnsiChar(url)) = 0); |
| 237 | +end; |
| 238 | + |
| 239 | +initialization |
| 240 | + RegisterTest('From libgit2/clar/network', Test_network_remotes.NamedSuite('remotes')); |
| 241 | + RegisterTest('From libgit2/clar/network', Test_network_remotelocal.NamedSuite('remotelocal')); |
| 242 | + RegisterTest('From libgit2/clar/network', Test_network_createremotethenload.NamedSuite('createremotethenload')); |
| 243 | + |
| 244 | +end. |
|
0 commit comments