1*07d7dbdcSHerbert Dürr /**************************************************************
2*07d7dbdcSHerbert Dürr *
3*07d7dbdcSHerbert Dürr * Licensed to the Apache Software Foundation (ASF) under one
4*07d7dbdcSHerbert Dürr * or more contributor license agreements. See the NOTICE file
5*07d7dbdcSHerbert Dürr * distributed with this work for additional information
6*07d7dbdcSHerbert Dürr * regarding copyright ownership. The ASF licenses this file
7*07d7dbdcSHerbert Dürr * to you under the Apache License, Version 2.0 (the
8*07d7dbdcSHerbert Dürr * "License"); you may not use this file except in compliance
9*07d7dbdcSHerbert Dürr * with the License. You may obtain a copy of the License at
10*07d7dbdcSHerbert Dürr *
11*07d7dbdcSHerbert Dürr * http://www.apache.org/licenses/LICENSE-2.0
12*07d7dbdcSHerbert Dürr *
13*07d7dbdcSHerbert Dürr * Unless required by applicable law or agreed to in writing,
14*07d7dbdcSHerbert Dürr * software distributed under the License is distributed on an
15*07d7dbdcSHerbert Dürr * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*07d7dbdcSHerbert Dürr * KIND, either express or implied. See the License for the
17*07d7dbdcSHerbert Dürr * specific language governing permissions and limitations
18*07d7dbdcSHerbert Dürr * under the License.
19*07d7dbdcSHerbert Dürr *
20*07d7dbdcSHerbert Dürr *************************************************************/
21*07d7dbdcSHerbert Dürr
22eba4d44aSLiu Zhe package fvt.uno.sc.rowcolumn;
23eba4d44aSLiu Zhe
24eba4d44aSLiu Zhe import static org.junit.Assert.*;
25eba4d44aSLiu Zhe import static testlib.uno.SCUtil.*;
26eba4d44aSLiu Zhe
27eba4d44aSLiu Zhe import org.junit.After;
28eba4d44aSLiu Zhe import org.junit.Before;
29eba4d44aSLiu Zhe import org.junit.Test;
30eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
31eba4d44aSLiu Zhe
32eba4d44aSLiu Zhe import com.sun.star.lang.XComponent;
33eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheet;
34eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument;
35eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheets;
36eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime;
37eba4d44aSLiu Zhe import com.sun.star.table.XTableColumns;
38eba4d44aSLiu Zhe import com.sun.star.table.XTableRows;
39eba4d44aSLiu Zhe import com.sun.star.table.XColumnRowRange;
40eba4d44aSLiu Zhe import com.sun.star.beans.XPropertySet;
41eba4d44aSLiu Zhe import com.sun.star.table.XCellRange;
42eba4d44aSLiu Zhe import com.sun.star.frame.XModel;
43eba4d44aSLiu Zhe import com.sun.star.frame.XController;
44eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheetView;
45eba4d44aSLiu Zhe
46eba4d44aSLiu Zhe
47eba4d44aSLiu Zhe public class ResizeHideShowRowColumn {
48eba4d44aSLiu Zhe
49eba4d44aSLiu Zhe UnoApp unoApp = new UnoApp();
50eba4d44aSLiu Zhe XSpreadsheetDocument scDocument = null;
51eba4d44aSLiu Zhe XComponent scComponent = null;
52eba4d44aSLiu Zhe
53eba4d44aSLiu Zhe @Before
setUp()54eba4d44aSLiu Zhe public void setUp() throws Exception {
55eba4d44aSLiu Zhe unoApp.start();
56eba4d44aSLiu Zhe }
57eba4d44aSLiu Zhe
58eba4d44aSLiu Zhe @After
tearDown()59eba4d44aSLiu Zhe public void tearDown() throws Exception {
60eba4d44aSLiu Zhe unoApp.closeDocument(scComponent);
61eba4d44aSLiu Zhe unoApp.close();
62eba4d44aSLiu Zhe }
63eba4d44aSLiu Zhe
64eba4d44aSLiu Zhe @Test
testResizeColumn()65eba4d44aSLiu Zhe public void testResizeColumn() throws Exception {
66eba4d44aSLiu Zhe String sheetname = "AddTest";
67eba4d44aSLiu Zhe XPropertySet PropSet = null;
68eba4d44aSLiu Zhe
69eba4d44aSLiu Zhe //Create Spreadsheet file.
70eba4d44aSLiu Zhe scComponent = unoApp.newDocument("scalc");
71eba4d44aSLiu Zhe scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent);
72eba4d44aSLiu Zhe
73eba4d44aSLiu Zhe //Create a sheet at the first place.
74eba4d44aSLiu Zhe XSpreadsheets spreadsheets = scDocument.getSheets();
75eba4d44aSLiu Zhe spreadsheets.insertNewByName(sheetname, (short) 0);
76eba4d44aSLiu Zhe Object sheetObj = spreadsheets.getByName(sheetname);
77eba4d44aSLiu Zhe
78eba4d44aSLiu Zhe XSpreadsheet sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
79eba4d44aSLiu Zhe
80eba4d44aSLiu Zhe //Active the new sheet.
81eba4d44aSLiu Zhe XModel scModel = (XModel) UnoRuntime.queryInterface(XModel.class, scDocument);
82eba4d44aSLiu Zhe XController scController = scModel.getCurrentController();
83eba4d44aSLiu Zhe XSpreadsheetView sheetview = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, scController);
84eba4d44aSLiu Zhe sheetview.setActiveSheet(sheet);
85eba4d44aSLiu Zhe
86eba4d44aSLiu Zhe //Set cell range to A1:B1
87eba4d44aSLiu Zhe XCellRange CellRange = sheet.getCellRangeByPosition(0, 0, 1, 0);
88eba4d44aSLiu Zhe
89eba4d44aSLiu Zhe //Get column A1 by index
90eba4d44aSLiu Zhe XColumnRowRange ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange );
91eba4d44aSLiu Zhe XTableColumns Columns = ColRowRange.getColumns();
92eba4d44aSLiu Zhe Object aColumnObj = Columns.getByIndex( 0 );
93eba4d44aSLiu Zhe
94eba4d44aSLiu Zhe PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aColumnObj);
95eba4d44aSLiu Zhe
96eba4d44aSLiu Zhe //Verify the default values of specified column A1
97eba4d44aSLiu Zhe assertTrue("Verify column is visible as default.", (Boolean) PropSet.getPropertyValue("IsVisible"));
98eba4d44aSLiu Zhe
99eba4d44aSLiu Zhe //Resize width of column A1 to "6001"
100eba4d44aSLiu Zhe PropSet.setPropertyValue( "Width", new Integer( 6001 ));
101eba4d44aSLiu Zhe
102eba4d44aSLiu Zhe //Save and reload document
103eba4d44aSLiu Zhe saveFileAs(scComponent, "TestColumn", "ods");
104eba4d44aSLiu Zhe XSpreadsheetDocument TempSCDocument = reloadFile(unoApp, scDocument, "TestColumn.ods");
105eba4d44aSLiu Zhe scDocument = TempSCDocument;
106eba4d44aSLiu Zhe
107eba4d44aSLiu Zhe spreadsheets = scDocument.getSheets();
108eba4d44aSLiu Zhe sheetObj = spreadsheets.getByName(sheetname);
109eba4d44aSLiu Zhe sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
110eba4d44aSLiu Zhe
111eba4d44aSLiu Zhe //Set cell range to A1:B1
112eba4d44aSLiu Zhe CellRange = sheet.getCellRangeByPosition(0, 0, 1, 0);
113eba4d44aSLiu Zhe ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange );
114eba4d44aSLiu Zhe Columns = ColRowRange.getColumns();
115eba4d44aSLiu Zhe
116eba4d44aSLiu Zhe //Get column A1 by index
117eba4d44aSLiu Zhe aColumnObj = Columns.getByIndex( 0 );
118eba4d44aSLiu Zhe
119eba4d44aSLiu Zhe PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aColumnObj);
120eba4d44aSLiu Zhe
121eba4d44aSLiu Zhe //Verify the values of specified column A1 after resize
122eba4d44aSLiu Zhe int expectedWidth = 6001;
123eba4d44aSLiu Zhe
124eba4d44aSLiu Zhe assertEquals("Verify current width value is 6001.", expectedWidth, PropSet.getPropertyValue("Width"));
125eba4d44aSLiu Zhe assertTrue("Verify column is visible as default.", (Boolean) PropSet.getPropertyValue("IsVisible"));
126eba4d44aSLiu Zhe
127eba4d44aSLiu Zhe //Set column is invisible
128eba4d44aSLiu Zhe PropSet.setPropertyValue("IsVisible", new Boolean(false));
129eba4d44aSLiu Zhe
130eba4d44aSLiu Zhe //Save and reload document
131eba4d44aSLiu Zhe //Save the modified spreadsheet first
132eba4d44aSLiu Zhe save(TempSCDocument);
133eba4d44aSLiu Zhe //close it and reload it
134eba4d44aSLiu Zhe TempSCDocument = reloadFile(unoApp, scDocument, "TestColumn.ods");
135eba4d44aSLiu Zhe scDocument = TempSCDocument;
136eba4d44aSLiu Zhe
137eba4d44aSLiu Zhe spreadsheets = scDocument.getSheets();
138eba4d44aSLiu Zhe sheetObj = spreadsheets.getByName(sheetname);
139eba4d44aSLiu Zhe sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
140eba4d44aSLiu Zhe
141eba4d44aSLiu Zhe //Set cell range to A1:B1
142eba4d44aSLiu Zhe CellRange = sheet.getCellRangeByPosition(0, 0, 1, 0);
143eba4d44aSLiu Zhe ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange );
144eba4d44aSLiu Zhe Columns = ColRowRange.getColumns();
145eba4d44aSLiu Zhe
146eba4d44aSLiu Zhe //Get column A1 by index
147eba4d44aSLiu Zhe aColumnObj = Columns.getByIndex( 0 );
148eba4d44aSLiu Zhe
149eba4d44aSLiu Zhe PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aColumnObj);
150eba4d44aSLiu Zhe
151eba4d44aSLiu Zhe //Verify the values of specified column A1 after save
152eba4d44aSLiu Zhe assertFalse("Verify column A1 is invisible", (Boolean) PropSet.getPropertyValue("IsVisible"));
153eba4d44aSLiu Zhe assertEquals("Verify current width value is 6001 after hide it.", expectedWidth, PropSet.getPropertyValue("Width"));
154eba4d44aSLiu Zhe }
155eba4d44aSLiu Zhe
156eba4d44aSLiu Zhe @Test
testResizeRow()157eba4d44aSLiu Zhe public void testResizeRow() throws Exception {
158eba4d44aSLiu Zhe String sheetname = "AddTest";
159eba4d44aSLiu Zhe XPropertySet PropSet = null;
160eba4d44aSLiu Zhe
161eba4d44aSLiu Zhe //Create Spreadsheet file.
162eba4d44aSLiu Zhe scComponent = unoApp.newDocument("scalc");
163eba4d44aSLiu Zhe scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent);
164eba4d44aSLiu Zhe
165eba4d44aSLiu Zhe //Create a sheet at the first place.
166eba4d44aSLiu Zhe XSpreadsheets spreadsheets = scDocument.getSheets();
167eba4d44aSLiu Zhe spreadsheets.insertNewByName(sheetname, (short) 0);
168eba4d44aSLiu Zhe Object sheetObj = spreadsheets.getByName(sheetname);
169eba4d44aSLiu Zhe XSpreadsheet sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
170eba4d44aSLiu Zhe
171eba4d44aSLiu Zhe //Active the new sheet.
172eba4d44aSLiu Zhe XModel scModel = (XModel) UnoRuntime.queryInterface(XModel.class, scDocument);
173eba4d44aSLiu Zhe XController scController = scModel.getCurrentController();
174eba4d44aSLiu Zhe XSpreadsheetView sheetview = (XSpreadsheetView) UnoRuntime.queryInterface(XSpreadsheetView.class, scController);
175eba4d44aSLiu Zhe sheetview.setActiveSheet(sheet);
176eba4d44aSLiu Zhe
177eba4d44aSLiu Zhe //Set cell range to A1:A2
178eba4d44aSLiu Zhe XCellRange CellRange = sheet.getCellRangeByPosition(0, 0, 0, 1);
179eba4d44aSLiu Zhe //XCell cell = sheet.getCellByPosition(1, 0);
180eba4d44aSLiu Zhe XColumnRowRange ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange );
181eba4d44aSLiu Zhe XTableRows Rows = ColRowRange.getRows();
182eba4d44aSLiu Zhe
183eba4d44aSLiu Zhe //Get Row 1 by index
184eba4d44aSLiu Zhe Object aRowObj = Rows.getByIndex( 0 );
185eba4d44aSLiu Zhe
186eba4d44aSLiu Zhe PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj );
187eba4d44aSLiu Zhe
188eba4d44aSLiu Zhe //Verify the default values of specified Row 1
189eba4d44aSLiu Zhe assertTrue("Verify column is visible as default.", (Boolean) PropSet.getPropertyValue("IsVisible"));
190eba4d44aSLiu Zhe
191eba4d44aSLiu Zhe //Resize Height of Row 1 to "5001"
192eba4d44aSLiu Zhe PropSet.setPropertyValue( "Height", new Integer( 5001 ) );
193eba4d44aSLiu Zhe
194eba4d44aSLiu Zhe // Save and reload document
195eba4d44aSLiu Zhe saveFileAs(scComponent, "TestRow", "xls");
196eba4d44aSLiu Zhe XSpreadsheetDocument TempSCDocument = reloadFile(unoApp, scDocument, "TestRow.xls");
197eba4d44aSLiu Zhe scDocument = TempSCDocument;
198eba4d44aSLiu Zhe
199eba4d44aSLiu Zhe spreadsheets = scDocument.getSheets();
200eba4d44aSLiu Zhe sheetObj = spreadsheets.getByName(sheetname);
201eba4d44aSLiu Zhe sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
202eba4d44aSLiu Zhe
203eba4d44aSLiu Zhe //Set cell range to A1:A2
204eba4d44aSLiu Zhe CellRange = sheet.getCellRangeByPosition(0, 0, 0, 1);
205eba4d44aSLiu Zhe ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange );
206eba4d44aSLiu Zhe Rows = ColRowRange.getRows();
207eba4d44aSLiu Zhe
208eba4d44aSLiu Zhe //Get Row 1 by index
209eba4d44aSLiu Zhe aRowObj = Rows.getByIndex( 0 );
210eba4d44aSLiu Zhe
211eba4d44aSLiu Zhe PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
212eba4d44aSLiu Zhe
213eba4d44aSLiu Zhe //Verify the values of specified Row 1 after resize
214eba4d44aSLiu Zhe int expectedHeight = 5001;
215eba4d44aSLiu Zhe
216eba4d44aSLiu Zhe assertEquals("Verify current width value is 5001.", expectedHeight, PropSet.getPropertyValue("Height"));
217eba4d44aSLiu Zhe assertTrue("Verify column is visible as default.", (Boolean) PropSet.getPropertyValue("IsVisible"));
218eba4d44aSLiu Zhe
219eba4d44aSLiu Zhe //Set Row is invisible
220eba4d44aSLiu Zhe PropSet.setPropertyValue("IsVisible", new Boolean(false));
221eba4d44aSLiu Zhe
222eba4d44aSLiu Zhe //Save and reload document
223eba4d44aSLiu Zhe //Save the modified spreadsheet first
224eba4d44aSLiu Zhe save(TempSCDocument);
225eba4d44aSLiu Zhe //Close and reload it
226eba4d44aSLiu Zhe TempSCDocument = reloadFile(unoApp, scDocument, "TestRow.xls");
227eba4d44aSLiu Zhe scDocument = TempSCDocument;
228eba4d44aSLiu Zhe
229eba4d44aSLiu Zhe spreadsheets = scDocument.getSheets();
230eba4d44aSLiu Zhe sheetObj = spreadsheets.getByName(sheetname);
231eba4d44aSLiu Zhe sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
232eba4d44aSLiu Zhe
233eba4d44aSLiu Zhe //Set cell range to A1:A2
234eba4d44aSLiu Zhe CellRange = sheet.getCellRangeByPosition(0, 0, 0, 1);
235eba4d44aSLiu Zhe ColRowRange = (XColumnRowRange)UnoRuntime.queryInterface( XColumnRowRange.class, CellRange );
236eba4d44aSLiu Zhe Rows = ColRowRange.getRows();
237eba4d44aSLiu Zhe
238eba4d44aSLiu Zhe //Get Row 1 by index
239eba4d44aSLiu Zhe aRowObj = Rows.getByIndex( 0 );
240eba4d44aSLiu Zhe
241eba4d44aSLiu Zhe PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
242eba4d44aSLiu Zhe
243eba4d44aSLiu Zhe //Verify the values of specified Row 1 after resize
244eba4d44aSLiu Zhe assertEquals("Verify current height value is 5001 after hide it.", expectedHeight, PropSet.getPropertyValue("Height"));
245eba4d44aSLiu Zhe assertFalse("Verify column is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible"));
246eba4d44aSLiu Zhe
247eba4d44aSLiu Zhe }
248eba4d44aSLiu Zhe
249eba4d44aSLiu Zhe }
250eba4d44aSLiu Zhe
251eba4d44aSLiu Zhe
252