tstFile.cpp revision a0561e53976ea3d22c8fc2735c144dff7791fa1b
/* $Id$ */
/** @file
* innotek Portable Runtime Testcase - File I/O.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
int main()
{
int cErrors = 0;
RTPrintf("tstFile: TESTING\n");
RTR3Init();
int rc = RTFileOpen(&File, "tstFile#1.tst", RTFILE_O_READWRITE | RTFILE_O_CREATE_REPLACE | RTFILE_O_DENY_NONE);
if (RT_FAILURE(rc))
{
return 1;
}
/* grow file beyond 2G */
if (RT_FAILURE(rc))
{
cErrors++;
}
else
{
if (RT_FAILURE(rc))
{
cErrors++;
}
{
cErrors++;
}
else
/*
* Try some writes at the beginning of the file.
*/
if (offFile != 0)
{
cErrors++;
}
static const char szTestBuf[] = "Sausages and bacon for breakfast again!";
{
if (RT_FAILURE(rc))
break;
}
if (RT_FAILURE(rc))
{
cErrors++;
}
else
{
/* check that it was written correctly. */
if (RT_FAILURE(rc))
{
cErrors++;
}
else
{
{
if (RT_FAILURE(rc))
break;
cbRead += cbReadPart;
}
if (RT_FAILURE(rc))
{
cErrors++;
}
else
{
RTPrintf("tstFile: head write ok\n");
else
{
RTPrintf("Data read from file #1 at offset 0 differs from what we wrote there.\n");
cErrors++;
}
}
}
}
/*
* Try some writes at the end of the file.
*/
if (RT_FAILURE(rc))
{
cErrors++;
}
else
{
{
cErrors++;
}
else
{
{
if (RT_FAILURE(rc))
break;
}
if (RT_FAILURE(rc))
{
cErrors++;
}
else
{
if (RT_FAILURE(rc))
{
cErrors++;
}
else
{
{
if (RT_FAILURE(rc))
break;
cbRead += cbReadPart;
}
if (RT_FAILURE(rc))
{
cErrors++;
}
else
{
RTPrintf("tstFile: tail write ok\n");
else
{
RTPrintf("Data read from file #1 at offset 2G + 1M differs from what we wrote there.\n");
cErrors++;
}
}
}
}
}
}
/*
* Some general seeking around.
*/
if (RT_FAILURE(rc))
{
cErrors++;
}
else
{
{
cErrors++;
}
}
/* seek end */
if (RT_FAILURE(rc))
{
cErrors++;
}
else
{
{
cErrors++;
}
}
/* seek start */
if (RT_FAILURE(rc))
{
cErrors++;
}
else
{
if (offFile != 0)
{
cErrors++;
}
}
}
/*
* Cleanup.
*/
if (RT_FAILURE(rc))
{
cErrors++;
}
if (RT_FAILURE(rc))
{
cErrors++;
}
/*
* Summary
*/
if (cErrors == 0)
RTPrintf("tstFile: SUCCESS\n");
else
return !!cErrors;
}