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