summaryrefslogtreecommitdiff
path: root/sd/qa/unit
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2017-01-08 23:32:05 +0100
committerTomaž Vajngerl <quikee@gmail.com>2017-01-09 21:15:17 +0000
commit0b87e17a4e122d53a765a9db2ae54908e0803b65 (patch)
tree769679ead3d1b961bff92ff100d013bbbdec564a /sd/qa/unit
parent735941713c81ec8ca9ac796b832d776f6ef633ef (diff)
Test that patterns are correctly imported for MS binary format
Change-Id: I8335ee35bae11c8014d6591744199e55bc3ec41b Reviewed-on: https://gerrit.libreoffice.org/32854 Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sd/qa/unit')
-rw-r--r--sd/qa/unit/data/ppt/FillPatterns.pptbin0 -> 19968 bytes
-rw-r--r--sd/qa/unit/import-tests.cxx339
2 files changed, 339 insertions, 0 deletions
diff --git a/sd/qa/unit/data/ppt/FillPatterns.ppt b/sd/qa/unit/data/ppt/FillPatterns.ppt
new file mode 100644
index 000000000000..bbd353b52b2b
--- /dev/null
+++ b/sd/qa/unit/data/ppt/FillPatterns.ppt
Binary files differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index dd5f2e0ee670..f0f523c515a1 100644
--- a/sd/qa/unit/import-tests.cxx
+++ b/sd/qa/unit/import-tests.cxx
@@ -69,6 +69,7 @@
#include <comphelper/processfactory.hxx>
#include <vcl/pngread.hxx>
#include <vcl/bitmapaccess.hxx>
+#include <vcl/dibtools.hxx>
#include <sfx2/frame.hxx>
#include <com/sun/star/frame/XModel2.hpp>
#include <com/sun/star/frame/XController2.hpp>
@@ -137,6 +138,9 @@ public:
void testTdf105150();
void testTdf105150PPT();
+ bool checkPattern(sd::DrawDocShellRef& rDocRef, int nShapeNumber, std::vector<sal_uInt8>& rExpected);
+ void testPatternImport();
+
CPPUNIT_TEST_SUITE(SdImportTest);
CPPUNIT_TEST(testDocumentLayout);
@@ -196,6 +200,7 @@ public:
CPPUNIT_TEST(testTdf104445);
CPPUNIT_TEST(testTdf105150);
CPPUNIT_TEST(testTdf105150PPT);
+ CPPUNIT_TEST(testPatternImport);
CPPUNIT_TEST_SUITE_END();
};
@@ -1719,6 +1724,340 @@ void SdImportTest::testTdf104445()
xDocShRef->DoClose();
}
+namespace
+{
+
+bool checkPatternValues(std::vector<sal_uInt8>& rExpected, Bitmap& rBitmap)
+{
+ bool bResult = true;
+
+ Color aFGColor(0xFF0000);
+ Color aBGColor(0xFFFFFF);
+
+ Bitmap::ScopedReadAccess pAccess(rBitmap);
+ for (long y = 0; y < pAccess->Height(); ++y)
+ {
+ for (long x = 0; x < pAccess->Width(); ++x)
+ {
+ Color aColor = pAccess->GetPixel(y, x);
+ sal_uInt8 aValue = rExpected[y*8+x];
+
+ if (aValue == 1 && aColor != aFGColor)
+ bResult = false;
+ else if (aValue == 0 && aColor != aBGColor)
+ bResult = false;
+ }
+ }
+
+ return bResult;
+}
+
+} // end anonymous namespace
+
+bool SdImportTest::checkPattern(sd::DrawDocShellRef& rDocRef, int nShapeNumber, std::vector<sal_uInt8>& rExpected)
+{
+ uno::Reference<beans::XPropertySet> xShape(getShapeFromPage(nShapeNumber, 0, rDocRef));
+ CPPUNIT_ASSERT_MESSAGE("Not a shape", xShape.is());
+
+ Bitmap aBitmap;
+ if (xShape.is())
+ {
+ uno::Any aBitmapAny = xShape->getPropertyValue("FillBitmap");
+ uno::Reference<awt::XBitmap> xBitmap;
+ if (aBitmapAny >>= xBitmap)
+ {
+ uno::Sequence<sal_Int8> aBitmapSequence(xBitmap->getDIB());
+ SvMemoryStream aBitmapStream(aBitmapSequence.getArray(),
+ aBitmapSequence.getLength(),
+ StreamMode::READ);
+ ReadDIB(aBitmap, aBitmapStream, true);
+ }
+ }
+ CPPUNIT_ASSERT_EQUAL(8L, aBitmap.GetSizePixel().Width());
+ CPPUNIT_ASSERT_EQUAL(8L, aBitmap.GetSizePixel().Height());
+ return checkPatternValues(rExpected, aBitmap);
+}
+
+/* Test checks that importing a PPT file with all supported fill patterns is
+ * correctly imported as a tiled fill bitmap with the expected pattern.
+ */
+void SdImportTest::testPatternImport()
+{
+ sd::DrawDocShellRef xDocRef = loadURL(m_directories.getURLFromSrc("sd/qa/unit/data/ppt/FillPatterns.ppt"), PPT);
+
+ std::vector<sal_uInt8> aExpectedPattern1 = {
+ 1,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 0,0,0,0,1,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ };
+ std::vector<sal_uInt8> aExpectedPattern2 = {
+ 1,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 0,0,0,0,1,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 1,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 0,0,0,0,1,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ };
+ std::vector<sal_uInt8> aExpectedPattern3 = {
+ 1,0,0,0,1,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 0,0,1,0,0,0,1,0,
+ 0,0,0,0,0,0,0,0,
+ 1,0,0,0,1,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 0,0,1,0,0,0,1,0,
+ 0,0,0,0,0,0,0,0,
+ };
+ std::vector<sal_uInt8> aExpectedPattern4 = {
+ 1,0,0,0,1,0,0,0,
+ 0,0,1,0,0,0,1,0,
+ 1,0,0,0,1,0,0,0,
+ 0,0,1,0,0,0,1,0,
+ 1,0,0,0,1,0,0,0,
+ 0,0,1,0,0,0,1,0,
+ 1,0,0,0,1,0,0,0,
+ 0,0,1,0,0,0,1,0,
+ };
+ std::vector<sal_uInt8> aExpectedPattern5 = {
+ 1,0,1,0,1,0,1,0,
+ 0,1,0,0,0,1,0,0,
+ 1,0,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1,0,1,0,1,
+ 0,1,0,1,0,1,0,1,
+ 0,1,0,1,0,1,0,1,
+ 0,1,0,1,0,1,0,1,
+ 0,1,0,1,0,1,0,1,
+ 0,1,0,1,0,1,0,1,
+ 0,1,0,1,0,1,0,1,
+ };
+ std::vector<sal_uInt8> aExpectedPatternLine10 = {
+ 1,1,1,1,1,1,1,1,
+ 0,0,0,0,0,0,0,0,
+ 1,1,1,1,1,1,1,1,
+ 0,0,0,0,0,0,0,0,
+ 1,1,1,1,1,1,1,1,
+ 0,0,0,0,0,0,0,0,
+ 1,1,1,1,1,1,1,1,
+ 0,0,0,0,0,0,0,0,
+ };
+ std::vector<sal_uInt8> aExpectedPatternLine11 = {
+ 1,1,0,0,1,1,0,0,
+ 1,1,0,0,1,1,0,0,
+ 1,1,0,0,1,1,0,0,
+ 1,1,0,0,1,1,0,0,
+ 1,1,0,0,1,1,0,0,
+ 1,1,0,0,1,1,0,0,
+ 1,1,0,0,1,1,0,0,
+ 1,1,0,0,1,1,0,0,
+ };
+ std::vector<sal_uInt8> aExpectedPatternLine12 = {
+ 1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,
+ 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ 1,1,1,1,1,1,1,1,
+ 1,1,1,1,1,1,1,1,
+ 0,0,0,0,0,0,0,0,
+ 0,0,0,0,0,0,0,0,
+ };
+
+ CPPUNIT_ASSERT_MESSAGE("Pattern1 - 5%" , checkPattern(xDocRef, 0, aExpectedPattern1));
+ CPPUNIT_ASSERT_MESSAGE("Pattern2 - 10%", checkPattern(xDocRef, 1, aExpectedPattern2));
+ CPPUNIT_ASSERT_MESSAGE("Pattern3 - 20%", checkPattern(xDocRef, 2, aExpectedPattern3));
+ CPPUNIT_ASSERT_MESSAGE("Pattern4 - 25%", checkPattern(xDocRef, 3, aExpectedPattern4));
+ CPPUNIT_ASSERT_MESSAGE("Pattern5 - 30%", checkPattern(xDocRef, 4, aExpectedPattern5));
+ CPPUNIT_ASSERT_MESSAGE("Pattern6 - 40%", checkPattern(xDocRef, 5, aExpectedPattern6));
+ CPPUNIT_ASSERT_MESSAGE("Pattern7 - 50%", checkPattern(xDocRef, 6, aExpectedPattern7));
+ CPPUNIT_ASSERT_MESSAGE("Pattern8 - 60%", checkPattern(xDocRef, 7, aExpectedPattern8));
+ CPPUNIT_ASSERT_MESSAGE("Pattern9 - 70%", checkPattern(xDocRef, 8, aExpectedPattern9));
+ CPPUNIT_ASSERT_MESSAGE("Pattern10 - 75%", checkPattern(xDocRef, 9, aExpectedPattern10));
+ CPPUNIT_ASSERT_MESSAGE("Pattern11 - 80%", checkPattern(xDocRef, 10, aExpectedPattern11));
+ CPPUNIT_ASSERT_MESSAGE("Pattern12 - 90%", checkPattern(xDocRef, 11, aExpectedPattern12));
+
+ CPPUNIT_ASSERT_MESSAGE("Pattern13 - Light downward diagonal", checkPattern(xDocRef, 12, aExpectedPatternLine1));
+ CPPUNIT_ASSERT_MESSAGE("Pattern14 - Light upward diagonal", checkPattern(xDocRef, 13, aExpectedPatternLine2));
+ CPPUNIT_ASSERT_MESSAGE("Pattern15 - Dark downward diagonal", checkPattern(xDocRef, 14, aExpectedPatternLine3));
+ CPPUNIT_ASSERT_MESSAGE("Pattern16 - Dark upward diagonal", checkPattern(xDocRef, 15, aExpectedPatternLine4));
+ CPPUNIT_ASSERT_MESSAGE("Pattern17 - Wide downward diagonal", checkPattern(xDocRef, 16, aExpectedPatternLine5));
+ CPPUNIT_ASSERT_MESSAGE("Pattern18 - Wide upward diagonal", checkPattern(xDocRef, 17, aExpectedPatternLine6));
+
+ CPPUNIT_ASSERT_MESSAGE("Pattern19 - Light vertical", checkPattern(xDocRef, 18, aExpectedPatternLine7));
+ CPPUNIT_ASSERT_MESSAGE("Pattern20 - Light horizontal", checkPattern(xDocRef, 19, aExpectedPatternLine8));
+ CPPUNIT_ASSERT_MESSAGE("Pattern21 - Narrow vertical", checkPattern(xDocRef, 20, aExpectedPatternLine9));
+ CPPUNIT_ASSERT_MESSAGE("Pattern22 - Narrow horizontal", checkPattern(xDocRef, 21, aExpectedPatternLine10));
+ CPPUNIT_ASSERT_MESSAGE("Pattern23 - Dark vertical", checkPattern(xDocRef, 22, aExpectedPatternLine11));
+ CPPUNIT_ASSERT_MESSAGE("Pattern24 - Dark horizontal", checkPattern(xDocRef, 23, aExpectedPatternLine12));
+
+ // TODO: other patterns in the test document
+
+ xDocRef->DoClose();
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(SdImportTest);
CPPUNIT_PLUGIN_IMPLEMENT();