summaryrefslogtreecommitdiff
path: root/vcl/qa
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-05-01 19:24:01 +0200
committerTomaž Vajngerl <quikee@gmail.com>2020-05-03 13:04:51 +0200
commit1114ebb37487bd0f7ad0e327fa571a5c925b237c (patch)
tree5c779904a6757730b1b9ed9d702e060e3e5e02a6 /vcl/qa
parent92b0a4d933d682bfce10fa5f04c7a966f20cde7a (diff)
vcl: add Graphic reading to TypeSerializer + tests
Change-Id: I73aafc4f9a6f964a31d116610df6cf15dc51770c Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93334 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r--vcl/qa/cppunit/TypeSerializerTest.cxx68
1 files changed, 65 insertions, 3 deletions
diff --git a/vcl/qa/cppunit/TypeSerializerTest.cxx b/vcl/qa/cppunit/TypeSerializerTest.cxx
index 0c737a4c4f03..c7ad8827a28d 100644
--- a/vcl/qa/cppunit/TypeSerializerTest.cxx
+++ b/vcl/qa/cppunit/TypeSerializerTest.cxx
@@ -51,12 +51,12 @@ std::string toHexString(const std::vector<unsigned char>& a)
class TypeSerializerTest : public CppUnit::TestFixture
{
void testGradient();
- void testGraphic();
+ void testGraphic_Vector();
void testGraphic_Bitmap_NoGfxLink();
CPPUNIT_TEST_SUITE(TypeSerializerTest);
CPPUNIT_TEST(testGradient);
- CPPUNIT_TEST(testGraphic);
+ CPPUNIT_TEST(testGraphic_Vector);
CPPUNIT_TEST(testGraphic_Bitmap_NoGfxLink);
CPPUNIT_TEST_SUITE_END();
};
@@ -91,7 +91,7 @@ void TypeSerializerTest::testGradient()
CPPUNIT_ASSERT_EQUAL(sal_uInt16(30), aReadGradient.GetSteps());
}
-void TypeSerializerTest::testGraphic()
+void TypeSerializerTest::testGraphic_Vector()
{
test::Directories aDirectories;
OUString aURL = aDirectories.getURLFromSrc(DATA_DIRECTORY) + "SimpleExample.svg";
@@ -99,6 +99,7 @@ void TypeSerializerTest::testGraphic()
GraphicFilter& rGraphicFilter = GraphicFilter::GetGraphicFilter();
Graphic aGraphic = rGraphicFilter.ImportUnloadedGraphic(aStream);
aGraphic.makeAvailable();
+ BitmapChecksum aChecksum = aGraphic.getVectorGraphicData()->GetChecksum();
// Test WriteGraphic - Native Format 5
{
@@ -117,6 +118,13 @@ void TypeSerializerTest::testGraphic()
sal_uInt32 nType;
aMemoryStream.ReadUInt32(nType);
CPPUNIT_ASSERT_EQUAL(COMPAT_FORMAT('N', 'A', 'T', '5'), nType);
+
+ // Read it back
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+ Graphic aNewGraphic;
+ ReadGraphic(aMemoryStream, aNewGraphic);
+ CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aNewGraphic.GetType());
+ CPPUNIT_ASSERT_EQUAL(aChecksum, aNewGraphic.getVectorGraphicData()->GetChecksum());
}
// Test WriteGraphic - Normal
@@ -129,6 +137,18 @@ void TypeSerializerTest::testGraphic()
std::vector<unsigned char> aHash = calculateHash(aMemoryStream);
CPPUNIT_ASSERT_EQUAL(std::string("c2bed2099ce617f1cc035701de5186f0d43e3064"),
toHexString(aHash));
+
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+ sal_uInt32 nType;
+ aMemoryStream.ReadUInt32(nType);
+ CPPUNIT_ASSERT_EQUAL(createMagic('s', 'v', 'g', '0'), nType);
+
+ // Read it back
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+ Graphic aNewGraphic;
+ ReadGraphic(aMemoryStream, aNewGraphic);
+ CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aNewGraphic.GetType());
+ CPPUNIT_ASSERT_EQUAL(aChecksum, aNewGraphic.getVectorGraphicData()->GetChecksum());
}
// Test TypeSerializer - Native Format 5
@@ -151,6 +171,16 @@ void TypeSerializerTest::testGraphic()
sal_uInt32 nType;
aMemoryStream.ReadUInt32(nType);
CPPUNIT_ASSERT_EQUAL(COMPAT_FORMAT('N', 'A', 'T', '5'), nType);
+
+ // Read it back
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+ Graphic aNewGraphic;
+ {
+ TypeSerializer aSerializer(aMemoryStream);
+ aSerializer.readGraphic(aNewGraphic);
+ }
+ CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aNewGraphic.GetType());
+ CPPUNIT_ASSERT_EQUAL(aChecksum, aNewGraphic.getVectorGraphicData()->GetChecksum());
}
// Test TypeSerializer - Normal
@@ -166,6 +196,21 @@ void TypeSerializerTest::testGraphic()
std::vector<unsigned char> aHash = calculateHash(aMemoryStream);
CPPUNIT_ASSERT_EQUAL(std::string("c2bed2099ce617f1cc035701de5186f0d43e3064"),
toHexString(aHash));
+
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+ sal_uInt32 nType;
+ aMemoryStream.ReadUInt32(nType);
+ CPPUNIT_ASSERT_EQUAL(createMagic('s', 'v', 'g', '0'), nType);
+
+ // Read it back
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+ Graphic aNewGraphic;
+ {
+ TypeSerializer aSerializer(aMemoryStream);
+ aSerializer.readGraphic(aNewGraphic);
+ }
+ CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aNewGraphic.GetType());
+ CPPUNIT_ASSERT_EQUAL(aChecksum, aNewGraphic.getVectorGraphicData()->GetChecksum());
}
}
@@ -191,6 +236,13 @@ void TypeSerializerTest::testGraphic_Bitmap_NoGfxLink()
sal_uInt16 nType;
aMemoryStream.ReadUInt16(nType);
CPPUNIT_ASSERT_EQUAL(sal_uInt16(0x4D42), nType); // Magic written with WriteDIBBitmapEx
+
+ // Read it back
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+ Graphic aNewGraphic;
+ ReadGraphic(aMemoryStream, aNewGraphic);
+ CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aNewGraphic.GetType());
+ CPPUNIT_ASSERT_EQUAL(aBitmapEx.GetChecksum(), aNewGraphic.GetBitmapExRef().GetChecksum());
}
// Test TypeSerializer
@@ -211,6 +263,16 @@ void TypeSerializerTest::testGraphic_Bitmap_NoGfxLink()
sal_uInt16 nType;
aMemoryStream.ReadUInt16(nType);
CPPUNIT_ASSERT_EQUAL(sal_uInt16(0x4D42), nType); // Magic written with WriteDIBBitmapEx
+
+ // Read it back
+ aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
+ Graphic aNewGraphic;
+ {
+ TypeSerializer aSerializer(aMemoryStream);
+ aSerializer.readGraphic(aNewGraphic);
+ }
+ CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aNewGraphic.GetType());
+ CPPUNIT_ASSERT_EQUAL(aBitmapEx.GetChecksum(), aNewGraphic.GetBitmapExRef().GetChecksum());
}
}