VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTFileQuerySize-1.cpp@ 97728

Last change on this file since 97728 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/* $Id: tstRTFileQuerySize-1.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTFileQuerySize.
4 */
5
6/*
7 * Copyright (C) 2011-2022 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/file.h>
42
43#include <iprt/err.h>
44#include <iprt/initterm.h>
45#include <iprt/path.h>
46#include <iprt/string.h>
47#include <iprt/test.h>
48
49
50static void test1(const char *pszSubTest, const char *pszFilename)
51{
52 int rc;
53 RTTestISub(pszSubTest);
54
55 RTFILE hFile;
56 rc = RTFileOpen(&hFile, pszFilename, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN);
57 if (RT_FAILURE(rc))
58 {
59 if ( rc == VERR_ACCESS_DENIED
60 || rc == VERR_PERMISSION_DENIED
61 || rc == VERR_FILE_NOT_FOUND)
62 {
63 RTTestIPrintf(RTTESTLVL_ALWAYS, "Cannot access '%s', skipping.", pszFilename);
64 return;
65 }
66 RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile, pszFilename, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN), VINF_SUCCESS);
67 }
68
69 uint64_t cbFile = UINT64_MAX - 42;
70 RTTESTI_CHECK_RC(rc = RTFileQuerySize(hFile, &cbFile), VINF_SUCCESS);
71 if (RT_SUCCESS(rc))
72 {
73 RTTESTI_CHECK(cbFile != UINT64_MAX - 42);
74 RTTestIValue(pszSubTest, cbFile, RTTESTUNIT_BYTES);
75 }
76
77 RTFileClose(hFile);
78 RTTestISubDone();
79}
80
81
82int main(int argc, char **argv)
83{
84 RTTEST hTest;
85 int rc = RTTestInitAndCreate("tstRTFileQuerySize-1", &hTest);
86 if (rc)
87 return rc;
88 RTTestBanner(hTest);
89
90 for (int i = 0; i < argc; i++)
91 {
92 char *pszNm = RTPathFilename(argv[i]);
93 if (!pszNm)
94 pszNm = argv[i];
95 test1(pszNm, argv[i]);
96 }
97
98#ifdef RT_OS_WINDOWS
99 test1("//./PhysicalDrive0", "//./PhysicalDrive0");
100 test1("//./HarddiskVolume1", "//./HarddiskVolume1");
101 test1("//./nul", "//./nul");
102#else
103 test1("/dev/null", "/dev/null");
104# ifdef RT_OS_LINUX
105 test1("/dev/sda", "/dev/sda");
106 test1("/dev/sda1", "/dev/sda1");
107 test1("/dev/sda5", "/dev/sda5");
108# endif
109#endif
110
111 /*
112 * Summary.
113 */
114 return RTTestSummaryAndDestroy(hTest);
115}
116
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