xref: /AOO41X/test/testuno/source/fvt/uno/sc/cell/CellEffectUnderline.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.assertEquals;
26*eba4d44aSLiu Zhe import static org.junit.Assert.assertFalse;
27*eba4d44aSLiu Zhe import static org.junit.Assert.assertTrue;
28*eba4d44aSLiu Zhe 
29*eba4d44aSLiu Zhe import java.util.Arrays;
30*eba4d44aSLiu Zhe import java.util.Collection;
31*eba4d44aSLiu Zhe 
32*eba4d44aSLiu Zhe import org.junit.After;
33*eba4d44aSLiu Zhe import org.junit.AfterClass;
34*eba4d44aSLiu Zhe import org.junit.Before;
35*eba4d44aSLiu Zhe import org.junit.BeforeClass;
36*eba4d44aSLiu Zhe import org.junit.Test;
37*eba4d44aSLiu Zhe import org.junit.runner.RunWith;
38*eba4d44aSLiu Zhe import org.junit.runners.Parameterized;
39*eba4d44aSLiu Zhe import org.junit.runners.Parameterized.Parameters;
40*eba4d44aSLiu Zhe import org.openoffice.test.uno.UnoApp;
41*eba4d44aSLiu Zhe 
42*eba4d44aSLiu Zhe import testlib.uno.SCUtil;
43*eba4d44aSLiu Zhe import testlib.uno.TestUtil;
44*eba4d44aSLiu Zhe import testlib.uno.CellInfo;
45*eba4d44aSLiu Zhe 
46*eba4d44aSLiu Zhe import com.sun.star.lang.XComponent;
47*eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheet;
48*eba4d44aSLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument;
49*eba4d44aSLiu Zhe import com.sun.star.table.XCell;
50*eba4d44aSLiu Zhe 
51*eba4d44aSLiu Zhe 
52*eba4d44aSLiu Zhe /**
53*eba4d44aSLiu Zhe  *  Check the cell background color and font color setting can be applied and saved
54*eba4d44aSLiu Zhe  *
55*eba4d44aSLiu Zhe  */
56*eba4d44aSLiu Zhe @RunWith(value = Parameterized.class)
57*eba4d44aSLiu Zhe public class CellEffectUnderline {
58*eba4d44aSLiu Zhe 
59*eba4d44aSLiu Zhe 	private int expectedLine;
60*eba4d44aSLiu Zhe 	private int expectedColor;
61*eba4d44aSLiu Zhe 	private String[] inputType;
62*eba4d44aSLiu Zhe 	private int inputStyle;
63*eba4d44aSLiu Zhe 	private int inputColor;
64*eba4d44aSLiu Zhe 	private String fileType;
65*eba4d44aSLiu Zhe 
66*eba4d44aSLiu Zhe 	private static final UnoApp unoApp = new UnoApp();
67*eba4d44aSLiu Zhe 
68*eba4d44aSLiu Zhe 	XComponent scComponent = null;
69*eba4d44aSLiu Zhe 	XSpreadsheetDocument scDocument = null;
70*eba4d44aSLiu Zhe 
71*eba4d44aSLiu Zhe 	@Parameters
data()72*eba4d44aSLiu Zhe 	public static Collection<Object[]> data() throws Exception {
73*eba4d44aSLiu Zhe 		String[] typeList = {"CharUnderline", "CharUnderlineHasColor", "CharUnderlineColor"};
74*eba4d44aSLiu Zhe 		int[] list = TestUtil.randColorList(19);
75*eba4d44aSLiu Zhe 		return Arrays.asList(new Object[][] {
76*eba4d44aSLiu Zhe 			{0, list[0], typeList, 0, list[0], "ods"}, //NONE 0
77*eba4d44aSLiu Zhe 			{1, list[1], typeList, 1, list[1], "ods"}, //SIGNLE 1
78*eba4d44aSLiu Zhe 			{2, list[2], typeList, 2, list[2], "ods"}, //DOUBLE 2
79*eba4d44aSLiu Zhe 			{3, list[3], typeList, 3, list[3], "ods"}, //DOTTED 3
80*eba4d44aSLiu Zhe 			{0, list[4], typeList, 4, list[4], "ods"}, //DONTKNOW 4  can not set this setting via UI
81*eba4d44aSLiu Zhe 			{5, list[5], typeList, 5, list[5], "ods"}, //DASH 5
82*eba4d44aSLiu Zhe 			{6, list[6], typeList, 6, list[6], "ods"}, //LONGDASH 6
83*eba4d44aSLiu Zhe 			{7, list[7], typeList, 7, list[7], "ods"}, //DASHDOT 7
84*eba4d44aSLiu Zhe 			{8, list[8], typeList, 8, list[8], "ods"}, //DASHDOTDOT 8
85*eba4d44aSLiu Zhe 			{9, list[9], typeList, 9, list[9], "ods"}, //SMALLWAVE 9  can not set this setting via UI
86*eba4d44aSLiu Zhe 			{10, list[10], typeList, 10, list[10], "ods"}, //WAVE 10
87*eba4d44aSLiu Zhe 			{11, list[11], typeList, 11, list[11], "ods"}, //DOUBLEWAVE 11
88*eba4d44aSLiu Zhe 			{12, list[12], typeList, 12, list[12], "ods"}, //BOLD 12
89*eba4d44aSLiu Zhe 			{13, list[13], typeList, 13, list[13], "ods"}, //BOLDDOTTED 13
90*eba4d44aSLiu Zhe 			{14, list[14], typeList, 14, list[14], "ods"}, //BOLDDASH 14
91*eba4d44aSLiu Zhe 			{15, list[15], typeList, 15, list[15], "ods"}, //BOLDLONGDASH 15
92*eba4d44aSLiu Zhe 			{16, list[16], typeList, 16, list[16], "ods"}, //BOLDDASHDOT 16
93*eba4d44aSLiu Zhe 			{17, list[17], typeList, 17, list[17], "ods"}, //BOLDDASHDOTDOT 17
94*eba4d44aSLiu Zhe 			{18, list[18], typeList, 18, list[18], "ods"}, //BOLDWAVE = 18
95*eba4d44aSLiu Zhe 
96*eba4d44aSLiu Zhe 			{0, list[0], typeList, 0, list[0], "xls"}, //NONE 0
97*eba4d44aSLiu Zhe 			{1, list[1], typeList, 1, list[1], "xls"}, //SIGNLE 1
98*eba4d44aSLiu Zhe 			{2, list[2], typeList, 2, list[2], "xls"}, //DOUBLE 2
99*eba4d44aSLiu Zhe 			{1, list[3], typeList, 3, list[3], "xls"}, //DOTTED 3
100*eba4d44aSLiu Zhe 			{0, list[4], typeList, 4, list[4], "xls"}, //DONTKNOW 4  can not set this setting via UI
101*eba4d44aSLiu Zhe 			{1, list[5], typeList, 5, list[5], "xls"}, //DASH 5
102*eba4d44aSLiu Zhe 			{1, list[6], typeList, 6, list[6], "xls"}, //LONGDASH 6
103*eba4d44aSLiu Zhe 			{1, list[7], typeList, 7, list[7], "xls"}, //DASHDOT 7
104*eba4d44aSLiu Zhe 			{1, list[8], typeList, 8, list[8], "xls"}, //DASHDOTDOT 8
105*eba4d44aSLiu Zhe 			{1, list[9], typeList, 9, list[9], "xls"}, //SMALLWAVE 9  can not set this setting via UI
106*eba4d44aSLiu Zhe 			{1, list[10], typeList, 10, list[10], "xls"}, //WAVE 10
107*eba4d44aSLiu Zhe 			{2, list[11], typeList, 11, list[11], "xls"}, //DOUBLEWAVE 11
108*eba4d44aSLiu Zhe 			{1, list[12], typeList, 12, list[12], "xls"}, //BOLD 12
109*eba4d44aSLiu Zhe 			{1, list[13], typeList, 13, list[13], "xls"}, //BOLDDOTTED 13
110*eba4d44aSLiu Zhe 			{1, list[14], typeList, 14, list[14], "xls"}, //BOLDDASH 14
111*eba4d44aSLiu Zhe 			{1, list[15], typeList, 15, list[15], "xls"}, //BOLDLONGDASH 15
112*eba4d44aSLiu Zhe 			{1, list[16], typeList, 16, list[16], "xls"}, //BOLDDASHDOT 16
113*eba4d44aSLiu Zhe 			{1, list[17], typeList, 17, list[17], "xls"}, //BOLDDASHDOTDOT 17
114*eba4d44aSLiu Zhe 			{1, list[18], typeList, 18, list[18], "xls"} //BOLDWAVE = 18
115*eba4d44aSLiu Zhe 		});
116*eba4d44aSLiu Zhe 	}
117*eba4d44aSLiu Zhe 
CellEffectUnderline(int expectedStyle, int expectedColor, String[] inputType, int inputStyle, int inputColor, String fileType)118*eba4d44aSLiu Zhe 	public CellEffectUnderline(int expectedStyle, int expectedColor, String[] inputType, int inputStyle, int inputColor, String fileType) {
119*eba4d44aSLiu Zhe 		this.expectedLine = expectedStyle;
120*eba4d44aSLiu Zhe 		this.expectedColor = expectedColor;
121*eba4d44aSLiu Zhe 		this.inputType = inputType;
122*eba4d44aSLiu Zhe 		this.inputStyle = inputStyle;
123*eba4d44aSLiu Zhe 		this.inputColor = inputColor;
124*eba4d44aSLiu Zhe 		this.fileType = fileType;
125*eba4d44aSLiu Zhe 	}
126*eba4d44aSLiu Zhe 
127*eba4d44aSLiu Zhe 
128*eba4d44aSLiu Zhe 	@Before
setUp()129*eba4d44aSLiu Zhe 	public void setUp() throws Exception {
130*eba4d44aSLiu Zhe 		scComponent = unoApp.newDocument("scalc");
131*eba4d44aSLiu Zhe 		scDocument = SCUtil.getSCDocument(scComponent);
132*eba4d44aSLiu Zhe 	}
133*eba4d44aSLiu Zhe 
134*eba4d44aSLiu Zhe 	@After
tearDown()135*eba4d44aSLiu Zhe 	public void tearDown() throws Exception {
136*eba4d44aSLiu Zhe 		unoApp.closeDocument(scComponent);
137*eba4d44aSLiu Zhe 
138*eba4d44aSLiu Zhe 	}
139*eba4d44aSLiu Zhe 
140*eba4d44aSLiu Zhe 	@BeforeClass
setUpConnection()141*eba4d44aSLiu Zhe 	public static void setUpConnection() throws Exception {
142*eba4d44aSLiu Zhe 		unoApp.start();
143*eba4d44aSLiu Zhe 	}
144*eba4d44aSLiu Zhe 
145*eba4d44aSLiu Zhe 	@AfterClass
tearDownConnection()146*eba4d44aSLiu Zhe 	public static void tearDownConnection() throws InterruptedException, Exception {
147*eba4d44aSLiu Zhe 		unoApp.close();
148*eba4d44aSLiu Zhe 		SCUtil.clearTempDir();
149*eba4d44aSLiu Zhe 	}
150*eba4d44aSLiu Zhe 
151*eba4d44aSLiu Zhe 	/**
152*eba4d44aSLiu Zhe 	 * Check the cell underline style and underline color
153*eba4d44aSLiu Zhe 	 * 1. Create a spreadsheet file.
154*eba4d44aSLiu Zhe 	 * 2. Input number, text, formula into many cell.
155*eba4d44aSLiu Zhe 	 * 3. Set cell underline style.
156*eba4d44aSLiu Zhe 	 * 4. Set cell underline color, if underline style is not NONE.
157*eba4d44aSLiu Zhe 	 * 4. Save file as ODF/MSBinary format.
158*eba4d44aSLiu Zhe 	 * 5. Close and reopen file.  -> Check the underline style and underline color setting.
159*eba4d44aSLiu Zhe 	 * @throws Exception
160*eba4d44aSLiu Zhe 	 */
161*eba4d44aSLiu Zhe 	@Test
testCharUnderline()162*eba4d44aSLiu Zhe 	public void testCharUnderline() throws Exception {
163*eba4d44aSLiu Zhe 		String fileName = "testCharUnderline";
164*eba4d44aSLiu Zhe 		int cellNum = 5;
165*eba4d44aSLiu Zhe 		XCell[] cells = new XCell[cellNum];
166*eba4d44aSLiu Zhe 		int[] styleResults = new int[cellNum];
167*eba4d44aSLiu Zhe 		boolean[] hasColor = new boolean[cellNum];
168*eba4d44aSLiu Zhe 		int[] colorResults = new int[cellNum];
169*eba4d44aSLiu Zhe 		CellInfo cInfo = TestUtil.randCell(100, 32768);
170*eba4d44aSLiu Zhe 
171*eba4d44aSLiu Zhe 		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
172*eba4d44aSLiu Zhe 
173*eba4d44aSLiu Zhe 		for (int i = 0; i < cellNum; i++) {
174*eba4d44aSLiu Zhe 			cells[i] = sheet.getCellByPosition(cInfo.getCol(), cInfo.getRow() + i);
175*eba4d44aSLiu Zhe 		}
176*eba4d44aSLiu Zhe 
177*eba4d44aSLiu Zhe 		cells[0].setValue(inputColor);
178*eba4d44aSLiu Zhe 		SCUtil.setTextToCell(cells[1], inputType[0]);
179*eba4d44aSLiu Zhe 		cells[2].setFormula("=\"ABC\"");
180*eba4d44aSLiu Zhe 		cells[3].setValue(-0.90000001);
181*eba4d44aSLiu Zhe 
182*eba4d44aSLiu Zhe 		for (int i = 0; i < cellNum; i++) {
183*eba4d44aSLiu Zhe 			SCUtil.setCellProperties(cells[i], inputType[0], inputStyle);
184*eba4d44aSLiu Zhe 			if (inputStyle > 0) {
185*eba4d44aSLiu Zhe 				SCUtil.setCellProperties(cells[i], inputType[1], true);
186*eba4d44aSLiu Zhe 				SCUtil.setCellProperties(cells[i], inputType[2], inputColor);
187*eba4d44aSLiu Zhe 			}
188*eba4d44aSLiu Zhe 		}
189*eba4d44aSLiu Zhe 
190*eba4d44aSLiu Zhe 		SCUtil.saveFileAs(scComponent, fileName, fileType);
191*eba4d44aSLiu Zhe 		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
192*eba4d44aSLiu Zhe 		sheet = SCUtil.getCurrentSheet(scDocument);
193*eba4d44aSLiu Zhe 
194*eba4d44aSLiu Zhe 		for (int i = 0; i < cellNum; i++) {
195*eba4d44aSLiu Zhe 			cells[i] = sheet.getCellByPosition(cInfo.getCol(), cInfo.getRow() + i);
196*eba4d44aSLiu Zhe 			styleResults[i] = ((Short) SCUtil.getCellProperties(cells[i], inputType[0])).shortValue();
197*eba4d44aSLiu Zhe 			if (inputStyle > 0) {
198*eba4d44aSLiu Zhe 				hasColor[i] = ((Boolean) SCUtil.getCellProperties(cells[i], inputType[1])).booleanValue();
199*eba4d44aSLiu Zhe 				colorResults[i] = ((Integer) SCUtil.getCellProperties(cells[i], inputType[2])).intValue();
200*eba4d44aSLiu Zhe 			}
201*eba4d44aSLiu Zhe 		}
202*eba4d44aSLiu Zhe 		SCUtil.closeFile(scDocument);
203*eba4d44aSLiu Zhe 
204*eba4d44aSLiu Zhe 		for (int i = 0; i < cellNum; i++) {
205*eba4d44aSLiu Zhe 			assertEquals("Incorrect cell underline style(" + inputType[0] + ") value got in ." + fileType + " file.", expectedLine, styleResults[i], 0);
206*eba4d44aSLiu Zhe 			if (inputStyle > 0) {
207*eba4d44aSLiu Zhe 				if( fileType.equalsIgnoreCase("xls") || fileType.equalsIgnoreCase("xlt")) {
208*eba4d44aSLiu Zhe 					assertFalse("Incorrect cell underline has color setting(" + inputType[1] + ") value got in ." + fileType + " file.", hasColor[i]);
209*eba4d44aSLiu Zhe 				}
210*eba4d44aSLiu Zhe 				else {
211*eba4d44aSLiu Zhe 					assertTrue("Incorrect cell underline has color setting(" + inputType[1] + ") value got in ." + fileType + " file.", hasColor[i]);
212*eba4d44aSLiu Zhe 					assertEquals("Incorrect cell underline color(" + inputType[2] + ") value got in ." + fileType + " file.", expectedColor, colorResults[i], 0);
213*eba4d44aSLiu Zhe 				}
214*eba4d44aSLiu Zhe 
215*eba4d44aSLiu Zhe 			}
216*eba4d44aSLiu Zhe 		}
217*eba4d44aSLiu Zhe 
218*eba4d44aSLiu Zhe 	}
219*eba4d44aSLiu Zhe 
220*eba4d44aSLiu Zhe }
221