LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / qa / python / check_sidebar.py
blob59cc955b8016c7100b50b8553bd032a8f1c448d6
1 # -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 import unittest
11 import unohelper
12 import os
13 from org.libreoffice.unotest import UnoInProcess
15 from com.sun.star.ui import XSidebarProvider
16 from com.sun.star.ui import XDecks
17 from com.sun.star.ui import XDeck
18 from com.sun.star.ui import XPanels
19 from com.sun.star.ui import XPanel
21 class CheckSidebar(unittest.TestCase):
23 @classmethod
24 def setUpClass(cls):
25 cls._uno = UnoInProcess()
26 cls._uno.setUp()
28 @classmethod
29 def tearDownClass(cls):
30 cls._uno.tearDown()
32 def test_check_sidebar(self):
34 xDoc = self.__class__._uno.openEmptyDoc( url = "private:factory/scalc", bHidden = False, bReadOnly = False)
35 xController = xDoc.getCurrentController()
37 xSidebar = xController.getSidebar()
38 assert(xSidebar)
40 xSidebar.setVisible(True)
41 isVisible = xSidebar.isVisible()
42 self.assertTrue ( xSidebar.isVisible() )
44 # TODO: does not work in unit test context
45 # xSidebar.setVisible(False)
46 # isVisible = xSidebar.isVisible()
47 # assert( not isVisible )
48 # xSidebar.setVisible(True)
50 xSidebar.showDecks(False)
51 xSidebar.showDecks(True)
53 xDecks = xSidebar.getDecks()
55 first_deck_name = "PropertyDeck";
57 deck_element_names = xDecks.getElementNames()
58 assert ( first_deck_name in deck_element_names )
59 assert ( xDecks.hasByName(first_deck_name) )
61 decks_count = len(xDecks)
62 self.assertEqual ( 5, decks_count )
64 xDeck = xDecks[first_deck_name]
65 assert ( xDeck )
66 assert ( xDeck.getId() == first_deck_name )
68 new_deck_title = "New title"
69 xDeck.setTitle(new_deck_title)
70 assert ( xDeck.getTitle() == new_deck_title )
72 xDeck.moveFirst()
73 initial_index = xDeck.getOrderIndex()
74 self.assertEqual(100, initial_index)
76 xDeck.moveLast()
77 assert ( xDeck.getOrderIndex() > initial_index )
79 initial_index = xDeck.getOrderIndex()
80 xDeck.moveFirst()
81 assert ( xDeck.getOrderIndex() < initial_index )
83 initial_index = xDeck.getOrderIndex()
84 xDeck.moveDown()
85 assert ( xDeck.getOrderIndex() > initial_index )
87 initial_index = xDeck.getOrderIndex()
88 xDeck.moveUp()
89 assert ( xDeck.getOrderIndex() < initial_index )
91 xPanels = xDeck.getPanels()
93 panels_count = len(xPanels)
94 self.assertEqual ( panels_count, 5 )
96 first_panel_name = self.getFirstPanel(xPanels)
98 panel_element_names = xPanels.getElementNames()
99 assert ( first_panel_name in panel_element_names )
100 assert ( xPanels.hasByName(first_panel_name) )
102 xPanel = xPanels[first_panel_name]
103 assert ( xPanel )
104 assert ( xPanel.getId() == first_panel_name )
106 new_title = "New title"
107 xPanel.setTitle(new_title)
108 assert ( xPanel.getTitle() == new_title )
110 initial_index = xPanel.getOrderIndex()
111 xPanel.moveLast()
112 assert ( xPanel.getOrderIndex() > initial_index )
114 initial_index = xPanel.getOrderIndex()
115 xPanel.moveFirst()
116 assert ( xPanel.getOrderIndex() < initial_index )
118 initial_index = xPanel.getOrderIndex()
119 xPanel.moveDown()
120 assert ( xPanel.getOrderIndex() > initial_index )
122 initial_index = xPanel.getOrderIndex()
123 xPanel.moveUp()
124 assert ( xPanel.getOrderIndex() < initial_index )
126 xPanel.collapse()
127 assert( not xPanel.isExpanded() )
129 last_panel_name = self.getLastPanel(xPanels)
131 other_panel = xPanels[last_panel_name]
132 other_panel.expand(False)
133 assert( other_panel.isExpanded() )
135 xPanel.expand(True)
136 assert( xPanel.isExpanded() )
137 assert( not other_panel.isExpanded() )
139 # close the document
140 xDoc.dispose()
142 def getFirstPanel(self, xPanels):
144 panel_name = ""
145 cur_index = 10000
147 for panel in xPanels:
148 if panel.getOrderIndex() < cur_index:
149 panel_name = panel.getId()
150 cur_index = panel.getOrderIndex()
152 return panel_name
154 def getLastPanel(self, xPanels):
156 panel_name = ""
157 cur_index = 0
159 for panel in xPanels:
160 if panel.getOrderIndex() > cur_index:
161 panel_name = panel.getId()
162 cur_index = panel.getOrderIndex()
164 return panel_name
166 if __name__ == "__main__":
167 unittest.main()
169 # vim: set shiftwidth=4 softtabstop=4 expandtab: