sc/qa/extras/scpdfexport.cxx         |   67 +++++++++++++++++++++++++++++
 sc/qa/uitest/calc_tests/tdf120161.py |   79 -----------------------------------
 2 files changed, 67 insertions(+), 79 deletions(-)

New commits:
commit 94314c0f2e0bee5bcb994b0cbfbfd9af9053eef8
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Fri Feb 5 14:17:43 2021 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Feb 5 20:31:01 2021 +0100

    tdf#120161: sc: Move UItest to CppUnitTest
    
    Change-Id: I0549b34902e04f2a6f9c07cfc1a293e5d572dee9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/110477
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sc/qa/extras/scpdfexport.cxx b/sc/qa/extras/scpdfexport.cxx
index 7b9610061bdb..58a93df8268e 100644
--- a/sc/qa/extras/scpdfexport.cxx
+++ b/sc/qa/extras/scpdfexport.cxx
@@ -15,6 +15,7 @@
 #include <com/sun/star/sheet/XSpreadsheet.hpp>
 #include <com/sun/star/table/XCellRange.hpp>
 #include <com/sun/star/view/XSelectionSupplier.hpp>
+#include <comphelper/propertysequence.hxx>
 #include <test/bootstrapfixture.hxx>
 #include <unotools/tempfile.hxx>
 #include <unotest/macros_test.hxx>
@@ -45,6 +46,8 @@ private:
     std::shared_ptr<utl::TempFile> exportToPDF(const 
uno::Reference<frame::XModel>& xModel,
                                                const ScRange& range);
 
+    std::shared_ptr<utl::TempFile> exportToPDFWithUnoCommands(const OUString& 
rRange);
+
     static bool hasTextInPdf(const std::shared_ptr<utl::TempFile>& pPDFFile, 
const char* sText,
                              bool& bFound);
 
@@ -55,13 +58,17 @@ private:
 public:
     void testExportRange_Tdf120161();
     void testExportFitToPage_Tdf103516();
+    void testUnoCommands_Tdf120161();
 
     CPPUNIT_TEST_SUITE(ScPDFExportTest);
     CPPUNIT_TEST(testExportRange_Tdf120161);
     CPPUNIT_TEST(testExportFitToPage_Tdf103516);
+    CPPUNIT_TEST(testUnoCommands_Tdf120161);
     CPPUNIT_TEST_SUITE_END();
 };
 
+constexpr OUStringLiteral DATA_DIRECTORY = u"/sc/qa/extras/testdocuments/";
+
 void ScPDFExportTest::setUp()
 {
     test::BootstrapFixture::setUp();
@@ -201,6 +208,36 @@ ScPDFExportTest::exportToPDF(const 
uno::Reference<frame::XModel>& xModel, const
     return pTempFile;
 }
 
+std::shared_ptr<utl::TempFile> 
ScPDFExportTest::exportToPDFWithUnoCommands(const OUString& rRange)
+{
+    // create temp file name
+    auto pTempFile = std::make_shared<utl::TempFile>();
+    pTempFile->EnableKillingFile();
+    OUString sFileURL = pTempFile->GetURL();
+    // Note: under Windows path path should be with "/" delimiters instead of 
"\\"
+    // due to usage of INetURLObject() that converts "\\" to hexadecimal 
notation.
+    ::osl::FileBase::getFileURLFromSystemPath(sFileURL, sFileURL);
+
+    uno::Sequence<beans::PropertyValue> aArgs
+        = comphelper::InitPropertySequence({ { "ToPoint", uno::makeAny(rRange) 
} });
+    dispatchCommand(mxComponent, ".uno:GoToCell", aArgs);
+
+    dispatchCommand(mxComponent, ".uno:DefinePrintArea", {});
+
+    uno::Sequence<beans::PropertyValue> 
aFilterData(comphelper::InitPropertySequence(
+        { { "ViewPDFAfterExport", uno::Any(true) }, { "Printing", 
uno::Any(sal_Int32(2)) } }));
+
+    uno::Sequence<beans::PropertyValue> aDescriptor(
+        comphelper::InitPropertySequence({ { "FilterName", 
uno::Any(OUString("calc_pdf_Export")) },
+                                           { "FilterData", 
uno::Any(aFilterData) },
+                                           { "URL", uno::Any(sFileURL) } }));
+
+    dispatchCommand(mxComponent, ".uno:ExportToPDF", aDescriptor);
+
+    // return file object with generated PDF
+    return pTempFile;
+}
+
 void ScPDFExportTest::setFont(ScFieldEditEngine& rEE, sal_Int32 nStart, 
sal_Int32 nEnd,
                               const OUString& rFontName)
 {
@@ -358,6 +395,36 @@ void ScPDFExportTest::testExportFitToPage_Tdf103516()
     }
 }
 
+void ScPDFExportTest::testUnoCommands_Tdf120161()
+{
+    mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY) 
+ "tdf120161.ods",
+                                  "com.sun.star.sheet.SpreadsheetDocument");
+
+    // A1:G1
+    {
+        std::shared_ptr<utl::TempFile> pPDFFile = 
exportToPDFWithUnoCommands("A1:G1");
+        bool bFound = false;
+        CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound));
+        CPPUNIT_ASSERT_EQUAL(false, bFound);
+    }
+
+    // G1:H1
+    {
+        std::shared_ptr<utl::TempFile> pPDFFile = 
exportToPDFWithUnoCommands("G1:H1");
+        bool bFound = false;
+        CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound));
+        CPPUNIT_ASSERT_EQUAL(true, bFound);
+    }
+
+    // H1:I1
+    {
+        std::shared_ptr<utl::TempFile> pPDFFile = 
exportToPDFWithUnoCommands("H1:I1");
+        bool bFound = false;
+        CPPUNIT_ASSERT(hasTextInPdf(pPDFFile, "DejaVuSans", bFound));
+        CPPUNIT_ASSERT_EQUAL(true, bFound);
+    }
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(ScPDFExportTest);
 CPPUNIT_PLUGIN_IMPLEMENT();
 
diff --git a/sc/qa/uitest/data/tdf120161.ods 
b/sc/qa/extras/testdocuments/tdf120161.ods
similarity index 100%
rename from sc/qa/uitest/data/tdf120161.ods
rename to sc/qa/extras/testdocuments/tdf120161.ods
diff --git a/sc/qa/uitest/calc_tests/tdf120161.py 
b/sc/qa/uitest/calc_tests/tdf120161.py
deleted file mode 100755
index a15384c1a0cc..000000000000
--- a/sc/qa/uitest/calc_tests/tdf120161.py
+++ /dev/null
@@ -1,79 +0,0 @@
-# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
-#
-# 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/.
-#
-from uitest.framework import UITestCase
-from libreoffice.uno.propertyvalue import mkPropertyValues
-import os
-from tempfile import TemporaryDirectory
-from uitest.uihelper.common import get_url_for_data_file
-
-# Bug 120161: PRINTING, PDF Export: Problem with selected cells which cross 
pages
-class tdf120161(UITestCase):
-    def getFileContent(self, pathAndFileName):
-        with open(pathAndFileName, 'rb') as theFile:  # b is important -> 
binary
-            # Return as binary string
-            data = theFile.read()
-        return data
-
-    def verifyExportToFile(self, xDoc, xContext, xRange, xFontName, xFilename):
-        # set selection
-        xGridWin = xDoc.getChild("grid_window")
-        xGridWin.executeAction("SELECT", mkPropertyValues({"RANGE": xRange}))
-
-        # set print area
-        self.xUITest.executeCommand(".uno:DefinePrintArea")
-
-        # create temp file name
-        xURL = 'file:///' + xFilename
-
-        # prepare to export into pdf
-        xServiceManager = xContext.ServiceManager
-        xDispatcher = xServiceManager.createInstanceWithContext(
-            'com.sun.star.frame.DispatchHelper', xContext)
-        xDocFrame = self.ui_test.get_desktop().getCurrentFrame()
-        document = self.ui_test.get_component()
-
-        # get selection
-        xSelection = 
document.Sheets.getByName("Sheet1").getCellRangeByName(xRange)
-        self.assertIsNotNone(xSelection)
-
-        # run export into pdf
-        xFilterData = mkPropertyValues(
-            {'Selection': xSelection, 'ViewPDFAfterExport': True, 'Printing': 
'2'})
-        xParams = mkPropertyValues(
-            {'URL': xURL, 'FilterName': 'calc_pdf_Export', 'FilterData': 
xFilterData})
-        xDispatcher.executeDispatch(xDocFrame, '.uno:ExportToPDF', '', 0, 
xParams)
-
-        # check resulting pdf file
-        xFileContent = self.getFileContent(xFilename)
-        position = xFileContent.find(xFontName)
-        return position > 0
-
-    # create temp directory and filename inside it
-    def verifyExport(self, xDoc, xContext, xRange, xFontName):
-        with TemporaryDirectory() as tempdir:
-            if os.altsep:  # we need URL so replace "\" with "/"
-                tempdir = tempdir.replace(os.sep, os.altsep)
-            xFilename = tempdir + "/tdf120161-temp.pdf"
-            return self.verifyExportToFile(xDoc, xContext, xRange, xFontName, 
xFilename)
-        return False
-
-    def test_tdf120161(self):
-        calc_doc = 
self.ui_test.load_file(get_url_for_data_file("tdf120161.ods"))
-        xDoc = self.xUITest.getTopFocusWindow()
-        xContext = self.xContext
-
-        # check different areas to be printed without any lost cell
-        # note:
-        # 1. Visually in GridView G1 is on page-1 and H1 is on page-2
-        # 2. DejaVuSans is used only in H1
-        self.assertFalse(self.verifyExport(xDoc, xContext, "A1:G1", 
b"DejaVuSans"))
-        self.assertTrue(self.verifyExport(xDoc, xContext, "H1:I1", 
b"DejaVuSans"))
-        self.assertTrue(self.verifyExport(xDoc, xContext, "G1:H1", 
b"DejaVuSans"))
-
-        self.ui_test.close_doc()
-
-# vim: set shiftwidth=4 softtabstop=4 expandtab:
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to