VirtualBox

source: vbox/trunk/src/VBox/Main/testcase/tstGuestCtrlPaths.cpp@ 97436

Last change on this file since 97436 was 97304, checked in by vboxsync, 2 years ago

Main/Guest Control: Added a force parameter to GuestPath::Translate() and made a little more flexible wrt same-same conversions. Adjusted testcase. ​bugref:10286

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.1 KB
Line 
1/* $Id */
2/** @file
3 * Guest Control path test cases.
4 */
5
6/*
7 * Copyright (C) 2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#define LOG_ENABLED
29#define LOG_GROUP LOG_GROUP_MAIN
30#include <VBox/log.h>
31
32#include "../include/GuestCtrlImplPrivate.h"
33
34using namespace com;
35
36#include <iprt/env.h>
37#include <iprt/rand.h>
38#include <iprt/stream.h>
39#include <iprt/test.h>
40
41
42DECLINLINE(void) tstPathTranslate(Utf8Str strPath, PathStyle_T enmSrcPathStyle, PathStyle_T enmDstPathStyle, int rcExp, Utf8Str strPathExp)
43{
44 Utf8Str strPath2 = strPath; \
45 int vrc = GuestPath::Translate(strPath2, enmSrcPathStyle, enmDstPathStyle);
46 RTTESTI_CHECK_MSG_RETV(vrc == rcExp, ("Expected %Rrc, got %Rrc for '%s'\n", rcExp, vrc, strPath.c_str()));
47 RTTESTI_CHECK_MSG_RETV(strPath2 == strPathExp, ("Expected '%s', got '%s'\n", strPathExp.c_str(), strPath2.c_str()));
48}
49
50int main()
51{
52 RTTEST hTest;
53 int vrc = RTTestInitAndCreate("tstGuestCtrlPaths", &hTest);
54 if (vrc)
55 return vrc;
56 RTTestBanner(hTest);
57
58 RTTestIPrintf(RTTESTLVL_DEBUG, "Initializing COM...\n");
59 HRESULT hrc = com::Initialize();
60 if (FAILED(hrc))
61 {
62 RTTestFailed(hTest, "Failed to initialize COM (%Rhrc)!\n", hrc);
63 return RTEXITCODE_FAILURE;
64 }
65
66 /* Don't let the assertions trigger here
67 * -- we rely on the return values in the test(s) below. */
68 RTAssertSetQuiet(true);
69
70 tstPathTranslate("", PathStyle_DOS, PathStyle_DOS, VINF_SUCCESS, "");
71
72 tstPathTranslate("foo", PathStyle_DOS, PathStyle_DOS, VINF_SUCCESS, "foo");
73 tstPathTranslate("foo", PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "foo");
74 tstPathTranslate("foo", PathStyle_DOS, PathStyle_UNIX, VINF_SUCCESS, "foo");
75 tstPathTranslate("foo", PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "foo");
76
77 tstPathTranslate("foo\\bar", PathStyle_DOS, PathStyle_DOS, VINF_SUCCESS, "foo\\bar");
78 tstPathTranslate("foo/bar", PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "foo/bar");
79
80 tstPathTranslate("foo\\bar\\", PathStyle_DOS, PathStyle_DOS, VINF_SUCCESS, "foo\\bar\\");
81 tstPathTranslate("foo/bar/", PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "foo/bar/");
82 /* Actually also allowed on Windows. */
83 tstPathTranslate("foo/bar/", PathStyle_DOS, PathStyle_UNIX, VINF_SUCCESS, "foo/bar/");
84
85 tstPathTranslate("foo\\bar\\BAZ", PathStyle_DOS, PathStyle_DOS, VINF_SUCCESS, "foo\\bar\\BAZ");
86 tstPathTranslate("foo/bar/BAZ", PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "foo/bar/BAZ");
87
88 tstPathTranslate("foo\\bar\\dir with space\\", PathStyle_DOS, PathStyle_UNIX, VINF_SUCCESS, "foo/bar/dir with space/");
89 tstPathTranslate("foo/bar/dir with space/", PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "foo/bar/dir with space/");
90
91 /** Do a mapping of "\", which marks an escape sequence for paths on UNIX-y OSes to DOS-based OSes (like Windows),
92 * however, on DOS "\" is a path separator. See @bugref{21095} */
93 tstPathTranslate("foo/bar/dir_with_escape_sequence\\ space", PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "foo/bar/dir_with_escape_sequence\\ space");
94 tstPathTranslate("foo/bar/dir_with_escape_sequence\\ space", PathStyle_UNIX, PathStyle_DOS, VINF_SUCCESS, "foo\\bar\\dir_with_escape_sequence space");
95 tstPathTranslate("foo/bar/1_dir_with_escape_sequence/the\\ space", PathStyle_UNIX, PathStyle_DOS, VINF_SUCCESS, "foo\\bar\\1_dir_with_escape_sequence\\the space");
96 tstPathTranslate("foo/bar/2_dir_with_escape_sequence/the\\ \\ space", PathStyle_UNIX, PathStyle_DOS, VINF_SUCCESS, "foo\\bar\\2_dir_with_escape_sequence\\the space");
97 tstPathTranslate("foo/bar/dir_with_escape_sequence/spaces at end\\ \\ ", PathStyle_UNIX, PathStyle_DOS, VINF_SUCCESS, "foo\\bar\\dir_with_escape_sequence\\spaces at end ");
98
99 /* Filter out double slashes (cosmetic only). */
100 tstPathTranslate("\\\\", PathStyle_DOS, PathStyle_DOS, VINF_SUCCESS, "\\");
101 tstPathTranslate("foo\\\\bar\\", PathStyle_DOS, PathStyle_DOS, VINF_SUCCESS, "foo\\bar\\");
102
103 /* Mixed slashes. */
104 tstPathTranslate("\\\\foo/bar\\\\baz", PathStyle_UNIX, PathStyle_UNIX, VINF_SUCCESS, "\\foo/bar\\baz");
105 tstPathTranslate("with spaces\\ foo/\\ bar", PathStyle_UNIX, PathStyle_DOS, VINF_SUCCESS, "with spaces foo\\ bar");
106
107 RTTestIPrintf(RTTESTLVL_DEBUG, "Shutting down COM...\n");
108 com::Shutdown();
109
110 /*
111 * Summary.
112 */
113 return RTTestSummaryAndDestroy(hTest);
114}
115
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