1 | /* $Id: tstDnDTransferObject.cpp 85382 2020-07-18 11:33:58Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DnD URI object (DNDTRANSFEROBJECT) tests.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2020 Oracle Corporation
|
---|
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 (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | #include <iprt/assert.h>
|
---|
19 | #include <iprt/env.h>
|
---|
20 | #include <iprt/errcore.h>
|
---|
21 | #include <iprt/mem.h>
|
---|
22 | #include <iprt/string.h>
|
---|
23 | #include <iprt/test.h>
|
---|
24 |
|
---|
25 | #include <VBox/GuestHost/DragAndDrop.h>
|
---|
26 |
|
---|
27 |
|
---|
28 | static void tstPaths(RTTEST hTest)
|
---|
29 | {
|
---|
30 | RTTestSub(hTest, "Testing path handling");
|
---|
31 |
|
---|
32 | char szBuf[64];
|
---|
33 |
|
---|
34 | DNDTRANSFEROBJECT Obj;
|
---|
35 | RT_ZERO(Obj);
|
---|
36 |
|
---|
37 | /*
|
---|
38 | * Initialization handling.
|
---|
39 | */
|
---|
40 | RTTEST_CHECK(hTest, DnDTransferObjectGetSourcePath(&Obj) == NULL);
|
---|
41 | RTTEST_CHECK_RC(hTest, DnDTransferObjectGetDestPathEx(&Obj, DNDTRANSFEROBJPATHSTYLE_TRANSPORT, szBuf, sizeof(szBuf)), VERR_NOT_FOUND);
|
---|
42 | RTTEST_CHECK(hTest, DnDTransferObjectGetMode(&Obj) == 0);
|
---|
43 | RTTEST_CHECK(hTest, DnDTransferObjectGetSize(&Obj) == 0);
|
---|
44 | RTTEST_CHECK(hTest, DnDTransferObjectGetProcessed(&Obj) == 0);
|
---|
45 | RTTEST_CHECK(hTest, DnDTransferObjectGetType(&Obj) == DNDTRANSFEROBJTYPE_UNKNOWN);
|
---|
46 |
|
---|
47 | /*
|
---|
48 | * Paths handling.
|
---|
49 | */
|
---|
50 | RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_FILE, "", "/rel/path/to/dst"));
|
---|
51 | RTTEST_CHECK_RC (hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_FILE, "", "/rel/path/to/dst"), VERR_WRONG_ORDER);
|
---|
52 | DnDTransferObjectReset(&Obj);
|
---|
53 |
|
---|
54 | RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_FILE, "/src/path1", "dst/path2"));
|
---|
55 | RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetSourcePath(&Obj), "/src/path1/dst/path2") == 0);
|
---|
56 | RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/path2") == 0);
|
---|
57 | RTTEST_CHECK(hTest, DnDTransferObjectGetDestPathEx(&Obj, DNDTRANSFEROBJPATHSTYLE_DOS, szBuf, sizeof(szBuf)) == VINF_SUCCESS
|
---|
58 | && RTStrCmp(szBuf, "dst\\path2") == 0);
|
---|
59 | DnDTransferObjectReset(&Obj);
|
---|
60 | RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_FILE, "", "dst/with/ending/slash/"));
|
---|
61 | RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/with/ending/slash/") == 0);
|
---|
62 | RTTEST_CHECK(hTest, DnDTransferObjectGetDestPathEx(&Obj, DNDTRANSFEROBJPATHSTYLE_TRANSPORT, szBuf, sizeof(szBuf)) == VINF_SUCCESS
|
---|
63 | && RTStrCmp(szBuf, "dst/with/ending/slash/") == 0);
|
---|
64 | DnDTransferObjectReset(&Obj);
|
---|
65 | RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "", "dst/path2"));
|
---|
66 | RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetSourcePath(&Obj), "dst/path2/") == 0);
|
---|
67 | RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/path2/") == 0);
|
---|
68 | DnDTransferObjectReset(&Obj);
|
---|
69 | RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "", "dst\\to\\path2"));
|
---|
70 | RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetSourcePath(&Obj), "dst/to/path2/") == 0);
|
---|
71 | RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/to/path2/") == 0);
|
---|
72 | DnDTransferObjectReset(&Obj);
|
---|
73 | /* Test that the destination does not have a beginning slash. */
|
---|
74 | RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/path2", "/dst/to/path2/"));
|
---|
75 | RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetSourcePath(&Obj), "/src/path2/dst/to/path2/") == 0);
|
---|
76 | RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/to/path2/") == 0);
|
---|
77 | DnDTransferObjectReset(&Obj);
|
---|
78 | RTTEST_CHECK_RC_OK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/path2", "//////dst/to/path2/"));
|
---|
79 | RTTEST_CHECK(hTest, RTStrCmp(DnDTransferObjectGetDestPath(&Obj), "dst/to/path2/") == 0);
|
---|
80 |
|
---|
81 | /*
|
---|
82 | * Invalid stuff.
|
---|
83 | */
|
---|
84 | DnDTransferObjectReset(&Obj);
|
---|
85 | RTTEST_CHECK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/path3", "../../dst/path3") == VERR_INVALID_PARAMETER);
|
---|
86 | RTTEST_CHECK(hTest, DnDTransferObjectInit(&Obj, DNDTRANSFEROBJTYPE_DIRECTORY, "/src/../../path3", "dst/path3") == VERR_INVALID_PARAMETER);
|
---|
87 |
|
---|
88 | /*
|
---|
89 | * Reset handling.
|
---|
90 | */
|
---|
91 | DnDTransferObjectReset(&Obj);
|
---|
92 | RTTEST_CHECK(hTest, DnDTransferObjectGetSourcePath(&Obj) == NULL);
|
---|
93 | RTTEST_CHECK(hTest, DnDTransferObjectGetDestPath(&Obj) == NULL);
|
---|
94 |
|
---|
95 | DnDTransferObjectDestroy(&Obj);
|
---|
96 | DnDTransferObjectDestroy(&Obj); /* Doing this twice here is intentional. */
|
---|
97 | }
|
---|
98 |
|
---|
99 | int main()
|
---|
100 | {
|
---|
101 | /*
|
---|
102 | * Init the runtime, test and say hello.
|
---|
103 | */
|
---|
104 | RTTEST hTest;
|
---|
105 | int rc = RTTestInitAndCreate("tstDnDTransferObject", &hTest);
|
---|
106 | if (rc)
|
---|
107 | return rc;
|
---|
108 | RTTestBanner(hTest);
|
---|
109 |
|
---|
110 | tstPaths(hTest);
|
---|
111 |
|
---|
112 | return RTTestSummaryAndDestroy(hTest);
|
---|
113 | }
|
---|
114 |
|
---|