VirtualBox

source: vbox/trunk/src/VBox/GuestHost/DragAndDrop/testcase/tstDnDTransferObject.cpp@ 104932

Last change on this file since 104932 was 98103, checked in by vboxsync, 23 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1/* $Id: tstDnDTransferObject.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * DnD URI object (DNDTRANSFEROBJECT) 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/mem.h>
32#include <iprt/string.h>
33#include <iprt/test.h>
34
35#include <VBox/GuestHost/DragAndDrop.h>
36
37
38static void tstPaths(RTTEST hTest)
39{
40 RTTestSub(hTest, "Testing path handling");
41
42 char szBuf[64];
43
44 DNDTRANSFEROBJECT Obj;
45 RT_ZERO(Obj);
46
47 /*
48 * Initialization handling.
49 */
50 RTTEST_CHECK(hTest, DnDTransferObjectGetSourcePath(&Obj) == NULL);
51 RTTEST_CHECK_RC(hTest, DnDTransferObjectGetDestPathEx(&Obj, DNDTRANSFEROBJPATHSTYLE_TRANSPORT, szBuf, sizeof(szBuf)), VERR_NOT_FOUND);
52 RTTEST_CHECK(hTest, DnDTransferObjectGetMode(&Obj) == 0);
53 RTTEST_CHECK(hTest, DnDTransferObjectGetSize(&Obj) == 0);
54 RTTEST_CHECK(hTest, DnDTransferObjectGetProcessed(&Obj) == 0);
55 RTTEST_CHECK(hTest, DnDTransferObjectGetType(&Obj) == DNDTRANSFEROBJTYPE_UNKNOWN);
56
57 /*
58 * Paths handling.
59 */
60 RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_FILE, "", "/rel/path/to/dst"));
61 RTTestDisableAssertions(hTest);
62 RTTEST_CHECK_RC (hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_FILE, "", "/rel/path/to/dst"), VERR_WRONG_ORDER);
63 RTTestRestoreAssertions(hTest);
64 DnDTransferObjectReset(&Obj);
65
66 RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_FILE, "/src/path1", "dst/path2"));
67 RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetSourcePath(&Obj), "/src/path1/dst/path2") == 0);
68 RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/path2") == 0);
69 RTTEST_CHECK(hTest, DnDTransferObjectGetDestPathEx(&Obj, DNDTRANSFEROBJPATHSTYLE_DOS, szBuf, sizeof(szBuf)) == VINF_SUCCESS
70 && RTStrCmp(szBuf, "dst\\path2") == 0);
71 DnDTransferObjectReset(&Obj);
72 RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_FILE, "", "dst/with/ending/slash/"));
73 RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/with/ending/slash/") == 0);
74 RTTEST_CHECK(hTest, DnDTransferObjectGetDestPathEx(&Obj, DNDTRANSFEROBJPATHSTYLE_TRANSPORT, szBuf, sizeof(szBuf)) == VINF_SUCCESS
75 && RTStrCmp(szBuf, "dst/with/ending/slash/") == 0);
76 DnDTransferObjectReset(&Obj);
77 RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "", "dst/path2"));
78 RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetSourcePath(&Obj), "dst/path2/") == 0);
79 RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/path2/") == 0);
80 DnDTransferObjectReset(&Obj);
81 RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "", "dst\\to\\path2"));
82 RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetSourcePath(&Obj), "dst/to/path2/") == 0);
83 RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/to/path2/") == 0);
84 DnDTransferObjectReset(&Obj);
85 /* Test that the destination does not have a beginning slash. */
86 RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/path2", "/dst/to/path2/"));
87 RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetSourcePath(&Obj), "/src/path2/dst/to/path2/") == 0);
88 RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/to/path2/") == 0);
89 DnDTransferObjectReset(&Obj);
90 RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/path2", "//////dst/to/path2/"));
91 RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/to/path2/") == 0);
92
93 /*
94 * Invalid stuff.
95 */
96 DnDTransferObjectReset(&Obj);
97 RTTestDisableAssertions(hTest);
98 RTTEST_CHECK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/path3", "../../dst/path3") == VERR_INVALID_PARAMETER);
99 RTTEST_CHECK(hTest, DnDTransferObjectInitEx(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/../../path3", "dst/path3") == VERR_INVALID_PARAMETER);
100 RTTestRestoreAssertions(hTest);
101
102 /*
103 * Reset handling.
104 */
105 DnDTransferObjectReset(&Obj);
106 RTTEST_CHECK(hTest, DnDTransferObjectGetSourcePath(&Obj) == NULL);
107 RTTEST_CHECK(hTest, DnDTransferObjectGetDestPath(&Obj) == NULL);
108
109 DnDTransferObjectDestroy(&Obj);
110 DnDTransferObjectDestroy(&Obj); /* Doing this twice here is intentional. */
111}
112
113int main()
114{
115 /*
116 * Init the runtime, test and say hello.
117 */
118 RTTEST hTest;
119 int rc = RTTestInitAndCreate("tstDnDTransferObject", &hTest);
120 if (rc)
121 return rc;
122 RTTestBanner(hTest);
123
124 tstPaths(hTest);
125
126 return RTTestSummaryAndDestroy(hTest);
127}
128
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