xref: /AOO41X/test/testuno/source/fvt/uno/sc/rowcolumn/CellMerge.java (revision eba4d44a33e5be0b2528d5a9a6f0dcbf65adaa0d)
1*eba4d44aSLiu Zhe /* Licensed to the Apache Software Foundation (ASF) under one
2*eba4d44aSLiu Zhe  * or more contributor license agreements.  See the NOTICE file
3*eba4d44aSLiu Zhe  * distributed with this work for additional information
4*eba4d44aSLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
5*eba4d44aSLiu Zhe  * to you under the Apache License, Version 2.0 (the
6*eba4d44aSLiu Zhe  * "License"); you may not use this file except in compliance
7*eba4d44aSLiu Zhe  * with the License.  You may obtain a copy of the License at
8*eba4d44aSLiu Zhe  *
9*eba4d44aSLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
10*eba4d44aSLiu Zhe  *
11*eba4d44aSLiu Zhe  * Unless required by applicable law or agreed to in writing,
12*eba4d44aSLiu Zhe  * software distributed under the License is distributed on an
13*eba4d44aSLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14*eba4d44aSLiu Zhe  * KIND, either express or implied.  See the License for the
15*eba4d44aSLiu Zhe  * specific language governing permissions and limitations
16*eba4d44aSLiu Zhe  * under the License.
17*eba4d44aSLiu Zhe  *
18*eba4d44aSLiu Zhe  *************************************************************/
19*eba4d44aSLiu Zhe 
20*eba4d44aSLiu Zhe 
21*eba4d44aSLiu Zhe package fvt.uno.sc.rowcolumn;
22*eba4d44aSLiu Zhe 
23*eba4d44aSLiu Zhe import static org.junit.Assert.*;
24*eba4d44aSLiu Zhe 
25*eba4d44aSLiu Zhe import java.util.ArrayList;
26*eba4d44aSLiu Zhe import java.util.Arrays;
27*eba4d44aSLiu Zhe import java.util.Collection;
28*eba4d44aSLiu Zhe 
29*eba4d44aSLiu Zhe import org.junit.After;
30*eba4d44aSLiu Zhe import org.junit.AfterClass;
31*eba4d44aSLiu Zhe import org.junit.Before;
32*eba4d44aSLiu Zhe import org.junit.BeforeClass;
33*eba4d44aSLiu Zhe import org.junit.Test;
34*eba4d44aSLiu Zhe import org.junit.runner.RunWith;
35*eba4d44aSLiu Zhe import org.junit.runners.Parameterized;
36*eba4d44aSLiu Zhe import org.junit.runners.Parameterized.Parameters;
37*eba4d44aSLiu Zhe 
38*eba4d44aSLiu Zhe import org.openoffice.test.common.Testspace;
39*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
40*eba4d44aSLiu Zhe 
41*eba4d44aSLiu Zhe import com.sun.star.beans.XPropertySet;
42*eba4d44aSLiu Zhe import com.sun.star.container.XIndexAccess;
43*eba4d44aSLiu Zhe import com.sun.star.lang.XComponent;
44*eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheet;
45*eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument;
46*eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheets;
47*eba4d44aSLiu Zhe import com.sun.star.table.XCellRange;
48*eba4d44aSLiu Zhe import com.sun.star.table.XCell;
49*eba4d44aSLiu Zhe import com.sun.star.uno.Type;
50*eba4d44aSLiu Zhe import com.sun.star.uno.UnoRuntime;
51*eba4d44aSLiu Zhe import com.sun.star.util.XMergeable;
52*eba4d44aSLiu Zhe 
53*eba4d44aSLiu Zhe /**
54*eba4d44aSLiu Zhe  * Check the content input in cell
55*eba4d44aSLiu Zhe  * @author test
56*eba4d44aSLiu Zhe  *
57*eba4d44aSLiu Zhe  */
58*eba4d44aSLiu Zhe 
59*eba4d44aSLiu Zhe public class CellMerge {
60*eba4d44aSLiu Zhe 
61*eba4d44aSLiu Zhe 	UnoApp unoApp = new UnoApp();
62*eba4d44aSLiu Zhe 	XSpreadsheetDocument scDocument = null;
63*eba4d44aSLiu Zhe 	XComponent scComponent = null;
64*eba4d44aSLiu Zhe 
65*eba4d44aSLiu Zhe 	@Before
setUp()66*eba4d44aSLiu Zhe 	public void setUp() throws Exception {
67*eba4d44aSLiu Zhe 		unoApp.start();
68*eba4d44aSLiu Zhe 	}
69*eba4d44aSLiu Zhe 
70*eba4d44aSLiu Zhe 	@After
tearDown()71*eba4d44aSLiu Zhe 	public void tearDown() throws Exception {
72*eba4d44aSLiu Zhe 		unoApp.closeDocument(scComponent);
73*eba4d44aSLiu Zhe 		unoApp.close();
74*eba4d44aSLiu Zhe 		}
75*eba4d44aSLiu Zhe 
76*eba4d44aSLiu Zhe 	@Test
testCellMerge()77*eba4d44aSLiu Zhe 	public void testCellMerge() throws Exception {
78*eba4d44aSLiu Zhe 
79*eba4d44aSLiu Zhe 		String sheetname = "sheet1";
80*eba4d44aSLiu Zhe 		scComponent = unoApp.newDocument("scalc");
81*eba4d44aSLiu Zhe 		scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent);
82*eba4d44aSLiu Zhe 		XSpreadsheets spreadsheets = scDocument.getSheets();
83*eba4d44aSLiu Zhe 		Object sheetObj = spreadsheets.getByName(sheetname);
84*eba4d44aSLiu Zhe 		XSpreadsheet sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
85*eba4d44aSLiu Zhe 
86*eba4d44aSLiu Zhe 		//Select A1 and input "12"
87*eba4d44aSLiu Zhe 		XCell cell = sheet.getCellByPosition(0, 0);
88*eba4d44aSLiu Zhe 		cell.setValue(12);
89*eba4d44aSLiu Zhe 
90*eba4d44aSLiu Zhe 		// Get cell range A1:B1 by position - (column, row, column, row)
91*eba4d44aSLiu Zhe         XCellRange CellRange = sheet.getCellRangeByPosition( 0, 0, 1, 0 );
92*eba4d44aSLiu Zhe         //XCellRange CellRange = sheet.getCellRangeByName("A1:B1");
93*eba4d44aSLiu Zhe 
94*eba4d44aSLiu Zhe         //Merge cell range A1:B1 into one cell
95*eba4d44aSLiu Zhe        XMergeable xMerge = (XMergeable) UnoRuntime.queryInterface(XMergeable.class, CellRange);
96*eba4d44aSLiu Zhe         xMerge.merge(true);
97*eba4d44aSLiu Zhe 
98*eba4d44aSLiu Zhe         //Verify if the cell range A1:B1 is completely merged
99*eba4d44aSLiu Zhe         assertEquals("Verify if the cell range A1:B1 is completely merged",true, xMerge.getIsMerged());
100*eba4d44aSLiu Zhe 
101*eba4d44aSLiu Zhe        //Undo Merge cell range A1:B1 into one cell
102*eba4d44aSLiu Zhe         xMerge.merge(false);
103*eba4d44aSLiu Zhe 
104*eba4d44aSLiu Zhe         //Verify if the cell range A1:B1 is no longer merged
105*eba4d44aSLiu Zhe         assertEquals("Verify if the cell range A1:B1 is no longer merged",false, xMerge.getIsMerged());
106*eba4d44aSLiu Zhe 
107*eba4d44aSLiu Zhe 
108*eba4d44aSLiu Zhe 	}
109*eba4d44aSLiu Zhe 
110*eba4d44aSLiu Zhe }
111