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 | |
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')
-rw-r--r-- | vcl/CppunitTest_vcl_graphic_test.mk | 1 | ||||
-rw-r--r-- | vcl/qa/cppunit/BinaryDataContainerTest.cxx | 63 | ||||
-rw-r--r-- | vcl/source/graphic/BinaryDataContainer.cxx | 5 |
3 files changed, 64 insertions, 5 deletions
diff --git a/vcl/CppunitTest_vcl_graphic_test.mk b/vcl/CppunitTest_vcl_graphic_test.mk index 2f2c61735ef8..9221fd474fdd 100644 --- a/vcl/CppunitTest_vcl_graphic_test.mk +++ b/vcl/CppunitTest_vcl_graphic_test.mk @@ -15,6 +15,7 @@ $(eval $(call gb_CppunitTest_add_exception_objects,vcl_graphic_test, \ vcl/qa/cppunit/GraphicFormatDetectorTest \ vcl/qa/cppunit/GraphicNativeMetadataTest \ vcl/qa/cppunit/VectorGraphicSearchTest \ + vcl/qa/cppunit/BinaryDataContainerTest \ )) $(eval $(call gb_CppunitTest_use_externals,vcl_graphic_test, \ 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: */ diff --git a/vcl/source/graphic/BinaryDataContainer.cxx b/vcl/source/graphic/BinaryDataContainer.cxx index 4c556195fe6a..7576852215b1 100644 --- a/vcl/source/graphic/BinaryDataContainer.cxx +++ b/vcl/source/graphic/BinaryDataContainer.cxx @@ -13,11 +13,6 @@ BinaryDataContainer::BinaryDataContainer() = default; -BinaryDataContainer::BinaryDataContainer(size_t nSize) - : mpData(std::make_shared<std::vector<sal_uInt8>>(nSize)) -{ -} - BinaryDataContainer::BinaryDataContainer(const sal_uInt8* pData, size_t nSize) : mpData(std::make_shared<std::vector<sal_uInt8>>(nSize)) { |