Update git submodules
[LibreOffice.git] / store / qa / store.cxx
blob69bc3f8f8674aa31747c7f75858b32a44de62b04
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <cppunit/TestFixture.h>
11 #include <cppunit/extensions/HelperMacros.h>
12 #include <cppunit/plugin/TestPlugIn.h>
14 #include <store/store.hxx>
16 #include <memory>
18 namespace
20 class StoreTest : public CppUnit::TestFixture
22 public:
23 void createMemoryStream();
24 void createStream();
25 void writeAndReadByte();
27 CPPUNIT_TEST_SUITE(StoreTest);
28 CPPUNIT_TEST(createMemoryStream);
29 CPPUNIT_TEST(createStream);
30 CPPUNIT_TEST(writeAndReadByte);
31 CPPUNIT_TEST_SUITE_END();
34 void StoreTest::createMemoryStream()
36 store::OStoreFile aFile;
37 CPPUNIT_ASSERT_EQUAL(store_E_None, aFile.createInMemory());
40 void StoreTest::createStream()
42 store::OStoreFile aFile;
43 CPPUNIT_ASSERT_EQUAL(store_E_None, aFile.createInMemory());
45 store::OStoreStream aStream;
46 CPPUNIT_ASSERT_EQUAL(store_E_None,
47 aStream.create(aFile, "testnode", "testname", storeAccessMode::Create));
49 aFile.close();
52 void StoreTest::writeAndReadByte()
54 store::OStoreFile aFile;
55 CPPUNIT_ASSERT_EQUAL(store_E_None, aFile.createInMemory());
57 store::OStoreStream aStream;
58 CPPUNIT_ASSERT_EQUAL(store_E_None,
59 aStream.create(aFile, "testnode", "testname", storeAccessMode::Create));
62 std::unique_ptr<sal_uInt8[]> pWriteBuffer(new sal_uInt8[1]);
63 pWriteBuffer[0] = 'a';
65 sal_uInt32 writtenBytes;
67 CPPUNIT_ASSERT_EQUAL(store_E_None, aStream.writeAt(0, pWriteBuffer.get(), 1, writtenBytes));
68 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(1), writtenBytes);
72 std::unique_ptr<sal_uInt8[]> pReadBuffer(new sal_uInt8[1]);
73 sal_uInt32 readBytes;
75 CPPUNIT_ASSERT_EQUAL(store_E_None, aStream.readAt(0, pReadBuffer.get(), 1, readBytes));
76 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(1), readBytes);
77 CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt8>('a'), pReadBuffer[0]);
80 aFile.close();
83 CPPUNIT_TEST_SUITE_REGISTRATION(StoreTest);
86 CPPUNIT_PLUGIN_IMPLEMENT();
88 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */