sc/CppunitTest_sc_sparkline_test.mk |    1 
 sc/qa/unit/SparklineTest.cxx        |   66 ++++++++++++++++++++++++++++++++++++
 sc/qa/unit/helper/qahelper.cxx      |   23 ++++++++++++
 sc/qa/unit/helper/qahelper.hxx      |    1 
 4 files changed, 91 insertions(+)

New commits:
commit 5ffd03c1316d7efbe197cfa3b649dddff165aa65
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Mar 10 14:08:35 2022 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Mon Apr 11 16:52:15 2022 +0200

    sc: simple unit test for adding a new Sparkline to a new document
    
    Change-Id: Ifb42167300dadd0e6c48bf178b7e8902985db3d1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132464
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>
    (cherry picked from commit b1349537f936dc1053e623b333c9c8f57345b8ff)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132779
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sc/CppunitTest_sc_sparkline_test.mk 
b/sc/CppunitTest_sc_sparkline_test.mk
index 30513b273791..499eaaf4ea38 100644
--- a/sc/CppunitTest_sc_sparkline_test.mk
+++ b/sc/CppunitTest_sc_sparkline_test.mk
@@ -15,6 +15,7 @@ $(eval $(call 
gb_CppunitTest_use_common_precompiled_header,sc_sparkline_test))
 
 $(eval $(call gb_CppunitTest_add_exception_objects,sc_sparkline_test, \
     sc/qa/unit/SparklineImportExportTest \
+    sc/qa/unit/SparklineTest \
 ))
 
 $(eval $(call gb_CppunitTest_use_libraries,sc_sparkline_test, \
diff --git a/sc/qa/unit/SparklineTest.cxx b/sc/qa/unit/SparklineTest.cxx
new file mode 100644
index 000000000000..d4a8d2d119a8
--- /dev/null
+++ b/sc/qa/unit/SparklineTest.cxx
@@ -0,0 +1,66 @@
+/* -*- 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 "helper/qahelper.hxx"
+#include <docsh.hxx>
+#include <Sparkline.hxx>
+#include <SparklineGroup.hxx>
+
+using namespace css;
+
+class SparklineTest : public ScBootstrapFixture
+{
+private:
+    uno::Reference<uno::XInterface> m_xCalcComponent;
+
+public:
+    SparklineTest()
+        : ScBootstrapFixture("sc/qa/unit/data")
+    {
+    }
+
+    virtual void setUp() override
+    {
+        test::BootstrapFixture::setUp();
+
+        // This is a bit of a fudge, we do this to ensure that 
ScGlobals::ensure,
+        // which is a private symbol to us, gets called
+        m_xCalcComponent = getMultiServiceFactory()->createInstance(
+            "com.sun.star.comp.Calc.SpreadsheetDocument");
+        CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is());
+    }
+
+    virtual void tearDown() override
+    {
+        uno::Reference<lang::XComponent>(m_xCalcComponent, 
uno::UNO_QUERY_THROW)->dispose();
+        test::BootstrapFixture::tearDown();
+    }
+
+    void testAddSparkline();
+
+    CPPUNIT_TEST_SUITE(SparklineTest);
+    CPPUNIT_TEST(testAddSparkline);
+    CPPUNIT_TEST_SUITE_END();
+};
+
+void SparklineTest::testAddSparkline()
+{
+    ScDocShellRef xDocSh = loadEmptyDocument();
+    CPPUNIT_ASSERT(xDocSh);
+
+    ScDocument& rDocument = xDocSh->GetDocument();
+    auto pSparklineGroup = std::make_shared<sc::SparklineGroup>();
+
+    sc::Sparkline* pSparkline = rDocument.CreateSparkline(ScAddress(0, 0, 0), 
pSparklineGroup);
+    CPPUNIT_ASSERT(pSparkline);
+}
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SparklineTest);
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/qa/unit/helper/qahelper.cxx b/sc/qa/unit/helper/qahelper.cxx
index 05b64eab5566..8ee02534927c 100644
--- a/sc/qa/unit/helper/qahelper.cxx
+++ b/sc/qa/unit/helper/qahelper.cxx
@@ -11,6 +11,7 @@
 #include "csv_handler.hxx"
 #include "debughelper.hxx"
 #include <drwlayer.hxx>
+#include <comphelper/processfactory.hxx>
 #include <comphelper/sequence.hxx>
 #include <comphelper/storagehelper.hxx>
 #include <compiler.hxx>
@@ -51,6 +52,9 @@
 #include <com/sun/star/chart2/XChartDocument.hpp>
 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
 #include <com/sun/star/document/MacroExecMode.hpp>
+#include <com/sun/star/frame/Desktop.hpp>
+#include <com/sun/star/frame/XModel2.hpp>
+
 
 using namespace com::sun::star;
 using namespace ::com::sun::star::uno;
@@ -641,6 +645,25 @@ ScDocShellRef ScBootstrapFixture::load(const OUString& 
rURL, sal_Int32 nFormat,
     return load(bReadWrite, rURL, aFilterName, OUString(), aFilterType, 
nFormatType, nClipboardId, static_cast<sal_uIntPtr>(nFormatType));
 }
 
+ScDocShellRef ScBootstrapFixture::loadEmptyDocument(const 
uno::Sequence<beans::PropertyValue>& rPropertyValues)
+{
+    uno::Reference< frame::XDesktop2 > xDesktop = 
frame::Desktop::create(::comphelper::getProcessComponentContext());
+    CPPUNIT_ASSERT(xDesktop.is());
+
+    uno::Reference< lang::XComponent > xComponent = 
xDesktop->loadComponentFromURL(
+        "private:factory/scalc",
+        "_blank",
+        0,
+        rPropertyValues);
+    CPPUNIT_ASSERT(xComponent.is());
+
+    // Get the document model
+    SfxObjectShell* pFoundShell = 
SfxObjectShell::GetShellFromComponent(xComponent);
+    CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
+
+    return dynamic_cast<ScDocShell*>(pFoundShell);
+}
+
 ScDocShellRef ScBootstrapFixture::loadDoc(
     std::u16string_view rFileName, sal_Int32 nFormat, bool bReadWrite )
 {
diff --git a/sc/qa/unit/helper/qahelper.hxx b/sc/qa/unit/helper/qahelper.hxx
index f0fc8105436d..b16278dd7429 100644
--- a/sc/qa/unit/helper/qahelper.hxx
+++ b/sc/qa/unit/helper/qahelper.hxx
@@ -202,6 +202,7 @@ protected:
 
     ScDocShellRef load(const OUString& rURL, sal_Int32 nFormat, bool 
bReadWrite = false);
 
+    ScDocShellRef loadEmptyDocument(const 
com::sun::star::uno::Sequence<com::sun::star::beans::PropertyValue>& 
rPropertyValues = {});
     ScDocShellRef loadDoc(
         std::u16string_view rFileName, sal_Int32 nFormat, bool bReadWrite = 
false );
 

Reply via email to