Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / uitest / calc_tests / calcSheetDelete.py
blob380d6766943e80aac33ae6e9f6d4bf59df46b754
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 from uitest.framework import UITestCase
11 from libreoffice.uno.propertyvalue import mkPropertyValues
12 from uitest.uihelper.calc import enter_text_to_cell
14 class calcSheetDelete(UITestCase):
16 def test_tdf114228_insert_and_delete_sheet(self):
18 with self.ui_test.create_doc_in_start_center("calc") as document:
20 xCalcDoc = self.xUITest.getTopFocusWindow()
21 xGridWindow = xCalcDoc.getChild("grid_window")
23 xGridWindow.executeAction("SELECT", mkPropertyValues({"CELL": "L12"}))
24 nrSheets = document.Sheets.getCount() #default number
26 with self.ui_test.execute_dialog_through_command(".uno:Insert"):
27 pass
29 self.assertEqual(document.Sheets.getCount(), nrSheets + 1)
31 self.xUITest.executeCommand(".uno:Remove")
32 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
33 xToolkit.processEventsToIdle()
35 self.assertEqual(document.Sheets.getCount(), nrSheets)
36 self.xUITest.executeCommand(".uno:Undo")
37 self.assertEqual(document.Sheets.getCount(), nrSheets + 1)
38 self.xUITest.executeCommand(".uno:Redo")
39 self.assertEqual(document.Sheets.getCount(), nrSheets)
42 def test_tdf43078_insert_and_delete_sheet_insert_text(self):
44 with self.ui_test.create_doc_in_start_center("calc") as document:
46 nrSheets = document.Sheets.getCount() #default number of sheets
48 with self.ui_test.execute_dialog_through_command(".uno:Insert"):
49 pass
51 with self.ui_test.execute_dialog_through_command(".uno:Insert"):
52 pass
53 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
54 xToolkit.processEventsToIdle()
56 self.assertEqual(document.Sheets.getCount(), nrSheets + 2)
57 xCalcDoc = self.xUITest.getTopFocusWindow()
58 xGridWindow = xCalcDoc.getChild("grid_window")
59 enter_text_to_cell(xGridWindow, "B2", "abcd")
61 with self.ui_test.execute_dialog_through_command(".uno:Remove", close_button="yes"):
62 pass
64 self.assertEqual(document.Sheets.getCount(), nrSheets + 1)
65 self.xUITest.executeCommand(".uno:Undo")
66 self.assertEqual(document.Sheets.getCount(), nrSheets + 2)
67 self.xUITest.executeCommand(".uno:Redo")
68 self.assertEqual(document.Sheets.getCount(), nrSheets + 1)
71 def test_delete_more_sheets_at_once(self):
73 with self.ui_test.create_doc_in_start_center("calc") as document:
74 nrSheets = document.Sheets.getCount() #default number
75 i = 0
76 while i < 6:
77 with self.ui_test.execute_dialog_through_command(".uno:Insert"):
78 pass
79 i = i + 1
80 self.assertEqual(document.Sheets.getCount(), nrSheets + 6)
82 i = 0
83 while i < 5:
84 self.xUITest.executeCommand(".uno:JumpToNextTableSel") #select next sheet
85 i = i + 1
87 self.xUITest.executeCommand(".uno:Remove")
89 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
90 xToolkit.processEventsToIdle()
91 self.assertEqual(document.Sheets.getCount(), nrSheets)
92 self.xUITest.executeCommand(".uno:Undo")
93 self.assertEqual(document.Sheets.getCount(), nrSheets + 6)
94 self.xUITest.executeCommand(".uno:Redo")
95 self.assertEqual(document.Sheets.getCount(), nrSheets)
98 def test_tdf105105_delete_lots_of_sheets_at_once(self):
100 with self.ui_test.create_doc_in_start_center("calc") as document:
101 nrSheets = document.Sheets.getCount() #default number
102 i = 0
103 while i < 100:
104 with self.ui_test.execute_dialog_through_command(".uno:Insert"):
105 pass
106 i = i + 1
107 xToolkit = self.xContext.ServiceManager.createInstance('com.sun.star.awt.Toolkit')
108 xToolkit.processEventsToIdle()
109 self.assertEqual(document.Sheets.getCount(), nrSheets + 100)
111 i = 0
112 while i < 99:
113 self.xUITest.executeCommand(".uno:JumpToNextTableSel") #select next sheet
114 i = i + 1
116 self.xUITest.executeCommand(".uno:Remove")
118 self.assertEqual(document.Sheets.getCount(), nrSheets)
119 self.xUITest.executeCommand(".uno:Undo")
120 self.assertEqual(document.Sheets.getCount(), nrSheets + 100)
121 self.xUITest.executeCommand(".uno:Redo")
122 self.assertEqual(document.Sheets.getCount(), nrSheets)
124 # vim: set shiftwidth=4 softtabstop=4 expandtab: