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