VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTFileGetSize-1.cpp@ 79325

Last change on this file since 79325 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: tstRTFileGetSize-1.cpp 76553 2019-01-01 01:45:53Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTFileGetSize.
4 */
5
6/*
7 * Copyright (C) 2011-2019 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/file.h>
32
33#include <iprt/err.h>
34#include <iprt/initterm.h>
35#include <iprt/path.h>
36#include <iprt/string.h>
37#include <iprt/test.h>
38
39
40static void test1(const char *pszSubTest, const char *pszFilename)
41{
42 int rc;
43 RTTestISub(pszSubTest);
44
45 RTFILE hFile;
46 rc = RTFileOpen(&hFile, pszFilename, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN);
47 if (RT_FAILURE(rc))
48 {
49 if ( rc == VERR_ACCESS_DENIED
50 || rc == VERR_PERMISSION_DENIED
51 || rc == VERR_FILE_NOT_FOUND)
52 {
53 RTTestIPrintf(RTTESTLVL_ALWAYS, "Cannot access '%s', skipping.", pszFilename);
54 return;
55 }
56 RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile, pszFilename, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN), VINF_SUCCESS);
57 }
58
59 uint64_t cbFile = UINT64_MAX - 42;
60 RTTESTI_CHECK_RC(rc = RTFileGetSize(hFile, &cbFile), VINF_SUCCESS);
61 if (RT_SUCCESS(rc))
62 {
63 RTTESTI_CHECK(cbFile != UINT64_MAX - 42);
64 RTTestIValue(pszSubTest, cbFile, RTTESTUNIT_BYTES);
65 }
66
67 RTFileClose(hFile);
68 RTTestISubDone();
69}
70
71
72int main(int argc, char **argv)
73{
74 RTTEST hTest;
75 int rc = RTTestInitAndCreate("tstRTFileGetSize-1", &hTest);
76 if (rc)
77 return rc;
78 RTTestBanner(hTest);
79
80 for (int i = 0; i < argc; i++)
81 {
82 char *pszNm = RTPathFilename(argv[i]);
83 if (!pszNm)
84 pszNm = argv[i];
85 test1(pszNm, argv[i]);
86 }
87
88#ifdef RT_OS_WINDOWS
89 test1("//./PhysicalDrive0", "//./PhysicalDrive0");
90 test1("//./HarddiskVolume1", "//./HarddiskVolume1");
91 test1("//./null", "//./nul");
92#else
93 test1("/dev/null", "/dev/null");
94# ifdef RT_OS_LINUX
95 test1("/dev/sda", "/dev/sda");
96 test1("/dev/sda1", "/dev/sda1");
97 test1("/dev/sda5", "/dev/sda5");
98# endif
99#endif
100
101 /*
102 * Summary.
103 */
104 return RTTestSummaryAndDestroy(hTest);
105}
106
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