office-gobmx/store/workben/t_file.cxx

216 lines
6.1 KiB
C++
Raw Normal View History

2000-09-18 09:18:43 -05:00
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 09:18:43 -05:00
*
* $RCSfile: t_file.cxx,v $
2000-09-18 09:18:43 -05:00
*
* $Revision: 1.7 $
2000-09-18 09:18:43 -05:00
*
* last change: $Author: obo $ $Date: 2006-09-17 01:13:42 $
2000-09-18 09:18:43 -05:00
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
2000-09-18 09:18:43 -05:00
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
2000-09-18 09:18:43 -05:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
2000-09-18 09:18:43 -05:00
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2000-09-18 09:18:43 -05:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
2000-09-18 09:18:43 -05:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_store.hxx"
#define _T_FILE_CXX "$Revision: 1.7 $"
2000-09-18 09:18:43 -05:00
#ifndef _SAL_TYPES_H_
#include <sal/types.h>
#endif
#ifndef _OSL_FILE_H_
#include <osl/file.h>
#endif
#ifndef _OSL_THREAD_H_
#include <osl/thread.h>
#endif
2000-09-18 09:18:43 -05:00
#ifndef _RTL_USTRING_HXX_
#include <rtl/ustring.hxx>
#endif
#ifndef _RTL_REF_HXX_
#include <rtl/ref.hxx>
2000-09-18 09:18:43 -05:00
#endif
#ifndef _STORE_FILELCKB_HXX_
#include <store/filelckb.hxx>
#endif
#ifndef INCLUDED_STDIO_H
#include <stdio.h>
#define INCLUDED_STDIO_H
#endif
2000-09-18 09:18:43 -05:00
using namespace store;
#define TEST_PAGESIZE 16384
2000-09-18 09:18:43 -05:00
/*========================================================================
*
* main.
*
*======================================================================*/
int SAL_CALL main (int argc, char **argv)
{
if (argc < 2)
{
fprintf (stderr, "usage: t_file <output-filename>\n");
2000-09-18 09:18:43 -05:00
return 0;
}
2000-09-18 09:18:43 -05:00
rtl::Reference<OFileLockBytes> xLockBytes (new OFileLockBytes());
if (!xLockBytes.is())
2000-09-18 09:18:43 -05:00
return 0;
rtl::OUString aFilename (
2000-09-18 09:18:43 -05:00
argv[1], rtl_str_getLength(argv[1]),
osl_getThreadTextEncoding());
2000-09-18 09:18:43 -05:00
storeError eErrCode = xLockBytes->create (
aFilename.pData, store_AccessReadWrite);
if (eErrCode != store_E_None)
{
// Check reason.
if (eErrCode != store_E_NotExists)
{
fprintf (stderr, "t_file: create() error: %d\n", eErrCode);
2000-09-18 09:18:43 -05:00
return eErrCode;
}
2000-09-18 09:18:43 -05:00
// Create.
eErrCode = xLockBytes->create (
aFilename.pData, store_AccessReadCreate);
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: create() error: %d\n", eErrCode);
2000-09-18 09:18:43 -05:00
return eErrCode;
}
2000-09-18 09:18:43 -05:00
}
sal_Char buffer[TEST_PAGESIZE];
rtl_fillMemory (buffer, sizeof(buffer), sal_uInt8('B'));
2000-09-18 09:18:43 -05:00
sal_uInt32 i, k;
for (k = 0; k < 4; k++)
{
sal_uInt32 index = k * TEST_PAGESIZE / 4;
buffer[index] = 'A';
}
2000-09-18 09:18:43 -05:00
for (i = 0; i < 256; i++)
{
sal_uInt32 offset = i * TEST_PAGESIZE;
eErrCode = xLockBytes->setSize (offset + TEST_PAGESIZE);
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: setSize() error: %d\n", eErrCode);
return eErrCode;
}
2000-09-18 09:18:43 -05:00
for (k = 0; k < 4; k++)
{
sal_uInt32 magic = i * 4 + k, done = 0;
if (magic)
{
sal_uInt32 verify = 0;
eErrCode = xLockBytes->readAt (
0, &verify, sizeof(verify), done);
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: readAt() error: %d\n", eErrCode);
return eErrCode;
}
if (verify != magic)
{
// Failure.
fprintf (stderr, "Expected %d read %d\n", magic, verify);
}
}
sal_uInt32 index = k * TEST_PAGESIZE / 4;
eErrCode = xLockBytes->writeAt (
offset + index, &(buffer[index]), TEST_PAGESIZE / 4, done);
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: writeAt() error: %d\n", eErrCode);
return eErrCode;
}
magic += 1;
eErrCode = xLockBytes->writeAt (
0, &magic, sizeof(magic), done);
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: writeAt() error: %d\n", eErrCode);
return eErrCode;
}
}
}
2000-09-18 09:18:43 -05:00
eErrCode = xLockBytes->flush();
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: flush() error: %d\n", eErrCode);
2000-09-18 09:18:43 -05:00
return eErrCode;
}
sal_Char verify[TEST_PAGESIZE];
for (i = 0; i < 256; i++)
{
sal_uInt32 offset = i * TEST_PAGESIZE, done = 0;
eErrCode = xLockBytes->readAt (offset, verify, TEST_PAGESIZE, done);
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: readAt() error: %d\n", eErrCode);
return eErrCode;
}
sal_uInt32 index = 0;
if (offset == 0)
{
sal_uInt32 magic = 256 * 4;
if (rtl_compareMemory (&verify[index], &magic, sizeof(magic)))
{
// Failure.
fprintf (stderr, "t_file: Unexpected value at 0x00000000\n");
}
index += 4;
}
if (rtl_compareMemory (
&verify[index], &buffer[index], TEST_PAGESIZE - index))
{
// Failure.
fprintf (stderr, "t_file: Unexpected block at 0x%08x\n", offset);
}
}
2000-09-18 09:18:43 -05:00
xLockBytes.clear();
2000-09-18 09:18:43 -05:00
return 0;
}