]> git.proxmox.com Git - libgit2.git/blob - tests/win32/longpath.c
Imported Upstream version 0.24.0
[libgit2.git] / tests / win32 / longpath.c
1 #include "clar_libgit2.h"
2
3 #include "git2/clone.h"
4 #include "clone.h"
5 #include "buffer.h"
6 #include "fileops.h"
7
8 static git_buf path = GIT_BUF_INIT;
9
10 void test_win32_longpath__initialize(void)
11 {
12 #ifdef GIT_WIN32
13 const char *base = clar_sandbox_path();
14 size_t base_len = strlen(base);
15 size_t remain = MAX_PATH - base_len;
16 size_t i;
17
18 git_buf_clear(&path);
19 git_buf_puts(&path, base);
20 git_buf_putc(&path, '/');
21
22 cl_assert(remain < (MAX_PATH - 5));
23
24 for (i = 0; i < (remain - 5); i++)
25 git_buf_putc(&path, 'a');
26 #endif
27 }
28
29 void test_win32_longpath__cleanup(void)
30 {
31 git_buf_free(&path);
32 }
33
34 #ifdef GIT_WIN32
35 void assert_name_too_long(void)
36 {
37 const git_error *err;
38 size_t expected_len, actual_len;
39 char *expected_msg;
40
41 err = giterr_last();
42 actual_len = strlen(err->message);
43
44 expected_msg = git_win32_get_error_message(ERROR_FILENAME_EXCED_RANGE);
45 expected_len = strlen(expected_msg);
46
47 /* check the suffix */
48 cl_assert_equal_s(expected_msg, err->message + (actual_len - expected_len));
49
50 git__free(expected_msg);
51 }
52 #endif
53
54 void test_win32_longpath__errmsg_on_checkout(void)
55 {
56 #ifdef GIT_WIN32
57 git_repository *repo;
58
59 cl_git_fail(git_clone(&repo, cl_fixture("testrepo.git"), path.ptr, NULL));
60 assert_name_too_long();
61 #endif
62 }