[Libreoffice-commits] core.git: include/vcl vcl/CppunitTest_vcl_graphic_test.mk vcl/qa vcl/source

Tomaž Vajngerl (via logerrit) logerrit at kemper.freedesktop.org
Sun Jan 10 23:00:42 UTC 2021


 include/vcl/BinaryDataContainer.hxx        |   26 +++++++++--
 vcl/CppunitTest_vcl_graphic_test.mk        |    1 
 vcl/qa/cppunit/BinaryDataContainerTest.cxx |   63 +++++++++++++++++++++++++++++
 vcl/source/graphic/BinaryDataContainer.cxx |    5 --
 4 files changed, 85 insertions(+), 10 deletions(-)

New commits:
commit 80497c7d81af36f703d122ac78baa26387a5854d
Author:     Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Dec 27 19:07:57 2020 +0900
Commit:     Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sun Jan 10 23:59:57 2021 +0100

    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 at gmail.com>

diff --git a/include/vcl/BinaryDataContainer.hxx b/include/vcl/BinaryDataContainer.hxx
index af79f474e3e4..f367b640c063 100644
--- a/include/vcl/BinaryDataContainer.hxx
+++ b/include/vcl/BinaryDataContainer.hxx
@@ -27,13 +27,29 @@ private:
 
 public:
     explicit BinaryDataContainer();
-    explicit BinaryDataContainer(size_t nSize);
     explicit BinaryDataContainer(const sal_uInt8* pData, size_t nSize);
 
-    explicit BinaryDataContainer(const BinaryDataContainer& rBinaryDataContainer) = default;
-    explicit BinaryDataContainer(BinaryDataContainer&& rBinaryDataContainer) = default;
-    BinaryDataContainer& operator=(const BinaryDataContainer& rBinaryDataContainer) = default;
-    BinaryDataContainer& operator=(BinaryDataContainer&& rBinaryDataContainer) = default;
+    BinaryDataContainer(const BinaryDataContainer& rBinaryDataContainer)
+        : mpData(rBinaryDataContainer.mpData)
+    {
+    }
+
+    BinaryDataContainer(BinaryDataContainer&& rBinaryDataContainer)
+        : mpData(std::move(rBinaryDataContainer.mpData))
+    {
+    }
+
+    BinaryDataContainer& operator=(const BinaryDataContainer& rBinaryDataContainer)
+    {
+        mpData = rBinaryDataContainer.mpData;
+        return *this;
+    }
+
+    BinaryDataContainer& operator=(BinaryDataContainer&& rBinaryDataContainer)
+    {
+        mpData = std::move(rBinaryDataContainer.mpData);
+        return *this;
+    }
 
     size_t getSize() const { return mpData ? mpData->size() : 0; }
     bool isEmpty() const { return !mpData || mpData->empty(); }
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))
 {


More information about the Libreoffice-commits mailing list