2 #include "clar_libgit2.h"
6 #include "win32/path_w32.h"
9 void test_utf8_to_utf16(const char *utf8_in
, const wchar_t *utf16_expected
)
12 git_win32_path path_utf16
;
15 cl_assert((path_utf16len
= git_win32_path_from_utf8(path_utf16
, utf8_in
)) >= 0);
16 cl_assert_equal_wcs(utf16_expected
, path_utf16
);
17 cl_assert_equal_i(wcslen(utf16_expected
), path_utf16len
);
20 GIT_UNUSED(utf16_expected
);
24 void test_path_win32__utf8_to_utf16(void)
27 test_utf8_to_utf16("C:\\", L
"\\\\?\\C:\\");
28 test_utf8_to_utf16("c:\\", L
"\\\\?\\c:\\");
29 test_utf8_to_utf16("C:/", L
"\\\\?\\C:\\");
30 test_utf8_to_utf16("c:/", L
"\\\\?\\c:\\");
34 void test_path_win32__removes_trailing_slash(void)
37 test_utf8_to_utf16("C:\\Foo\\", L
"\\\\?\\C:\\Foo");
38 test_utf8_to_utf16("C:\\Foo\\\\", L
"\\\\?\\C:\\Foo");
39 test_utf8_to_utf16("C:\\Foo\\\\", L
"\\\\?\\C:\\Foo");
40 test_utf8_to_utf16("C:/Foo/", L
"\\\\?\\C:\\Foo");
41 test_utf8_to_utf16("C:/Foo///", L
"\\\\?\\C:\\Foo");
45 void test_path_win32__squashes_multiple_slashes(void)
48 test_utf8_to_utf16("C:\\\\Foo\\Bar\\\\Foobar", L
"\\\\?\\C:\\Foo\\Bar\\Foobar");
49 test_utf8_to_utf16("C://Foo/Bar///Foobar", L
"\\\\?\\C:\\Foo\\Bar\\Foobar");
53 void test_path_win32__unc(void)
56 test_utf8_to_utf16("\\\\server\\c$\\unc\\path", L
"\\\\?\\UNC\\server\\c$\\unc\\path");
57 test_utf8_to_utf16("//server/git/style/unc/path", L
"\\\\?\\UNC\\server\\git\\style\\unc\\path");
61 void test_path_win32__honors_max_path(void)
64 git_win32_path path_utf16
;
66 test_utf8_to_utf16("C:\\This path is 259 chars and is the max length in windows\\0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij",
67 L
"\\\\?\\C:\\This path is 259 chars and is the max length in windows\\0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij");
68 test_utf8_to_utf16("\\\\unc\\paths may also be 259 characters including the server\\123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij",
69 L
"\\\\?\\UNC\\unc\\paths may also be 259 characters including the server\\123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij");
71 cl_check_fail(git_win32_path_from_utf8(path_utf16
, "C:\\This path is 260 chars and is sadly too long for windows\\0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij"));
72 cl_check_fail(git_win32_path_from_utf8(path_utf16
, "\\\\unc\\paths are also bound by 260 character restrictions\\including the server name portion\\bcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij0123456789abcdefghij"));
76 void test_path_win32__dot_and_dotdot(void)
79 test_utf8_to_utf16("C:\\Foo\\..\\Foobar", L
"\\\\?\\C:\\Foobar");
80 test_utf8_to_utf16("C:\\Foo\\Bar\\..\\Foobar", L
"\\\\?\\C:\\Foo\\Foobar");
81 test_utf8_to_utf16("C:\\Foo\\Bar\\..\\Foobar\\..", L
"\\\\?\\C:\\Foo");
82 test_utf8_to_utf16("C:\\Foobar\\..", L
"\\\\?\\C:\\");
83 test_utf8_to_utf16("C:/Foo/Bar/../Foobar", L
"\\\\?\\C:\\Foo\\Foobar");
84 test_utf8_to_utf16("C:/Foo/Bar/../Foobar/../Asdf/", L
"\\\\?\\C:\\Foo\\Asdf");
85 test_utf8_to_utf16("C:/Foo/Bar/../Foobar/..", L
"\\\\?\\C:\\Foo");
86 test_utf8_to_utf16("C:/Foo/..", L
"\\\\?\\C:\\");
88 test_utf8_to_utf16("C:\\Foo\\Bar\\.\\Foobar", L
"\\\\?\\C:\\Foo\\Bar\\Foobar");
89 test_utf8_to_utf16("C:\\.\\Foo\\.\\Bar\\.\\Foobar\\.\\", L
"\\\\?\\C:\\Foo\\Bar\\Foobar");
90 test_utf8_to_utf16("C:/Foo/Bar/./Foobar", L
"\\\\?\\C:\\Foo\\Bar\\Foobar");
91 test_utf8_to_utf16("C:/Foo/../Bar/./Foobar/../", L
"\\\\?\\C:\\Bar");
93 test_utf8_to_utf16("C:\\Foo\\..\\..\\Bar", L
"\\\\?\\C:\\Bar");
97 void test_path_win32__absolute_from_no_drive_letter(void)
100 test_utf8_to_utf16("\\Foo", L
"\\\\?\\C:\\Foo");
101 test_utf8_to_utf16("\\Foo\\Bar", L
"\\\\?\\C:\\Foo\\Bar");
102 test_utf8_to_utf16("/Foo/Bar", L
"\\\\?\\C:\\Foo\\Bar");
106 void test_path_win32__absolute_from_relative(void)
109 char cwd_backup
[MAX_PATH
];
111 cl_must_pass(p_getcwd(cwd_backup
, MAX_PATH
));
112 cl_must_pass(p_chdir("C:/"));
114 test_utf8_to_utf16("Foo", L
"\\\\?\\C:\\Foo");
115 test_utf8_to_utf16("..\\..\\Foo", L
"\\\\?\\C:\\Foo");
116 test_utf8_to_utf16("Foo\\..", L
"\\\\?\\C:\\");
117 test_utf8_to_utf16("Foo\\..\\..", L
"\\\\?\\C:\\");
118 test_utf8_to_utf16("", L
"\\\\?\\C:\\");
120 cl_must_pass(p_chdir("C:/Windows"));
122 test_utf8_to_utf16("Foo", L
"\\\\?\\C:\\Windows\\Foo");
123 test_utf8_to_utf16("Foo\\Bar", L
"\\\\?\\C:\\Windows\\Foo\\Bar");
124 test_utf8_to_utf16("..\\Foo", L
"\\\\?\\C:\\Foo");
125 test_utf8_to_utf16("Foo\\..\\Bar", L
"\\\\?\\C:\\Windows\\Bar");
126 test_utf8_to_utf16("", L
"\\\\?\\C:\\Windows");
128 cl_must_pass(p_chdir(cwd_backup
));
132 void test_canonicalize(const wchar_t *in
, const wchar_t *expected
)
135 git_win32_path canonical
;
137 cl_assert(wcslen(in
) < MAX_PATH
);
138 wcscpy(canonical
, in
);
140 cl_must_pass(git_win32_path_canonicalize(canonical
));
141 cl_assert_equal_wcs(expected
, canonical
);
144 GIT_UNUSED(expected
);
148 void test_path_win32__canonicalize(void)
151 test_canonicalize(L
"C:\\Foo\\Bar", L
"C:\\Foo\\Bar");
152 test_canonicalize(L
"C:\\Foo\\", L
"C:\\Foo");
153 test_canonicalize(L
"C:\\Foo\\\\", L
"C:\\Foo");
154 test_canonicalize(L
"C:\\Foo\\..\\Bar", L
"C:\\Bar");
155 test_canonicalize(L
"C:\\Foo\\..\\..\\Bar", L
"C:\\Bar");
156 test_canonicalize(L
"C:\\Foo\\..\\..\\..\\..\\", L
"C:\\");
157 test_canonicalize(L
"C:/Foo/Bar", L
"C:\\Foo\\Bar");
158 test_canonicalize(L
"C:/", L
"C:\\");
160 test_canonicalize(L
"Foo\\\\Bar\\\\Asdf\\\\", L
"Foo\\Bar\\Asdf");
161 test_canonicalize(L
"Foo\\\\Bar\\\\..\\\\Asdf\\", L
"Foo\\Asdf");
162 test_canonicalize(L
"Foo\\\\Bar\\\\.\\\\Asdf\\", L
"Foo\\Bar\\Asdf");
163 test_canonicalize(L
"Foo\\\\..\\Bar\\\\.\\\\Asdf\\", L
"Bar\\Asdf");
164 test_canonicalize(L
"\\", L
"");
165 test_canonicalize(L
"", L
"");
166 test_canonicalize(L
"Foo\\..\\..\\..\\..", L
"");
167 test_canonicalize(L
"..\\..\\..\\..", L
"");
168 test_canonicalize(L
"\\..\\..\\..\\..", L
"");
170 test_canonicalize(L
"\\\\?\\C:\\Foo\\Bar", L
"\\\\?\\C:\\Foo\\Bar");
171 test_canonicalize(L
"\\\\?\\C:\\Foo\\Bar\\", L
"\\\\?\\C:\\Foo\\Bar");
172 test_canonicalize(L
"\\\\?\\C:\\\\Foo\\.\\Bar\\\\..\\", L
"\\\\?\\C:\\Foo");
173 test_canonicalize(L
"\\\\?\\C:\\\\", L
"\\\\?\\C:\\");
174 test_canonicalize(L
"//?/C:/", L
"\\\\?\\C:\\");
175 test_canonicalize(L
"//?/C:/../../Foo/", L
"\\\\?\\C:\\Foo");
176 test_canonicalize(L
"//?/C:/Foo/../../", L
"\\\\?\\C:\\");
178 test_canonicalize(L
"\\\\?\\UNC\\server\\C$\\folder", L
"\\\\?\\UNC\\server\\C$\\folder");
179 test_canonicalize(L
"\\\\?\\UNC\\server\\C$\\folder\\", L
"\\\\?\\UNC\\server\\C$\\folder");
180 test_canonicalize(L
"\\\\?\\UNC\\server\\C$\\folder\\", L
"\\\\?\\UNC\\server\\C$\\folder");
181 test_canonicalize(L
"\\\\?\\UNC\\server\\C$\\folder\\..\\..\\..\\..\\share\\", L
"\\\\?\\UNC\\server\\share");
183 test_canonicalize(L
"\\\\server\\share", L
"\\\\server\\share");
184 test_canonicalize(L
"\\\\server\\share\\", L
"\\\\server\\share");
185 test_canonicalize(L
"\\\\server\\share\\\\foo\\\\bar", L
"\\\\server\\share\\foo\\bar");
186 test_canonicalize(L
"\\\\server\\\\share\\\\foo\\\\bar", L
"\\\\server\\share\\foo\\bar");
187 test_canonicalize(L
"\\\\server\\share\\..\\foo", L
"\\\\server\\foo");
188 test_canonicalize(L
"\\\\server\\..\\..\\share\\.\\foo", L
"\\\\server\\share\\foo");
192 void test_path_win32__8dot3_name(void)
197 /* Some guaranteed short names */
198 cl_assert_equal_s("PROGRA~1", (shortname
= git_win32_path_8dot3_name("C:\\Program Files")));
199 git__free(shortname
);
201 cl_assert_equal_s("WINDOWS", (shortname
= git_win32_path_8dot3_name("C:\\WINDOWS")));
202 git__free(shortname
);
204 /* Create some predictible short names */
205 cl_must_pass(p_mkdir(".foo", 0777));
206 cl_assert_equal_s("FOO~1", (shortname
= git_win32_path_8dot3_name(".foo")));
207 git__free(shortname
);
209 cl_git_write2file("bar~1", "foobar\n", 7, O_RDWR
|O_CREAT
, 0666);
210 cl_must_pass(p_mkdir(".bar", 0777));
211 cl_assert_equal_s("BAR~2", (shortname
= git_win32_path_8dot3_name(".bar")));
212 git__free(shortname
);