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 CellColor { 56 57 private int[] expected; 58 private String inputType; 59 private int[] 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 int[] list1 = TestUtil.randColorList(30); 70 int[] list2 = TestUtil.randColorList(56); 71 int[] list3 = TestUtil.randColorList(5); 72 return Arrays.asList(new Object[][] { 73 {list1, "CellBackColor", list1, "ods"}, 74 {list2, "CellBackColor", list2, "ods"}, 75 {list3, "CellBackColor", list3, "ods"}, 76 {list1, "CellBackColor", list1, "xls"}, 77 // {list2, "CellBackColor", list2, "xls"}, Bug 120679 78 {list3, "CellBackColor", list3, "xls"}, 79 80 {list1, "CharColor", list1, "ods"}, 81 {list2, "CharColor", list2, "ods"}, 82 {list3, "CharColor", list3, "ods"}, 83 {list1, "CharColor", list1, "xls"}, 84 // {list2, "CharColor", list2, "xls"}, Bug 120679 85 {list3, "CharColor", list3, "xls"} 86 }); 87 } 88 CellColor(int[] expected, String inputType, int[] inputData, String fileType)89 public CellColor(int[] expected, String inputType, int[] inputData, String fileType) { 90 this.expected = expected; 91 this.inputType = inputType; 92 this.inputData = inputData; 93 this.fileType = fileType; 94 } 95 96 97 @Before setUp()98 public void setUp() throws Exception { 99 scComponent = unoApp.newDocument("scalc"); 100 scDocument = SCUtil.getSCDocument(scComponent); 101 } 102 103 @After tearDown()104 public void tearDown() throws Exception { 105 unoApp.closeDocument(scComponent); 106 107 } 108 109 @BeforeClass setUpConnection()110 public static void setUpConnection() throws Exception { 111 unoApp.start(); 112 } 113 114 @AfterClass tearDownConnection()115 public static void tearDownConnection() throws InterruptedException, Exception { 116 unoApp.close(); 117 SCUtil.clearTempDir(); 118 } 119 120 /** 121 * Check the cell background color and font color 122 * 1. Create a spreadsheet file. 123 * 2. Input number, text, formula into many cell. 124 * 3a. Set cell background color. 125 * 3b. Set cell font color. 126 * 4. Save file as ODF/MSBinary format. 127 * 5. Close and reopen file. -> Check the color setting. 128 * @throws Exception 129 */ 130 @Test testCellColor()131 public void testCellColor() throws Exception { 132 String fileName = "testCellColor"; 133 134 int cellNum = inputData.length; 135 XCell[] cells = new XCell[cellNum]; 136 int[] results = new int[cellNum]; 137 CellInfo cInfo = TestUtil.randCell(256, 100); 138 139 XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument); 140 141 for (int i = 0; i < cellNum; i++) { 142 cells[i] = sheet.getCellByPosition(cInfo.getCol(), cInfo.getRow() + i); 143 } 144 145 cells[0].setValue(inputData[0]); 146 SCUtil. setTextToCell(cells[1], inputType); 147 cells[2].setFormula("=100*23/5"); 148 cells[3].setValue(-0.0003424); 149 150 for (int i = 0; i < cellNum; i++) { 151 SCUtil.setCellProperties(cells[i], inputType, inputData[i]); 152 } 153 154 SCUtil.saveFileAs(scComponent, fileName, fileType); 155 scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType); 156 sheet = SCUtil.getCurrentSheet(scDocument); 157 158 for (int i = 0; i < cellNum; i++) { 159 cells[i] = sheet.getCellByPosition(cInfo.getCol(), cInfo.getRow() + i); 160 results[i] = ((Integer) SCUtil.getCellProperties(cells[i], inputType)).intValue(); 161 } 162 SCUtil.closeFile(scDocument); 163 164 assertArrayEquals("Incorrect cell background color(" + inputType + ") value got in ." + fileType + " file.", expected, results); 165 166 } 167 168 } 169