VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstPath.cpp@ 4029

Last change on this file since 4029 was 4029, checked in by vboxsync, 18 years ago

Added missing checks and a fallback path for RTPathUserHome.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.4 KB
Line 
1/* $Id: tstPath.cpp 4029 2007-08-03 22:00:58Z 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 * 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
42int 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, RTPathUserHome
55 */
56 char szPath[RTPATH_MAX];
57 CHECK_RC(RTPathProgram(szPath, sizeof(szPath)));
58 if (RT_SUCCESS(rc))
59 RTPrintf("Program={%s}\n", szPath);
60 CHECK_RC(RTPathUserHome(szPath, sizeof(szPath)));
61 if (RT_SUCCESS(rc))
62 RTPrintf("UserHome={%s}\n", szPath);
63
64 /*
65 * RTPathAbsEx
66 */
67 RTPrintf("tstPath: TESTING RTPathAbsEx()\n");
68 static const char *aInput[] =
69 {
70 // NULL, NULL, -- assertion in RTStrUtf8ToUcs2
71 NULL, "/absolute/..",
72 NULL, "/absolute\\\\../..",
73 NULL, "/absolute//../path",
74 NULL, "/absolute/../../path",
75 NULL, "relative/../dir\\.\\.\\.\\file.txt",
76 NULL, "\\",
77 "relative_base/dir\\", "\\from_root",
78 "relative_base/dir/", "relative_also",
79#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
80 NULL, "C:\\",
81 "C:\\", "..",
82 "C:\\temp", "..",
83 "C:\\VirtualBox/Machines", "..\\VirtualBox.xml",
84 "C:\\MustDie", "\\from_root/dir/..",
85 "C:\\temp", "D:\\data",
86 NULL, "\\\\server\\../share", // -- on Win32, GetFullPathName doesn't remove .. here
87 /* the three below use cases should fail with VERR_INVALID_NAME */
88 //NULL, "\\\\server",
89 //NULL, "\\\\",
90 //NULL, "\\\\\\something",
91 "\\\\server\\share_as_base", "/from_root",
92 "\\\\just_server", "/from_root",
93 "\\\\server\\share_as_base", "relative\\data",
94 "base", "\\\\?\\UNC\\relative/edwef/..",
95 "base", "\\\\?\\UNC\\relative/edwef/..",
96 /* this is not (and I guess should not be) supported, should fail */
97 ///@todo "\\\\?\\UNC\\base", "/from_root",
98#else
99 "\\temp", "..",
100 "\\VirtualBox/Machines", "..\\VirtualBox.xml",
101 "\\MustDie", "\\from_root/dir/..",
102 "\\temp", "\\data",
103#endif
104 };
105
106 for (unsigned i = 0; i < ELEMENTS(aInput); i += 2)
107 {
108 RTPrintf("tstPath: base={%s}, path={%s}, ", aInput[i], aInput[i + 1]);
109 CHECK_RC(RTPathAbsEx(aInput[i], aInput[i + 1], szPath, sizeof(szPath)));
110 if (RT_SUCCESS(rc))
111 RTPrintf("abs={%s}\n", szPath);
112 }
113
114 /*
115 * Summary.
116 */
117 if (!cErrors)
118 RTPrintf("tstTimer: SUCCESS\n");
119 else
120 RTPrintf("tstTimer: FAILURE %d errors\n", cErrors);
121 return !!cErrors;
122}
123
Note: See TracBrowser for help on using the repository browser.

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