1425e3132SLiu Zhe /* Licensed to the Apache Software Foundation (ASF) under one
2425e3132SLiu Zhe  * or more contributor license agreements.  See the NOTICE file
3425e3132SLiu Zhe  * distributed with this work for additional information
4425e3132SLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
5425e3132SLiu Zhe  * to you under the Apache License, Version 2.0 (the
6425e3132SLiu Zhe  * "License"); you may not use this file except in compliance
7425e3132SLiu Zhe  * with the License.  You may obtain a copy of the License at
8425e3132SLiu Zhe  *
9425e3132SLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
10425e3132SLiu Zhe  *
11425e3132SLiu Zhe  * Unless required by applicable law or agreed to in writing,
12425e3132SLiu Zhe  * software distributed under the License is distributed on an
13425e3132SLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14425e3132SLiu Zhe  * KIND, either express or implied.  See the License for the
15425e3132SLiu Zhe  * specific language governing permissions and limitations
16425e3132SLiu Zhe  * under the License.
17425e3132SLiu Zhe  *
18425e3132SLiu Zhe  *************************************************************/
19425e3132SLiu Zhe 
20425e3132SLiu Zhe 
21*eba4d44aSLiu Zhe package fvt.uno.sc.rowcolumn;
22425e3132SLiu Zhe 
23425e3132SLiu Zhe import static org.junit.Assert.*;
24425e3132SLiu Zhe 
25425e3132SLiu Zhe import java.util.ArrayList;
26425e3132SLiu Zhe import java.util.Arrays;
27425e3132SLiu Zhe import java.util.Collection;
28425e3132SLiu Zhe 
29425e3132SLiu Zhe import org.junit.After;
30425e3132SLiu Zhe import org.junit.AfterClass;
31425e3132SLiu Zhe import org.junit.Before;
32425e3132SLiu Zhe import org.junit.BeforeClass;
33425e3132SLiu Zhe import org.junit.Test;
34425e3132SLiu Zhe import org.junit.runner.RunWith;
35425e3132SLiu Zhe import org.junit.runners.Parameterized;
36425e3132SLiu Zhe import org.junit.runners.Parameterized.Parameters;
37425e3132SLiu Zhe 
38425e3132SLiu Zhe import org.openoffice.test.common.Testspace;
39425e3132SLiu Zhe import org.openoffice.test.uno.UnoApp;
40425e3132SLiu Zhe 
41425e3132SLiu Zhe import com.sun.star.beans.XPropertySet;
42425e3132SLiu Zhe import com.sun.star.container.XIndexAccess;
43425e3132SLiu Zhe import com.sun.star.lang.XComponent;
44425e3132SLiu Zhe import com.sun.star.sheet.XSpreadsheet;
45425e3132SLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument;
46425e3132SLiu Zhe import com.sun.star.sheet.XSpreadsheets;
47425e3132SLiu Zhe import com.sun.star.table.XCellRange;
48425e3132SLiu Zhe import com.sun.star.table.XCell;
49425e3132SLiu Zhe import com.sun.star.uno.Type;
50425e3132SLiu Zhe import com.sun.star.uno.UnoRuntime;
51425e3132SLiu Zhe import com.sun.star.util.XMergeable;
52425e3132SLiu Zhe 
53425e3132SLiu Zhe /**
54425e3132SLiu Zhe  * Check the content input in cell
55425e3132SLiu Zhe  * @author test
56425e3132SLiu Zhe  *
57425e3132SLiu Zhe  */
58425e3132SLiu Zhe 
59425e3132SLiu Zhe public class CellMerge {
60425e3132SLiu Zhe 
61425e3132SLiu Zhe 	UnoApp unoApp = new UnoApp();
62425e3132SLiu Zhe 	XSpreadsheetDocument scDocument = null;
63425e3132SLiu Zhe 	XComponent scComponent = null;
64425e3132SLiu Zhe 
65425e3132SLiu Zhe 	@Before
66425e3132SLiu Zhe 	public void setUp() throws Exception {
67425e3132SLiu Zhe 		unoApp.start();
68425e3132SLiu Zhe 	}
69425e3132SLiu Zhe 
70425e3132SLiu Zhe 	@After
71425e3132SLiu Zhe 	public void tearDown() throws Exception {
72425e3132SLiu Zhe 		unoApp.closeDocument(scComponent);
73425e3132SLiu Zhe 		unoApp.close();
74425e3132SLiu Zhe 		}
75425e3132SLiu Zhe 
76425e3132SLiu Zhe 	@Test
77425e3132SLiu Zhe 	public void testCellMerge() throws Exception {
78425e3132SLiu Zhe 
79425e3132SLiu Zhe 		String sheetname = "sheet1";
80425e3132SLiu Zhe 		scComponent = unoApp.newDocument("scalc");
81425e3132SLiu Zhe 		scDocument = (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, scComponent);
82425e3132SLiu Zhe 		XSpreadsheets spreadsheets = scDocument.getSheets();
83425e3132SLiu Zhe 		Object sheetObj = spreadsheets.getByName(sheetname);
84425e3132SLiu Zhe 		XSpreadsheet sheet = (XSpreadsheet) UnoRuntime.queryInterface(XSpreadsheet.class, sheetObj);
85425e3132SLiu Zhe 
86425e3132SLiu Zhe 		//Select A1 and input "12"
87425e3132SLiu Zhe 		XCell cell = sheet.getCellByPosition(0, 0);
88425e3132SLiu Zhe 		cell.setValue(12);
89425e3132SLiu Zhe 
90425e3132SLiu Zhe 		// Get cell range A1:B1 by position - (column, row, column, row)
91425e3132SLiu Zhe         XCellRange CellRange = sheet.getCellRangeByPosition( 0, 0, 1, 0 );
92425e3132SLiu Zhe         //XCellRange CellRange = sheet.getCellRangeByName("A1:B1");
93425e3132SLiu Zhe 
94425e3132SLiu Zhe         //Merge cell range A1:B1 into one cell
95425e3132SLiu Zhe        XMergeable xMerge = (XMergeable) UnoRuntime.queryInterface(XMergeable.class, CellRange);
96425e3132SLiu Zhe         xMerge.merge(true);
97425e3132SLiu Zhe 
98425e3132SLiu Zhe         //Verify if the cell range A1:B1 is completely merged
99425e3132SLiu Zhe         assertEquals("Verify if the cell range A1:B1 is completely merged",true, xMerge.getIsMerged());
100425e3132SLiu Zhe 
101425e3132SLiu Zhe        //Undo Merge cell range A1:B1 into one cell
102425e3132SLiu Zhe         xMerge.merge(false);
103425e3132SLiu Zhe 
104425e3132SLiu Zhe         //Verify if the cell range A1:B1 is no longer merged
105425e3132SLiu Zhe         assertEquals("Verify if the cell range A1:B1 is no longer merged",false, xMerge.getIsMerged());
106425e3132SLiu Zhe 
107425e3132SLiu Zhe 
108425e3132SLiu Zhe 	}
109425e3132SLiu Zhe 
110425e3132SLiu Zhe }
111