sc/CppunitTest_sc_scriptforge_test.mk |   64 ++++++++++++++++++++++++++++++++++
 sc/Module_sc.mk                       |    1 
 sc/qa/extras/scriptforge.cxx          |   55 +++++++++++++++++++++++++++++
 3 files changed, 120 insertions(+)

New commits:
commit c0e792cc6ed3eedd05f483e95415b996992a3b15
Author:     Xisco Fauli <[email protected]>
AuthorDate: Thu Oct 10 13:33:43 2024 +0200
Commit:     Xisco Fauli <[email protected]>
CommitDate: Thu Oct 10 23:29:40 2024 +0200

    sc: Add simple unittest for ScriptForge
    
    Change-Id: Ief1808219862273643a3bfae212b1d0e454b3e86
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/174763
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <[email protected]>

diff --git a/sc/CppunitTest_sc_scriptforge_test.mk 
b/sc/CppunitTest_sc_scriptforge_test.mk
new file mode 100644
index 000000000000..4aa19ba1086b
--- /dev/null
+++ b/sc/CppunitTest_sc_scriptforge_test.mk
@@ -0,0 +1,64 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# 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/.
+#
+
+$(eval $(call gb_CppunitTest_CppunitTest,sc_scriptforge_test))
+
+$(eval $(call gb_CppunitTest_use_externals,sc_scriptforge_test, \
+    boost_headers \
+    mdds_headers \
+    libxml2 \
+))
+
+$(eval $(call 
gb_CppunitTest_use_common_precompiled_header,sc_scriptforge_test))
+
+$(eval $(call gb_CppunitTest_add_exception_objects,sc_scriptforge_test, \
+    sc/qa/extras/scriptforge \
+))
+
+$(eval $(call gb_CppunitTest_use_libraries,sc_scriptforge_test, \
+       sal \
+       sc \
+       scqahelper \
+       cppu \
+       cppuhelper \
+       subsequenttest \
+       svl \
+       svt \
+       svx \
+       svxcore \
+       test \
+       tk \
+       tl \
+       ucbhelper \
+       unotest \
+       utl \
+       xo \
+))
+
+$(eval $(call gb_CppunitTest_set_include,sc_scriptforge_test,\
+    -I$(SRCDIR)/sc/source/ui/inc \
+    -I$(SRCDIR)/sc/inc \
+    -I$(SRCDIR)/sc/qa/unit \
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_CppunitTest_use_api,sc_scriptforge_test,\
+    offapi \
+    oovbaapi \
+    udkapi \
+))
+
+$(eval $(call gb_CppunitTest_use_ure,sc_scriptforge_test))
+$(eval $(call gb_CppunitTest_use_vcl,sc_scriptforge_test))
+
+$(eval $(call gb_CppunitTest_use_rdb,sc_scriptforge_test,services))
+
+$(eval $(call gb_CppunitTest_use_configuration,sc_scriptforge_test))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sc/Module_sc.mk b/sc/Module_sc.mk
index 88172016d52b..4d9f7c9618a6 100644
--- a/sc/Module_sc.mk
+++ b/sc/Module_sc.mk
@@ -87,6 +87,7 @@ $(eval $(call gb_Module_add_slowcheck_targets,sc, \
        CppunitTest_sc_pdf_export \
        CppunitTest_sc_pivottable_filters_test \
        CppunitTest_sc_pivottable_formats_import_export_test \
+       CppunitTest_sc_scriptforge_test \
        CppunitTest_sc_sparkline_test \
        CppunitTest_sc_subsequent_filters_test \
        CppunitTest_sc_subsequent_filters_test2 \
diff --git a/sc/qa/extras/scriptforge.cxx b/sc/qa/extras/scriptforge.cxx
new file mode 100644
index 000000000000..4f6b1b5dc2c6
--- /dev/null
+++ b/sc/qa/extras/scriptforge.cxx
@@ -0,0 +1,55 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * 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/.
+ */
+
+#include <sal/config.h>
+#include <helper/qahelper.hxx>
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+
+/* Implementation of Macros test */
+
+class ScScriptForgeTest : public ScModelTestBase
+{
+public:
+    ScScriptForgeTest();
+};
+
+CPPUNIT_TEST_FIXTURE(ScScriptForgeTest, testSetValue)
+{
+    createScDoc();
+
+    // insert initial library
+    css::uno::Reference<css::document::XEmbeddedScripts> xDocScr(mxComponent, 
UNO_QUERY_THROW);
+    auto xLibs = xDocScr->getBasicLibraries();
+    auto xLibrary = xLibs->createLibrary(u"TestLibrary"_ustr);
+    xLibrary->insertByName(
+        u"TestModule"_ustr,
+        uno::Any(u"Function Main
"
+                 " GlobalScope.BasicLibraries.LoadLibrary(\"ScriptForge\")
"
+                 " Dim oDoc : oDoc = CreateScriptService(\"Calc\", 
ThisComponent)
"
+                 " oDoc.setValue(\"A1\", 10)
"
+                 "End Function
"_ustr));
+
+    // Without the fix in place, this test would have crashed
+    executeMacro(
+        
u"vnd.sun.Star.script:TestLibrary.TestModule.Main?language=Basic&location=document"_ustr);
+
+    ScDocument* pDoc = getScDoc();
+    CPPUNIT_ASSERT_EQUAL(u"10"_ustr, pDoc->GetString(ScAddress(0, 0, 0)));
+}
+
+ScScriptForgeTest::ScScriptForgeTest()
+    : ScModelTestBase(u"/sc/qa/extras/testdocuments"_ustr)
+{
+}
+
+CPPUNIT_PLUGIN_IMPLEMENT();
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to