1 | /* $Id: tstPath.cpp 4071 2007-08-07 17:07:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * innotek Portable Runtime Testcase - Test various path functions.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 innotek 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 |
|
---|
18 | /*******************************************************************************
|
---|
19 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 | #include <iprt/path.h>
|
---|
22 | #include <iprt/runtime.h>
|
---|
23 | #include <iprt/stream.h>
|
---|
24 | #include <iprt/err.h>
|
---|
25 | #include <iprt/param.h>
|
---|
26 |
|
---|
27 |
|
---|
28 | #define CHECK_RC(method) \
|
---|
29 | do { \
|
---|
30 | rc = method; \
|
---|
31 | if (RT_FAILURE(rc)) \
|
---|
32 | { \
|
---|
33 | cErrors++; \
|
---|
34 | RTPrintf("\ntstPath: FAILED calling " #method " at line %d: rc=%Vrc\n", __LINE__, rc); \
|
---|
35 | } \
|
---|
36 | } while (0)
|
---|
37 |
|
---|
38 | int main()
|
---|
39 | {
|
---|
40 | /*
|
---|
41 | * Init RT.
|
---|
42 | */
|
---|
43 | int rc;
|
---|
44 | int cErrors = 0;
|
---|
45 | CHECK_RC(RTR3Init());
|
---|
46 | if (RT_FAILURE(rc))
|
---|
47 | return 1;
|
---|
48 |
|
---|
49 | /*
|
---|
50 | * RTPathProgram, RTPathUserHome
|
---|
51 | */
|
---|
52 | char szPath[RTPATH_MAX];
|
---|
53 | CHECK_RC(RTPathProgram(szPath, sizeof(szPath)));
|
---|
54 | if (RT_SUCCESS(rc))
|
---|
55 | RTPrintf("Program={%s}\n", szPath);
|
---|
56 | CHECK_RC(RTPathUserHome(szPath, sizeof(szPath)));
|
---|
57 | if (RT_SUCCESS(rc))
|
---|
58 | RTPrintf("UserHome={%s}\n", szPath);
|
---|
59 |
|
---|
60 | /*
|
---|
61 | * RTPathAbsEx
|
---|
62 | */
|
---|
63 | RTPrintf("tstPath: TESTING RTPathAbsEx()\n");
|
---|
64 | static const char *aInput[] =
|
---|
65 | {
|
---|
66 | // NULL, NULL, -- assertion in RTStrUtf8ToUcs2
|
---|
67 | NULL, "/absolute/..",
|
---|
68 | NULL, "/absolute\\\\../..",
|
---|
69 | NULL, "/absolute//../path",
|
---|
70 | NULL, "/absolute/../../path",
|
---|
71 | NULL, "relative/../dir\\.\\.\\.\\file.txt",
|
---|
72 | NULL, "\\",
|
---|
73 | "relative_base/dir\\", "\\from_root",
|
---|
74 | "relative_base/dir/", "relative_also",
|
---|
75 | #if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
|
---|
76 | NULL, "C:\\",
|
---|
77 | "C:\\", "..",
|
---|
78 | "C:\\temp", "..",
|
---|
79 | "C:\\VirtualBox/Machines", "..\\VirtualBox.xml",
|
---|
80 | "C:\\MustDie", "\\from_root/dir/..",
|
---|
81 | "C:\\temp", "D:\\data",
|
---|
82 | NULL, "\\\\server\\../share", // -- on Win32, GetFullPathName doesn't remove .. here
|
---|
83 | /* the three below use cases should fail with VERR_INVALID_NAME */
|
---|
84 | //NULL, "\\\\server",
|
---|
85 | //NULL, "\\\\",
|
---|
86 | //NULL, "\\\\\\something",
|
---|
87 | "\\\\server\\share_as_base", "/from_root",
|
---|
88 | "\\\\just_server", "/from_root",
|
---|
89 | "\\\\server\\share_as_base", "relative\\data",
|
---|
90 | "base", "\\\\?\\UNC\\relative/edwef/..",
|
---|
91 | "base", "\\\\?\\UNC\\relative/edwef/..",
|
---|
92 | /* this is not (and I guess should not be) supported, should fail */
|
---|
93 | ///@todo "\\\\?\\UNC\\base", "/from_root",
|
---|
94 | #else
|
---|
95 | "\\temp", "..",
|
---|
96 | "\\VirtualBox/Machines", "..\\VirtualBox.xml",
|
---|
97 | "\\MustDie", "\\from_root/dir/..",
|
---|
98 | "\\temp", "\\data",
|
---|
99 | #endif
|
---|
100 | };
|
---|
101 |
|
---|
102 | for (unsigned i = 0; i < ELEMENTS(aInput); i += 2)
|
---|
103 | {
|
---|
104 | RTPrintf("tstPath: base={%s}, path={%s}, ", aInput[i], aInput[i + 1]);
|
---|
105 | CHECK_RC(RTPathAbsEx(aInput[i], aInput[i + 1], szPath, sizeof(szPath)));
|
---|
106 | if (RT_SUCCESS(rc))
|
---|
107 | RTPrintf("abs={%s}\n", szPath);
|
---|
108 | }
|
---|
109 |
|
---|
110 | /*
|
---|
111 | * Summary.
|
---|
112 | */
|
---|
113 | if (!cErrors)
|
---|
114 | RTPrintf("tstTimer: SUCCESS\n");
|
---|
115 | else
|
---|
116 | RTPrintf("tstTimer: FAILURE %d errors\n", cErrors);
|
---|
117 | return !!cErrors;
|
---|
118 | }
|
---|
119 |
|
---|