1 | /* $Id: tstDnDPath.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DnD path tests.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2020-2023 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 | #include <iprt/assert.h>
|
---|
29 | #include <iprt/env.h>
|
---|
30 | #include <iprt/errcore.h>
|
---|
31 | #include <iprt/path.h>
|
---|
32 | #include <iprt/string.h>
|
---|
33 | #include <iprt/test.h>
|
---|
34 |
|
---|
35 | #include <VBox/GuestHost/DragAndDrop.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | static void tstPathRebase(RTTEST hTest)
|
---|
39 | {
|
---|
40 | static struct
|
---|
41 | {
|
---|
42 | char const *pszPath;
|
---|
43 | char const *pszPathOld;
|
---|
44 | char const *pszPathNew;
|
---|
45 | int rc;
|
---|
46 | char const *pszResult;
|
---|
47 | } const s_aTests[] = {
|
---|
48 | /* Invalid stuff. */
|
---|
49 | { NULL, NULL, NULL, VERR_INVALID_POINTER, NULL },
|
---|
50 | { "foo", "old", NULL, VERR_INVALID_POINTER, NULL },
|
---|
51 | /* Actual rebasing. */
|
---|
52 | { "old/foo", "old", "new", VINF_SUCCESS, "new/foo" },
|
---|
53 | /* Note: DnDPathRebase intentionally does not do any path conversions. */
|
---|
54 | #ifdef RT_OS_WINDOWS
|
---|
55 | { "old\\foo", "old", "new", VINF_SUCCESS, "new/foo" },
|
---|
56 | { "\\totally\\different\\path\\foo", "/totally/different/path", "/totally/different/path", VINF_SUCCESS, "/totally/different/path/foo" },
|
---|
57 | { "\\old\\path\\foo", "", "/new/root/", VINF_SUCCESS, "/new/root/old/path/foo" },
|
---|
58 | { "\\\\old\\path\\\\foo", "", "/new/root/", VINF_SUCCESS, "/new/root/old/path\\\\foo" }
|
---|
59 | #else
|
---|
60 | { "old/foo", "old", "new", VINF_SUCCESS, "new/foo" },
|
---|
61 | { "/totally/different/path/foo", "/totally/different/path", "/totally/different/path", VINF_SUCCESS, "/totally/different/path/foo" },
|
---|
62 | { "/old/path/foo", "", "/new/root/", VINF_SUCCESS, "/new/root/old/path/foo" },
|
---|
63 | { "//old/path//foo", "", "/new/root/", VINF_SUCCESS, "/new/root/old/path//foo" }
|
---|
64 | #endif
|
---|
65 | };
|
---|
66 |
|
---|
67 | char *pszPath = NULL;
|
---|
68 | for (size_t i = 0; i < RT_ELEMENTS(s_aTests); i++)
|
---|
69 | {
|
---|
70 | RTTestDisableAssertions(hTest);
|
---|
71 | RTTEST_CHECK_RC(hTest, DnDPathRebase(s_aTests[i].pszPath, s_aTests[i].pszPathOld, s_aTests[i].pszPathNew, &pszPath),
|
---|
72 | s_aTests[i].rc);
|
---|
73 | RTTestRestoreAssertions(hTest);
|
---|
74 | if (RT_SUCCESS(s_aTests[i].rc))
|
---|
75 | {
|
---|
76 | if (s_aTests[i].pszResult)
|
---|
77 | RTTEST_CHECK_MSG(hTest, RTPathCompare(pszPath, s_aTests[i].pszResult) == 0,
|
---|
78 | (hTest, "Test #%zu failed: Got '%s', expected '%s'", i, pszPath, s_aTests[i].pszResult));
|
---|
79 | RTStrFree(pszPath);
|
---|
80 | pszPath = NULL;
|
---|
81 | }
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | int main()
|
---|
86 | {
|
---|
87 | /*
|
---|
88 | * Init the runtime, test and say hello.
|
---|
89 | */
|
---|
90 | RTTEST hTest;
|
---|
91 | int rc = RTTestInitAndCreate("tstDnDPath", &hTest);
|
---|
92 | if (rc)
|
---|
93 | return rc;
|
---|
94 | RTTestBanner(hTest);
|
---|
95 |
|
---|
96 | tstPathRebase(hTest);
|
---|
97 |
|
---|
98 | return RTTestSummaryAndDestroy(hTest);
|
---|
99 | }
|
---|
100 |
|
---|