1 | /* $Id: tstPath.cpp 1 1970-01-01 00:00:00Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * InnoTek Portable Runtime Testcase - Test various path functions.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006 InnoTek Systemberatung GmbH
|
---|
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 as published by the Free Software Foundation,
|
---|
13 | * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
|
---|
14 | * distribution. VirtualBox OSE is distributed in the hope that it will
|
---|
15 | * be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * If you received this file as part of a commercial VirtualBox
|
---|
18 | * distribution, then only the terms of your commercial VirtualBox
|
---|
19 | * license agreement apply instead of the previous paragraph.
|
---|
20 | */
|
---|
21 |
|
---|
22 | /*******************************************************************************
|
---|
23 | * Header Files *
|
---|
24 | *******************************************************************************/
|
---|
25 | #include <iprt/path.h>
|
---|
26 | #include <iprt/runtime.h>
|
---|
27 | #include <iprt/stream.h>
|
---|
28 | #include <iprt/err.h>
|
---|
29 | #include <iprt/param.h>
|
---|
30 |
|
---|
31 |
|
---|
32 | #define CHECK_RC(method) \
|
---|
33 | do { \
|
---|
34 | rc = method; \
|
---|
35 | if (RT_FAILURE(rc)) \
|
---|
36 | { \
|
---|
37 | cErrors++; \
|
---|
38 | RTPrintf("\ntstPath: FAILED calling " #method " at line %d: rc=%Vrc\n", __LINE__, rc); \
|
---|
39 | } \
|
---|
40 | } while (0)
|
---|
41 |
|
---|
42 | int main()
|
---|
43 | {
|
---|
44 | /*
|
---|
45 | * Init RT.
|
---|
46 | */
|
---|
47 | int rc;
|
---|
48 | int cErrors = 0;
|
---|
49 | CHECK_RC(RTR3Init());
|
---|
50 | if (RT_FAILURE(rc))
|
---|
51 | return 1;
|
---|
52 |
|
---|
53 | /*
|
---|
54 | * RTPathProgram
|
---|
55 | */
|
---|
56 | char szPath[RTPATH_MAX];
|
---|
57 | CHECK_RC(RTPathProgram(szPath, sizeof(szPath)));
|
---|
58 |
|
---|
59 | /*
|
---|
60 | * RTPathAbsEx
|
---|
61 | */
|
---|
62 | RTPrintf("tstPath: TESTING RTPathAbsEx()\n");
|
---|
63 | static const char *aInput[] =
|
---|
64 | {
|
---|
65 | // NULL, NULL, -- assertion in RTStrUtf8ToUcs2
|
---|
66 | NULL, "/absolute/..",
|
---|
67 | NULL, "/absolute\\\\../..",
|
---|
68 | NULL, "/absolute//../path",
|
---|
69 | NULL, "/absolute/../../path",
|
---|
70 | NULL, "relative/../dir\\.\\.\\.\\file.txt",
|
---|
71 | "relative_base/dir\\", "\\from_root",
|
---|
72 | "relative_base/dir/", "relative_also",
|
---|
73 | #if defined (__OS2__) || defined (__WIN__)
|
---|
74 | "C:\\temp", "..",
|
---|
75 | "C:\\VirtualBox/Machines", "..\\VirtualBox.xml",
|
---|
76 | "C:\\MustDie", "\\from_root/dir/..",
|
---|
77 | "C:\\temp", "D:\\data",
|
---|
78 | NULL, "\\\\server\\../share", // -- GetFullPathName doesn't remove .. here
|
---|
79 | "\\\\server\\share_as_base", "/from_root",
|
---|
80 | "\\\\just_server", "/from_root",
|
---|
81 | "\\\\server\\share_as_base", "relative\\data",
|
---|
82 | "base", "\\\\?\\UNC\\relative/edwef/..",
|
---|
83 | // this is not (and I guess should not be) supported
|
---|
84 | ///@todo "\\\\?\\UNC\\base", "/from_root", - r=bird: negative tests shouldn't fail the testcase!
|
---|
85 | #else
|
---|
86 | "\\temp", "..",
|
---|
87 | "\\VirtualBox/Machines", "..\\VirtualBox.xml",
|
---|
88 | "\\MustDie", "\\from_root/dir/..",
|
---|
89 | "\\temp", "\\data",
|
---|
90 | #endif
|
---|
91 | };
|
---|
92 |
|
---|
93 | for (unsigned i = 0; i < ELEMENTS(aInput); i += 2)
|
---|
94 | {
|
---|
95 | RTPrintf("tstPath: base={%s}, path={%s}, ", aInput[i], aInput[i + 1]);
|
---|
96 | CHECK_RC(RTPathAbsEx(aInput[i], aInput[i + 1], szPath, sizeof(szPath)));
|
---|
97 | if (RT_SUCCESS(rc))
|
---|
98 | RTPrintf("abs={%s}\n", szPath);
|
---|
99 | }
|
---|
100 |
|
---|
101 | /*
|
---|
102 | * Summary.
|
---|
103 | */
|
---|
104 | if (!cErrors)
|
---|
105 | RTPrintf("tstTimer: SUCCESS\n");
|
---|
106 | else
|
---|
107 | RTPrintf("tstTimer: FAILURE %d errors\n", cErrors);
|
---|
108 | return !!cErrors;
|
---|
109 | }
|
---|
110 |
|
---|