sd/qa/unit/tiledrendering/data/PresentationInfoTest.odp |binary
 sd/qa/unit/tiledrendering/tiledrendering.cxx            |   86 ++++++++++++++++
 sd/source/ui/inc/unomodel.hxx                           |    2 
 sd/source/ui/unoidl/unomodel.cxx                        |    5 
 4 files changed, 90 insertions(+), 3 deletions(-)

New commits:
commit 43c8ec415a25637231ffa4ae0825fec58431e300
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Thu Jun 27 13:23:56 2024 +0900
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Sep 11 13:55:24 2024 +0200

    lok: test for getPresentationInfo LOK API function
    
    Also fix getting the slides, so we don't rely that a WeakReference
    is set, as it is not set (yet) when running the test.
    
    Change-Id: Icd338e31fbd0bb7c45a06357b955b85081ed38c9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172868
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sd/qa/unit/tiledrendering/data/PresentationInfoTest.odp 
b/sd/qa/unit/tiledrendering/data/PresentationInfoTest.odp
new file mode 100644
index 000000000000..77aa85a25356
Binary files /dev/null and 
b/sd/qa/unit/tiledrendering/data/PresentationInfoTest.odp differ
diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx 
b/sd/qa/unit/tiledrendering/tiledrendering.cxx
index 87371647db85..12cbefb28328 100644
--- a/sd/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx
@@ -3001,6 +3001,92 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, 
testStartPresentation)
     CPPUNIT_ASSERT_EQUAL(std::string("true"), 
value.get_child("state").get_value<std::string>());
 }
 
+namespace
+{
+
+boost::property_tree::ptree const& child_at(boost::property_tree::ptree const& 
rTree, std::string_view aName, size_t nIndex)
+{
+    return std::next(rTree.get_child(std::string(aName)).find(""), 
nIndex)->second;
+}
+
+bool has_child(boost::property_tree::ptree const& rTree, std::string_view 
aName)
+{
+    return rTree.count(std::string(aName)) > 0;
+}
+
+} // end anonymous ns
+
+CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testPresentationInfo)
+{
+    SdXImpressDocument* pXImpressDocument = 
createDoc("PresentationInfoTest.odp");
+    
pXImpressDocument->initializeForTiledRendering(uno::Sequence<beans::PropertyValue>());
+
+    sd::ViewShell* pViewShell = 
pXImpressDocument->GetDocShell()->GetViewShell();
+    CPPUNIT_ASSERT(pViewShell);
+
+    Scheduler::ProcessEventsToIdle();
+
+    SdPage* pPage = pViewShell->GetActualPage();
+    CPPUNIT_ASSERT(pPage);
+
+    OString aString = pXImpressDocument->getPresentationInfo();
+
+    boost::property_tree::ptree aTree;
+    std::stringstream aStream((std::string(aString)));
+    boost::property_tree::read_json(aStream, aTree);
+
+    CPPUNIT_ASSERT_EQUAL(15875, aTree.get_child("docWidth").get_value<int>());
+    CPPUNIT_ASSERT_EQUAL(8930,  aTree.get_child("docHeight").get_value<int>());
+
+    CPPUNIT_ASSERT_EQUAL(size_t(4),  aTree.get_child("slides").size());
+
+    // Slide Index 0
+    {
+        const boost::property_tree::ptree& rChild = child_at(aTree, "slides", 
0);
+        CPPUNIT_ASSERT_EQUAL(0, rChild.get_child("index").get_value<int>());
+        CPPUNIT_ASSERT_EQUAL(false, 
rChild.get_child("empty").get_value<bool>());
+
+        CPPUNIT_ASSERT(has_child(rChild, "hash"));
+        CPPUNIT_ASSERT(has_child(rChild, "masterPage"));
+        CPPUNIT_ASSERT(has_child(rChild, "masterPageObjectsVisible"));
+    }
+
+    // Slide Index 1
+    {
+        const boost::property_tree::ptree& rChild = child_at(aTree, "slides", 
1);
+        CPPUNIT_ASSERT_EQUAL(1, rChild.get_child("index").get_value<int>());
+        CPPUNIT_ASSERT_EQUAL(false, 
rChild.get_child("empty").get_value<bool>());
+
+        CPPUNIT_ASSERT(has_child(rChild, "hash"));
+        CPPUNIT_ASSERT(has_child(rChild, "masterPage"));
+        CPPUNIT_ASSERT(has_child(rChild, "masterPageObjectsVisible"));
+    }
+
+    // Slide Index 2
+    {
+        const boost::property_tree::ptree& rChild = child_at(aTree, "slides", 
2);
+        CPPUNIT_ASSERT_EQUAL(2, rChild.get_child("index").get_value<int>());
+        CPPUNIT_ASSERT_EQUAL(false, 
rChild.get_child("empty").get_value<bool>());
+
+        CPPUNIT_ASSERT(has_child(rChild, "hash"));
+        CPPUNIT_ASSERT(has_child(rChild, "masterPage"));
+        CPPUNIT_ASSERT(has_child(rChild, "masterPageObjectsVisible"));
+    }
+
+    // Slide Index 3 - Hidden
+
+    // Slide Index 4
+    {
+        const boost::property_tree::ptree& rChild = child_at(aTree, "slides", 
3);
+        CPPUNIT_ASSERT_EQUAL(4, rChild.get_child("index").get_value<int>());
+        CPPUNIT_ASSERT_EQUAL(false, 
rChild.get_child("empty").get_value<bool>());
+
+        CPPUNIT_ASSERT(has_child(rChild, "hash"));
+        CPPUNIT_ASSERT(has_child(rChild, "masterPage"));
+        CPPUNIT_ASSERT(has_child(rChild, "masterPageObjectsVisible"));
+    }
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/source/ui/inc/unomodel.hxx b/sd/source/ui/inc/unomodel.hxx
index 3b5532759cc4..2945a308005d 100644
--- a/sd/source/ui/inc/unomodel.hxx
+++ b/sd/source/ui/inc/unomodel.hxx
@@ -287,7 +287,7 @@ public:
     SD_DLLPUBLIC OString getViewRenderState(SfxViewShell* pViewShell = 
nullptr) override;
 
     /// @see vcl::ITiledRenderable::getPresentationInfo().
-    OString getPresentationInfo() const override;
+    SD_DLLPUBLIC OString getPresentationInfo() const override;
     /// @see vcl::ITiledRenderable::createSlideRenderer().
     bool createSlideRenderer(
         sal_Int32 nSlideNumber, sal_Int32& nViewWidth, sal_Int32& nViewHeight,
diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx
index df18005f934d..e7b77cf52b97 100644
--- a/sd/source/ui/unoidl/unomodel.cxx
+++ b/sd/source/ui/unoidl/unomodel.cxx
@@ -3027,7 +3027,8 @@ OString SdXImpressDocument::getPresentationInfo() const
 
     try
     {
-        uno::Reference<container::XIndexAccess> 
xSlides(mxDrawPagesAccess.get(), uno::UNO_QUERY_THROW);
+        uno::Reference<drawing::XDrawPages> xDrawPages = 
const_cast<SdXImpressDocument*>(this)->getDrawPages();
+        uno::Reference<container::XIndexAccess> xSlides(xDrawPages, 
uno::UNO_QUERY_THROW);
         if (xSlides.is())
         {
             // size in twips
@@ -3100,7 +3101,7 @@ OString SdXImpressDocument::getPresentationInfo() const
     }
     catch (uno::Exception& )
     {
-        TOOLS_WARN_EXCEPTION( "sd", "SdXImpressDocument::getSlideShowInfo ... 
maybe some property can't be retrieved" );
+        TOOLS_WARN_EXCEPTION("sd", "SdXImpressDocument::getSlideShowInfo ... 
maybe some property can't be retrieved");
     }
     return aJsonWriter.finishAndGetAsOString();
 }

Reply via email to