VirtualBox

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

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

RT_OS_* and RT_ARCH_* for Runtime/ and Support/

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1/* $Id: tstPath.cpp 3672 2007-07-17 12:39:30Z 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
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 NULL, "\\",
72 "relative_base/dir\\", "\\from_root",
73 "relative_base/dir/", "relative_also",
74#if defined (RT_OS_OS2) || defined (RT_OS_WINDOWS)
75 NULL, "C:\\",
76 "C:\\", "..",
77 "C:\\temp", "..",
78 "C:\\VirtualBox/Machines", "..\\VirtualBox.xml",
79 "C:\\MustDie", "\\from_root/dir/..",
80 "C:\\temp", "D:\\data",
81 NULL, "\\\\server\\../share", // -- on Win32, GetFullPathName doesn't remove .. here
82 /* the three below use cases should fail with VERR_INVALID_NAME */
83 //NULL, "\\\\server",
84 //NULL, "\\\\",
85 //NULL, "\\\\\\something",
86 "\\\\server\\share_as_base", "/from_root",
87 "\\\\just_server", "/from_root",
88 "\\\\server\\share_as_base", "relative\\data",
89 "base", "\\\\?\\UNC\\relative/edwef/..",
90 "base", "\\\\?\\UNC\\relative/edwef/..",
91 /* this is not (and I guess should not be) supported, should fail */
92 ///@todo "\\\\?\\UNC\\base", "/from_root",
93#else
94 "\\temp", "..",
95 "\\VirtualBox/Machines", "..\\VirtualBox.xml",
96 "\\MustDie", "\\from_root/dir/..",
97 "\\temp", "\\data",
98#endif
99 };
100
101 for (unsigned i = 0; i < ELEMENTS(aInput); i += 2)
102 {
103 RTPrintf("tstPath: base={%s}, path={%s}, ", aInput[i], aInput[i + 1]);
104 CHECK_RC(RTPathAbsEx(aInput[i], aInput[i + 1], szPath, sizeof(szPath)));
105 if (RT_SUCCESS(rc))
106 RTPrintf("abs={%s}\n", szPath);
107 }
108
109 /*
110 * Summary.
111 */
112 if (!cErrors)
113 RTPrintf("tstTimer: SUCCESS\n");
114 else
115 RTPrintf("tstTimer: FAILURE %d errors\n", cErrors);
116 return !!cErrors;
117}
118
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