kernelbase/tests: Fix a couple of typos in skip messages.
[wine.git] / dlls / kernelbase / tests / path.c
blob7c8851357f145a061383913022356e5208749e2a
1 /*
2 * Path tests for kernelbase.dll
4 * Copyright 2017 Michael Müller
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <windef.h>
23 #include <winbase.h>
24 #include <stdlib.h>
25 #include <winerror.h>
26 #include <winnls.h>
27 #include <pathcch.h>
28 #include <strsafe.h>
30 #include "wine/test.h"
32 HRESULT (WINAPI *pPathCchAddBackslash)(WCHAR *out, SIZE_T size);
33 HRESULT (WINAPI *pPathCchAddBackslashEx)(WCHAR *out, SIZE_T size, WCHAR **endptr, SIZE_T *remaining);
34 HRESULT (WINAPI *pPathCchCombineEx)(WCHAR *out, SIZE_T size, const WCHAR *path1, const WCHAR *path2, DWORD flags);
36 static const struct
38 const char *path1;
39 const char *path2;
40 const char *result;
42 combine_test[] =
44 /* normal paths */
45 {"C:\\", "a", "C:\\a" },
46 {"C:\\b", "..\\a", "C:\\a" },
47 {"C:", "a", "C:\\a" },
48 {"C:\\", ".", "C:\\" },
49 {"C:\\", "..", "C:\\" },
50 {"\\a", "b", "\\a\\b" },
52 /* normal UNC paths */
53 {"\\\\192.168.1.1\\test", "a", "\\\\192.168.1.1\\test\\a" },
54 {"\\\\192.168.1.1\\test", "..", "\\\\192.168.1.1" },
56 /* NT paths */
57 {"\\\\?\\C:\\", "a", "C:\\a" },
58 {"\\\\?\\C:\\", "..", "C:\\" },
60 /* NT UNC path */
61 {"\\\\?\\UNC\\192.168.1.1\\test", "a", "\\\\192.168.1.1\\test\\a" },
62 {"\\\\?\\UNC\\192.168.1.1\\test", "..", "\\\\192.168.1.1" },
65 static void test_PathCchCombineEx(void)
67 WCHAR expected[MAX_PATH] = {'C',':','\\','a',0};
68 WCHAR p1[MAX_PATH] = {'C',':','\\',0};
69 WCHAR p2[MAX_PATH] = {'a',0};
70 WCHAR output[MAX_PATH];
71 HRESULT hr;
72 int i;
74 if (!pPathCchCombineEx)
76 skip("PathCchCombineEx() is not available.\n");
77 return;
80 hr = pPathCchCombineEx(NULL, 2, p1, p2, 0);
81 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
83 memset(output, 0xff, sizeof(output));
84 hr = pPathCchCombineEx(output, 0, p1, p2, 0);
85 ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr);
86 ok(output[0] == 0xffff, "Expected output buffer to be unchanged\n");
88 memset(output, 0xff, sizeof(output));
89 hr = pPathCchCombineEx(output, 1, p1, p2, 0);
90 ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "Expected STRSAFE_E_INSUFFICIENT_BUFFER, got %08x\n", hr);
91 ok(output[0] == 0, "Expected output buffer to contain NULL string\n");
93 memset(output, 0xff, sizeof(output));
94 hr = pPathCchCombineEx(output, 4, p1, p2, 0);
95 ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "Expected STRSAFE_E_INSUFFICIENT_BUFFER, got %08x\n", hr);
96 ok(output[0] == 0x0, "Expected output buffer to contain NULL string\n");
98 memset(output, 0xff, sizeof(output));
99 hr = pPathCchCombineEx(output, 5, p1, p2, 0);
100 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
101 ok(!lstrcmpW(output, expected),
102 "Combination of %s + %s returned %s, expected %s\n",
103 wine_dbgstr_w(p1), wine_dbgstr_w(p2), wine_dbgstr_w(output), wine_dbgstr_w(expected));
105 for (i = 0; i < sizeof(combine_test)/sizeof(combine_test[0]); i++)
107 MultiByteToWideChar(CP_ACP, 0, combine_test[i].path1, -1, p1, MAX_PATH);
108 MultiByteToWideChar(CP_ACP, 0, combine_test[i].path2, -1, p2, MAX_PATH);
109 MultiByteToWideChar(CP_ACP, 0, combine_test[i].result, -1, expected, MAX_PATH);
111 hr = pPathCchCombineEx(output, MAX_PATH, p1, p2, 0);
112 ok(hr == S_OK, "Expected S_OK, got %08x\n", hr);
113 ok(!lstrcmpW(output, expected), "Combining %s with %s returned %s, expected %s\n",
114 wine_dbgstr_w(p1), wine_dbgstr_w(p2), wine_dbgstr_w(output), wine_dbgstr_w(expected));
118 struct addbackslash_test
120 const char *path;
121 const char *result;
122 HRESULT hr;
123 SIZE_T size;
124 SIZE_T remaining;
127 static const struct addbackslash_test addbackslash_tests[] =
129 { "C:", "C:\\", S_OK, MAX_PATH, MAX_PATH - 3 },
130 { "a.txt", "a.txt\\", S_OK, MAX_PATH, MAX_PATH - 6 },
131 { "a/b", "a/b\\", S_OK, MAX_PATH, MAX_PATH - 4 },
133 { "C:\\", "C:\\", S_FALSE, MAX_PATH, MAX_PATH - 3 },
134 { "C:\\", "C:\\", S_FALSE, 4, 1 },
136 { "C:", "C:", STRSAFE_E_INSUFFICIENT_BUFFER, 2, 0 },
137 { "C:", "C:", STRSAFE_E_INSUFFICIENT_BUFFER, 3, 1 },
138 { "C:\\", "C:\\", STRSAFE_E_INSUFFICIENT_BUFFER, 2, 0 },
139 { "C:\\", "C:\\", STRSAFE_E_INSUFFICIENT_BUFFER, 3, 0 },
140 { "C:\\", "C:\\", STRSAFE_E_INSUFFICIENT_BUFFER, 0, 0 },
141 { "C:", "C:", STRSAFE_E_INSUFFICIENT_BUFFER, 0, 0 },
144 static void test_PathCchAddBackslash(void)
146 WCHAR pathW[MAX_PATH];
147 unsigned int i;
148 HRESULT hr;
150 if (!pPathCchAddBackslash)
152 win_skip("PathCchAddBackslash() is not available.\n");
153 return;
156 pathW[0] = 0;
157 hr = pPathCchAddBackslash(pathW, 0);
158 ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "Unexpected hr %#x.\n", hr);
159 ok(pathW[0] == 0, "Unexpected path.\n");
161 pathW[0] = 0;
162 hr = pPathCchAddBackslash(pathW, 1);
163 ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
164 ok(pathW[0] == 0, "Unexpected path.\n");
166 pathW[0] = 0;
167 hr = pPathCchAddBackslash(pathW, 2);
168 ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
169 ok(pathW[0] == 0, "Unexpected path.\n");
171 for (i = 0; i < sizeof(addbackslash_tests)/sizeof(addbackslash_tests[0]); i++)
173 const struct addbackslash_test *test = &addbackslash_tests[i];
174 char path[MAX_PATH];
176 MultiByteToWideChar(CP_ACP, 0, test->path, -1, pathW, sizeof(pathW)/sizeof(pathW[0]));
177 hr = pPathCchAddBackslash(pathW, test->size);
178 ok(hr == test->hr, "%u: unexpected return value %#x.\n", i, hr);
180 WideCharToMultiByte(CP_ACP, 0, pathW, -1, path, sizeof(path)/sizeof(path[0]), NULL, NULL);
181 ok(!strcmp(path, test->result), "%u: unexpected resulting path %s.\n", i, path);
185 static void test_PathCchAddBackslashEx(void)
187 WCHAR pathW[MAX_PATH];
188 SIZE_T remaining;
189 unsigned int i;
190 HRESULT hr;
191 WCHAR *ptrW;
193 if (!pPathCchAddBackslashEx)
195 win_skip("PathCchAddBackslashEx() is not available.\n");
196 return;
199 pathW[0] = 0;
200 hr = pPathCchAddBackslashEx(pathW, 0, NULL, NULL);
201 ok(hr == STRSAFE_E_INSUFFICIENT_BUFFER, "Unexpected hr %#x.\n", hr);
202 ok(pathW[0] == 0, "Unexpected path.\n");
204 pathW[0] = 0;
205 ptrW = (void *)0xdeadbeef;
206 remaining = 123;
207 hr = pPathCchAddBackslashEx(pathW, 1, &ptrW, &remaining);
208 ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
209 ok(pathW[0] == 0, "Unexpected path.\n");
210 ok(ptrW == pathW, "Unexpected endptr %p.\n", ptrW);
211 ok(remaining == 1, "Unexpected remaining size.\n");
213 pathW[0] = 0;
214 hr = pPathCchAddBackslashEx(pathW, 2, NULL, NULL);
215 ok(hr == S_FALSE, "Unexpected hr %#x.\n", hr);
216 ok(pathW[0] == 0, "Unexpected path.\n");
218 for (i = 0; i < sizeof(addbackslash_tests)/sizeof(addbackslash_tests[0]); i++)
220 const struct addbackslash_test *test = &addbackslash_tests[i];
221 char path[MAX_PATH];
223 MultiByteToWideChar(CP_ACP, 0, test->path, -1, pathW, sizeof(pathW)/sizeof(pathW[0]));
224 hr = pPathCchAddBackslashEx(pathW, test->size, NULL, NULL);
225 ok(hr == test->hr, "%u: unexpected return value %#x.\n", i, hr);
227 WideCharToMultiByte(CP_ACP, 0, pathW, -1, path, sizeof(path)/sizeof(path[0]), NULL, NULL);
228 ok(!strcmp(path, test->result), "%u: unexpected resulting path %s.\n", i, path);
230 ptrW = (void *)0xdeadbeef;
231 remaining = 123;
232 MultiByteToWideChar(CP_ACP, 0, test->path, -1, pathW, sizeof(pathW)/sizeof(pathW[0]));
233 hr = pPathCchAddBackslashEx(pathW, test->size, &ptrW, &remaining);
234 ok(hr == test->hr, "%u: unexpected return value %#x.\n", i, hr);
235 if (SUCCEEDED(hr))
237 ok(ptrW == (pathW + lstrlenW(pathW)), "%u: unexpected end pointer.\n", i);
238 ok(remaining == test->remaining, "%u: unexpected remaining buffer length.\n", i);
240 else
242 ok(ptrW == NULL, "%u: unexpecred end pointer.\n", i);
243 ok(remaining == 0, "%u: unexpected remaining buffer length.\n", i);
248 START_TEST(path)
250 HMODULE hmod = LoadLibraryA("kernelbase.dll");
252 pPathCchCombineEx = (void *)GetProcAddress(hmod, "PathCchCombineEx");
253 pPathCchAddBackslash = (void *)GetProcAddress(hmod, "PathCchAddBackslash");
254 pPathCchAddBackslashEx = (void *)GetProcAddress(hmod, "PathCchAddBackslashEx");
256 test_PathCchCombineEx();
257 test_PathCchAddBackslash();
258 test_PathCchAddBackslashEx();