VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTPath.cpp@ 31632

Last change on this file since 31632 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 21.8 KB
Line 
1/* $Id: tstRTPath.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Test various path functions.
4 */
5
6/*
7 * Copyright (C) 2006-2010 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include <iprt/path.h>
31
32#include <iprt/err.h>
33#include <iprt/initterm.h>
34#include <iprt/param.h>
35#include <iprt/process.h>
36#include <iprt/stream.h>
37#include <iprt/string.h>
38#include <iprt/test.h>
39
40
41int main()
42{
43 char szPath[RTPATH_MAX];
44
45 /*
46 * Init RT+Test.
47 */
48 RTTEST hTest;
49 int rc = RTTestInitAndCreate("tstRTPath", &hTest);
50 if (rc)
51 return rc;
52 RTTestBanner(hTest);
53
54 /*
55 * RTPathExecDir, RTPathUserHome and RTProcGetExecutableName.
56 */
57 RTTestSub(hTest, "RTPathExecDir");
58 RTTESTI_CHECK_RC(RTPathExecDir(szPath, sizeof(szPath)), VINF_SUCCESS);
59 if (RT_SUCCESS(rc))
60 RTTestIPrintf(RTTESTLVL_INFO, "ExecDir={%s}\n", szPath);
61
62 RTTestSub(hTest, "RTProcGetExecutableName");
63 if (RTProcGetExecutableName(szPath, sizeof(szPath)) == szPath)
64 RTTestIPrintf(RTTESTLVL_INFO, "ExecutableName={%s}\n", szPath);
65 else
66 RTTestIFailed("RTProcGetExecutableName -> NULL");
67
68 RTTestSub(hTest, "RTPathUserHome");
69 RTTESTI_CHECK_RC(RTPathUserHome(szPath, sizeof(szPath)), VINF_SUCCESS);
70 if (RT_SUCCESS(rc))
71 RTTestIPrintf(RTTESTLVL_INFO, "UserHome={%s}\n", szPath);
72
73 RTTestSub(hTest, "RTPathTemp");
74 RTTESTI_CHECK_RC(RTPathTemp(szPath, sizeof(szPath)), VINF_SUCCESS);
75 if (RT_SUCCESS(rc))
76 RTTestIPrintf(RTTESTLVL_INFO, "PathTemp={%s}\n", szPath);
77 size_t cch = strlen(szPath);
78 RTTESTI_CHECK_RC(RTPathTemp(szPath, cch), VERR_BUFFER_OVERFLOW);
79 RTTESTI_CHECK_RC(RTPathTemp(szPath, cch+1), VINF_SUCCESS);
80 RTTESTI_CHECK_RC(RTPathTemp(szPath, cch+2), VINF_SUCCESS);
81
82
83 /*
84 * RTPathAbsEx
85 */
86 RTTestSub(hTest, "RTPathAbsEx");
87 static const struct
88 {
89 const char *pcszInputBase;
90 const char *pcszInputPath;
91 int rc;
92 const char *pcszOutput;
93 }
94 s_aRTPathAbsExTests[] =
95 {
96#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
97 { NULL, "", VERR_INVALID_PARAMETER, NULL },
98 { NULL, ".", VINF_SUCCESS, "%p" },
99 { NULL, "\\", VINF_SUCCESS, "%d\\" },
100 { NULL, "\\..", VINF_SUCCESS, "%d\\" },
101 { NULL, "/absolute/..", VINF_SUCCESS, "%d\\" },
102 { NULL, "/absolute\\\\../..", VINF_SUCCESS, "%d\\" },
103 { NULL, "/absolute//../path\\", VINF_SUCCESS, "%d\\path" },
104 { NULL, "/absolute/../../path", VINF_SUCCESS, "%d\\path" },
105 { NULL, "relative/../dir\\.\\.\\.\\file.txt", VINF_SUCCESS, "%p\\dir\\file.txt" },
106 { NULL, "\\data\\", VINF_SUCCESS, "%d\\data" },
107 { "relative_base/dir\\", "\\from_root", VINF_SUCCESS, "%d\\from_root" },
108 { "relative_base/dir/", "relative_also", VINF_SUCCESS, "%p\\relative_base\\dir\\relative_also" },
109#else
110 { NULL, "", VERR_INVALID_PARAMETER, NULL },
111 { NULL, ".", VINF_SUCCESS, "%p" },
112 { NULL, "/", VINF_SUCCESS, "/" },
113 { NULL, "/..", VINF_SUCCESS, "/" },
114 { NULL, "/absolute/..", VINF_SUCCESS, "/" },
115 { NULL, "/absolute\\\\../..", VINF_SUCCESS, "/" },
116 { NULL, "/absolute//../path/", VINF_SUCCESS, "/path" },
117 { NULL, "/absolute/../../path", VINF_SUCCESS, "/path" },
118 { NULL, "relative/../dir/./././file.txt", VINF_SUCCESS, "%p/dir/file.txt" },
119 { NULL, "relative/../dir\\.\\.\\.\\file.txt", VINF_SUCCESS, "%p/dir\\.\\.\\.\\file.txt" }, /* linux-specific */
120 { NULL, "/data/", VINF_SUCCESS, "/data" },
121 { "relative_base/dir/", "/from_root", VINF_SUCCESS, "/from_root" },
122 { "relative_base/dir/", "relative_also", VINF_SUCCESS, "%p/relative_base/dir/relative_also" },
123#endif
124#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
125 { NULL, "C:\\", VINF_SUCCESS, "C:\\" },
126 { "C:\\", "..", VINF_SUCCESS, "C:\\" },
127 { "C:\\temp", "..", VINF_SUCCESS, "C:\\" },
128 { "C:\\VirtualBox/Machines", "..\\VirtualBox.xml", VINF_SUCCESS, "C:\\VirtualBox\\VirtualBox.xml" },
129 { "C:\\MustDie", "\\from_root/dir/..", VINF_SUCCESS, "C:\\from_root" },
130 { "C:\\temp", "D:\\data", VINF_SUCCESS, "D:\\data" },
131 { NULL, "\\\\server\\..\\share", VINF_SUCCESS, "\\\\server\\..\\share" /* kind of strange */ },
132 { NULL, "\\\\server/", VINF_SUCCESS, "\\\\server" },
133 { NULL, "\\\\", VINF_SUCCESS, "\\\\" },
134 { NULL, "\\\\\\something", VINF_SUCCESS, "\\\\\\something" /* kind of strange */ },
135 { "\\\\server\\share_as_base", "/from_root", VINF_SUCCESS, "\\\\server\\from_root" },
136 { "\\\\just_server", "/from_root", VINF_SUCCESS, "\\\\just_server\\from_root" },
137 { "\\\\server\\share_as_base", "relative\\data", VINF_SUCCESS, "\\\\server\\share_as_base\\relative\\data" },
138 { "base", "\\\\?\\UNC\\relative/edwef/..", VINF_SUCCESS, "\\\\?\\UNC\\relative" },
139 { "\\\\?\\UNC\\base", "/from_root", VERR_INVALID_NAME, NULL },
140#else
141 { "/temp", "..", VINF_SUCCESS, "/" },
142 { "/VirtualBox/Machines", "../VirtualBox.xml", VINF_SUCCESS, "/VirtualBox/VirtualBox.xml" },
143 { "/MustDie", "/from_root/dir/..", VINF_SUCCESS, "/from_root" },
144 { "\\temp", "\\data", VINF_SUCCESS, "%p/\\temp/\\data" },
145#endif
146 };
147
148 for (unsigned i = 0; i < RT_ELEMENTS(s_aRTPathAbsExTests); ++ i)
149 {
150 rc = RTPathAbsEx(s_aRTPathAbsExTests[i].pcszInputBase,
151 s_aRTPathAbsExTests[i].pcszInputPath,
152 szPath, sizeof(szPath));
153 if (rc != s_aRTPathAbsExTests[i].rc)
154 {
155 RTTestIFailed("unexpected result code!\n"
156 " input base: '%s'\n"
157 " input path: '%s'\n"
158 " output: '%s'\n"
159 " rc: %Rrc\n"
160 " expected rc: %Rrc",
161 s_aRTPathAbsExTests[i].pcszInputBase,
162 s_aRTPathAbsExTests[i].pcszInputPath,
163 szPath, rc,
164 s_aRTPathAbsExTests[i].rc);
165 continue;
166 }
167
168 char szTmp[RTPATH_MAX];
169 char *pszExpected = NULL;
170 if (s_aRTPathAbsExTests[i].pcszOutput != NULL)
171 {
172 if (s_aRTPathAbsExTests[i].pcszOutput[0] == '%')
173 {
174 RTTESTI_CHECK_RC(rc = RTPathGetCurrent(szTmp, sizeof(szTmp)), VINF_SUCCESS);
175 if (RT_FAILURE(rc))
176 break;
177
178 pszExpected = szTmp;
179
180 if (s_aRTPathAbsExTests[i].pcszOutput[1] == 'p')
181 {
182 cch = strlen(szTmp);
183 if (cch + strlen(s_aRTPathAbsExTests[i].pcszOutput) - 2 <= sizeof(szTmp))
184 strcpy(szTmp + cch, s_aRTPathAbsExTests[i].pcszOutput + 2);
185 }
186#if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS)
187 else if (s_aRTPathAbsExTests[i].pcszOutput[1] == 'd')
188 {
189 if (2 + strlen(s_aRTPathAbsExTests[i].pcszOutput) - 2 <= sizeof(szTmp))
190 strcpy(szTmp + 2, s_aRTPathAbsExTests[i].pcszOutput + 2);
191 }
192#endif
193 }
194 else
195 {
196 strcpy(szTmp, s_aRTPathAbsExTests[i].pcszOutput);
197 pszExpected = szTmp;
198 }
199
200 if (strcmp(szPath, pszExpected))
201 {
202 RTTestIFailed("Unexpected result\n"
203 " input base: '%s'\n"
204 " input path: '%s'\n"
205 " output: '%s'\n"
206 " expected: '%s'",
207 s_aRTPathAbsExTests[i].pcszInputBase,
208 s_aRTPathAbsExTests[i].pcszInputPath,
209 szPath,
210 s_aRTPathAbsExTests[i].pcszOutput);
211 }
212 }
213 }
214
215 /*
216 * RTPathStripFilename
217 */
218 RTTestSub(hTest, "RTPathStripFilename");
219 static const char *s_apszStripFilenameTests[] =
220 {
221 "/usr/include///", "/usr/include//",
222 "/usr/include/", "/usr/include",
223 "/usr/include", "/usr",
224 "/usr", "/",
225 "usr", ".",
226#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
227 "c:/windows", "c:/",
228 "c:/", "c:/",
229 "D:", "D:",
230 "C:\\OS2\\DLLS", "C:\\OS2",
231#endif
232 };
233 for (unsigned i = 0; i < RT_ELEMENTS(s_apszStripFilenameTests); i += 2)
234 {
235 const char *pszInput = s_apszStripFilenameTests[i];
236 const char *pszExpect = s_apszStripFilenameTests[i + 1];
237 strcpy(szPath, pszInput);
238 RTPathStripFilename(szPath);
239 if (strcmp(szPath, pszExpect))
240 {
241 RTTestIFailed("Unexpected result\n"
242 " input: '%s'\n"
243 " output: '%s'\n"
244 "expected: '%s'",
245 pszInput, szPath, pszExpect);
246 }
247 }
248
249 /*
250 * RTPathAppend.
251 */
252 RTTestSub(hTest, "RTPathAppend");
253 static const char *s_apszAppendTests[] =
254 {
255 /* base append result */
256 "/", "", "/",
257 "", "/", "/",
258 "/", "/", "/",
259 "/x", "", "/x",
260 "/x", "/", "/x/",
261 "/", "x", "/x",
262 "dir", "file", "dir/file",
263 "dir", "/file", "dir/file",
264 "dir", "//file", "dir/file",
265 "dir", "///file", "dir/file",
266 "dir/", "/file", "dir/file",
267 "dir/", "//file", "dir/file",
268 "dir/", "///file", "dir/file",
269 "dir//", "file", "dir/file",
270 "dir//", "/file", "dir/file",
271 "dir//", "//file", "dir/file",
272 "dir///", "///file", "dir/file",
273 "/bin/testcase", "foo.r0", "/bin/testcase/foo.r0",
274#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
275 "/", "\\", "/",
276 "\\", "/", "\\",
277 "\\\\srv\\shr", "dir//", "\\\\srv\\shr/dir//",
278 "\\\\srv\\shr", "dir//file", "\\\\srv\\shr/dir//file",
279 "\\\\srv\\shr", "//dir//", "\\\\srv\\shr/dir//",
280 "\\\\srv\\shr", "/\\dir//", "\\\\srv\\shr\\dir//",
281 "\\\\", "not-srv/not-shr/file", "\\not-srv/not-shr/file",
282 "C:", "autoexec.bat", "C:autoexec.bat",
283 "C:", "/autoexec.bat", "C:/autoexec.bat",
284 "C:", "\\autoexec.bat", "C:\\autoexec.bat",
285 "C:\\", "/autoexec.bat", "C:\\autoexec.bat",
286 "C:\\\\", "autoexec.bat", "C:\\autoexec.bat",
287 "E:\\bin\\testcase", "foo.r0", "E:\\bin\\testcase/foo.r0",
288#endif
289 };
290 for (unsigned i = 0; i < RT_ELEMENTS(s_apszAppendTests); i += 3)
291 {
292 const char *pszInput = s_apszAppendTests[i];
293 const char *pszAppend = s_apszAppendTests[i + 1];
294 const char *pszExpect = s_apszAppendTests[i + 2];
295 strcpy(szPath, pszInput);
296 RTTESTI_CHECK_RC(rc = RTPathAppend(szPath, sizeof(szPath), pszAppend), VINF_SUCCESS);
297 if (RT_FAILURE(rc))
298 continue;
299 if (strcmp(szPath, pszExpect))
300 {
301 RTTestIFailed("Unexpected result\n"
302 " input: '%s'\n"
303 " append: '%s'\n"
304 " output: '%s'\n"
305 "expected: '%s'",
306 pszInput, pszAppend, szPath, pszExpect);
307 }
308 else
309 {
310 size_t const cchResult = strlen(szPath);
311
312 strcpy(szPath, pszInput);
313 RTTESTI_CHECK_RC(rc = RTPathAppend(szPath, cchResult + 2, pszAppend), VINF_SUCCESS);
314 RTTESTI_CHECK(RT_FAILURE(rc) || !strcmp(szPath, pszExpect));
315
316 strcpy(szPath, pszInput);
317 RTTESTI_CHECK_RC(rc = RTPathAppend(szPath, cchResult + 1, pszAppend), VINF_SUCCESS);
318 RTTESTI_CHECK(RT_FAILURE(rc) || !strcmp(szPath, pszExpect));
319
320 if (strlen(pszInput) < cchResult)
321 {
322 strcpy(szPath, pszInput);
323 RTTESTI_CHECK_RC(RTPathAppend(szPath, cchResult, pszAppend), VERR_BUFFER_OVERFLOW);
324 }
325 }
326 }
327
328 /*
329 * RTPathJoin - reuse the append tests.
330 */
331 RTTestSub(hTest, "RTPathJoin");
332 for (unsigned i = 0; i < RT_ELEMENTS(s_apszAppendTests); i += 3)
333 {
334 const char *pszInput = s_apszAppendTests[i];
335 const char *pszAppend = s_apszAppendTests[i + 1];
336 const char *pszExpect = s_apszAppendTests[i + 2];
337
338 memset(szPath, 'a', sizeof(szPath)); szPath[sizeof(szPath) - 1] = '\0';
339
340 RTTESTI_CHECK_RC(rc = RTPathJoin(szPath, sizeof(szPath), pszInput, pszAppend), VINF_SUCCESS);
341 if (RT_FAILURE(rc))
342 continue;
343 if (strcmp(szPath, pszExpect))
344 {
345 RTTestIFailed("Unexpected result\n"
346 " input: '%s'\n"
347 " append: '%s'\n"
348 " output: '%s'\n"
349 "expected: '%s'",
350 pszInput, pszAppend, szPath, pszExpect);
351 }
352 else
353 {
354 size_t const cchResult = strlen(szPath);
355
356 memset(szPath, 'a', sizeof(szPath)); szPath[sizeof(szPath) - 1] = '\0';
357 RTTESTI_CHECK_RC(rc = RTPathJoin(szPath, cchResult + 2, pszInput, pszAppend), VINF_SUCCESS);
358 RTTESTI_CHECK(RT_FAILURE(rc) || !strcmp(szPath, pszExpect));
359
360 memset(szPath, 'a', sizeof(szPath)); szPath[sizeof(szPath) - 1] = '\0';
361 RTTESTI_CHECK_RC(rc = RTPathJoin(szPath, cchResult + 1, pszInput, pszAppend), VINF_SUCCESS);
362 RTTESTI_CHECK(RT_FAILURE(rc) || !strcmp(szPath, pszExpect));
363
364 RTTESTI_CHECK_RC(rc = RTPathJoin(szPath, cchResult, pszInput, pszAppend), VERR_BUFFER_OVERFLOW);
365 }
366 }
367
368 /*
369 * RTPathStripTrailingSlash
370 */
371 static const char *s_apszStripTrailingSlash[] =
372 {
373 /* input result */
374 "/", "/",
375 "//", "/",
376 "////////////////////", "/",
377 "/tmp", "/tmp",
378 "/tmp////////////////", "/tmp",
379 "tmp", "tmp",
380 "tmp////////////////", "tmp",
381 "./", ".",
382#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
383 "////////////////////", "/",
384 "D:", "D:",
385 "D:/", "D:/",
386 "D:\\", "D:\\",
387 "D:\\/\\", "D:\\",
388 "D:/\\/\\", "D:/",
389 "C:/Temp", "D:/Temp",
390 "C:/Temp/", "D:/Temp/",
391 "C:/Temp\\/", "D:/Temp",
392#endif
393 };
394 for (unsigned i = 0; i < RT_ELEMENTS(s_apszStripTrailingSlash); i += 2)
395 {
396 const char *pszInput = s_apszStripTrailingSlash[i];
397 const char *pszExpect = s_apszStripTrailingSlash[i + 1];
398
399 strcpy(szPath, pszInput);
400 cch = RTPathStripTrailingSlash(szPath);
401 if (strcmp(szPath, pszExpect))
402 RTTestIFailed("Unexpected result\n"
403 " input: '%s'\n"
404 " output: '%s'\n"
405 "expected: '%s'",
406 pszInput, szPath, pszExpect);
407 else
408 RTTESTI_CHECK(cch == strlen(szPath));
409 }
410
411 /*
412 * RTPathCountComponents
413 */
414 RTTestSub(hTest, "RTPathCountComponents");
415 RTTESTI_CHECK(RTPathCountComponents("") == 0);
416 RTTESTI_CHECK(RTPathCountComponents("/") == 1);
417 RTTESTI_CHECK(RTPathCountComponents("//") == 1);
418 RTTESTI_CHECK(RTPathCountComponents("//////////////") == 1);
419 RTTESTI_CHECK(RTPathCountComponents("//////////////bin") == 2);
420 RTTESTI_CHECK(RTPathCountComponents("//////////////bin/") == 2);
421 RTTESTI_CHECK(RTPathCountComponents("//////////////bin/////") == 2);
422 RTTESTI_CHECK(RTPathCountComponents("..") == 1);
423 RTTESTI_CHECK(RTPathCountComponents("../") == 1);
424 RTTESTI_CHECK(RTPathCountComponents("../..") == 2);
425 RTTESTI_CHECK(RTPathCountComponents("../../") == 2);
426#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
427 RTTESTI_CHECK(RTPathCountComponents("d:") == 1);
428 RTTESTI_CHECK(RTPathCountComponents("d:/") == 1);
429 RTTESTI_CHECK(RTPathCountComponents("d:/\\") == 1);
430 RTTESTI_CHECK(RTPathCountComponents("d:\\") == 1);
431 RTTESTI_CHECK(RTPathCountComponents("c:\\config.sys") == 2);
432 RTTESTI_CHECK(RTPathCountComponents("c:\\windows") == 2);
433 RTTESTI_CHECK(RTPathCountComponents("c:\\windows\\") == 2);
434 RTTESTI_CHECK(RTPathCountComponents("c:\\windows\\system32") == 3);
435 RTTESTI_CHECK(RTPathCountComponents("//./C$") == 1);
436 RTTESTI_CHECK(RTPathCountComponents("\\\\.\\C$") == 1);
437 RTTESTI_CHECK(RTPathCountComponents("/\\.\\C$") == 1);
438 RTTESTI_CHECK(RTPathCountComponents("//myserver") == 1);
439 RTTESTI_CHECK(RTPathCountComponents("//myserver/") == 1);
440 RTTESTI_CHECK(RTPathCountComponents("//myserver/share") == 1);
441 RTTESTI_CHECK(RTPathCountComponents("//myserver/share/") == 1);
442 RTTESTI_CHECK(RTPathCountComponents("//myserver/share\\") == 1);
443 RTTESTI_CHECK(RTPathCountComponents("//myserver/share\\x") == 2);
444 RTTESTI_CHECK(RTPathCountComponents("//myserver/share\\x\\y") == 3);
445 RTTESTI_CHECK(RTPathCountComponents("//myserver/share\\x\\y\\") == 3);
446#endif
447
448 /*
449 * RTPathCopyComponents
450 */
451 struct
452 {
453 const char *pszSrc;
454 size_t cComponents;
455 const char *pszResult;
456 } s_aCopyComponents[] =
457 {
458 { "", 0, "" },
459 { "", 5, "" },
460 { "/", 0, "" },
461 { "/", 1, "/" },
462 { "/", 2, "/" },
463 { "/usr/bin/sed", 0, "" },
464 { "/usr/bin/sed", 1, "/" },
465 { "/usr/bin/sed", 2, "/usr/" },
466 { "/usr/bin/sed", 3, "/usr/bin/" },
467 { "/usr/bin/sed", 4, "/usr/bin/sed" },
468 { "/usr/bin/sed", 5, "/usr/bin/sed" },
469 { "/usr/bin/sed", 6, "/usr/bin/sed" },
470 { "/usr///bin/sed", 2, "/usr///" },
471 };
472 for (unsigned i = 0; i < RT_ELEMENTS(s_aCopyComponents); i++)
473 {
474 const char *pszInput = s_aCopyComponents[i].pszSrc;
475 size_t cComponents = s_aCopyComponents[i].cComponents;
476 const char *pszResult = s_aCopyComponents[i].pszResult;
477
478 memset(szPath, 'a', sizeof(szPath));
479 rc = RTPathCopyComponents(szPath, sizeof(szPath), pszInput, cComponents);
480 RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
481 if (RT_SUCCESS(rc) && strcmp(szPath, pszResult))
482 RTTestIFailed("Unexpected result\n"
483 " input: '%s' cComponents=%u\n"
484 " output: '%s'\n"
485 "expected: '%s'",
486 pszInput, cComponents, szPath, pszResult);
487 else if (RT_SUCCESS(rc))
488 {
489 RTTESTI_CHECK_RC(RTPathCopyComponents(szPath, strlen(pszResult) + 1, pszInput, cComponents), VINF_SUCCESS);
490 RTTESTI_CHECK_RC(RTPathCopyComponents(szPath, strlen(pszResult), pszInput, cComponents), VERR_BUFFER_OVERFLOW);
491 }
492 }
493
494
495 /*
496 * RTPathStripExt
497 */
498 RTTestSub(hTest, "RTPathStripExt");
499 struct
500 {
501 const char *pszSrc;
502 const char *pszResult;
503 } s_aStripExt[] =
504 {
505 { "filename.ext", "filename" },
506 { "filename.ext1.ext2.ext3", "filename.ext1.ext2" },
507 { "filename..ext", "filename." },
508 { "filename.ext.", "filename.ext" }, /** @todo This is a bit weird/wrong, but not half as weird as the way Windows+OS/2 deals with a trailing dots. */
509 };
510 for (unsigned i = 0; i < RT_ELEMENTS(s_aStripExt); i++)
511 {
512 const char *pszInput = s_aStripExt[i].pszSrc;
513 const char *pszResult = s_aStripExt[i].pszResult;
514
515 strcpy(szPath, pszInput);
516 RTPathStripExt(szPath);
517 if (strcmp(szPath, pszResult))
518 RTTestIFailed("Unexpected result\n"
519 " input: '%s'\n"
520 " output: '%s'\n"
521 "expected: '%s'",
522 pszInput, szPath, pszResult);
523 }
524
525
526 /*
527 * Summary.
528 */
529 return RTTestSummaryAndDestroy(hTest);
530}
531
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette