Remvoe store/workben/

...probably not worth dragging that unused code around any more

Change-Id: I4f22a704af862d8a1fe1f2202609f355ccee7c9c
This commit is contained in:
Stephan Bergmann 2014-11-21 14:51:45 +01:00
parent e91ab2104b
commit 4ecbc7e63c
6 changed files with 0 additions and 2585 deletions

View file

@ -1,99 +0,0 @@
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This file incorporates work covered by the following license notice:
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed
# with this work for additional information regarding copyright
# ownership. The ASF licenses this file to you under the Apache
# License, Version 2.0 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.apache.org/licenses/LICENSE-2.0 .
#
PRJ=..
PRJNAME=store
TARGET=workben
LIBTARGET=NO
TARGETTYPE=CUI
NO_DEFAULT_STL=TRUE
# --- Settings ---
.INCLUDE : settings.mk
.IF "$(STORELIB)" == ""
.IF "$(OS)" != "WNT"
STORELIB= -lstore
.ELSE # unx
.IF "$(OS)$(COM)"=="WNTGCC"
STORELIB= -lstore$(UDK_MAJOR)
.ELSE
STORELIB= $(LB)$/istore.lib
.ENDIF
.ENDIF # unx
.ENDIF # storelib
.IF "$(OS)" != "WNT"
STOREDBGLIB= $(LB)$/libstoredbg.a
.ELSE # unx
.IF "$(OS)$(COM)"=="WNTGCC"
STOREDBGLIB= $(LB)$/libstoredbg.a
.ELSE
STOREDBGLIB= $(LB)$/storedbg.lib
.ENDIF
.ENDIF # unx
CFLAGS+= -I..$/source
# --- Files ---
OBJFILES= \
$(OBJ)$/t_leak.obj \
$(OBJ)$/t_file.obj \
$(OBJ)$/t_page.obj \
$(OBJ)$/t_base.obj \
$(OBJ)$/t_store.obj
APP1TARGET= t_file
APP1OBJS= $(OBJ)$/t_file.obj
APP1STDLIBS= $(STOREDBGLIB)
APP1STDLIBS+= $(SALLIB)
APP1DEPN= $(STOREDBGLIB)
APP1RPATH= UREBIN
APP2TARGET= t_page
APP2OBJS= $(OBJ)$/t_page.obj
APP2STDLIBS= $(STOREDBGLIB)
APP2STDLIBS+= $(SALLIB)
APP2DEPN= $(STOREDBGLIB)
APP3TARGET= t_base
APP3OBJS= $(OBJ)$/t_base.obj
APP3STDLIBS= $(STOREDBGLIB)
APP3STDLIBS+= $(SALLIB)
APP3DEPN= $(STOREDBGLIB)
APP3RPATH= UREBIN
APP4TARGET= t_store
APP4OBJS= $(OBJ)$/t_store.obj
APP4STDLIBS= $(STORELIB)
APP4STDLIBS+= $(SALLIB)
APP4DEPN= $(SLB)$/store.lib
APP4RPATH= UREBIN
APP5TARGET= t_leak
APP5OBJS= $(OBJ)$/t_leak.obj
APP5STDLIBS+= $(SALLIB)
# --- Targets ---
.INCLUDE : target.mk

View file

@ -1,346 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <string.h>
#include "sal/types.h"
#include "osl/diagnose.h"
#include "osl/thread.h"
#include "rtl/ustring.hxx"
#include "object.hxx"
#include "storbase.hxx"
#include "storbios.hxx"
#include "lockbyte.hxx"
using namespace store;
#define TEST_PAGESIZE 1024
/*========================================================================
*
* OTestObject.
*
*======================================================================*/
class OTestObject : public store::OStoreObject
{
public:
OTestObject (void);
virtual sal_Bool SAL_CALL isKindOf (sal_uInt32 nTypeId);
protected:
virtual ~OTestObject (void);
};
OTestObject::OTestObject (void)
{
}
OTestObject::~OTestObject (void)
{
}
sal_Bool SAL_CALL OTestObject::isKindOf (sal_uInt32 nTypeId)
{
return (nTypeId == 42);
}
namespace store
{
static OTestObject* SAL_CALL query (IStoreHandle *pHandle, OTestObject*)
{
if (pHandle && pHandle->isKindOf (42))
return static_cast<OTestObject*>(pHandle);
else
return 0;
}
}
/*========================================================================
*
* OTestBIOS.
*
*======================================================================*/
namespace store
{
class OTestBIOS : public store::OStorePageBIOS
{
typedef store::OStorePageBIOS base;
friend OTestBIOS* SAL_CALL query<> (IStoreHandle * pHandle, OTestBIOS *);
public:
OTestBIOS (void);
virtual storeError initialize (
ILockBytes * pLockBytes,
storeAccessMode eAccessMode,
sal_uInt16 & rnPageSize);
virtual sal_Bool SAL_CALL isKindOf (sal_uInt32 nTypeId);
protected:
virtual ~OTestBIOS (void);
};
} // namespace store
OTestBIOS::OTestBIOS (void)
{
}
OTestBIOS::~OTestBIOS (void)
{
}
sal_Bool SAL_CALL OTestBIOS::isKindOf (sal_uInt32 nTypeId)
{
return (nTypeId == 4242);
}
storeError OTestBIOS::initialize (
ILockBytes *pLockBytes, storeAccessMode eAccessMode, sal_uInt16 & rnPageSize)
{
return base::initialize (pLockBytes, eAccessMode, rnPageSize);
}
namespace store
{
template<> OTestBIOS* SAL_CALL query (IStoreHandle *pHandle, OTestBIOS*)
{
if (pHandle && pHandle->isKindOf (4242))
return static_cast<OTestBIOS*>(pHandle);
else
return 0;
}
}
/*========================================================================
*
* __store_test_handle.
*
*======================================================================*/
static void __store_test_handle (void* Handle)
{
IStoreHandle *pHandle = static_cast<IStoreHandle*>(Handle);
if (pHandle)
{
pHandle->acquire();
pHandle->isKindOf (42);
pHandle->release();
}
OTestObject *pObj = query (pHandle, static_cast<OTestObject*>(0));
if (pObj)
{
pObj->acquire();
pObj->isKindOf (42);
pObj->release();
}
}
/*========================================================================
*
* unicode.
*
*======================================================================*/
static void __store_string_newFromUnicode_WithLength (
rtl_String **newString, const sal_Unicode *value, sal_Int32 length)
{
rtl_uString2String (
newString,
value, length,
RTL_TEXTENCODING_UTF8,
OUSTRING_TO_OSTRING_CVTFLAGS);
}
static void __store_string_newFromUnicode (
rtl_String **newString, const sal_Unicode *value)
{
__store_string_newFromUnicode_WithLength (
newString, value, rtl_ustr_getLength (value));
}
static storeError __store_namei (
const sal_Unicode *pszPath,
const sal_Unicode *pszName,
OStorePageKey &rKey)
{
OString aName (
pszName, rtl_ustr_getLength (pszName), RTL_TEXTENCODING_UTF8);
rtl_String *pszNameA = 0;
__store_string_newFromUnicode (&pszNameA, pszName);
storeError eErrCode = store_E_NameTooLong;
if (pszNameA->length < sal_Int32(sizeof(sal_Char[STORE_MAXIMUM_NAMESIZE])))
{
rtl_String *pszPathA = 0;
__store_string_newFromUnicode (&pszPathA, pszPath);
rKey.m_nLow = rtl_crc32 (0, pszNameA->buffer, pszNameA->length);
rKey.m_nHigh = rtl_crc32 (0, pszPathA->buffer, pszPathA->length);
rtl_string_release (pszPathA);
eErrCode = store_E_None;
}
rtl_string_release (pszNameA);
return eErrCode;
}
static sal_Size __store_convertTextToUnicode (
rtl_TextToUnicodeConverter hConvert,
const sal_Char *pszText, sal_Size nTextLen,
sal_Unicode *pBuffer, sal_Size nBuffer)
{
sal_uInt32 nInfo = 0;
sal_Size nSrcLen = 0;
sal_Int32 nDstLen = rtl_convertTextToUnicode (
hConvert, 0,
pszText, nTextLen,
pBuffer, nBuffer,
OSTRING_TO_OUSTRING_CVTFLAGS,
&nInfo, &nSrcLen);
pBuffer[nDstLen] = 0;
return nDstLen;
}
struct MyFindData
{
sal_Unicode m_pszName[STORE_MAXIMUM_NAMESIZE];
sal_Int32 m_nLength;
sal_uInt32 m_nAttrib;
sal_uInt32 m_nSize;
sal_uInt32 m_nReserved;
};
static void __store_testUnicode (const sal_Char *pszFilename)
{
rtl_TextToUnicodeConverter hConvert;
hConvert = rtl_createTextToUnicodeConverter (RTL_TEXTENCODING_UTF8);
MyFindData it;
memset (&it, 0, sizeof(it));
sal_Int32 n = rtl_str_getLength (pszFilename);
n = __store_convertTextToUnicode (
hConvert, pszFilename, n,
it.m_pszName, STORE_MAXIMUM_NAMESIZE - 1);
if (it.m_nLength > n)
memset (
&it.m_pszName[n], 0, ((it.m_nLength - n) * sizeof(sal_Unicode)));
it.m_nLength = n;
rtl_destroyTextToUnicodeConverter (hConvert);
rtl_String *pszFileA = NULL;
rtl_uString *pszFileW = NULL;
// rtl_uString_newFromAscii (&pszFileW, pszFilename);
rtl_string_newFromStr (&pszFileA, pszFilename);
rtl_string2UString (
&pszFileW,
pszFileA->buffer, pszFileA->length,
RTL_TEXTENCODING_MS_1252,
OSTRING_TO_OUSTRING_CVTFLAGS);
rtl_string_release (pszFileA);
OStorePageKey aKey;
__store_namei (pszFileW->buffer, pszFileW->buffer, aKey);
rtl_uString2String (
&pszFileA,
pszFileW->buffer, pszFileW->length,
RTL_TEXTENCODING_UTF8,
OUSTRING_TO_OSTRING_CVTFLAGS);
rtl_uString_release (pszFileW);
rtl_string_release (pszFileA);
}
/*========================================================================
*
* main.
*
*======================================================================*/
int SAL_CALL main (int argc, char **argv)
{
OSL_PRECOND(argc > 1, "t_base: error: insufficient number of arguments.");
if (argc < 2)
return 0;
__store_testUnicode (argv[1]);
rtl::Reference<ILockBytes> xLockBytes;
OUString aFilename (
argv[1], rtl_str_getLength(argv[1]),
osl_getThreadTextEncoding());
storeError eErrCode = FileLockBytes_createInstance (
xLockBytes, aFilename.pData, store_AccessReadCreate);
if (eErrCode != store_E_None)
return eErrCode;
rtl::Reference<OTestObject> xObject (new OTestObject());
__store_test_handle (&*xObject);
rtl::Reference<OTestBIOS> xBIOS (new OTestBIOS());
__store_test_handle (&*xBIOS);
if (!xBIOS.is())
return 0;
sal_uInt16 nPageSize = TEST_PAGESIZE;
eErrCode = xBIOS->initialize (&*xLockBytes, store_AccessReadWrite, nPageSize);
if (eErrCode != store_E_None)
{
// Check reason.
if (eErrCode != store_E_NotExists)
return eErrCode;
// Create.
eErrCode = xBIOS->initialize (&*xLockBytes, store_AccessReadCreate, nPageSize);
if (eErrCode != store_E_None)
return eErrCode;
}
xLockBytes.clear();
sal_Char pBuffer[TEST_PAGESIZE];
memset (pBuffer, 0, sizeof (pBuffer));
memcpy (pBuffer, argv[0], rtl_str_getLength(argv[0]) + 1);
eErrCode = xBIOS->write (TEST_PAGESIZE, pBuffer, sizeof (pBuffer));
if (eErrCode != store_E_None)
return eErrCode;
xBIOS.clear();
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -1,211 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "sal/types.h"
#include "osl/thread.h"
#include "rtl/ustring.hxx"
#include "lockbyte.hxx"
#include <string.h>
#include <stdio.h>
#include "osl/file.h"
#include "osl/process.h"
using namespace store;
#define TEST_PAGESIZE 16384
/*========================================================================
*
* main.
*
*======================================================================*/
int SAL_CALL main (int argc, char **argv)
{
storeError eErrCode = store_E_None;
rtl::Reference<ILockBytes> xLockBytes;
if (argc > 1)
{
OUString aFilename (
argv[1], rtl_str_getLength(argv[1]),
osl_getThreadTextEncoding());
eErrCode = FileLockBytes_createInstance (
xLockBytes, 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);
return eErrCode;
}
// Create.
eErrCode = FileLockBytes_createInstance (
xLockBytes, aFilename.pData, store_AccessReadCreate);
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: create() error: %d\n", eErrCode);
return eErrCode;
}
}
fprintf (stdout, "t_file: using FileLockBytes(\"%s\") implementation.\n", argv[1]);
}
else
{
eErrCode = MemoryLockBytes_createInstance (xLockBytes);
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: create() error: %d\n", eErrCode);
return eErrCode;
}
fprintf (stdout, "t_file: using MemoryLockBytes implementation.\n");
}
rtl::Reference< PageData::Allocator > xAllocator;
eErrCode = xLockBytes->initialize (xAllocator, TEST_PAGESIZE);
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: initialize() error: %d\n", eErrCode);
return eErrCode;
}
sal_Char buffer[TEST_PAGESIZE];
memset (buffer, sal_uInt8('B'), sizeof(buffer));
sal_uInt32 i, k;
for (k = 0; k < 4; k++)
{
sal_uInt32 index = k * TEST_PAGESIZE / 4;
buffer[index] = 'A';
}
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;
}
for (k = 0; k < 4; k++)
{
sal_uInt32 magic = i * 4 + k;
if (magic)
{
sal_uInt32 verify = 0;
eErrCode = xLockBytes->readAt (
0, &verify, sizeof(verify));
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: readAt() error: %d\n", eErrCode);
return eErrCode;
}
if (verify != magic)
{
// Failure.
fprintf (stderr, "Expected %ld read %ld\n", (unsigned long)(magic), (unsigned long)(verify));
}
}
sal_uInt32 index = k * TEST_PAGESIZE / 4;
eErrCode = xLockBytes->writeAt (
offset + index, &(buffer[index]), TEST_PAGESIZE / 4);
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));
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: writeAt() error: %d\n", eErrCode);
return eErrCode;
}
}
}
eErrCode = xLockBytes->flush();
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: flush() error: %d\n", eErrCode);
return eErrCode;
}
sal_Char verify[TEST_PAGESIZE];
for (i = 0; i < 256; i++)
{
sal_uInt32 offset = i * TEST_PAGESIZE;
eErrCode = xLockBytes->readAt (offset, verify, TEST_PAGESIZE);
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 (memcmp (&verify[index], &magic, sizeof(magic)))
{
// Failure.
fprintf (stderr, "t_file: Unexpected value at 0x00000000\n");
}
index += 4;
}
if (memcmp (
&verify[index], &buffer[index], TEST_PAGESIZE - index))
{
// Failure.
fprintf (stderr, "t_file: Unexpected block at 0x%08x\n", (unsigned)(offset));
}
}
for (i = 0; i < 256; i++)
{
PageHolder xPage;
sal_uInt32 offset = i * TEST_PAGESIZE;
eErrCode = xLockBytes->readPageAt (xPage, offset);
if (eErrCode != store_E_None)
{
fprintf (stderr, "t_file: readPageAt() error: %d\n", eErrCode);
return eErrCode;
}
PageData * page = xPage.get();
(void)page; // UNUSED
}
xLockBytes.clear();
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -1,31 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include "sal/main.h"
#include "osl/process.h"
#include "osl/thread.h"
int main (int /*argc*/, char ** /*argv*/)
{
rtl_Locale * pLocale = 0;
osl_getProcessLocale (&pLocale);
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

File diff suppressed because it is too large Load diff

View file

@ -1,543 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/types.h>
#include <osl/diagnose.h>
#include <osl/thread.h>
#include <osl/time.h>
#include <rtl/ustring.hxx>
#include <store/store.hxx>
#include <stdio.h>
/*========================================================================
*
* Internals.
*
*======================================================================*/
#define _DEMOSTOR_BUFSIZ 512 /* 4096, 1024, 512 */
#define _DEMOSTOR_LOOPS 1000 /* 1000, 2000 */
#define _DEMOSTOR_REMOVE 0
#define _DEMOSTOR_REBUILD 0
enum Options
{
OPTION_HELP = 0x0001,
OPTION_FILE = 0x0002,
OPTION_PAUSE = 0x0004,
OPTION_REBUILD = 0x0008,
OPTION_DUMP = 0x0010,
OPTION_ITER = 0x0020,
OPTION_LINK = 0x0040,
OPTION_READ = 0x0100,
OPTION_WRITE = 0x0200,
OPTION_CREAT = 0x0400,
OPTION_TRUNC = 0x0800
};
inline sal_Char ascii_toLowerCase (sal_Char ch)
{
if ((ch >= 0x41) && (ch <= 0x5A))
return (ch + 0x20);
else
return (ch);
}
/*========================================================================
*
* Timing.
*
*======================================================================*/
struct OTime : public TimeValue
{
OTime (void)
{
Seconds = 0;
Nanosec = 0;
}
static OTime getSystemTime (void)
{
OTime tv;
osl_getSystemTime (&tv);
return tv;
}
OTime& operator-= (const OTime& rPast)
{
Seconds -= rPast.Seconds;
if (Nanosec < rPast.Nanosec)
{
Seconds -= 1;
Nanosec += 1000000000;
}
Nanosec -= rPast.Nanosec;
return *this;
}
friend OTime operator- (const OTime& rTimeA, const OTime& rTimeB)
{
OTime aTimeC (rTimeA);
aTimeC -= rTimeB;
return aTimeC;
}
};
/*========================================================================
*
* DirectoryTraveller.
*
*======================================================================*/
typedef store::OStoreDirectory Directory;
class DirectoryTraveller : public Directory::traveller
{
typedef store::OStoreFile file;
typedef Directory::iterator iter;
store::OStoreFile m_aFile;
OUString m_aPath;
sal_uInt32 m_nOptions;
unsigned int m_nLevel;
unsigned int m_nCount;
public:
DirectoryTraveller (
const file& rFile,
const OUString &rPath,
const OUString &rName,
sal_uInt32 nOptions,
unsigned int nLevel = 0);
virtual ~DirectoryTraveller (void);
virtual sal_Bool visit (const iter& it);
};
/*
* DirectoryTraveller.
*/
DirectoryTraveller::DirectoryTraveller (
const file& rFile,
const OUString &rPath,
const OUString &rName,
sal_uInt32 nOptions,
unsigned int nLevel)
: m_aFile (rFile),
m_aPath (rPath),
m_nOptions (nOptions),
m_nLevel (nLevel),
m_nCount (0)
{
m_aPath += rName + "/";
}
/*
* ~DirectoryTraveller.
*/
DirectoryTraveller::~DirectoryTraveller (void)
{
}
/*
* visit.
*/
sal_Bool DirectoryTraveller::visit (const iter& it)
{
m_nCount++;
if (m_nOptions & OPTION_DUMP)
{
OString aName (it.m_pszName, it.m_nLength, RTL_TEXTENCODING_UTF8);
printf ("Visit(%u,%u): %s [0x%08x] %d [Bytes]\n",
m_nLevel, m_nCount,
aName.pData->buffer, (unsigned int)(it.m_nAttrib), (unsigned int)(it.m_nSize));
}
if (it.m_nAttrib & STORE_ATTRIB_ISDIR)
{
OUString aName (it.m_pszName, it.m_nLength);
if (aName.equalsAscii("XTextViewCursorSupplier"))
{
m_nCount += 1 - 1;
}
Directory aSubDir;
storeError eErrCode = aSubDir.create (
m_aFile, m_aPath, aName, store_AccessReadOnly);
if (eErrCode == store_E_None)
{
sal_uInt32 nRefCount = 0;
m_aFile.getRefererCount (nRefCount);
DirectoryTraveller aSubTraveller (
m_aFile, m_aPath, aName, m_nOptions, m_nLevel + 1);
aSubDir.travel (aSubTraveller);
}
}
return sal_True;
}
/*========================================================================
*
* main.
*
*======================================================================*/
int SAL_CALL main (int argc, char **argv)
{
OTime aMainStartTime (OTime::getSystemTime());
store::OStoreFile aFile;
storeError eErrCode = store_E_None;
sal_uInt32 nOptions = 0;
for (int i = 1; i < argc; i++)
{
const char *opt = argv[i];
if (opt[0] == '-')
{
switch (ascii_toLowerCase(sal_Char(opt[1])))
{
case 'f':
nOptions |= OPTION_FILE;
break;
case 'd':
nOptions |= OPTION_DUMP;
break;
case 'i':
nOptions |= OPTION_ITER;
break;
case 'l':
nOptions |= OPTION_LINK;
break;
case 'r':
nOptions |= OPTION_READ;
break;
case 'w':
nOptions |= OPTION_WRITE;
break;
case 'c':
nOptions |= OPTION_CREAT;
break;
case 't':
nOptions |= OPTION_TRUNC;
break;
case 'p':
nOptions |= OPTION_PAUSE;
break;
case 'h':
default:
nOptions |= OPTION_HELP;
break;
}
}
else
{
if (nOptions & OPTION_FILE)
{
OUString aName (
argv[i], rtl_str_getLength(argv[i]),
osl_getThreadTextEncoding());
if ((nOptions & OPTION_CREAT) && (nOptions & OPTION_TRUNC))
eErrCode = aFile.create (aName, store_AccessCreate);
else if (nOptions & OPTION_CREAT)
eErrCode = aFile.create (aName, store_AccessReadCreate);
else if (nOptions & OPTION_WRITE)
eErrCode = aFile.create (aName, store_AccessReadWrite);
else
eErrCode = aFile.create (aName, store_AccessReadOnly);
if (eErrCode != store_E_None)
{
printf ("Error: can't open file: %s\n", argv[i]);
exit (0);
}
}
}
}
if ((nOptions == 0) || (nOptions & OPTION_HELP))
{
printf ("Usage:\tt_store "
"[[-c] [-t] [-r] [-w]] [[-i] [-d] [-h]] "
"[-f filename]\n");
printf ("\nOptions:\n");
printf ("-c\tcreate\n");
printf ("-t\ttruncate\n");
printf ("-r\tread\n");
printf ("-w\twrite\n");
printf ("-i\titerate\n");
printf ("-d\tdump\n");
printf ("-h\thelp\n");
printf ("-f\tfilename\n");
printf ("\nExamples:");
printf ("\nt_store -c -w -f t_store.rdb\n");
printf ("\tCreate file 't_store.rdb',\n"
"\twrite fixed number (1000) of streams.\n");
printf ("\nt_store -c -i -d -f t_store.rdb\n");
printf ("\tOpen file 't_store.rdb', "
"create '/' directory,\n"
"\titerate directory tree, "
"dump directory info.\n");
exit (0);
}
if (!aFile.isValid())
{
eErrCode = aFile.createInMemory();
if (eErrCode != store_E_None)
{
printf ("Error: can't create memory file\n");
exit (0);
}
}
// Stream Read/Write.
OUString aPath ("/");
if ((nOptions & OPTION_READ) || (nOptions & OPTION_WRITE))
{
// Mode.
storeAccessMode eMode = store_AccessReadOnly;
if (nOptions & OPTION_WRITE)
eMode = store_AccessReadWrite;
if (nOptions & OPTION_CREAT)
eMode = store_AccessCreate;
// Buffer.
char pBuffer[_DEMOSTOR_BUFSIZ] = "Hello World";
pBuffer[_DEMOSTOR_BUFSIZ - 2] = 'B';
pBuffer[_DEMOSTOR_BUFSIZ - 1] = '\0';
// Load/Save.
OTime aStartTime (OTime::getSystemTime());
for (int i = 0; i < _DEMOSTOR_LOOPS; i++)
{
OUString aName ("demostor-");
aName += OUString::valueOf ((sal_Int32)(i + 1), 10);
aName += ".dat";
#if (_DEMOSTOR_REMOVE == 1)
eErrCode = aFile.remove (aPath, aName);
if ((eErrCode != store_E_None ) &&
(eErrCode != store_E_NotExists) )
break;
#endif /* _REMOVE */
store::OStoreStream aStream;
eErrCode = aStream.create (aFile, aPath, aName, eMode);
if (eErrCode != store_E_None)
{
OSL_TRACE("OStoreStream(%d)::create(): error: %d", i, eErrCode);
break;
}
if (nOptions & OPTION_TRUNC)
{
eErrCode = aStream.setSize(0);
if (eErrCode != store_E_None)
{
OSL_TRACE("OStoreStream(%d)::setSize(0): error: %d", i, eErrCode);
break;
}
}
sal_uInt32 nDone = 0;
if (nOptions & OPTION_WRITE)
{
eErrCode = aStream.writeAt (
0, pBuffer, sizeof(pBuffer), nDone);
if (eErrCode != store_E_None)
{
OSL_TRACE("OStoreStream(%d)::writeAt(): error: %d", i, eErrCode);
break;
}
}
if (nOptions & OPTION_READ)
{
sal_uInt32 nOffset = 0;
for (;;)
{
eErrCode = aStream.readAt (
nOffset, pBuffer, sizeof(pBuffer), nDone);
if (eErrCode != store_E_None)
{
OSL_TRACE("OStoreStream(%d)::readAt(): error: %d", i, eErrCode);
break;
}
if (nDone == 0)
break;
nOffset += nDone;
}
}
aStream.close();
if (((i + 1) % (_DEMOSTOR_LOOPS/10)) == 0)
{
OTime aDelta (OTime::getSystemTime() - aStartTime);
sal_uInt32 nDelta = aDelta.Seconds * 1000000;
nDelta += (aDelta.Nanosec / 1000);
printf ("%d: %12.4g[usec]\n", (i+1),
(double)(nDelta)/(double)(i+1));
}
}
OTime aDelta (OTime::getSystemTime() - aStartTime);
sal_uInt32 nDelta = aDelta.Seconds * 1000000;
nDelta += (aDelta.Nanosec / 1000);
printf ("Total(rd,wr): %d[usec]\n", (unsigned int)(nDelta));
}
// Link/Rename.
if (nOptions & OPTION_LINK)
{
// Create symlink to (root) directory.
eErrCode = aFile.symlink (
aPath, OUString("000000/"),
OUString(), aPath);
SAL_WARN_IF(
eErrCode != store_E_None && eErrCode != store_E_AlreadyExists,
"store",
"t_store::main(): store_symlink() failed");
// Create symlink to file.
OUString aLinkName ("demostor-1.lnk");
eErrCode = aFile.symlink (
aPath, aLinkName,
aPath, OUString("demostor-1.dat"));
SAL_WARN_IF(
eErrCode != store_E_None && eErrCode != store_E_AlreadyExists,
"store",
"t_store::main(): store_symlink() failed");
if ((eErrCode == store_E_None ) ||
(eErrCode == store_E_AlreadyExists) )
{
OUString aShortcut (
"Shortcut to demostor-1.dat");
eErrCode = aFile.rename (
aPath, aLinkName,
aPath, aShortcut);
SAL_WARN_IF(
eErrCode != store_E_None && eErrCode != store_E_AlreadyExists,
"store",
"t_store::main(): store_rename() failed");
}
// Create directory.
OUString aDirName ("demostor-1.dir");
store::OStoreDirectory aDir;
eErrCode = aDir.create (
aFile, aPath, aDirName, store_AccessReadCreate);
SAL_WARN_IF(
eErrCode != store_E_None,
"t_store::main(): store_createDirectory() failed");
}
// Directory iteration.
if (nOptions & OPTION_ITER)
{
OTime aStartTime (OTime::getSystemTime());
OUString aEmpty;
// Root directory.
store::OStoreDirectory aRootDir;
if (nOptions & OPTION_LINK)
{
// Open symlink entry.
eErrCode = aRootDir.create (
aFile, aPath, OUString("000000"),
store_AccessReadOnly);
}
else
{
// Open direct entry.
if (nOptions & OPTION_CREAT)
eErrCode = aRootDir.create (
aFile, aEmpty, aEmpty, store_AccessReadCreate);
else if (nOptions & OPTION_WRITE)
eErrCode = aRootDir.create (
aFile, aEmpty, aEmpty, store_AccessReadWrite);
else
eErrCode = aRootDir.create (
aFile, aEmpty, aEmpty, store_AccessReadOnly);
}
if (eErrCode == store_E_None)
{
// Traverse directory tree.
DirectoryTraveller aTraveller (
aFile, aEmpty, aEmpty, nOptions, 0);
aRootDir.travel (aTraveller);
}
else
{
// Failure.
printf ("Error: can't open directory: \"/\"\n");
}
OTime aDelta (OTime::getSystemTime() - aStartTime);
sal_uInt32 nDelta = aDelta.Seconds * 1000000;
nDelta += (aDelta.Nanosec / 1000);
printf ("Total(iter): %d[usec]\n", (unsigned int)(nDelta));
}
if (nOptions & OPTION_PAUSE)
{
TimeValue tv;
tv.Seconds = 300;
tv.Nanosec = 0;
osl_waitThread (&tv);
}
// Size.
sal_uInt32 nSize = 0;
aFile.getSize (nSize);
// Done.
aFile.close();
OTime aDelta (OTime::getSystemTime() - aMainStartTime);
sal_uInt32 nDelta = aDelta.Seconds * 1000000;
nDelta += (aDelta.Nanosec / 1000);
printf ("Total: %d[usec]\n", (unsigned int)(nDelta));
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */