dev/null                        |binary
 sc/qa/extras/vba-macro-test.cxx |   37 ++++++++++++++++++++++++++++++++++---
 2 files changed, 34 insertions(+), 3 deletions(-)

New commits:
commit 0a27403bbc36c89efa321fb3c5061fe4ee7095fb
Author:     Balazs Varga <balazs.varga.ext...@allotropia.de>
AuthorDate: Thu Feb 16 20:06:02 2023 +0100
Commit:     Balazs Varga <balazs.varga.ext...@allotropia.de>
CommitDate: Sat Feb 18 18:23:51 2023 +0000

    Related tdf#149786: add better unit test for vba pdf export macro
    
    Better unit test for vba pdf export.
    
    Change-Id: Ifa3dff79c457e21ca24b8d99c024bd59917bc990
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147171
    Tested-by: Jenkins
    Reviewed-by: Balazs Varga <balazs.varga.ext...@allotropia.de>

diff --git a/sc/qa/extras/testdocuments/ExportAsPDF.xlsm 
b/sc/qa/extras/testdocuments/ExportAsPDF.xlsm
deleted file mode 100644
index 6cb410beec21..000000000000
Binary files a/sc/qa/extras/testdocuments/ExportAsPDF.xlsm and /dev/null differ
diff --git a/sc/qa/extras/vba-macro-test.cxx b/sc/qa/extras/vba-macro-test.cxx
index 268b35ee33fe..29fdf213f8e7 100644
--- a/sc/qa/extras/vba-macro-test.cxx
+++ b/sc/qa/extras/vba-macro-test.cxx
@@ -11,6 +11,8 @@
 #include <test/unoapi_test.hxx>
 #include <osl/file.hxx>
 #include <sal/log.hxx>
+#include <vcl/filter/pdfdocument.hxx>
+#include <vcl/filter/PDFiumLibrary.hxx>
 #include <vcl/scheduler.hxx>
 #include <vcl/svapp.hxx>
 #include <viewdata.hxx>
@@ -834,10 +836,39 @@ void VBAMacroTest::testTdf126457()
 
 void VBAMacroTest::testVbaPDFExport()
 {
-    loadFromURL(u"ExportAsPDF.xlsm");
+    mxComponent = loadFromDesktop("private:factory/scalc");
+
+    // Save a copy of the file to get its URL
+    uno::Reference<frame::XStorable> xDocStorable(mxComponent, uno::UNO_QUERY);
+    utl::TempFileNamed aTempFile(u"testVBA_PDF_Export", true, u".ods");
+    aTempFile.EnableKillingFile();
+    uno::Sequence<beans::PropertyValue> descSaveAs(
+        comphelper::InitPropertySequence({ { "FilterName", 
uno::Any(OUString("calc8")) } }));
+    xDocStorable->storeAsURL(aTempFile.GetURL(), descSaveAs);
+
+    utl::TempFileNamed aTempPdfFile(u"exportedfile", true, u".pdf");
+    aTempPdfFile.EnableKillingFile();
+
+    css::uno::Reference<css::document::XEmbeddedScripts> xDocScr(mxComponent, 
uno::UNO_QUERY_THROW);
+    auto xLibs = xDocScr->getBasicLibraries();
+    auto xLibrary = xLibs->createLibrary("TestLibrary");
+    OUString sMacro = "Option VBASupport 1\n"
+                      "Sub ExportAsPDF\n"
+                      "  fileName = \""
+                      + aTempPdfFile.GetFileName()
+                      + "\"\n  ActiveSheet.ExportAsFixedFormat 
Type:=xlTypePDF, "
+                        "FileName:=fileName, Quality:=xlQualityStandard, "
+                        "IncludeDocProperties:=True, OpenAfterPublish:=False\n"
+                        "End Sub\n";
+    xLibrary->insertByName("TestModule", uno::Any(sMacro));
+
+    
executeMacro("vnd.sun.Star.script:TestLibrary.TestModule.ExportAsPDF?language=Basic&location="
+                 "document");
 
-    executeMacro("vnd.sun.Star.script:VBAProject.Module1.ExportAsPDF?"
-                 "language=Basic&location=document");
+    // Parse the export result.
+    vcl::filter::PDFDocument aDocument;
+    SvFileStream aStream(aTempPdfFile.GetURL(), StreamMode::READ);
+    CPPUNIT_ASSERT_MESSAGE("Failed to get the pdf document", 
aDocument.Read(aStream));
 }
 CPPUNIT_TEST_SUITE_REGISTRATION(VBAMacroTest);
 

Reply via email to