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/.
9 from uitest
.framework
import UITestCase
10 from libreoffice
.uno
.propertyvalue
import mkPropertyValues
11 from uitest
.uihelper
.common
import get_url_for_data_file
12 from uitest
.uihelper
.calc
import enter_text_to_cell
14 #Calc sheet to Writer table
16 class sheetToTable(UITestCase
):
17 def test_sheet_to_table_without_hidden_rows(self
):
18 with self
.ui_test
.load_file(get_url_for_data_file("hiddenRow.ods")):
19 self
.xUITest
.executeCommand(".uno:SelectAll")
20 self
.xUITest
.executeCommand(".uno:Copy")
22 with self
.ui_test
.load_file(get_url_for_data_file("tableToText.odt")) as writer_doc
:
23 self
.xUITest
.executeCommand(".uno:Paste")
24 #verify (don't copy hidden cells)
25 self
.assertEqual(len(writer_doc
.TextTables
), 1)
26 table
= writer_doc
.getTextTables()[0]
27 # This was 3 (copied hidden row)
28 self
.assertEqual(len(table
.getRows()), 2)
29 self
.assertEqual(table
.getCellByName("A1").getString(), "1")
30 # This was "2 (hidden)" (copied hidden row)
31 self
.assertEqual(table
.getCellByName("A2").getString(), "3")
33 def test_tdf138688(self
):
34 with self
.ui_test
.load_file(get_url_for_data_file("hiddenRow.ods")):
35 self
.xUITest
.executeCommand(".uno:SelectAll")
36 self
.xUITest
.executeCommand(".uno:Copy")
38 with self
.ui_test
.load_file(get_url_for_data_file("tableToText.odt")) as writer_doc
:
40 # set numbering in the paragraph after the table
41 self
.xUITest
.executeCommand(".uno:GoDown")
42 self
.xUITest
.executeCommand(".uno:GoDown")
43 self
.xUITest
.executeCommand(".uno:DefaultNumbering")
44 self
.xUITest
.executeCommand(".uno:GoUp")
45 self
.xUITest
.executeCommand(".uno:GoUp")
47 #verify (this was a freezing/crash)
48 self
.xUITest
.executeCommand(".uno:Paste")
50 #verify also tdf#124646 (don't copy hidden cells)
51 self
.assertEqual(len(writer_doc
.TextTables
), 1)
52 table
= writer_doc
.getTextTables()[0]
53 # This was 3 (copied hidden row)
54 self
.assertEqual(len(table
.getRows()), 2)
55 self
.assertEqual(table
.getCellByName("A1").getString(), "1")
56 # This was "2 (hidden)" (copied hidden row)
57 self
.assertEqual(table
.getCellByName("A2").getString(), "3")
59 def test_tdf129083(self
):
60 with self
.ui_test
.create_doc_in_start_center("calc"):
62 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
63 gridwin
= xCalcDoc
.getChild("grid_window")
65 enter_text_to_cell(gridwin
, "A1", "Test 1")
66 enter_text_to_cell(gridwin
, "A2", "Test 2")
67 enter_text_to_cell(gridwin
, "A3", "Test 3")
68 enter_text_to_cell(gridwin
, "A4", "Test 4")
70 gridwin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A4"}))
72 self
.xUITest
.executeCommand(".uno:Copy")
75 with self
.ui_test
.load_empty_file("writer") as writer_doc
:
77 self
.xUITest
.executeCommand(".uno:InsertTable?Columns:short=1&Rows:short=4")
79 self
.xUITest
.executeCommand(".uno:Paste")
81 self
.assertEqual(len(writer_doc
.TextTables
), 1)
82 table
= writer_doc
.getTextTables()[0]
83 self
.assertEqual(len(table
.getRows()), 4)
84 self
.assertEqual(table
.getCellByName("A1").getString(), "Test 1")
85 self
.assertEqual(table
.getCellByName("A2").getString(), "Test 2")
86 self
.assertEqual(table
.getCellByName("A3").getString(), "Test 3")
87 self
.assertEqual(table
.getCellByName("A4").getString(), "Test 4")
89 def test_tdf116685(self
):
90 with self
.ui_test
.create_doc_in_start_center("calc"):
92 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
93 gridwin
= xCalcDoc
.getChild("grid_window")
95 enter_text_to_cell(gridwin
, "A1", "Test 1")
96 enter_text_to_cell(gridwin
, "A2", "Test 2")
97 enter_text_to_cell(gridwin
, "A3", "Test 3")
98 enter_text_to_cell(gridwin
, "A4", "Test 4")
100 self
.xUITest
.executeCommand(".uno:SelectAll")
101 self
.xUITest
.executeCommand(".uno:Copy")
103 with self
.ui_test
.load_empty_file("writer") as writer_doc
:
105 self
.xUITest
.executeCommand(".uno:Paste")
107 # Without the fix in place, this test would have failed with
108 # AssertionError: 0 != 1
109 self
.assertEqual(len(writer_doc
.TextTables
), 1)
110 table
= writer_doc
.getTextTables()[0]
111 self
.assertEqual(len(table
.getRows()), 4)
112 self
.assertEqual(table
.getCellByName("A1").getString(), "Test 1")
113 self
.assertEqual(table
.getCellByName("A2").getString(), "Test 2")
114 self
.assertEqual(table
.getCellByName("A3").getString(), "Test 3")
115 self
.assertEqual(table
.getCellByName("A4").getString(), "Test 4")
117 def test_tdf152245(self
):
118 with self
.ui_test
.create_doc_in_start_center("calc"):
120 xCalcDoc
= self
.xUITest
.getTopFocusWindow()
121 gridwin
= xCalcDoc
.getChild("grid_window")
123 enter_text_to_cell(gridwin
, "A1", "Test 1")
124 enter_text_to_cell(gridwin
, "A2", "Test 2")
125 enter_text_to_cell(gridwin
, "A3", "Test 3")
126 enter_text_to_cell(gridwin
, "A4", "Test 4")
128 gridwin
.executeAction("SELECT", mkPropertyValues({"RANGE": "A1:A4"}))
130 self
.xUITest
.executeCommand(".uno:Copy")
133 with self
.ui_test
.load_empty_file("writer") as writer_doc
:
135 self
.xUITest
.executeCommand(".uno:InsertTable?Columns:short=1&Rows:short=4")
137 # redlining should be on
138 self
.xUITest
.executeCommand(".uno:TrackChanges")
141 self
.xUITest
.executeCommand(".uno:Paste")
143 self
.assertEqual(len(writer_doc
.TextTables
), 1)
144 table
= writer_doc
.getTextTables()[0]
145 self
.assertEqual(len(table
.getRows()), 4)
146 self
.assertEqual(table
.getCellByName("A1").getString(), "Test 1")
147 self
.assertEqual(table
.getCellByName("A2").getString(), "Test 2")
148 self
.assertEqual(table
.getCellByName("A3").getString(), "Test 3")
149 self
.assertEqual(table
.getCellByName("A4").getString(), "Test 4")
151 # vim: set shiftwidth=4 softtabstop=4 expandtab: