10d8ff32eSLiu Zhe /**************************************************************
20d8ff32eSLiu Zhe  *
30d8ff32eSLiu Zhe  * Licensed to the Apache Software Foundation (ASF) under one
40d8ff32eSLiu Zhe  * or more contributor license agreements.  See the NOTICE file
50d8ff32eSLiu Zhe  * distributed with this work for additional information
60d8ff32eSLiu Zhe  * regarding copyright ownership.  The ASF licenses this file
70d8ff32eSLiu Zhe  * to you under the Apache License, Version 2.0 (the
80d8ff32eSLiu Zhe  * "License"); you may not use this file except in compliance
90d8ff32eSLiu Zhe  * with the License.  You may obtain a copy of the License at
100d8ff32eSLiu Zhe  *
110d8ff32eSLiu Zhe  *   http://www.apache.org/licenses/LICENSE-2.0
120d8ff32eSLiu Zhe  *
130d8ff32eSLiu Zhe  * Unless required by applicable law or agreed to in writing,
140d8ff32eSLiu Zhe  * software distributed under the License is distributed on an
150d8ff32eSLiu Zhe  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
160d8ff32eSLiu Zhe  * KIND, either express or implied.  See the License for the
170d8ff32eSLiu Zhe  * specific language governing permissions and limitations
180d8ff32eSLiu Zhe  * under the License.
190d8ff32eSLiu Zhe  *
200d8ff32eSLiu Zhe  *************************************************************/
210d8ff32eSLiu Zhe 
220d8ff32eSLiu Zhe 
23*eba4d44aSLiu Zhe package fvt.uno.sc.cell;
240d8ff32eSLiu Zhe 
250d8ff32eSLiu Zhe import static org.junit.Assert.assertEquals;
260d8ff32eSLiu Zhe import static org.junit.Assert.assertFalse;
270d8ff32eSLiu Zhe import static org.junit.Assert.assertTrue;
280d8ff32eSLiu Zhe 
290d8ff32eSLiu Zhe import java.util.Arrays;
300d8ff32eSLiu Zhe import java.util.Collection;
310d8ff32eSLiu Zhe 
320d8ff32eSLiu Zhe import org.junit.After;
330d8ff32eSLiu Zhe import org.junit.AfterClass;
340d8ff32eSLiu Zhe import org.junit.Before;
350d8ff32eSLiu Zhe import org.junit.BeforeClass;
360d8ff32eSLiu Zhe import org.junit.Test;
370d8ff32eSLiu Zhe import org.junit.runner.RunWith;
380d8ff32eSLiu Zhe import org.junit.runners.Parameterized;
390d8ff32eSLiu Zhe import org.junit.runners.Parameterized.Parameters;
400d8ff32eSLiu Zhe import org.openoffice.test.uno.UnoApp;
410d8ff32eSLiu Zhe 
420d8ff32eSLiu Zhe import testlib.uno.SCUtil;
430d8ff32eSLiu Zhe import testlib.uno.TestUtil;
440d8ff32eSLiu Zhe import testlib.uno.CellInfo;
450d8ff32eSLiu Zhe 
460d8ff32eSLiu Zhe import com.sun.star.lang.XComponent;
470d8ff32eSLiu Zhe import com.sun.star.sheet.XSpreadsheet;
480d8ff32eSLiu Zhe import com.sun.star.sheet.XSpreadsheetDocument;
490d8ff32eSLiu Zhe import com.sun.star.table.XCell;
500d8ff32eSLiu Zhe 
510d8ff32eSLiu Zhe 
520d8ff32eSLiu Zhe /**
530d8ff32eSLiu Zhe  *  Check the cell background color and font color setting can be applied and saved
540d8ff32eSLiu Zhe  *
550d8ff32eSLiu Zhe  */
560d8ff32eSLiu Zhe @RunWith(value = Parameterized.class)
570d8ff32eSLiu Zhe public class CellEffectOverline {
580d8ff32eSLiu Zhe 
590d8ff32eSLiu Zhe 	private int expectedLine;
600d8ff32eSLiu Zhe 	private int expectedColor;
610d8ff32eSLiu Zhe 	private String[] inputType;
620d8ff32eSLiu Zhe 	private int inputStyle;
630d8ff32eSLiu Zhe 	private int inputColor;
640d8ff32eSLiu Zhe 	private String fileType;
650d8ff32eSLiu Zhe 
660d8ff32eSLiu Zhe 	private static final UnoApp unoApp = new UnoApp();
670d8ff32eSLiu Zhe 
680d8ff32eSLiu Zhe 	XComponent scComponent = null;
690d8ff32eSLiu Zhe 	XSpreadsheetDocument scDocument = null;
700d8ff32eSLiu Zhe 
710d8ff32eSLiu Zhe 	@Parameters
data()720d8ff32eSLiu Zhe 	public static Collection<Object[]> data() throws Exception {
730d8ff32eSLiu Zhe 		String[] typeList = {"CharOverline", "CharOverlineHasColor", "CharOverlineColor"};
740d8ff32eSLiu Zhe 		int[] list = TestUtil.randColorList(19);
750d8ff32eSLiu Zhe 		return Arrays.asList(new Object[][] {
760d8ff32eSLiu Zhe 			{0, list[0], typeList, 0, list[0], "ods"}, //NONE 0
770d8ff32eSLiu Zhe 			{1, list[1], typeList, 1, list[1], "ods"}, //SIGNLE 1
780d8ff32eSLiu Zhe 			{2, list[2], typeList, 2, list[2], "ods"}, //DOUBLE 2
790d8ff32eSLiu Zhe 			{3, list[3], typeList, 3, list[3], "ods"}, //DOTTED 3
800d8ff32eSLiu Zhe 			{0, list[4], typeList, 4, list[4], "ods"}, //DONTKNOW 4  can not set this setting via UI
810d8ff32eSLiu Zhe 			{5, list[5], typeList, 5, list[5], "ods"}, //DASH 5
820d8ff32eSLiu Zhe 			{6, list[6], typeList, 6, list[6], "ods"}, //LONGDASH 6
830d8ff32eSLiu Zhe 			{7, list[7], typeList, 7, list[7], "ods"}, //DASHDOT 7
840d8ff32eSLiu Zhe 			{8, list[8], typeList, 8, list[8], "ods"}, //DASHDOTDOT 8
850d8ff32eSLiu Zhe 			{9, list[9], typeList, 9, list[9], "ods"}, //SMALLWAVE 9  can not set this setting via UI
860d8ff32eSLiu Zhe 			{10, list[10], typeList, 10, list[10], "ods"}, //WAVE 10
870d8ff32eSLiu Zhe 			{11, list[11], typeList, 11, list[11], "ods"}, //DOUBLEWAVE 11
880d8ff32eSLiu Zhe 			{12, list[12], typeList, 12, list[12], "ods"}, //BOLD 12
890d8ff32eSLiu Zhe 			{13, list[13], typeList, 13, list[13], "ods"}, //BOLDDOTTED 13
900d8ff32eSLiu Zhe 			{14, list[14], typeList, 14, list[14], "ods"}, //BOLDDASH 14
910d8ff32eSLiu Zhe 			{15, list[15], typeList, 15, list[15], "ods"}, //BOLDLONGDASH 15
920d8ff32eSLiu Zhe 			{16, list[16], typeList, 16, list[16], "ods"}, //BOLDDASHDOT 16
930d8ff32eSLiu Zhe 			{17, list[17], typeList, 17, list[17], "ods"}, //BOLDDASHDOTDOT 17
940d8ff32eSLiu Zhe 			{18, list[18], typeList, 18, list[18], "ods"}, //BOLDWAVE = 18
950d8ff32eSLiu Zhe 
960d8ff32eSLiu Zhe 			{0, list[0], typeList, 0, list[0], "xls"}, //NONE 0
970d8ff32eSLiu Zhe 			{0, list[1], typeList, 1, list[1], "xls"}, //SIGNLE 1
980d8ff32eSLiu Zhe 			{0, list[2], typeList, 2, list[2], "xls"}, //DOUBLE 2
990d8ff32eSLiu Zhe 			{0, list[3], typeList, 3, list[3], "xls"}, //DOTTED 3
1000d8ff32eSLiu Zhe 			{0, list[4], typeList, 4, list[4], "xls"}, //DONTKNOW 4  can not set this setting via UI
1010d8ff32eSLiu Zhe 			{0, list[5], typeList, 5, list[5], "xls"}, //DASH 5
1020d8ff32eSLiu Zhe 			{0, list[6], typeList, 6, list[6], "xls"}, //LONGDASH 6
1030d8ff32eSLiu Zhe 			{0, list[7], typeList, 7, list[7], "xls"}, //DASHDOT 7
1040d8ff32eSLiu Zhe 			{0, list[8], typeList, 8, list[8], "xls"}, //DASHDOTDOT 8
1050d8ff32eSLiu Zhe 			{0, list[9], typeList, 9, list[9], "xls"}, //SMALLWAVE 9  can not set this setting via UI
1060d8ff32eSLiu Zhe 			{0, list[10], typeList, 10, list[10], "xls"}, //WAVE 10
1070d8ff32eSLiu Zhe 			{0, list[11], typeList, 11, list[11], "xls"}, //DOUBLEWAVE 11
1080d8ff32eSLiu Zhe 			{0, list[12], typeList, 12, list[12], "xls"}, //BOLD 12
1090d8ff32eSLiu Zhe 			{0, list[13], typeList, 13, list[13], "xls"}, //BOLDDOTTED 13
1100d8ff32eSLiu Zhe 			{0, list[14], typeList, 14, list[14], "xls"}, //BOLDDASH 14
1110d8ff32eSLiu Zhe 			{0, list[15], typeList, 15, list[15], "xls"}, //BOLDLONGDASH 15
1120d8ff32eSLiu Zhe 			{0, list[16], typeList, 16, list[16], "xls"}, //BOLDDASHDOT 16
1130d8ff32eSLiu Zhe 			{0, list[17], typeList, 17, list[17], "xls"}, //BOLDDASHDOTDOT 17
1140d8ff32eSLiu Zhe 			{0, list[18], typeList, 18, list[18], "xls"} //BOLDWAVE = 18
1150d8ff32eSLiu Zhe 
1160d8ff32eSLiu Zhe 		});
1170d8ff32eSLiu Zhe 	}
1180d8ff32eSLiu Zhe 
CellEffectOverline(int expectedStyle, int expectedColor, String[] inputType, int inputStyle, int inputColor, String fileType)1190d8ff32eSLiu Zhe 	public CellEffectOverline(int expectedStyle, int expectedColor, String[] inputType, int inputStyle, int inputColor, String fileType) {
1200d8ff32eSLiu Zhe 		this.expectedLine = expectedStyle;
1210d8ff32eSLiu Zhe 		this.expectedColor = expectedColor;
1220d8ff32eSLiu Zhe 		this.inputType = inputType;
1230d8ff32eSLiu Zhe 		this.inputStyle = inputStyle;
1240d8ff32eSLiu Zhe 		this.inputColor = inputColor;
1250d8ff32eSLiu Zhe 		this.fileType = fileType;
1260d8ff32eSLiu Zhe 	}
1270d8ff32eSLiu Zhe 
1280d8ff32eSLiu Zhe 
1290d8ff32eSLiu Zhe 	@Before
setUp()1300d8ff32eSLiu Zhe 	public void setUp() throws Exception {
1310d8ff32eSLiu Zhe 		scComponent = unoApp.newDocument("scalc");
1320d8ff32eSLiu Zhe 		scDocument = SCUtil.getSCDocument(scComponent);
1330d8ff32eSLiu Zhe 	}
1340d8ff32eSLiu Zhe 
1350d8ff32eSLiu Zhe 	@After
tearDown()1360d8ff32eSLiu Zhe 	public void tearDown() throws Exception {
1370d8ff32eSLiu Zhe 		unoApp.closeDocument(scComponent);
1380d8ff32eSLiu Zhe 
1390d8ff32eSLiu Zhe 	}
1400d8ff32eSLiu Zhe 
1410d8ff32eSLiu Zhe 	@BeforeClass
setUpConnection()1420d8ff32eSLiu Zhe 	public static void setUpConnection() throws Exception {
1430d8ff32eSLiu Zhe 		unoApp.start();
1440d8ff32eSLiu Zhe 	}
1450d8ff32eSLiu Zhe 
1460d8ff32eSLiu Zhe 	@AfterClass
tearDownConnection()1470d8ff32eSLiu Zhe 	public static void tearDownConnection() throws InterruptedException, Exception {
1480d8ff32eSLiu Zhe 		unoApp.close();
1490d8ff32eSLiu Zhe 		SCUtil.clearTempDir();
1500d8ff32eSLiu Zhe 	}
1510d8ff32eSLiu Zhe 
1520d8ff32eSLiu Zhe 	/**
1530d8ff32eSLiu Zhe 	 * Check the cell overline style and overline color
1540d8ff32eSLiu Zhe 	 * 1. Create a spreadsheet file.
1550d8ff32eSLiu Zhe 	 * 2. Input number, text, formula into many cell.
1560d8ff32eSLiu Zhe 	 * 3. Set cell overline style.
1570d8ff32eSLiu Zhe 	 * 4. Set cell overline color, if overline style is not NONE.
1580d8ff32eSLiu Zhe 	 * 4. Save file as ODF/MSBinary format. (MSBinary file can not support overline, save as .xls, the overline setting will be lost)
1590d8ff32eSLiu Zhe 	 * 5. Close and reopen file.  -> Check the overline style and overline color setting.
1600d8ff32eSLiu Zhe 	 * @throws Exception
1610d8ff32eSLiu Zhe 	 */
1620d8ff32eSLiu Zhe 	@Test
testCharOverline()1630d8ff32eSLiu Zhe 	public void testCharOverline() throws Exception {
1640d8ff32eSLiu Zhe 		String fileName = "testCharOverline";
1650d8ff32eSLiu Zhe 		int cellNum = 5;
1660d8ff32eSLiu Zhe 		XCell[] cells = new XCell[cellNum];
1670d8ff32eSLiu Zhe 		int[] styleResults = new int[cellNum];
1680d8ff32eSLiu Zhe 		boolean[] hasColor = new boolean[cellNum];
1690d8ff32eSLiu Zhe 		int[] colorResults = new int[cellNum];
1700d8ff32eSLiu Zhe 		CellInfo cInfo = TestUtil.randCell(100, 100);
1710d8ff32eSLiu Zhe 
1720d8ff32eSLiu Zhe 		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
1730d8ff32eSLiu Zhe 
1740d8ff32eSLiu Zhe 		for (int i = 0; i < cellNum; i++) {
1750d8ff32eSLiu Zhe 			cells[i] = sheet.getCellByPosition(cInfo.getCol(), cInfo.getRow() + i);
1760d8ff32eSLiu Zhe 		}
1770d8ff32eSLiu Zhe 
1780d8ff32eSLiu Zhe 		cells[0].setValue(inputColor);
1790d8ff32eSLiu Zhe 		SCUtil.setTextToCell(cells[1], inputType[0]);
1800d8ff32eSLiu Zhe 		cells[2].setFormula("=10/0");
1810d8ff32eSLiu Zhe 		cells[3].setValue(-0.0000001);
1820d8ff32eSLiu Zhe 
1830d8ff32eSLiu Zhe 		for (int i = 0; i < cellNum; i++) {
1840d8ff32eSLiu Zhe 			SCUtil.setCellProperties(cells[i], inputType[0], inputStyle);
1850d8ff32eSLiu Zhe 			if (inputStyle > 0) {
1860d8ff32eSLiu Zhe 				SCUtil.setCellProperties(cells[i], inputType[1], true);
1870d8ff32eSLiu Zhe 				SCUtil.setCellProperties(cells[i], inputType[2], inputColor);
1880d8ff32eSLiu Zhe 			}
1890d8ff32eSLiu Zhe 		}
1900d8ff32eSLiu Zhe 
1910d8ff32eSLiu Zhe 		SCUtil.saveFileAs(scComponent, fileName, fileType);
1920d8ff32eSLiu Zhe 		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
1930d8ff32eSLiu Zhe 		sheet = SCUtil.getCurrentSheet(scDocument);
1940d8ff32eSLiu Zhe 
1950d8ff32eSLiu Zhe 		for (int i = 0; i < cellNum; i++) {
1960d8ff32eSLiu Zhe 			cells[i] = sheet.getCellByPosition(cInfo.getCol(), cInfo.getRow() + i);
1970d8ff32eSLiu Zhe 			styleResults[i] = ((Short) SCUtil.getCellProperties(cells[i], inputType[0])).shortValue();
1980d8ff32eSLiu Zhe 
1990d8ff32eSLiu Zhe 			if (inputStyle > 0) {
2000d8ff32eSLiu Zhe 				hasColor[i] = ((Boolean) SCUtil.getCellProperties(cells[i], inputType[1])).booleanValue();
2010d8ff32eSLiu Zhe 				colorResults[i] = ((Integer) SCUtil.getCellProperties(cells[i], inputType[2])).intValue();
2020d8ff32eSLiu Zhe 			}
2030d8ff32eSLiu Zhe 		}
2040d8ff32eSLiu Zhe 
2050d8ff32eSLiu Zhe 		SCUtil.closeFile(scDocument);
2060d8ff32eSLiu Zhe 
2070d8ff32eSLiu Zhe 		for (int i = 0; i < cellNum; i++) {
2080d8ff32eSLiu Zhe 			assertEquals("Incorrect cell overline style(" + inputType[0] + ") value got in ." + fileType + " file.", expectedLine, styleResults[i], 0);
2090d8ff32eSLiu Zhe 
2100d8ff32eSLiu Zhe 			if (inputStyle > 0) {
2110d8ff32eSLiu Zhe 
2120d8ff32eSLiu Zhe 				if( fileType.equalsIgnoreCase("xls") || fileType.equalsIgnoreCase("xlt")) {
2130d8ff32eSLiu Zhe 					assertFalse("Incorrect cell overline has color setting(" + inputType[1] + ") value got in ." + fileType + " file.", hasColor[i]);
2140d8ff32eSLiu Zhe 				}
2150d8ff32eSLiu Zhe 
2160d8ff32eSLiu Zhe 				else {
2170d8ff32eSLiu Zhe 					assertTrue("Incorrect cell overline has color setting(" + inputType[1] + ") value got in ." + fileType + " file.", hasColor[i]);
2180d8ff32eSLiu Zhe 					assertEquals("Incorrect cell overline color(" + inputType[2] + ") value got in ." + fileType + " file.", expectedColor, colorResults[i], 0);
2190d8ff32eSLiu Zhe 				}
2200d8ff32eSLiu Zhe 
2210d8ff32eSLiu Zhe 			}
2220d8ff32eSLiu Zhe 		}
2230d8ff32eSLiu Zhe 
2240d8ff32eSLiu Zhe 	}
2250d8ff32eSLiu Zhe 
2260d8ff32eSLiu Zhe }
227