xref: /AOO41X/test/testuno/source/fvt/uno/sc/cell/CellFontSize.java (revision eba4d44a33e5be0b2528d5a9a6f0dcbf65adaa0d)
1*eba4d44aSLiu Zhe /**************************************************************
2*eba4d44aSLiu Zhe  *
3*eba4d44aSLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
4*eba4d44aSLiu Zhe  * or more contributor license agreements.  See the NOTICE file
5*eba4d44aSLiu Zhe  * distributed with this work for additional information
6*eba4d44aSLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
7*eba4d44aSLiu Zhe  * to you under the Apache License, Version 2.0 (the
8*eba4d44aSLiu Zhe  * "License"); you may not use this file except in compliance
9*eba4d44aSLiu Zhe  * with the License.  You may obtain a copy of the License at
10*eba4d44aSLiu Zhe  *
11*eba4d44aSLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
12*eba4d44aSLiu Zhe  *
13*eba4d44aSLiu Zhe  * Unless required by applicable law or agreed to in writing,
14*eba4d44aSLiu Zhe  * software distributed under the License is distributed on an
15*eba4d44aSLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*eba4d44aSLiu Zhe  * KIND, either express or implied.  See the License for the
17*eba4d44aSLiu Zhe  * specific language governing permissions and limitations
18*eba4d44aSLiu Zhe  * under the License.
19*eba4d44aSLiu Zhe  *
20*eba4d44aSLiu Zhe  *************************************************************/
21*eba4d44aSLiu Zhe 
22*eba4d44aSLiu Zhe 
23*eba4d44aSLiu Zhe package fvt.uno.sc.cell;
24*eba4d44aSLiu Zhe 
25*eba4d44aSLiu Zhe import static org.junit.Assert.assertArrayEquals;
26*eba4d44aSLiu Zhe 
27*eba4d44aSLiu Zhe import java.util.Arrays;
28*eba4d44aSLiu Zhe import java.util.Collection;
29*eba4d44aSLiu Zhe 
30*eba4d44aSLiu Zhe import org.junit.After;
31*eba4d44aSLiu Zhe import org.junit.AfterClass;
32*eba4d44aSLiu Zhe import org.junit.Before;
33*eba4d44aSLiu Zhe import org.junit.BeforeClass;
34*eba4d44aSLiu Zhe import org.junit.Test;
35*eba4d44aSLiu Zhe import org.junit.runner.RunWith;
36*eba4d44aSLiu Zhe import org.junit.runners.Parameterized;
37*eba4d44aSLiu Zhe import org.junit.runners.Parameterized.Parameters;
38*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
39*eba4d44aSLiu Zhe 
40*eba4d44aSLiu Zhe import testlib.uno.SCUtil;
41*eba4d44aSLiu Zhe import testlib.uno.TestUtil;
42*eba4d44aSLiu Zhe import testlib.uno.CellInfo;
43*eba4d44aSLiu Zhe 
44*eba4d44aSLiu Zhe import com.sun.star.lang.XComponent;
45*eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheet;
46*eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument;
47*eba4d44aSLiu Zhe import com.sun.star.table.XCell;
48*eba4d44aSLiu Zhe 
49*eba4d44aSLiu Zhe 
50*eba4d44aSLiu Zhe /**
51*eba4d44aSLiu Zhe  *  Check the cell background color and font color setting can be applied and saved
52*eba4d44aSLiu Zhe  *
53*eba4d44aSLiu Zhe  */
54*eba4d44aSLiu Zhe @RunWith(value = Parameterized.class)
55*eba4d44aSLiu Zhe public class CellFontSize {
56*eba4d44aSLiu Zhe 
57*eba4d44aSLiu Zhe 	private double[] expected;
58*eba4d44aSLiu Zhe 	private String inputType;
59*eba4d44aSLiu Zhe 	private double[] inputData;
60*eba4d44aSLiu Zhe 	private String fileType;
61*eba4d44aSLiu Zhe 
62*eba4d44aSLiu Zhe 	private static final UnoApp unoApp = new UnoApp();
63*eba4d44aSLiu Zhe 
64*eba4d44aSLiu Zhe 	XComponent scComponent = null;
65*eba4d44aSLiu Zhe 	XSpreadsheetDocument scDocument = null;
66*eba4d44aSLiu Zhe 
67*eba4d44aSLiu Zhe 	@Parameters
data()68*eba4d44aSLiu Zhe 	public static Collection<Object[]> data() throws Exception {
69*eba4d44aSLiu Zhe 		double[] list1 = TestUtil.randFontSizeList(30, 409); // Excel2003's value range [is 1,409]
70*eba4d44aSLiu Zhe 		double[] list2 = TestUtil.randFontSizeList(10, 76);
71*eba4d44aSLiu Zhe 		double[] list3 = TestUtil.randFontSizeList(5, 20);
72*eba4d44aSLiu Zhe 		double[] list4 = TestUtil.randFontSizeList(20, 999); //OO's value range is [1, 1000)
73*eba4d44aSLiu Zhe 		return Arrays.asList(new Object[][] {
74*eba4d44aSLiu Zhe 			{list1, "CharHeight", list1, "ods"},
75*eba4d44aSLiu Zhe 			{list2, "CharHeight", list2, "ods"},
76*eba4d44aSLiu Zhe 			{list3, "CharHeight", list3, "ods"},
77*eba4d44aSLiu Zhe 			{list4, "CharHeight", list4, "ods"},
78*eba4d44aSLiu Zhe 			{list1, "CharHeight", list1, "xls"},
79*eba4d44aSLiu Zhe 			{list2, "CharHeight", list2, "xls"},
80*eba4d44aSLiu Zhe 			{list3, "CharHeight", list3, "xls"}
81*eba4d44aSLiu Zhe 		});
82*eba4d44aSLiu Zhe 	}
83*eba4d44aSLiu Zhe 
CellFontSize(double[] expected, String inputType, double[] inputData, String fileType)84*eba4d44aSLiu Zhe 	public CellFontSize(double[] expected, String inputType, double[] inputData, String fileType) {
85*eba4d44aSLiu Zhe 		this.expected = expected;
86*eba4d44aSLiu Zhe 		this.inputType = inputType;
87*eba4d44aSLiu Zhe 		this.inputData = inputData;
88*eba4d44aSLiu Zhe 		this.fileType = fileType;
89*eba4d44aSLiu Zhe 	}
90*eba4d44aSLiu Zhe 
91*eba4d44aSLiu Zhe 
92*eba4d44aSLiu Zhe 	@Before
setUp()93*eba4d44aSLiu Zhe 	public void setUp() throws Exception {
94*eba4d44aSLiu Zhe 		scComponent = unoApp.newDocument("scalc");
95*eba4d44aSLiu Zhe 		scDocument = SCUtil.getSCDocument(scComponent);
96*eba4d44aSLiu Zhe 	}
97*eba4d44aSLiu Zhe 
98*eba4d44aSLiu Zhe 	@After
tearDown()99*eba4d44aSLiu Zhe 	public void tearDown() throws Exception {
100*eba4d44aSLiu Zhe 		unoApp.closeDocument(scComponent);
101*eba4d44aSLiu Zhe 
102*eba4d44aSLiu Zhe 	}
103*eba4d44aSLiu Zhe 
104*eba4d44aSLiu Zhe 	@BeforeClass
setUpConnection()105*eba4d44aSLiu Zhe 	public static void setUpConnection() throws Exception {
106*eba4d44aSLiu Zhe 		unoApp.start();
107*eba4d44aSLiu Zhe 	}
108*eba4d44aSLiu Zhe 
109*eba4d44aSLiu Zhe 	@AfterClass
tearDownConnection()110*eba4d44aSLiu Zhe 	public static void tearDownConnection() throws InterruptedException, Exception {
111*eba4d44aSLiu Zhe 		unoApp.close();
112*eba4d44aSLiu Zhe 		SCUtil.clearTempDir();
113*eba4d44aSLiu Zhe 	}
114*eba4d44aSLiu Zhe 
115*eba4d44aSLiu Zhe 	/**
116*eba4d44aSLiu Zhe 	 * Check the cell background color and font color
117*eba4d44aSLiu Zhe 	 * 1. Create a spreadsheet file.
118*eba4d44aSLiu Zhe 	 * 2. Input number, text, formula into many cell.
119*eba4d44aSLiu Zhe 	 * 3. Set cell font size
120*eba4d44aSLiu Zhe 	 * 4. Save file as ODF/MSBinary format.
121*eba4d44aSLiu Zhe 	 * 5. Close and reopen file.  -> Check the font size setting.
122*eba4d44aSLiu Zhe 	 * @throws Exception
123*eba4d44aSLiu Zhe 	 */
124*eba4d44aSLiu Zhe 	@Test
testCellFontSize()125*eba4d44aSLiu Zhe 	public void testCellFontSize() throws Exception {
126*eba4d44aSLiu Zhe 		String fileName = "testCellFontSize";
127*eba4d44aSLiu Zhe 
128*eba4d44aSLiu Zhe 		int cellNum = inputData.length;
129*eba4d44aSLiu Zhe 		XCell[] cells = new XCell[cellNum];
130*eba4d44aSLiu Zhe 		double[] results = new double[cellNum];
131*eba4d44aSLiu Zhe 		CellInfo cInfo = TestUtil.randCell(256, 100);
132*eba4d44aSLiu Zhe 
133*eba4d44aSLiu Zhe 		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
134*eba4d44aSLiu Zhe 
135*eba4d44aSLiu Zhe 		for (int i = 0; i < cellNum; i++) {
136*eba4d44aSLiu Zhe 			cells[i] = sheet.getCellByPosition(cInfo.getCol(), cInfo.getRow() + i);
137*eba4d44aSLiu Zhe 		}
138*eba4d44aSLiu Zhe 
139*eba4d44aSLiu Zhe 		cells[0].setValue(inputData[0]);
140*eba4d44aSLiu Zhe 		SCUtil. setTextToCell(cells[1], inputType);
141*eba4d44aSLiu Zhe 		cells[2].setFormula("=TRUE()");
142*eba4d44aSLiu Zhe 		cells[3].setValue(-0.000999999);
143*eba4d44aSLiu Zhe 
144*eba4d44aSLiu Zhe 		for (int i = 0; i < cellNum; i++) {
145*eba4d44aSLiu Zhe 			SCUtil.setCellProperties(cells[i], inputType, inputData[i]);
146*eba4d44aSLiu Zhe 		}
147*eba4d44aSLiu Zhe 
148*eba4d44aSLiu Zhe 		SCUtil.saveFileAs(scComponent, fileName, fileType);
149*eba4d44aSLiu Zhe 		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
150*eba4d44aSLiu Zhe 		sheet = SCUtil.getCurrentSheet(scDocument);
151*eba4d44aSLiu Zhe 
152*eba4d44aSLiu Zhe 		for (int i = 0; i < cellNum; i++) {
153*eba4d44aSLiu Zhe 			cells[i] = sheet.getCellByPosition(cInfo.getCol(), cInfo.getRow() + i);
154*eba4d44aSLiu Zhe 			results[i] = ((Float) SCUtil.getCellProperties(cells[i], inputType)).floatValue();
155*eba4d44aSLiu Zhe 		}
156*eba4d44aSLiu Zhe 		SCUtil.closeFile(scDocument);
157*eba4d44aSLiu Zhe 
158*eba4d44aSLiu Zhe 		assertArrayEquals("Incorrect cell font size(" + inputType + ") value got in ." + fileType + " file.", expected, results, 0);
159*eba4d44aSLiu Zhe 
160*eba4d44aSLiu Zhe 	}
161*eba4d44aSLiu Zhe 
162*eba4d44aSLiu Zhe }
163