xref: /aoo41x/main/store/workben/t_store.cxx (revision 73d9b18a)
1*73d9b18aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*73d9b18aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*73d9b18aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*73d9b18aSAndrew Rist  * distributed with this work for additional information
6*73d9b18aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*73d9b18aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*73d9b18aSAndrew Rist  * "License"); you may not use this file except in compliance
9*73d9b18aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*73d9b18aSAndrew Rist  *
11*73d9b18aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*73d9b18aSAndrew Rist  *
13*73d9b18aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*73d9b18aSAndrew Rist  * software distributed under the License is distributed on an
15*73d9b18aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*73d9b18aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*73d9b18aSAndrew Rist  * specific language governing permissions and limitations
18*73d9b18aSAndrew Rist  * under the License.
19*73d9b18aSAndrew Rist  *
20*73d9b18aSAndrew Rist  *************************************************************/
21*73d9b18aSAndrew Rist 
22*73d9b18aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_store.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define _T_STORE_CXX "$Revision: 1.7.8.2 $"
28cdf0e10cSrcweir #include <sal/types.h>
29cdf0e10cSrcweir #include <osl/diagnose.h>
30cdf0e10cSrcweir #include <osl/thread.h>
31cdf0e10cSrcweir #include <osl/time.h>
32cdf0e10cSrcweir #include <rtl/ustring.hxx>
33cdf0e10cSrcweir #include <store/store.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include <stdio.h>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #if (defined(WNT) && defined(PROFILE))
38cdf0e10cSrcweir extern "C"
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 	void StartCAP (void);
41cdf0e10cSrcweir 	void StopCAP  (void);
42cdf0e10cSrcweir 	void DumpCAP  (void);
43cdf0e10cSrcweir }
44cdf0e10cSrcweir #endif /* PROFILE */
45cdf0e10cSrcweir 
46cdf0e10cSrcweir using rtl::OUString;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir /*========================================================================
49cdf0e10cSrcweir  *
50cdf0e10cSrcweir  * Internals.
51cdf0e10cSrcweir  *
52cdf0e10cSrcweir  *======================================================================*/
53cdf0e10cSrcweir #define _DEMOSTOR_BUFSIZ          512  /* 4096, 1024, 512 */
54cdf0e10cSrcweir #define _DEMOSTOR_LOOPS           1000 /* 1000, 2000 */
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #define _DEMOSTOR_REMOVE          0
57cdf0e10cSrcweir #define _DEMOSTOR_REBUILD         0
58cdf0e10cSrcweir 
59cdf0e10cSrcweir enum Options
60cdf0e10cSrcweir {
61cdf0e10cSrcweir 	OPTION_HELP    = 0x0001,
62cdf0e10cSrcweir 	OPTION_FILE    = 0x0002,
63cdf0e10cSrcweir 	OPTION_PAUSE   = 0x0004,
64cdf0e10cSrcweir 	OPTION_REBUILD = 0x0008,
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	OPTION_DUMP    = 0x0010,
67cdf0e10cSrcweir 	OPTION_ITER    = 0x0020,
68cdf0e10cSrcweir 	OPTION_LINK    = 0x0040,
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	OPTION_READ    = 0x0100,
71cdf0e10cSrcweir 	OPTION_WRITE   = 0x0200,
72cdf0e10cSrcweir 	OPTION_CREAT   = 0x0400,
73cdf0e10cSrcweir 	OPTION_TRUNC   = 0x0800
74cdf0e10cSrcweir };
75cdf0e10cSrcweir 
ascii_toLowerCase(sal_Char ch)76cdf0e10cSrcweir inline sal_Char ascii_toLowerCase (sal_Char ch)
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	if ((ch >= 0x41) && (ch <= 0x5A))
79cdf0e10cSrcweir 		return (ch + 0x20);
80cdf0e10cSrcweir 	else
81cdf0e10cSrcweir 		return (ch);
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir /*========================================================================
85cdf0e10cSrcweir  *
86cdf0e10cSrcweir  * Timing.
87cdf0e10cSrcweir  *
88cdf0e10cSrcweir  *======================================================================*/
89cdf0e10cSrcweir struct OTime : public TimeValue
90cdf0e10cSrcweir {
OTimeOTime91cdf0e10cSrcweir 	OTime (void)
92cdf0e10cSrcweir 	{
93cdf0e10cSrcweir 		Seconds = 0;
94cdf0e10cSrcweir 		Nanosec = 0;
95cdf0e10cSrcweir 	}
96cdf0e10cSrcweir 
getSystemTimeOTime97cdf0e10cSrcweir 	static OTime getSystemTime (void)
98cdf0e10cSrcweir 	{
99cdf0e10cSrcweir 		OTime tv;
100cdf0e10cSrcweir 		osl_getSystemTime (&tv);
101cdf0e10cSrcweir 		return tv;
102cdf0e10cSrcweir 	}
103cdf0e10cSrcweir 
operator -=OTime104cdf0e10cSrcweir 	OTime& operator-= (const OTime& rPast)
105cdf0e10cSrcweir 	{
106cdf0e10cSrcweir 		Seconds -= rPast.Seconds;
107cdf0e10cSrcweir 		if (Nanosec < rPast.Nanosec)
108cdf0e10cSrcweir 		{
109cdf0e10cSrcweir 			Seconds -= 1;
110cdf0e10cSrcweir 			Nanosec += 1000000000;
111cdf0e10cSrcweir 		}
112cdf0e10cSrcweir 		Nanosec -= rPast.Nanosec;
113cdf0e10cSrcweir 		return *this;
114cdf0e10cSrcweir 	}
115cdf0e10cSrcweir 
operator -(const OTime & rTimeA,const OTime & rTimeB)116cdf0e10cSrcweir 	friend OTime operator- (const OTime& rTimeA, const OTime& rTimeB)
117cdf0e10cSrcweir 	{
118cdf0e10cSrcweir 		OTime aTimeC (rTimeA);
119cdf0e10cSrcweir 		aTimeC -= rTimeB;
120cdf0e10cSrcweir 		return aTimeC;
121cdf0e10cSrcweir 	}
122cdf0e10cSrcweir };
123cdf0e10cSrcweir 
124cdf0e10cSrcweir /*========================================================================
125cdf0e10cSrcweir  *
126cdf0e10cSrcweir  * DirectoryTraveller.
127cdf0e10cSrcweir  *
128cdf0e10cSrcweir  *======================================================================*/
129cdf0e10cSrcweir typedef store::OStoreDirectory Directory;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir class DirectoryTraveller : public Directory::traveller
132cdf0e10cSrcweir {
133cdf0e10cSrcweir 	typedef store::OStoreFile   file;
134cdf0e10cSrcweir 	typedef Directory::iterator iter;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	store::OStoreFile m_aFile;
137cdf0e10cSrcweir 	OUString          m_aPath;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	sal_uInt32  m_nOptions;
140cdf0e10cSrcweir 	unsigned int  m_nLevel;
141cdf0e10cSrcweir 	unsigned int  m_nCount;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir public:
144cdf0e10cSrcweir 	DirectoryTraveller (
145cdf0e10cSrcweir 		const file&     rFile,
146cdf0e10cSrcweir 		const OUString &rPath,
147cdf0e10cSrcweir 		const OUString &rName,
148cdf0e10cSrcweir 		sal_uInt32      nOptions,
149cdf0e10cSrcweir 		unsigned int nLevel = 0);
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	virtual ~DirectoryTraveller (void);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	virtual sal_Bool visit (const iter& it);
154cdf0e10cSrcweir };
155cdf0e10cSrcweir 
156cdf0e10cSrcweir /*
157cdf0e10cSrcweir  * DirectoryTraveller.
158cdf0e10cSrcweir  */
DirectoryTraveller(const file & rFile,const OUString & rPath,const OUString & rName,sal_uInt32 nOptions,unsigned int nLevel)159cdf0e10cSrcweir DirectoryTraveller::DirectoryTraveller (
160cdf0e10cSrcweir 	const file&     rFile,
161cdf0e10cSrcweir 	const OUString &rPath,
162cdf0e10cSrcweir 	const OUString &rName,
163cdf0e10cSrcweir 	sal_uInt32      nOptions,
164cdf0e10cSrcweir 	unsigned int nLevel)
165cdf0e10cSrcweir 	: m_aFile    (rFile),
166cdf0e10cSrcweir 	  m_aPath    (rPath),
167cdf0e10cSrcweir 	  m_nOptions (nOptions),
168cdf0e10cSrcweir 	  m_nLevel   (nLevel),
169cdf0e10cSrcweir 	  m_nCount   (0)
170cdf0e10cSrcweir {
171cdf0e10cSrcweir 	m_aPath += rName;
172cdf0e10cSrcweir 	m_aPath += OUString::createFromAscii("/");
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir /*
176cdf0e10cSrcweir  * ~DirectoryTraveller.
177cdf0e10cSrcweir  */
~DirectoryTraveller(void)178cdf0e10cSrcweir DirectoryTraveller::~DirectoryTraveller (void)
179cdf0e10cSrcweir {
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir /*
183cdf0e10cSrcweir  * visit.
184cdf0e10cSrcweir  */
visit(const iter & it)185cdf0e10cSrcweir sal_Bool DirectoryTraveller::visit (const iter& it)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir 	m_nCount++;
188cdf0e10cSrcweir 	if (m_nOptions & OPTION_DUMP)
189cdf0e10cSrcweir 	{
190cdf0e10cSrcweir 		rtl::OString aName (it.m_pszName, it.m_nLength, RTL_TEXTENCODING_UTF8);
191cdf0e10cSrcweir 		printf ("Visit(%d,%d): %s [0x%08x] %d [Bytes]\n",
192cdf0e10cSrcweir 				m_nLevel, m_nCount,
193cdf0e10cSrcweir 				aName.pData->buffer, (unsigned int)(it.m_nAttrib), (unsigned int)(it.m_nSize));
194cdf0e10cSrcweir 	}
195cdf0e10cSrcweir 	if (it.m_nAttrib & STORE_ATTRIB_ISDIR)
196cdf0e10cSrcweir 	{
197cdf0e10cSrcweir 		OUString  aName (it.m_pszName, it.m_nLength);
198cdf0e10cSrcweir 		if (aName.compareToAscii ("XTextViewCursorSupplier") == 0)
199cdf0e10cSrcweir 		{
200cdf0e10cSrcweir 			m_nCount += 1 - 1;
201cdf0e10cSrcweir 		}
202cdf0e10cSrcweir 		Directory aSubDir;
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 		storeError eErrCode = aSubDir.create (
205cdf0e10cSrcweir 			m_aFile, m_aPath, aName, store_AccessReadOnly);
206cdf0e10cSrcweir 		if (eErrCode == store_E_None)
207cdf0e10cSrcweir 		{
208cdf0e10cSrcweir 			sal_uInt32 nRefCount = 0;
209cdf0e10cSrcweir 			m_aFile.getRefererCount (nRefCount);
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 			DirectoryTraveller aSubTraveller (
212cdf0e10cSrcweir 				m_aFile, m_aPath, aName, m_nOptions, m_nLevel + 1);
213cdf0e10cSrcweir 			aSubDir.travel (aSubTraveller);
214cdf0e10cSrcweir 		}
215cdf0e10cSrcweir 	}
216cdf0e10cSrcweir 	return sal_True;
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir /*========================================================================
220cdf0e10cSrcweir  *
221cdf0e10cSrcweir  * main.
222cdf0e10cSrcweir  *
223cdf0e10cSrcweir  *======================================================================*/
main(int argc,char ** argv)224cdf0e10cSrcweir int SAL_CALL main (int argc, char **argv)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir #if (defined(WNT) && defined(PROFILE))
227cdf0e10cSrcweir 	StartCAP();
228cdf0e10cSrcweir #else
229cdf0e10cSrcweir 	OTime aMainStartTime (OTime::getSystemTime());
230cdf0e10cSrcweir #endif /* PROFILE */
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 	store::OStoreFile aFile;
233cdf0e10cSrcweir 	storeError eErrCode = store_E_None;
234cdf0e10cSrcweir 
235cdf0e10cSrcweir 	sal_uInt32 nOptions = 0;
236cdf0e10cSrcweir 	for (int i = 1; i < argc; i++)
237cdf0e10cSrcweir 	{
238cdf0e10cSrcweir 		const char *opt = argv[i];
239cdf0e10cSrcweir 		if (opt[0] == '-')
240cdf0e10cSrcweir 		{
241cdf0e10cSrcweir 			switch (ascii_toLowerCase(sal_Char(opt[1])))
242cdf0e10cSrcweir 			{
243cdf0e10cSrcweir 				case 'f':
244cdf0e10cSrcweir 					nOptions |= OPTION_FILE;
245cdf0e10cSrcweir 					break;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 				case 'd':
248cdf0e10cSrcweir 					nOptions |= OPTION_DUMP;
249cdf0e10cSrcweir 					break;
250cdf0e10cSrcweir 				case 'i':
251cdf0e10cSrcweir 					nOptions |= OPTION_ITER;
252cdf0e10cSrcweir 					break;
253cdf0e10cSrcweir 				case 'l':
254cdf0e10cSrcweir 					nOptions |= OPTION_LINK;
255cdf0e10cSrcweir 					break;
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 				case 'r':
258cdf0e10cSrcweir 					nOptions |= OPTION_READ;
259cdf0e10cSrcweir 					break;
260cdf0e10cSrcweir 				case 'w':
261cdf0e10cSrcweir 					nOptions |= OPTION_WRITE;
262cdf0e10cSrcweir 					break;
263cdf0e10cSrcweir 				case 'c':
264cdf0e10cSrcweir 					nOptions |= OPTION_CREAT;
265cdf0e10cSrcweir 					break;
266cdf0e10cSrcweir 				case 't':
267cdf0e10cSrcweir 					nOptions |= OPTION_TRUNC;
268cdf0e10cSrcweir 					break;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 				case 'p':
271cdf0e10cSrcweir 					nOptions |= OPTION_PAUSE;
272cdf0e10cSrcweir 					break;
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 				case 'h':
275cdf0e10cSrcweir 				default:
276cdf0e10cSrcweir 					nOptions |= OPTION_HELP;
277cdf0e10cSrcweir 					break;
278cdf0e10cSrcweir 			}
279cdf0e10cSrcweir 		}
280cdf0e10cSrcweir 		else
281cdf0e10cSrcweir 		{
282cdf0e10cSrcweir 			if (nOptions & OPTION_FILE)
283cdf0e10cSrcweir 			{
284cdf0e10cSrcweir 				OUString aName (
285cdf0e10cSrcweir 					argv[i], rtl_str_getLength(argv[i]),
286cdf0e10cSrcweir 					osl_getThreadTextEncoding());
287cdf0e10cSrcweir 				if ((nOptions & OPTION_CREAT) && (nOptions & OPTION_TRUNC))
288cdf0e10cSrcweir 					eErrCode = aFile.create (aName, store_AccessCreate);
289cdf0e10cSrcweir 				else if (nOptions & OPTION_CREAT)
290cdf0e10cSrcweir 					eErrCode = aFile.create (aName, store_AccessReadCreate);
291cdf0e10cSrcweir 				else if (nOptions & OPTION_WRITE)
292cdf0e10cSrcweir 					eErrCode = aFile.create (aName, store_AccessReadWrite);
293cdf0e10cSrcweir 				else
294cdf0e10cSrcweir 					eErrCode = aFile.create (aName, store_AccessReadOnly);
295cdf0e10cSrcweir 				if (eErrCode != store_E_None)
296cdf0e10cSrcweir 				{
297cdf0e10cSrcweir 					printf ("Error: can't open file: %s\n", argv[i]);
298cdf0e10cSrcweir 					exit (0);
299cdf0e10cSrcweir 				}
300cdf0e10cSrcweir 			}
301cdf0e10cSrcweir 		}
302cdf0e10cSrcweir 	}
303cdf0e10cSrcweir 
304cdf0e10cSrcweir 	if ((nOptions == 0) || (nOptions & OPTION_HELP))
305cdf0e10cSrcweir 	{
306cdf0e10cSrcweir 		printf ("Usage:\tt_store "
307cdf0e10cSrcweir 				"[[-c] [-t] [-r] [-w]] [[-i] [-d] [-h]] "
308cdf0e10cSrcweir 				"[-f filename]\n");
309cdf0e10cSrcweir 
310cdf0e10cSrcweir 		printf ("\nOptions:\n");
311cdf0e10cSrcweir 		printf ("-c\tcreate\n");
312cdf0e10cSrcweir 		printf ("-t\ttruncate\n");
313cdf0e10cSrcweir 		printf ("-r\tread\n");
314cdf0e10cSrcweir 		printf ("-w\twrite\n");
315cdf0e10cSrcweir 		printf ("-i\titerate\n");
316cdf0e10cSrcweir 		printf ("-d\tdump\n");
317cdf0e10cSrcweir 		printf ("-h\thelp\n");
318cdf0e10cSrcweir 		printf ("-f\tfilename\n");
319cdf0e10cSrcweir 
320cdf0e10cSrcweir 		printf ("\nExamples:");
321cdf0e10cSrcweir 		printf ("\nt_store -c -w -f t_store.rdb\n");
322cdf0e10cSrcweir 		printf ("\tCreate file 't_store.rdb',\n"
323cdf0e10cSrcweir 				"\twrite fixed number (1000) of streams.\n");
324cdf0e10cSrcweir 		printf ("\nt_store -c -i -d -f t_store.rdb\n");
325cdf0e10cSrcweir 		printf ("\tOpen file 't_store.rdb', "
326cdf0e10cSrcweir 				"create '/' directory,\n"
327cdf0e10cSrcweir 				"\titerate directory tree, "
328cdf0e10cSrcweir 				"dump directory info.\n");
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 		exit (0);
331cdf0e10cSrcweir 	}
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 	if (!aFile.isValid())
334cdf0e10cSrcweir 	{
335cdf0e10cSrcweir 		eErrCode = aFile.createInMemory();
336cdf0e10cSrcweir 		if (eErrCode != store_E_None)
337cdf0e10cSrcweir 		{
338cdf0e10cSrcweir 			printf ("Error: can't create memory file\n");
339cdf0e10cSrcweir 			exit (0);
340cdf0e10cSrcweir 		}
341cdf0e10cSrcweir 	}
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 	// Stream Read/Write.
344cdf0e10cSrcweir 	OUString aPath (RTL_CONSTASCII_USTRINGPARAM("/"));
345cdf0e10cSrcweir 	if ((nOptions & OPTION_READ) || (nOptions & OPTION_WRITE))
346cdf0e10cSrcweir 	{
347cdf0e10cSrcweir 		// Mode.
348cdf0e10cSrcweir 		storeAccessMode eMode = store_AccessReadOnly;
349cdf0e10cSrcweir 		if (nOptions & OPTION_WRITE)
350cdf0e10cSrcweir 			eMode = store_AccessReadWrite;
351cdf0e10cSrcweir 		if (nOptions & OPTION_CREAT)
352cdf0e10cSrcweir 			eMode = store_AccessCreate;
353cdf0e10cSrcweir 
354cdf0e10cSrcweir 		// Buffer.
355cdf0e10cSrcweir 		char pBuffer[_DEMOSTOR_BUFSIZ] = "Hello World";
356cdf0e10cSrcweir 		pBuffer[_DEMOSTOR_BUFSIZ - 2] = 'B';
357cdf0e10cSrcweir 		pBuffer[_DEMOSTOR_BUFSIZ - 1] = '\0';
358cdf0e10cSrcweir 
359cdf0e10cSrcweir 		// Load/Save.
360cdf0e10cSrcweir #ifndef PROFILE
361cdf0e10cSrcweir 		OTime aStartTime (OTime::getSystemTime());
362cdf0e10cSrcweir #endif /* PROFILE */
363cdf0e10cSrcweir 
364cdf0e10cSrcweir 		for (int i = 0; i < _DEMOSTOR_LOOPS; i++)
365cdf0e10cSrcweir 		{
366cdf0e10cSrcweir 			OUString aName (RTL_CONSTASCII_USTRINGPARAM("demostor-"));
367cdf0e10cSrcweir 			aName += OUString::valueOf ((sal_Int32)(i + 1), 10);
368cdf0e10cSrcweir 			aName += OUString::createFromAscii (".dat");
369cdf0e10cSrcweir 
370cdf0e10cSrcweir #if (_DEMOSTOR_REMOVE == 1)
371cdf0e10cSrcweir 			eErrCode = aFile.remove (aPath, aName);
372cdf0e10cSrcweir 			if ((eErrCode != store_E_None     ) &&
373cdf0e10cSrcweir 				(eErrCode != store_E_NotExists)    )
374cdf0e10cSrcweir 				break;
375cdf0e10cSrcweir #endif /* _REMOVE */
376cdf0e10cSrcweir 
377cdf0e10cSrcweir 			store::OStoreStream aStream;
378cdf0e10cSrcweir 			eErrCode = aStream.create (aFile, aPath, aName, eMode);
379cdf0e10cSrcweir 			if (eErrCode != store_E_None)
380cdf0e10cSrcweir             {
381cdf0e10cSrcweir                 OSL_TRACE("OStoreStream(%d)::create(): error: %d", i, eErrCode);
382cdf0e10cSrcweir 				break;
383cdf0e10cSrcweir             }
384cdf0e10cSrcweir 
385cdf0e10cSrcweir 			if (nOptions & OPTION_TRUNC)
386cdf0e10cSrcweir 			{
387cdf0e10cSrcweir 				eErrCode = aStream.setSize(0);
388cdf0e10cSrcweir 				if (eErrCode != store_E_None)
389cdf0e10cSrcweir                 {
390cdf0e10cSrcweir                     OSL_TRACE("OStoreStream(%d)::setSize(0): error: %d", i, eErrCode);
391cdf0e10cSrcweir 					break;
392cdf0e10cSrcweir                 }
393cdf0e10cSrcweir 			}
394cdf0e10cSrcweir 
395cdf0e10cSrcweir 			sal_uInt32 nDone = 0;
396cdf0e10cSrcweir 			if (nOptions & OPTION_WRITE)
397cdf0e10cSrcweir 			{
398cdf0e10cSrcweir 				eErrCode = aStream.writeAt (
399cdf0e10cSrcweir 					0, pBuffer, sizeof(pBuffer), nDone);
400cdf0e10cSrcweir 				if (eErrCode != store_E_None)
401cdf0e10cSrcweir                 {
402cdf0e10cSrcweir                     OSL_TRACE("OStoreStream(%d)::writeAt(): error: %d", i, eErrCode);
403cdf0e10cSrcweir 					break;
404cdf0e10cSrcweir                 }
405cdf0e10cSrcweir 			}
406cdf0e10cSrcweir 
407cdf0e10cSrcweir 			if (nOptions & OPTION_READ)
408cdf0e10cSrcweir 			{
409cdf0e10cSrcweir 				sal_uInt32 nOffset = 0;
410cdf0e10cSrcweir 				for (;;)
411cdf0e10cSrcweir 				{
412cdf0e10cSrcweir 					eErrCode = aStream.readAt (
413cdf0e10cSrcweir 						nOffset, pBuffer, sizeof(pBuffer), nDone);
414cdf0e10cSrcweir 					if (eErrCode != store_E_None)
415cdf0e10cSrcweir                     {
416cdf0e10cSrcweir                         OSL_TRACE("OStoreStream(%d)::readAt(): error: %d", i, eErrCode);
417cdf0e10cSrcweir 						break;
418cdf0e10cSrcweir                     }
419cdf0e10cSrcweir 					if (nDone == 0)
420cdf0e10cSrcweir 						break;
421cdf0e10cSrcweir 					nOffset += nDone;
422cdf0e10cSrcweir 				}
423cdf0e10cSrcweir 			}
424cdf0e10cSrcweir 
425cdf0e10cSrcweir 			aStream.close();
426cdf0e10cSrcweir 
427cdf0e10cSrcweir #ifndef PROFILE
428cdf0e10cSrcweir 			if (((i + 1) % (_DEMOSTOR_LOOPS/10)) == 0)
429cdf0e10cSrcweir 			{
430cdf0e10cSrcweir 				OTime aDelta (OTime::getSystemTime() - aStartTime);
431cdf0e10cSrcweir 
432cdf0e10cSrcweir 				sal_uInt32 nDelta = aDelta.Seconds * 1000000;
433cdf0e10cSrcweir 				nDelta += (aDelta.Nanosec / 1000);
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 				printf ("%d: %12.4g[usec]\n", (i+1),
436cdf0e10cSrcweir 						(double)(nDelta)/(double)(i+1));
437cdf0e10cSrcweir 			}
438cdf0e10cSrcweir #endif /* PROFILE */
439cdf0e10cSrcweir 		}
440cdf0e10cSrcweir 
441cdf0e10cSrcweir #ifndef PROFILE
442cdf0e10cSrcweir 		OTime aDelta (OTime::getSystemTime() - aStartTime);
443cdf0e10cSrcweir 
444cdf0e10cSrcweir 		sal_uInt32 nDelta = aDelta.Seconds * 1000000;
445cdf0e10cSrcweir 		nDelta += (aDelta.Nanosec / 1000);
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 		printf ("Total(rd,wr): %d[usec]\n", (unsigned int)(nDelta));
448cdf0e10cSrcweir #endif /* PROFILE */
449cdf0e10cSrcweir 	}
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 	// Link/Rename.
452cdf0e10cSrcweir 	if (nOptions & OPTION_LINK)
453cdf0e10cSrcweir 	{
454cdf0e10cSrcweir 		// Create symlink to (root) directory.
455cdf0e10cSrcweir 		eErrCode = aFile.symlink (
456cdf0e10cSrcweir 			aPath,      OUString::createFromAscii("000000/"),
457cdf0e10cSrcweir 			OUString(), aPath);
458cdf0e10cSrcweir 		OSL_POSTCOND(
459cdf0e10cSrcweir 			((eErrCode == store_E_None         ) ||
460cdf0e10cSrcweir 			 (eErrCode == store_E_AlreadyExists)    ),
461cdf0e10cSrcweir 			"t_store::main(): store_symlink() failed");
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 		// Create symlink to file.
464cdf0e10cSrcweir 		OUString aLinkName (RTL_CONSTASCII_USTRINGPARAM("demostor-1.lnk"));
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 		eErrCode = aFile.symlink (
467cdf0e10cSrcweir 			aPath, aLinkName,
468cdf0e10cSrcweir 			aPath, OUString::createFromAscii("demostor-1.dat"));
469cdf0e10cSrcweir 		OSL_POSTCOND(
470cdf0e10cSrcweir 			((eErrCode == store_E_None         ) ||
471cdf0e10cSrcweir 			 (eErrCode == store_E_AlreadyExists)    ),
472cdf0e10cSrcweir 			"t_store::main(): store_symlink() failed");
473cdf0e10cSrcweir 		if ((eErrCode == store_E_None         ) ||
474cdf0e10cSrcweir 			(eErrCode == store_E_AlreadyExists)    )
475cdf0e10cSrcweir 		{
476cdf0e10cSrcweir 			OUString aShortcut (
477cdf0e10cSrcweir 				RTL_CONSTASCII_USTRINGPARAM("Shortcut to demostor-1.dat"));
478cdf0e10cSrcweir 			eErrCode = aFile.rename (
479cdf0e10cSrcweir 				aPath, aLinkName,
480cdf0e10cSrcweir 				aPath, aShortcut);
481cdf0e10cSrcweir 			OSL_POSTCOND(
482cdf0e10cSrcweir 				((eErrCode == store_E_None         ) ||
483cdf0e10cSrcweir 				 (eErrCode == store_E_AlreadyExists)    ),
484cdf0e10cSrcweir 				"t_store::main(): store_rename() failed");
485cdf0e10cSrcweir 		}
486cdf0e10cSrcweir 
487cdf0e10cSrcweir 		// Create directory.
488cdf0e10cSrcweir 		OUString aDirName (RTL_CONSTASCII_USTRINGPARAM("demostor-1.dir"));
489cdf0e10cSrcweir 		store::OStoreDirectory aDir;
490cdf0e10cSrcweir 
491cdf0e10cSrcweir 		eErrCode = aDir.create (
492cdf0e10cSrcweir 			aFile, aPath, aDirName, store_AccessReadCreate);
493cdf0e10cSrcweir 		OSL_POSTCOND(
494cdf0e10cSrcweir 			(eErrCode == store_E_None),
495cdf0e10cSrcweir 			"t_store::main(): store_createDirectory() failed");
496cdf0e10cSrcweir 		if (eErrCode == store_E_None)
497cdf0e10cSrcweir 		{
498cdf0e10cSrcweir #if 0  /* NYI */
499cdf0e10cSrcweir 			// Rename directory.
500cdf0e10cSrcweir 			eErrCode = aFile.rename (
501cdf0e10cSrcweir 				aPath, "demostor-1.dir/",
502cdf0e10cSrcweir 				aPath, "Renamed demostor-1.dir");
503cdf0e10cSrcweir 			OSL_POSTCOND(
504cdf0e10cSrcweir 				((eErrCode == store_E_None         ) ||
505cdf0e10cSrcweir 				 (eErrCode == store_E_AlreadyExists)    ),
506cdf0e10cSrcweir 				"t_store::main(): store_rename() failed");
507cdf0e10cSrcweir 
508cdf0e10cSrcweir 			eErrCode = aFile.rename (
509cdf0e10cSrcweir 				aPath, "Renamed demostor-1.dir/",
510cdf0e10cSrcweir 				aPath, "demostor-1.dir");
511cdf0e10cSrcweir 			OSL_POSTCOND(
512cdf0e10cSrcweir 				(eErrCode == store_E_None),
513cdf0e10cSrcweir 				"t_store::main(): store_rename() failed");
514cdf0e10cSrcweir #endif  /* NYI */
515cdf0e10cSrcweir 		}
516cdf0e10cSrcweir 	}
517cdf0e10cSrcweir 
518cdf0e10cSrcweir 	// Directory iteration.
519cdf0e10cSrcweir 	if (nOptions & OPTION_ITER)
520cdf0e10cSrcweir 	{
521cdf0e10cSrcweir #ifndef PROFILE
522cdf0e10cSrcweir 		OTime aStartTime (OTime::getSystemTime());
523cdf0e10cSrcweir #endif /* PROFILE */
524cdf0e10cSrcweir 		OUString aEmpty;
525cdf0e10cSrcweir 
526cdf0e10cSrcweir 		// Root directory.
527cdf0e10cSrcweir 		store::OStoreDirectory aRootDir;
528cdf0e10cSrcweir 		if (nOptions & OPTION_LINK)
529cdf0e10cSrcweir 		{
530cdf0e10cSrcweir 			// Open symlink entry.
531cdf0e10cSrcweir 			eErrCode = aRootDir.create (
532cdf0e10cSrcweir 				aFile, aPath, OUString::createFromAscii("000000"),
533cdf0e10cSrcweir 				store_AccessReadOnly);
534cdf0e10cSrcweir 		}
535cdf0e10cSrcweir 		else
536cdf0e10cSrcweir 		{
537cdf0e10cSrcweir 			// Open direct entry.
538cdf0e10cSrcweir 			if (nOptions & OPTION_CREAT)
539cdf0e10cSrcweir 				eErrCode = aRootDir.create (
540cdf0e10cSrcweir 					aFile, aEmpty, aEmpty, store_AccessReadCreate);
541cdf0e10cSrcweir 			else if (nOptions & OPTION_WRITE)
542cdf0e10cSrcweir 				eErrCode = aRootDir.create (
543cdf0e10cSrcweir 					aFile, aEmpty, aEmpty, store_AccessReadWrite);
544cdf0e10cSrcweir 			else
545cdf0e10cSrcweir 				eErrCode = aRootDir.create (
546cdf0e10cSrcweir 					aFile, aEmpty, aEmpty, store_AccessReadOnly);
547cdf0e10cSrcweir 		}
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 		if (eErrCode == store_E_None)
550cdf0e10cSrcweir 		{
551cdf0e10cSrcweir 			// Traverse directory tree.
552cdf0e10cSrcweir 			DirectoryTraveller aTraveller (
553cdf0e10cSrcweir 				aFile, aEmpty, aEmpty, nOptions, 0);
554cdf0e10cSrcweir 			aRootDir.travel (aTraveller);
555cdf0e10cSrcweir 		}
556cdf0e10cSrcweir 		else
557cdf0e10cSrcweir 		{
558cdf0e10cSrcweir 			// Failure.
559cdf0e10cSrcweir 			printf ("Error: can't open directory: \"/\"\n");
560cdf0e10cSrcweir 		}
561cdf0e10cSrcweir 
562cdf0e10cSrcweir #ifndef PROFILE
563cdf0e10cSrcweir 		OTime aDelta (OTime::getSystemTime() - aStartTime);
564cdf0e10cSrcweir 
565cdf0e10cSrcweir 		sal_uInt32 nDelta = aDelta.Seconds * 1000000;
566cdf0e10cSrcweir 		nDelta += (aDelta.Nanosec / 1000);
567cdf0e10cSrcweir 
568cdf0e10cSrcweir 		printf ("Total(iter): %d[usec]\n", (unsigned int)(nDelta));
569cdf0e10cSrcweir #endif /* PROFILE */
570cdf0e10cSrcweir 	}
571cdf0e10cSrcweir 
572cdf0e10cSrcweir 	if (nOptions & OPTION_PAUSE)
573cdf0e10cSrcweir 	{
574cdf0e10cSrcweir 		TimeValue tv;
575cdf0e10cSrcweir 		tv.Seconds = 300;
576cdf0e10cSrcweir 		tv.Nanosec = 0;
577cdf0e10cSrcweir 		osl_waitThread (&tv);
578cdf0e10cSrcweir 	}
579cdf0e10cSrcweir 
580cdf0e10cSrcweir 	// Size.
581cdf0e10cSrcweir 	sal_uInt32 nSize = 0;
582cdf0e10cSrcweir 	aFile.getSize (nSize);
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 	// Done.
585cdf0e10cSrcweir 	aFile.close();
586cdf0e10cSrcweir 
587cdf0e10cSrcweir #if (defined(WNT) && defined(PROFILE))
588cdf0e10cSrcweir 	StopCAP();
589cdf0e10cSrcweir 	DumpCAP();
590cdf0e10cSrcweir #endif /* PROFILE */
591cdf0e10cSrcweir #ifndef PROFILE
592cdf0e10cSrcweir 	OTime aDelta (OTime::getSystemTime() - aMainStartTime);
593cdf0e10cSrcweir 
594cdf0e10cSrcweir 	sal_uInt32 nDelta = aDelta.Seconds * 1000000;
595cdf0e10cSrcweir 	nDelta += (aDelta.Nanosec / 1000);
596cdf0e10cSrcweir 
597cdf0e10cSrcweir 	printf ("Total: %d[usec]\n", (unsigned int)(nDelta));
598cdf0e10cSrcweir #endif /* PROFILE */
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 	return 0;
601cdf0e10cSrcweir }
602