VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTFsQueries.cpp@ 102647

Last change on this file since 102647 was 102647, checked in by vboxsync, 11 months ago

IPRT: Implemented RTFsMountpointsEnum(). Extended tstRTFsQueries testcase. bugref:10415

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 5.1 KB
Line 
1/* $Id: tstRTFsQueries.cpp 102647 2023-12-20 12:01:26Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTFs Queries..
4 */
5
6/*
7 * Copyright (C) 2006-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 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/path.h>
42#include <iprt/initterm.h>
43#include <iprt/stream.h>
44#include <iprt/test.h>
45#include <iprt/errcore.h>
46
47
48struct TSTCTX
49{
50 int var;
51 int rc;
52} TestCtx = { 42, VINF_SUCCESS };
53
54DECLCALLBACK(int) mountpointsEnumCallback(const char *pszMountpoint, void *pvUser)
55{
56 TSTCTX *pCtx = (TSTCTX *)pvUser;
57 RTTESTI_CHECK(pCtx->var == 42);
58
59 RTTestIPrintf(RTTESTLVL_ALWAYS, "Mountpoint: %s\n", pszMountpoint);
60
61 return pCtx->rc;
62}
63
64static void tstMountpointsEnum(RTTEST hTest)
65{
66 RTTEST_CHECK_RC_OK(hTest, RTFsMountpointsEnum(mountpointsEnumCallback, &TestCtx));
67}
68
69/** @todo r=andy Overhaul this code to make use of the RTTEST APIs. */
70int main(int argc, char **argv)
71{
72 RTTEST hTest;
73 RTEXITCODE rcExit = RTTestInitExAndCreate(argc, &argv, 0 /* fFlags */, "tstRTFsQueries", &hTest);
74 if (rcExit != RTEXITCODE_SUCCESS)
75 return rcExit;
76 RTTestBanner(hTest);
77
78 /*
79 * Process all arguments (including the executable).
80 */
81 int cErrors = 0;
82 for (int i = 0; i < argc; i++)
83 {
84 RTPrintf("tstRTFsQueries: '%s'...\n", argv[i]);
85
86 uint32_t u32Serial;
87 int rc = RTFsQuerySerial(argv[i], &u32Serial);
88 if (RT_SUCCESS(rc))
89 RTPrintf("tstRTFsQueries: u32Serial=%#010RX32\n", u32Serial);
90 else
91 {
92 RTPrintf("tstRTFsQueries: RTFsQuerySerial failed, rc=%Rrc\n", rc);
93 cErrors++;
94 }
95
96 RTFOFF cbTotal = 42;
97 RTFOFF cbFree = 42;
98 uint32_t cbBlock = 42;
99 uint32_t cbSector = 42;
100 rc = RTFsQuerySizes(argv[i], &cbTotal, &cbFree, &cbBlock, &cbSector);
101 if (RT_SUCCESS(rc))
102 RTPrintf("tstRTFsQueries: cbTotal=%RTfoff cbFree=%RTfoff cbBlock=%d cbSector=%d\n",
103 cbTotal, cbFree, cbBlock, cbSector);
104 else
105 {
106 RTPrintf("tstRTFsQueries: RTFsQuerySerial failed, rc=%Rrc\n", rc);
107 cErrors++;
108 }
109
110 rc = RTFsQuerySizes(argv[i], NULL, NULL, NULL, NULL);
111 if (RT_FAILURE(rc))
112 {
113 RTPrintf("tstRTFsQueries: RTFsQuerySizes(nop) failed, rc=%Rrc\n", rc);
114 cErrors++;
115 }
116
117 RTFSTYPE enmType;
118 rc = RTFsQueryType(argv[i], &enmType);
119 if (RT_SUCCESS(rc))
120 RTPrintf("tstRTFsQueries: file system type is '%s'\n", RTFsTypeName(enmType));
121 else
122 {
123 RTPrintf("tstRTFsQueries: RTFsQueryType failed, rc=%Rrc\n", rc);
124 cErrors++;
125 }
126
127 RTFSPROPERTIES Props;
128 rc = RTFsQueryProperties(argv[i], &Props);
129 if (RT_SUCCESS(rc))
130 RTPrintf("tstRTFsQueries: cbMaxComponent=%u %s %s %s %s %s %s\n",
131 Props.cbMaxComponent,
132 Props.fCaseSensitive ? "case" : "not-case",
133 Props.fCompressed ? "compressed" : "not-compressed",
134 Props.fFileCompression ? "file-compression" : "no-file-compression",
135 Props.fReadOnly ? "readonly" : "readwrite",
136 Props.fRemote ? "remote" : "not-remote",
137 Props.fSupportsUnicode ? "supports-unicode" : "doesn't-support-unicode");
138 else
139 {
140 RTPrintf("tstRTFsQueries: RTFsQueryProperties failed, rc=%Rrc\n", rc);
141 cErrors++;
142 }
143 }
144
145 tstMountpointsEnum(hTest);
146
147 if (cErrors)
148 RTTestFailed(hTest, "tstRTFsQueries: FAIlURE - %u errors\n", cErrors);
149
150 /*
151 * Done.
152 */
153 return RTTestSummaryAndDestroy(hTest);
154}
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