VirtualBox

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

Last change on this file since 39028 was 39028, checked in by vboxsync, 14 years ago

RTFileGetSize/win: Made it grok volume & disks (some disks anyway).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.9 KB
Line 
1/* $Id: tstRTFileGetSize-1.cpp 39028 2011-10-19 09:59:03Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTFileGetSize.
4 */
5
6/*
7 * Copyright (C) 2011 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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* Header Files *
29*******************************************************************************/
30#include <iprt/file.h>
31
32#include <iprt/err.h>
33#include <iprt/initterm.h>
34#include <iprt/path.h>
35#include <iprt/string.h>
36#include <iprt/test.h>
37
38
39static void test1(const char *pszSubTest, const char *pszFilename)
40{
41 int rc;
42 RTTestISub(pszSubTest);
43
44 RTFILE hFile;
45 rc = RTFileOpen(&hFile, pszFilename, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN);
46 if (RT_FAILURE(rc))
47 {
48 if ( rc == VERR_ACCESS_DENIED
49 || rc == VERR_PERMISSION_DENIED)
50 {
51 RTTestIPrintf(RTTESTLVL_ALWAYS, "Cannot access '%s', skipping.", pszFilename);
52 return;
53 }
54 RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile, pszFilename, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN), VINF_SUCCESS);
55 }
56
57 uint64_t cbFile = UINT64_MAX - 42;
58 RTTESTI_CHECK_RC(rc = RTFileGetSize(hFile, &cbFile), VINF_SUCCESS);
59 if (RT_SUCCESS(rc))
60 {
61 RTTESTI_CHECK(cbFile != UINT64_MAX - 42);
62 RTTestIValue(pszFilename, cbFile, RTTESTUNIT_BYTES);
63 }
64
65 RTFileClose(hFile);
66 RTTestISubDone();
67}
68
69
70int main(int argc, char **argv)
71{
72 RTTEST hTest;
73 int rc = RTTestInitAndCreate("tstRTFileGetSize-1", &hTest);
74 if (rc)
75 return rc;
76 RTTestBanner(hTest);
77
78 for (int i = 0; i < argc; i++)
79 {
80 char *pszNm = RTPathFilename(argv[i]);
81 if (!pszNm)
82 pszNm = argv[i];
83 test1(pszNm, argv[i]);
84 }
85
86#ifdef RT_OS_WINDOWS
87 test1("PhysicalDrive0", "//./PhysicalDrive0");
88 test1("HarddiskVolume1", "//./HarddiskVolume1");
89 test1("null", "//./nul");
90#else
91#endif
92
93 /*
94 * Summary.
95 */
96 return RTTestSummaryAndDestroy(hTest);
97}
98
99
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette