[Libreoffice-commits] core.git: sd/qa

Tomaž Vajngerl tomaz.vajngerl at collabora.co.uk
Mon Jan 9 21:15:53 UTC 2017


 sd/qa/unit/data/ppt/FillPatterns.ppt |binary
 sd/qa/unit/import-tests.cxx          |  339 +++++++++++++++++++++++++++++++++++
 2 files changed, 339 insertions(+)

New commits:
commit 0b87e17a4e122d53a765a9db2ae54908e0803b65
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
Date:   Sun Jan 8 23:32:05 2017 +0100

    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 at gmail.com>
    Tested-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/sd/qa/unit/data/ppt/FillPatterns.ppt b/sd/qa/unit/data/ppt/FillPatterns.ppt
new file mode 100644
index 0000000..bbd353b
Binary files /dev/null and b/sd/qa/unit/data/ppt/FillPatterns.ppt differ
diff --git a/sd/qa/unit/import-tests.cxx b/sd/qa/unit/import-tests.cxx
index dd5f2e0..f0f523c 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,1,0,1,0,1,0,
+        0,0,0,1,0,0,0,1,
+        1,0,1,0,1,0,1,0,
+        0,1,0,0,0,1,0,0,
+        1,0,1,0,1,0,1,0,
+        0,0,0,1,0,0,0,1,
+    };
+    std::vector<sal_uInt8> aExpectedPattern6 = {
+        1,0,1,0,1,0,1,0,
+        0,1,0,1,0,1,0,1,
+        1,0,1,0,1,0,1,0,
+        0,1,0,1,0,0,0,1,
+        1,0,1,0,1,0,1,0,
+        0,1,0,1,0,1,0,1,
+        1,0,1,0,1,0,1,0,
+        0,0,0,1,0,1,0,1,
+    };
+    std::vector<sal_uInt8> aExpectedPattern7 = {
+        1,0,1,0,1,0,1,0,
+        0,1,0,1,0,1,0,1,
+        1,0,1,0,1,0,1,0,
+        0,1,0,1,0,1,0,1,
+        1,0,1,0,1,0,1,0,
+        0,1,0,1,0,1,0,1,
+        1,0,1,0,1,0,1,0,
+        0,1,0,1,0,1,0,1,
+    };
+    std::vector<sal_uInt8> aExpectedPattern8 = {
+        1,1,1,0,1,1,1,0,
+        0,1,0,1,0,1,0,1,
+        1,0,1,1,1,0,1,1,
+        0,1,0,1,0,1,0,1,
+        1,1,1,0,1,1,1,0,
+        0,1,0,1,0,1,0,1,
+        1,0,1,1,1,0,1,1,
+        0,1,0,1,0,1,0,1,
+    };
+    std::vector<sal_uInt8> aExpectedPattern9 = {
+        0,1,1,1,0,1,1,1,
+        1,1,0,1,1,1,0,1,
+        0,1,1,1,0,1,1,1,
+        1,1,0,1,1,1,0,1,
+        0,1,1,1,0,1,1,1,
+        1,1,0,1,1,1,0,1,
+        0,1,1,1,0,1,1,1,
+        1,1,0,1,1,1,0,1,
+    };
+    std::vector<sal_uInt8> aExpectedPattern10 = {
+        0,1,1,1,0,1,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,0,1,1,1,0,1,
+        1,1,1,1,1,1,1,1,
+        0,1,1,1,0,1,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,0,1,1,1,0,1,
+        1,1,1,1,1,1,1,1,
+    };
+    std::vector<sal_uInt8> aExpectedPattern11 = {
+        1,1,1,0,1,1,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,0,
+        1,1,1,1,1,1,1,1,
+        1,1,1,0,1,1,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,0,
+        1,1,1,1,1,1,1,1,
+    };
+    std::vector<sal_uInt8> aExpectedPattern12 = {
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,0,1,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,1,
+        1,1,1,1,1,1,1,1,
+        0,1,1,1,1,1,1,1,
+    };
+    std::vector<sal_uInt8> aExpectedPatternLine1 = {
+        1,0,0,0,1,0,0,0,
+        0,1,0,0,0,1,0,0,
+        0,0,1,0,0,0,1,0,
+        0,0,0,1,0,0,0,1,
+        1,0,0,0,1,0,0,0,
+        0,1,0,0,0,1,0,0,
+        0,0,1,0,0,0,1,0,
+        0,0,0,1,0,0,0,1,
+    };
+    std::vector<sal_uInt8> aExpectedPatternLine2 = {
+        0,0,0,1,0,0,0,1,
+        0,0,1,0,0,0,1,0,
+        0,1,0,0,0,1,0,0,
+        1,0,0,0,1,0,0,0,
+        0,0,0,1,0,0,0,1,
+        0,0,1,0,0,0,1,0,
+        0,1,0,0,0,1,0,0,
+        1,0,0,0,1,0,0,0,
+    };
+    std::vector<sal_uInt8> aExpectedPatternLine3 = {
+        1,1,0,0,1,1,0,0,
+        0,1,1,0,0,1,1,0,
+        0,0,1,1,0,0,1,1,
+        1,0,0,1,1,0,0,1,
+        1,1,0,0,1,1,0,0,
+        0,1,1,0,0,1,1,0,
+        0,0,1,1,0,0,1,1,
+        1,0,0,1,1,0,0,1,
+    };
+    std::vector<sal_uInt8> aExpectedPatternLine4 = {
+        0,0,1,1,0,0,1,1,
+        0,1,1,0,0,1,1,0,
+        1,1,0,0,1,1,0,0,
+        1,0,0,1,1,0,0,1,
+        0,0,1,1,0,0,1,1,
+        0,1,1,0,0,1,1,0,
+        1,1,0,0,1,1,0,0,
+        1,0,0,1,1,0,0,1,
+    };
+    std::vector<sal_uInt8> aExpectedPatternLine5 = {
+        1,1,0,0,0,0,0,1,
+        1,1,1,0,0,0,0,0,
+        0,1,1,1,0,0,0,0,
+        0,0,1,1,1,0,0,0,
+        0,0,0,1,1,1,0,0,
+        0,0,0,0,1,1,1,0,
+        0,0,0,0,0,1,1,1,
+        1,0,0,0,0,0,1,1,
+    };
+    std::vector<sal_uInt8> aExpectedPatternLine6 = {
+        1,0,0,0,0,0,1,1,
+        0,0,0,0,0,1,1,1,
+        0,0,0,0,1,1,1,0,
+        0,0,0,1,1,1,0,0,
+        0,0,1,1,1,0,0,0,
+        0,1,1,1,0,0,0,0,
+        1,1,1,0,0,0,0,0,
+        1,1,0,0,0,0,0,1,
+    };
+    std::vector<sal_uInt8> aExpectedPatternLine7 = {
+        1,0,0,0,1,0,0,0,
+        1,0,0,0,1,0,0,0,
+        1,0,0,0,1,0,0,0,
+        1,0,0,0,1,0,0,0,
+        1,0,0,0,1,0,0,0,
+        1,0,0,0,1,0,0,0,
+        1,0,0,0,1,0,0,0,
+        1,0,0,0,1,0,0,0,
+    };
+    std::vector<sal_uInt8> aExpectedPatternLine8 = {
+        1,1,1,1,1,1,1,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,
+        1,1,1,1,1,1,1,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,
+    };
+    std::vector<sal_uInt8> aExpectedPatternLine9 = {
+        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,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();


More information about the Libreoffice-commits mailing list