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