[Libreoffice-commits] core.git: include/sfx2 sfx2/Module_sfx2.mk sfx2/PythonTest_sfx2_python.mk sfx2/qa sfx2/source unotest/source

Laurent Godard lgodard.libre at laposte.net
Mon Jun 22 23:39:18 PDT 2015


 include/sfx2/sidebar/ResourceManager.hxx         |    2 
 include/sfx2/sidebar/SidebarController.hxx       |    2 
 sfx2/Module_sfx2.mk                              |    6 
 sfx2/PythonTest_sfx2_python.mk                   |   20 +++
 sfx2/qa/python/check_sidebar.py                  |  149 +++++++++++++++++++++++
 sfx2/source/sidebar/ResourceManager.cxx          |   16 ++
 sfx2/source/sidebar/SidebarController.cxx        |   12 +
 sfx2/source/sidebar/UnoDeck.cxx                  |    9 +
 unotest/source/python/org/libreoffice/unotest.py |   14 ++
 9 files changed, 230 insertions(+)

New commits:
commit 187445b2d2885ced92be37ffb11cd2a9bb11f8d6
Author: Laurent Godard <lgodard.libre at laposte.net>
Date:   Mon Jun 8 10:24:42 2015 +0200

    Uno api sidebar unit test tdf#91806
    
    - python test subsequentcheck
    - correct deck setTitle APi (UI update)
    - enhance UnoInProcess for flexiility in loading parameter
    
    Change-Id: Id04cb78c6162ac84fb3bfd8577f84763109d993e
    Reviewed-on: https://gerrit.libreoffice.org/16180
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>

diff --git a/include/sfx2/sidebar/ResourceManager.hxx b/include/sfx2/sidebar/ResourceManager.hxx
index 4e6247d..5768db0 100644
--- a/include/sfx2/sidebar/ResourceManager.hxx
+++ b/include/sfx2/sidebar/ResourceManager.hxx
@@ -58,6 +58,8 @@ public:
     */
     void SetIsDeckEnabled(const OUString& rsDeckId, const bool bIsEnabled);
 
+    void SetDeckTitle(const OUString& rsDeckId, const OUString& sTitle);
+
     void SetDeckToDescriptor(const OUString& rsDeckId, VclPtr<Deck> aDeck);
 
     void SetDeckOrderIndex(const OUString& rsDeckId, const sal_Int32 orderIndex);
diff --git a/include/sfx2/sidebar/SidebarController.hxx b/include/sfx2/sidebar/SidebarController.hxx
index 58bca04..29c7d43 100644
--- a/include/sfx2/sidebar/SidebarController.hxx
+++ b/include/sfx2/sidebar/SidebarController.hxx
@@ -154,6 +154,8 @@ public:
     ResourceManager::DeckContextDescriptorContainer GetMatchingDecks();
     ResourceManager::PanelContextDescriptorContainer GetMatchingPanels( const ::rtl::OUString& rDeckId);
 
+    void notifyDeckTitle(const OUString& targetDeckId);
+
 private:
     typedef ::std::map<
         const css::uno::Reference<css::frame::XFrame>,
diff --git a/sfx2/Module_sfx2.mk b/sfx2/Module_sfx2.mk
index 3ebdfa1..792668e 100644
--- a/sfx2/Module_sfx2.mk
+++ b/sfx2/Module_sfx2.mk
@@ -40,6 +40,12 @@ $(eval $(call gb_Module_add_subsequentcheck_targets,sfx2,\
 ))
 endif
 
+ifneq ($(DISABLE_PYTHON),TRUE)
+$(eval $(call gb_Module_add_subsequentcheck_targets,sfx2,\
+	PythonTest_sfx2_python \
+))
+endif
+
 ifneq (,$(filter LINUX DRAGONFLY OPENBSD FREEBSD NETBSD SOLARIS, $(OS)))
 ifeq ($(ENABLE_SYSTRAY_GTK),TRUE)
 $(eval $(call gb_Module_add_targets,sfx2,\
diff --git a/sfx2/PythonTest_sfx2_python.mk b/sfx2/PythonTest_sfx2_python.mk
new file mode 100644
index 0000000..4300110
--- /dev/null
+++ b/sfx2/PythonTest_sfx2_python.mk
@@ -0,0 +1,20 @@
+# -*- 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_PythonTest_PythonTest,sfx2_python))
+
+$(eval $(call gb_PythonTest_set_defs,sfx2_python,\
+    TDOC="$(SRCDIR)/sfx2/qa/python/testdocuments" \
+))
+
+$(eval $(call gb_PythonTest_add_modules,sfx2_python,$(SRCDIR)/sfx2/qa/python,\
+	check_sidebar \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/sfx2/qa/python/check_sidebar.py b/sfx2/qa/python/check_sidebar.py
new file mode 100644
index 0000000..355951a
--- /dev/null
+++ b/sfx2/qa/python/check_sidebar.py
@@ -0,0 +1,149 @@
+# -*- 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/.
+#
+
+import unittest
+import unohelper
+import os
+from org.libreoffice.unotest import UnoInProcess
+
+from com.sun.star.ui import XSidebarProvider
+from com.sun.star.ui import XDecks
+from com.sun.star.ui import XDeck
+from com.sun.star.ui import XPanels
+from com.sun.star.ui import XPanel
+
+class CheckSidebar(unittest.TestCase):
+    _uno = None
+    _xDoc = None
+
+    @classmethod
+    def setUpClass(cls):
+        cls._uno = UnoInProcess()
+        cls._uno.setUp()
+        cls._xDoc = cls._uno.openEmptyDoc( url = "private:factory/scalc", bHidden = False, bReadOnly = False)
+
+    @classmethod
+    def tearDownClass(cls):
+        cls._uno.tearDown() 
+
+    def test_check_sidebar(self):
+
+        xDoc = self.__class__._xDoc
+        xController = xDoc.getCurrentController()
+
+        xSidebar = xController.getSidebar()
+        assert(xSidebar)
+
+        xSidebar.setVisible(True)
+        isVisible = xSidebar.isVisible()
+        self.assertTrue ( xSidebar.isVisible() )
+
+        # TODO: does not work in unit test context 
+#        xSidebar.setVisible(False)
+#        isVisible = xSidebar.isVisible()
+#        assert( not isVisible )
+#        xSidebar.setVisible(True)
+
+        xSidebar.showDecks(False)
+        xSidebar.showDecks(True)
+
+        xDecks = xSidebar.getDecks()
+
+        firstDeckName = "PropertyDeck";
+
+        deckElementNames = xDecks.getElementNames()
+        assert ( firstDeckName in deckElementNames )
+        assert ( xDecks.hasByName(firstDeckName) )
+
+        decksCount = xDecks.getCount()
+        self.assertEqual ( 5, decksCount )
+
+        xDeck = xDecks.getByName(firstDeckName)
+        assert ( xDeck )
+        assert ( xDeck.getId() == firstDeckName )
+
+        newDeckTitle = "New title"
+        xDeck.setTitle(newDeckTitle)
+        assert ( xDeck.getTitle() == newDeckTitle )
+
+        xDeck.moveFirst()
+        initialIndex = xDeck.getOrderIndex()
+        self.assertEqual(100, initialIndex)
+
+        xDeck.moveLast()
+        assert ( xDeck.getOrderIndex() > initialIndex )
+
+        initialIndex = xDeck.getOrderIndex()
+        xDeck.moveFirst()
+        assert ( xDeck.getOrderIndex() < initialIndex )
+
+        initialIndex = xDeck.getOrderIndex()
+        xDeck.moveDown()
+        assert ( xDeck.getOrderIndex() > initialIndex )
+
+        initialIndex = xDeck.getOrderIndex()
+        xDeck.moveUp()
+        assert ( xDeck.getOrderIndex() < initialIndex )
+
+        xPanels = xDeck.getPanels()
+
+        panelsCount = xPanels.getCount()
+        self.assertEqual ( panelsCount, 4 )
+
+        firstPanelName = "TextPropertyPanel"
+
+        panelElementNames = xPanels.getElementNames()
+        assert ( firstPanelName in panelElementNames )
+        assert ( xPanels.hasByName(firstPanelName) )
+
+        xPanel = xPanels.getByName(firstPanelName)
+        assert ( xPanel )
+        assert ( xPanel.getId() == firstPanelName )
+
+        newTitle = "New title"
+        xPanel.setTitle(newTitle)
+        assert ( xPanel.getTitle() == newTitle )
+
+        xPanel.moveFirst()
+        initialIndex = xPanel.getOrderIndex()
+        assert ( initialIndex == 120 )
+
+        xPanel.moveLast()
+        assert ( xPanel.getOrderIndex() > initialIndex )
+
+        initialIndex = xPanel.getOrderIndex()
+        xPanel.moveFirst()
+        assert ( xPanel.getOrderIndex() < initialIndex )
+
+        initialIndex = xPanel.getOrderIndex()
+        xPanel.moveDown()
+        assert ( xPanel.getOrderIndex() > initialIndex )
+
+        initialIndex = xPanel.getOrderIndex()
+        xPanel.moveUp()
+        assert ( xPanel.getOrderIndex() < initialIndex )
+
+        xPanel.collapse()
+        assert( not xPanel.isExpanded() )
+
+        otherPanel = xPanels.getByName("NumberFormatPropertyPanel")
+        otherPanel.expand(False)
+        assert( otherPanel.isExpanded() )
+
+        xPanel.expand(True)
+        assert( xPanel.isExpanded() )
+        assert( not otherPanel.isExpanded() )
+
+    # close the document
+        xDoc.dispose()
+
+if __name__ == "__main__":
+    unittest.main()
+
+# vim: set noet sw=4 ts=4:
\ No newline at end of file
diff --git a/sfx2/source/sidebar/ResourceManager.cxx b/sfx2/source/sidebar/ResourceManager.cxx
index 79b2432..21a6f8b 100644
--- a/sfx2/source/sidebar/ResourceManager.cxx
+++ b/sfx2/source/sidebar/ResourceManager.cxx
@@ -114,6 +114,22 @@ void ResourceManager::SetIsDeckEnabled(const OUString& rsDeckId, const bool bIsE
     }
 }
 
+void ResourceManager::SetDeckTitle(const OUString& rsDeckId, const OUString& sTitle)
+{
+    DeckContainer::iterator iDeck;
+    for (iDeck = maDecks.begin(); iDeck != maDecks.end(); ++iDeck)
+    {
+        if (iDeck->mbExperimental && !maMiscOptions.IsExperimentalMode())
+            continue;
+        if (iDeck->msId.equals(rsDeckId))
+        {
+            iDeck->msTitle = sTitle;
+            iDeck->msHelpText = sTitle;
+            return;
+        }
+    }
+}
+
 void ResourceManager::SetDeckToDescriptor(const OUString& rsDeckId, VclPtr<Deck> aDeck)
 {
     DeckContainer::iterator iDeck;
diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx
index cb03b2d..867aa20 100644
--- a/sfx2/source/sidebar/SidebarController.cxx
+++ b/sfx2/source/sidebar/SidebarController.cxx
@@ -249,6 +249,8 @@ void SAL_CALL SidebarController::notifyContextChangeEvent (const css::ui::Contex
     {
         maAsynchronousDeckSwitch.CancelRequest();
         maContextChangeUpdate.RequestCall();
+        // TODO: this call is redundant but mandatory for unit test to update context on document loading
+        UpdateConfigurations();
     }
 }
 
@@ -710,6 +712,16 @@ void SidebarController::SwitchToDeck (
     UpdateTitleBarIcons();
 }
 
+void SidebarController::notifyDeckTitle(const OUString& targetDeckId)
+{
+    if (msCurrentDeckId == targetDeckId)
+    {
+        maFocusManager.SetDeckTitle(mpCurrentDeck->GetTitleBar());
+        mpTabBar->UpdateFocusManager(maFocusManager);
+        UpdateTitleBarIcons();
+    }
+}
+
 VclPtr<Panel> SidebarController::CreatePanel (
     const OUString& rsPanelId,
     vcl::Window* pParentWindow,
diff --git a/sfx2/source/sidebar/UnoDeck.cxx b/sfx2/source/sidebar/UnoDeck.cxx
index f65b215..094fa8a 100644
--- a/sfx2/source/sidebar/UnoDeck.cxx
+++ b/sfx2/source/sidebar/UnoDeck.cxx
@@ -71,6 +71,11 @@ void SAL_CALL SfxUnoDeck::setTitle( const OUString& newTitle )
 
     DeckTitleBar* pTitleBar = pDeck->GetTitleBar();
     pTitleBar->SetTitle(newTitle);
+
+    // update the ResourceManager
+    pSidebarController->GetResourceManager()->SetDeckTitle(mDeckId, newTitle);
+    pSidebarController->notifyDeckTitle(mDeckId);
+
 }
 
 sal_Bool SAL_CALL SfxUnoDeck::isActive()
@@ -94,6 +99,9 @@ void SAL_CALL SfxUnoDeck::activate( const sal_Bool bActivate )
         pSidebarController->SwitchToDeck(mDeckId);
     else
         pSidebarController->SwitchToDefaultDeck();
+
+    // update the sidebar
+    pSidebarController->NotifyResize();
 }
 
 uno::Reference<ui::XPanels> SAL_CALL SfxUnoDeck::getPanels()
@@ -123,6 +131,7 @@ void SAL_CALL SfxUnoDeck::setOrderIndex( const sal_Int32 newOrderIndex )
 
     pSidebarController->GetResourceManager()->SetDeckOrderIndex(mDeckId, newOrderIndex);
 
+    // update the sidebar
     pSidebarController->NotifyResize();
 }
 
diff --git a/unotest/source/python/org/libreoffice/unotest.py b/unotest/source/python/org/libreoffice/unotest.py
index eb13d37..ab3cd8a 100644
--- a/unotest/source/python/org/libreoffice/unotest.py
+++ b/unotest/source/python/org/libreoffice/unotest.py
@@ -186,6 +186,20 @@ class UnoInProcess:
         assert(self.xDoc)
         return self.xDoc
 
+    def openEmptyCalcDoc(self):
+        self.xDoc = self.openEmptyDoc("private:factory/scalc")
+        return self.xDoc
+
+    def openEmptyDoc(self, url, bHidden = True, bReadOnly = False):
+        assert(self.xContext)
+        smgr = self.getContext().ServiceManager
+        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", self.getContext())
+        props = [("Hidden", bHidden), ("ReadOnly", bReadOnly)]
+        loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
+        self.xDoc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps)
+        assert(self.xDoc)
+        return self.xDoc
+
     def openWriterTemplateDoc(self, file):
         assert(self.xContext)
         smgr = self.getContext().ServiceManager


More information about the Libreoffice-commits mailing list