1 | /* $Id: tstRTFileGetSize-1.cpp 44529 2013-02-04 15:54:15Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT Testcase - RTFileGetSize.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2012 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 | * 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 |
|
---|
39 | static 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 | || rc == VERR_FILE_NOT_FOUND)
|
---|
51 | {
|
---|
52 | RTTestIPrintf(RTTESTLVL_ALWAYS, "Cannot access '%s', skipping.", pszFilename);
|
---|
53 | return;
|
---|
54 | }
|
---|
55 | RTTESTI_CHECK_RC_RETV(RTFileOpen(&hFile, pszFilename, RTFILE_O_READ | RTFILE_O_DENY_NONE | RTFILE_O_OPEN), VINF_SUCCESS);
|
---|
56 | }
|
---|
57 |
|
---|
58 | uint64_t cbFile = UINT64_MAX - 42;
|
---|
59 | RTTESTI_CHECK_RC(rc = RTFileGetSize(hFile, &cbFile), VINF_SUCCESS);
|
---|
60 | if (RT_SUCCESS(rc))
|
---|
61 | {
|
---|
62 | RTTESTI_CHECK(cbFile != UINT64_MAX - 42);
|
---|
63 | RTTestIValue(pszSubTest, cbFile, RTTESTUNIT_BYTES);
|
---|
64 | }
|
---|
65 |
|
---|
66 | RTFileClose(hFile);
|
---|
67 | RTTestISubDone();
|
---|
68 | }
|
---|
69 |
|
---|
70 |
|
---|
71 | int main(int argc, char **argv)
|
---|
72 | {
|
---|
73 | RTTEST hTest;
|
---|
74 | int rc = RTTestInitAndCreate("tstRTFileGetSize-1", &hTest);
|
---|
75 | if (rc)
|
---|
76 | return rc;
|
---|
77 | RTTestBanner(hTest);
|
---|
78 |
|
---|
79 | for (int i = 0; i < argc; i++)
|
---|
80 | {
|
---|
81 | char *pszNm = RTPathFilename(argv[i]);
|
---|
82 | if (!pszNm)
|
---|
83 | pszNm = argv[i];
|
---|
84 | test1(pszNm, argv[i]);
|
---|
85 | }
|
---|
86 |
|
---|
87 | #ifdef RT_OS_WINDOWS
|
---|
88 | test1("//./PhysicalDrive0", "//./PhysicalDrive0");
|
---|
89 | test1("//./HarddiskVolume1", "//./HarddiskVolume1");
|
---|
90 | test1("//./null", "//./nul");
|
---|
91 | #else
|
---|
92 | test1("/dev/null", "/dev/null");
|
---|
93 | # ifdef RT_OS_LINUX
|
---|
94 | test1("/dev/sda", "/dev/sda");
|
---|
95 | test1("/dev/sda1", "/dev/sda1");
|
---|
96 | test1("/dev/sda5", "/dev/sda5");
|
---|
97 | # endif
|
---|
98 | #endif
|
---|
99 |
|
---|
100 | /*
|
---|
101 | * Summary.
|
---|
102 | */
|
---|
103 | return RTTestSummaryAndDestroy(hTest);
|
---|
104 | }
|
---|
105 |
|
---|