tstFileAppend-1.cpp revision e64031e20c39650a7bc902a3e1aba613b9415dee
/* $Id$ */
/** @file
* IPRT Testcase - File Appending.
*/
/*
* Copyright (C) 2009 Oracle Corporation
*
* 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 *
*******************************************************************************/
#include <iprt/initterm.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static int g_cErrors = 0;
{
RTPrintf("tstFileAppend-1: FATAL: ");
g_cErrors++;
return 1;
}
{
RTPrintf("tstFileAppend-1: ERROR: ");
g_cErrors++;
}
int main()
{
int rc;
char szBuf[256];
RTPrintf("tstFileAppend-1: TESTING...\n");
RTR3Init();
/*
* Open it write only and do some appending.
* Checking that read fails and that the file position changes after the write.
*/
"tstFileAppend-1.tst",
| (0644 << RTFILE_O_CREATE_MODE_SHIFT)
);
if (RT_FAILURE(rc))
off = 0;
if (RT_FAILURE(rc))
else if (offActual != 0)
if (RT_FAILURE(rc))
off = 0;
if (RT_FAILURE(rc))
else if (offActual != 10)
else
if (RT_SUCCESS(rc))
off = 5;
if (RT_FAILURE(rc))
else if (offActual != 5)
/*
* Open it write only and do some more appending.
* Checking the initial position and that it changes after the write.
*/
"tstFileAppend-1.tst",
);
if (RT_FAILURE(rc))
off = 0;
if (RT_FAILURE(rc))
else if (offActual != 0)
else
if (RT_FAILURE(rc))
off = 0;
if (RT_FAILURE(rc))
else if (offActual != 20)
else
/*
* Check the initial position and read stuff. Then append some more and
* check the new position and see that read returns 0/EOF. Finally,
* do some seeking and read from a new position.
*/
"tstFileAppend-1.tst",
);
if (RT_FAILURE(rc))
off = 0;
if (RT_FAILURE(rc))
else if (offActual != 0)
else
off = 0;
if (RT_FAILURE(rc))
else if (offActual != 10)
else
if (RT_FAILURE(rc))
off = 0;
if (RT_FAILURE(rc))
else if (offActual != 30)
else
off = 15;
if (RT_FAILURE(rc))
else if (offActual != 15)
else
{
off = 0;
if (RT_FAILURE(rc))
else if (offActual != 25)
else
}
/*
* Open it read only + append and check that we cannot write to it.
*/
"tstFileAppend-1.tst",
);
if (RT_FAILURE(rc))
if (RT_SUCCESS(rc))
if (g_cErrors)
RTPrintf("tstFileAppend-1: FAILED\n");
else
RTPrintf("tstFileAppend-1: SUCCESS\n");
return g_cErrors ? 1 : 0;
}