VirtualBox

source: vbox/trunk/src/VBox/GuestHost/DragAndDrop/testcase/tstDnDPath.cpp@ 86194

Last change on this file since 86194 was 85660, checked in by vboxsync, 4 years ago

DnD/GuestHost: Fixed testcases.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1/* $Id: tstDnDPath.cpp 85660 2020-08-10 11:29:43Z vboxsync $ */
2/** @file
3 * DnD path 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/path.h>
22#include <iprt/string.h>
23#include <iprt/test.h>
24
25#include <VBox/GuestHost/DragAndDrop.h>
26
27
28static void tstPathRebase(RTTEST hTest)
29{
30 struct
31 {
32 char const *pszPath;
33 char const *pszPathOld;
34 char const *pszPathNew;
35 int rc;
36 char const *pszResult;
37 } aTests[] = {
38 /* Invalid stuff. */
39 { NULL, NULL, NULL, VERR_INVALID_POINTER, NULL },
40 { "foo", "old", NULL, VERR_INVALID_POINTER, NULL },
41 /* Actual rebasing. */
42 { "old/foo", "old", "new", VINF_SUCCESS, "new/foo" },
43 /* Note: DnDPathRebase intentionally does not do any path conversions. */
44#ifdef RT_OS_WINDOWS
45 { "old\\foo", "old", "new", VINF_SUCCESS, "new/foo" },
46 { "\\totally\\different\\path\\foo", "/totally/different/path", "/totally/different/path", VINF_SUCCESS, "/totally/different/path/foo" },
47 { "\\old\\path\\foo", "", "/new/root/", VINF_SUCCESS, "/new/root/old/path/foo" },
48 { "\\\\old\\path\\\\foo", "", "/new/root/", VINF_SUCCESS, "/new/root/old/path\\\\foo" }
49#else
50 { "old/foo", "old", "new", VINF_SUCCESS, "new/foo" },
51 { "/totally/different/path/foo", "/totally/different/path", "/totally/different/path", VINF_SUCCESS, "/totally/different/path/foo" },
52 { "/old/path/foo", "", "/new/root/", VINF_SUCCESS, "/new/root/old/path/foo" },
53 { "//old/path//foo", "", "/new/root/", VINF_SUCCESS, "/new/root/old/path//foo" }
54#endif
55 };
56
57 char *pszPath = NULL;
58 for (size_t i = 0; i < RT_ELEMENTS(aTests); i++)
59 {
60 RTTEST_CHECK_RC(hTest, DnDPathRebase(aTests[i].pszPath, aTests[i].pszPathOld, aTests[i].pszPathNew, &pszPath), aTests[i].rc);
61 if (RT_SUCCESS(aTests[i].rc))
62 {
63 if (aTests[i].pszResult)
64 RTTEST_CHECK_MSG(hTest, RTPathCompare(pszPath, aTests[i].pszResult) == 0,
65 (hTest, "Test #%zu failed: Got '%s', expected '%s'", i, pszPath, aTests[i].pszResult));
66 RTStrFree(pszPath);
67 pszPath = NULL;
68 }
69 }
70}
71
72int main()
73{
74 /*
75 * Init the runtime, test and say hello.
76 */
77 RTTEST hTest;
78 int rc = RTTestInitAndCreate("tstDnDPath", &hTest);
79 if (rc)
80 return rc;
81 RTTestBanner(hTest);
82
83 tstPathRebase(hTest);
84
85 return RTTestSummaryAndDestroy(hTest);
86}
87
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