diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2020-12-27 19:07:57 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-01-10 23:59:57 +0100 |
commit | 80497c7d81af36f703d122ac78baa26387a5854d (patch) | |
tree | 79e119b88b6a133564a3a0e605fdd6f40f950e3e /vcl/qa/cppunit/BinaryDataContainerTest.cxx | |
parent | 070084c4d62bc05d7d9fdd7b4368b91ccd9c1e8b (diff) |
vcl: implement BinaryDataContainer copy, move + test
Also remove constructor that takes size only - BinaryDataContainer
should always be constructed with data, that is copied into the
container and should be immutable.
Change-Id: Ic61b393b7729b948843bd20e6676c9290c68936f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108439
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/qa/cppunit/BinaryDataContainerTest.cxx')
-rw-r--r-- | vcl/qa/cppunit/BinaryDataContainerTest.cxx | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/BinaryDataContainerTest.cxx b/vcl/qa/cppunit/BinaryDataContainerTest.cxx new file mode 100644 index 000000000000..94e774ec9969 --- /dev/null +++ b/vcl/qa/cppunit/BinaryDataContainerTest.cxx @@ -0,0 +1,63 @@ +/* -*- 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/. + */ + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> + +#include <vcl/BinaryDataContainer.hxx> + +using namespace css; + +namespace +{ +class BinaryDataContainerTest : public CppUnit::TestFixture +{ + void test(); + + CPPUNIT_TEST_SUITE(BinaryDataContainerTest); + CPPUNIT_TEST(test); + CPPUNIT_TEST_SUITE_END(); +}; + +void BinaryDataContainerTest::test() +{ + { + BinaryDataContainer aContainer; + CPPUNIT_ASSERT_EQUAL(true, aContainer.isEmpty()); + CPPUNIT_ASSERT_EQUAL(size_t(0), aContainer.getSize()); + } + { + std::vector<sal_uInt8> aTestByteArray = { 1, 2, 3, 4 }; + BinaryDataContainer aContainer(aTestByteArray.data(), aTestByteArray.size()); + CPPUNIT_ASSERT_EQUAL(false, aContainer.isEmpty()); + CPPUNIT_ASSERT_EQUAL(size_t(4), aContainer.getSize()); + + // Test Copy + BinaryDataContainer aCopyOfContainer = aContainer; + CPPUNIT_ASSERT_EQUAL(false, aCopyOfContainer.isEmpty()); + CPPUNIT_ASSERT_EQUAL(size_t(4), aCopyOfContainer.getSize()); + CPPUNIT_ASSERT_EQUAL(aCopyOfContainer.getData(), aContainer.getData()); + + // Test Move + BinaryDataContainer aMovedInContainer = std::move(aCopyOfContainer); + CPPUNIT_ASSERT_EQUAL(false, aMovedInContainer.isEmpty()); + CPPUNIT_ASSERT_EQUAL(size_t(4), aMovedInContainer.getSize()); + CPPUNIT_ASSERT_EQUAL(aMovedInContainer.getData(), aContainer.getData()); + + CPPUNIT_ASSERT_EQUAL(true, aCopyOfContainer.isEmpty()); + CPPUNIT_ASSERT_EQUAL(size_t(0), aCopyOfContainer.getSize()); + } +} + +} // namespace + +CPPUNIT_TEST_SUITE_REGISTRATION(BinaryDataContainerTest); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |