[Libreoffice-commits] core.git: vcl/CppunitTest_vcl_type_serializer_test.mk vcl/qa
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Sat May 2 20:56:08 UTC 2020
vcl/CppunitTest_vcl_type_serializer_test.mk | 11 --
vcl/qa/cppunit/TypeSerializerTest.cxx | 104 +++++++++++++++++++++++++++-
2 files changed, 103 insertions(+), 12 deletions(-)
New commits:
commit b8ab04486fdcd38cfc55350a991f314cda1448d0
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Thu Apr 30 10:42:56 2020 +0200
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sat May 2 22:55:29 2020 +0200
vcl: test Graphic serialization to a stream - WriteGraphic funct.
Change-Id: Ic365d27e9ef1c676e47de22b8949b5679c0a2841
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93326
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/vcl/CppunitTest_vcl_type_serializer_test.mk b/vcl/CppunitTest_vcl_type_serializer_test.mk
index aa4a36e2ee32..b2d78c34a6a1 100644
--- a/vcl/CppunitTest_vcl_type_serializer_test.mk
+++ b/vcl/CppunitTest_vcl_type_serializer_test.mk
@@ -33,18 +33,9 @@ $(eval $(call gb_CppunitTest_use_libraries,vcl_type_serializer_test, \
))
$(eval $(call gb_CppunitTest_use_sdk_api,vcl_type_serializer_test))
-
+$(eval $(call gb_CppunitTest_use_rdb,vcl_type_serializer_test,services))
$(eval $(call gb_CppunitTest_use_ure,vcl_type_serializer_test))
$(eval $(call gb_CppunitTest_use_vcl,vcl_type_serializer_test))
-
-$(eval $(call gb_CppunitTest_use_components,vcl_type_serializer_test,\
- configmgr/source/configmgr \
- i18npool/util/i18npool \
- ucb/source/core/ucb1 \
- ucb/source/ucp/file/ucpfile1 \
- uui/util/uui \
-))
-
$(eval $(call gb_CppunitTest_use_configuration,vcl_type_serializer_test))
# vim: set noet sw=4 ts=4:
diff --git a/vcl/qa/cppunit/TypeSerializerTest.cxx b/vcl/qa/cppunit/TypeSerializerTest.cxx
index cf5985211076..e5d3a259f803 100644
--- a/vcl/qa/cppunit/TypeSerializerTest.cxx
+++ b/vcl/qa/cppunit/TypeSerializerTest.cxx
@@ -7,23 +7,57 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <config_features.h>
+
#include <cppunit/TestAssert.h>
#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/plugin/TestPlugIn.h>
-#include <config_features.h>
-#include <vcl/dllapi.h>
+
+#include <unotest/directories.hxx>
+#include <vcl/graph.hxx>
+#include <vcl/graphicfilter.hxx>
+#include <comphelper/hash.hxx>
+#include <tools/vcompat.hxx>
+#include <comphelper/fileformat.h>
#include <TypeSerializer.hxx>
namespace
{
+constexpr char DATA_DIRECTORY[] = "/vcl/qa/cppunit/data/";
+
+std::vector<unsigned char> calculateHash(SvStream& rStream)
+{
+ rStream.Seek(STREAM_SEEK_TO_BEGIN);
+ comphelper::Hash aHashEngine(comphelper::HashType::SHA1);
+ const sal_uInt32 nSize(rStream.remainingSize());
+ std::vector<sal_uInt8> aData(nSize);
+ aHashEngine.update(aData.data(), nSize);
+ return aHashEngine.finalize();
+}
+
+std::string toHexString(const std::vector<unsigned char>& a)
+{
+ std::stringstream aStrm;
+ for (auto& i : a)
+ {
+ aStrm << std::setw(2) << std::setfill('0') << std::hex << static_cast<int>(i);
+ }
+
+ return aStrm.str();
+}
+
class TypeSerializerTest : public CppUnit::TestFixture
{
void testGradient();
+ void testGraphic();
+ void testGraphic_Bitmap_NoGfxLink();
CPPUNIT_TEST_SUITE(TypeSerializerTest);
CPPUNIT_TEST(testGradient);
+ CPPUNIT_TEST(testGraphic);
+ CPPUNIT_TEST(testGraphic_Bitmap_NoGfxLink);
CPPUNIT_TEST_SUITE_END();
};
@@ -57,6 +91,72 @@ void TypeSerializerTest::testGradient()
CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), aReadGradient.GetSteps());
}
+void TypeSerializerTest::testGraphic()
+{
+ test::Directories aDirectories;
+ OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "SimpleExample.svg";
+ SvFileStream aStream(aURL, StreamMode::READ);
+ GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
+ Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
+ aGraphic.makeAvailable();
+
+ // Test WriteGraphic - Native Format 5
+ {
+ SvMemoryStream aMemoryStream;
+ aMemoryStream.SetVersion(SOFFICE_FILEFORMAT_50);
+ aMemoryStream.SetCompressMode(SvStreamCompressFlags::NATIVE);
+ WriteGraphic(aMemoryStream, aGraphic);
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+
+ CPPUNIT_ASSERT_EQUAL(sal_uInt64(290), aMemoryStream.remainingSize());
+ std::vector<unsigned char> aHash = calculateHash(aMemoryStream);
+ CPPUNIT_ASSERT_EQUAL(std::string("ee55ab6faa73b61b68bc3d5628d95f0d3c528e2a"),
+ toHexString(aHash));
+
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+ sal_uInt32 nType;
+ aMemoryStream.ReadUInt32(nType);
+ CPPUNIT_ASSERT_EQUAL(COMPAT_FORMAT('N', 'A', 'T', '5'), nType);
+ }
+
+ // Test WriteGraphic - Normal
+ {
+ SvMemoryStream aMemoryStream;
+ WriteGraphic(aMemoryStream, aGraphic);
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+
+ CPPUNIT_ASSERT_EQUAL(sal_uInt64(233), aMemoryStream.remainingSize());
+ std::vector<unsigned char> aHash = calculateHash(aMemoryStream);
+ CPPUNIT_ASSERT_EQUAL(std::string("c2bed2099ce617f1cc035701de5186f0d43e3064"),
+ toHexString(aHash));
+ }
+}
+
+void TypeSerializerTest::testGraphic_Bitmap_NoGfxLink()
+{
+ Bitmap aBitmap(Size(10, 10), 24);
+ aBitmap.Erase(COL_LIGHTGRAYBLUE);
+ BitmapEx aBitmapEx(aBitmap);
+ Graphic aGraphic(aBitmapEx);
+
+ // Test WriteGraphic
+ {
+ SvMemoryStream aMemoryStream;
+ WriteGraphic(aMemoryStream, aGraphic);
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+
+ CPPUNIT_ASSERT_EQUAL(sal_uInt64(383), aMemoryStream.remainingSize());
+ std::vector<unsigned char> aHash = calculateHash(aMemoryStream);
+ CPPUNIT_ASSERT_EQUAL(std::string("da831418499146d51bf245fadf60b9111faa76c2"),
+ toHexString(aHash));
+
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+ sal_uInt16 nType;
+ aMemoryStream.ReadUInt16(nType);
+ CPPUNIT_ASSERT_EQUAL(sal_uInt16(0x4D42), nType); // Magic written with WriteDIBBitmapEx
+ }
+}
+
} // namespace
CPPUNIT_TEST_SUITE_REGISTRATION(TypeSerializerTest);
More information about the Libreoffice-commits
mailing list