1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "sal/types.h"
31 #include "osl/thread.h"
32 #include "rtl/ustring.hxx"
34 #include "lockbyte.hxx"
36 #ifndef INCLUDED_STDIO_H
38 #define INCLUDED_STDIO_H
42 #include "osl/process.h"
44 using namespace store
;
46 #define TEST_PAGESIZE 16384
48 /*========================================================================
52 *======================================================================*/
53 int SAL_CALL
main (int argc
, char **argv
)
55 storeError eErrCode
= store_E_None
;
56 rtl::Reference
<ILockBytes
> xLockBytes
;
60 rtl::OUString
aFilename (
61 argv
[1], rtl_str_getLength(argv
[1]),
62 osl_getThreadTextEncoding());
64 eErrCode
= FileLockBytes_createInstance (
65 xLockBytes
, aFilename
.pData
, store_AccessReadWrite
);
66 if (eErrCode
!= store_E_None
)
69 if (eErrCode
!= store_E_NotExists
)
71 fprintf (stderr
, "t_file: create() error: %d\n", eErrCode
);
76 eErrCode
= FileLockBytes_createInstance (
77 xLockBytes
, aFilename
.pData
, store_AccessReadCreate
);
78 if (eErrCode
!= store_E_None
)
80 fprintf (stderr
, "t_file: create() error: %d\n", eErrCode
);
84 fprintf (stdout
, "t_file: using FileLockBytes(\"%s\") implementation.\n", argv
[1]);
88 eErrCode
= MemoryLockBytes_createInstance (xLockBytes
);
89 if (eErrCode
!= store_E_None
)
91 fprintf (stderr
, "t_file: create() error: %d\n", eErrCode
);
94 fprintf (stdout
, "t_file: using MemoryLockBytes implementation.\n");
97 rtl::Reference
< PageData::Allocator
> xAllocator
;
98 eErrCode
= xLockBytes
->initialize (xAllocator
, TEST_PAGESIZE
);
99 if (eErrCode
!= store_E_None
)
101 fprintf (stderr
, "t_file: initialize() error: %d\n", eErrCode
);
105 sal_Char buffer
[TEST_PAGESIZE
];
106 rtl_fillMemory (buffer
, sizeof(buffer
), sal_uInt8('B'));
109 for (k
= 0; k
< 4; k
++)
111 sal_uInt32 index
= k
* TEST_PAGESIZE
/ 4;
115 for (i
= 0; i
< 256; i
++)
117 sal_uInt32 offset
= i
* TEST_PAGESIZE
;
118 eErrCode
= xLockBytes
->setSize (offset
+ TEST_PAGESIZE
);
119 if (eErrCode
!= store_E_None
)
121 fprintf (stderr
, "t_file: setSize() error: %d\n", eErrCode
);
125 for (k
= 0; k
< 4; k
++)
127 sal_uInt32 magic
= i
* 4 + k
;
130 sal_uInt32 verify
= 0;
131 eErrCode
= xLockBytes
->readAt (
132 0, &verify
, sizeof(verify
));
133 if (eErrCode
!= store_E_None
)
135 fprintf (stderr
, "t_file: readAt() error: %d\n", eErrCode
);
141 fprintf (stderr
, "Expected %ld read %ld\n", (unsigned long)(magic
), (unsigned long)(verify
));
145 sal_uInt32 index
= k
* TEST_PAGESIZE
/ 4;
146 eErrCode
= xLockBytes
->writeAt (
147 offset
+ index
, &(buffer
[index
]), TEST_PAGESIZE
/ 4);
148 if (eErrCode
!= store_E_None
)
150 fprintf (stderr
, "t_file: writeAt() error: %d\n", eErrCode
);
155 eErrCode
= xLockBytes
->writeAt (
156 0, &magic
, sizeof(magic
));
157 if (eErrCode
!= store_E_None
)
159 fprintf (stderr
, "t_file: writeAt() error: %d\n", eErrCode
);
165 eErrCode
= xLockBytes
->flush();
166 if (eErrCode
!= store_E_None
)
168 fprintf (stderr
, "t_file: flush() error: %d\n", eErrCode
);
172 sal_Char verify
[TEST_PAGESIZE
];
173 for (i
= 0; i
< 256; i
++)
175 sal_uInt32 offset
= i
* TEST_PAGESIZE
;
177 eErrCode
= xLockBytes
->readAt (offset
, verify
, TEST_PAGESIZE
);
178 if (eErrCode
!= store_E_None
)
180 fprintf (stderr
, "t_file: readAt() error: %d\n", eErrCode
);
184 sal_uInt32 index
= 0;
187 sal_uInt32 magic
= 256 * 4;
188 if (rtl_compareMemory (&verify
[index
], &magic
, sizeof(magic
)))
191 fprintf (stderr
, "t_file: Unexpected value at 0x00000000\n");
195 if (rtl_compareMemory (
196 &verify
[index
], &buffer
[index
], TEST_PAGESIZE
- index
))
199 fprintf (stderr
, "t_file: Unexpected block at 0x%08x\n", (unsigned)(offset
));
203 for (i
= 0; i
< 256; i
++)
206 sal_uInt32 offset
= i
* TEST_PAGESIZE
;
208 eErrCode
= xLockBytes
->readPageAt (xPage
, offset
);
209 if (eErrCode
!= store_E_None
)
211 fprintf (stderr
, "t_file: readPageAt() error: %d\n", eErrCode
);
215 PageData
* page
= xPage
.get();
216 (void)page
; // UNUSED
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */