VirtualBox

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

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

iprt/path.h: Adjustments and a bunch of todos for RTPathFindCommon[Ex].

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.4 KB
Line 
1/* $Id: tstDnDPath.cpp 85382 2020-07-18 11:33:58Z 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 { "old\\foo", "old", "new", VINF_SUCCESS, "new/foo" },
44 { "\\totally\\different\\path\\foo", "/totally/different/path", "/totally/different/path", VINF_SUCCESS, "/totally/different/path/foo" },
45 { "\\old\\path\\foo", "", "/new/root/", VINF_SUCCESS, "/new/root/old/path/foo" },
46 { "\\\\old\\path\\\\foo", "", "/new/root/", VINF_SUCCESS, "/new/root/old/path\\\\foo" }
47 };
48
49 char *pszPath = NULL;
50 for (size_t i = 0; i < RT_ELEMENTS(aTests); i++)
51 {
52 RTTEST_CHECK_RC(hTest, DnDPathRebase(aTests[i].pszPath, aTests[i].pszPathOld, aTests[i].pszPathNew, &pszPath), aTests[i].rc);
53 if (RT_SUCCESS(aTests[i].rc))
54 {
55 if (aTests[i].pszResult)
56 RTTEST_CHECK_MSG(hTest, RTPathCompare(pszPath, aTests[i].pszResult) == 0,
57 (hTest, "Test #%zu failed: Got '%s', expected '%s'", i, pszPath, aTests[i].pszResult));
58 RTStrFree(pszPath);
59 pszPath = NULL;
60 }
61 }
62}
63
64int main()
65{
66 /*
67 * Init the runtime, test and say hello.
68 */
69 RTTEST hTest;
70 int rc = RTTestInitAndCreate("tstDnDPath", &hTest);
71 if (rc)
72 return rc;
73 RTTestBanner(hTest);
74
75 tstPathRebase(hTest);
76
77 return RTTestSummaryAndDestroy(hTest);
78}
79
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