You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by li...@apache.org on 2012/08/27 04:42:46 UTC

svn commit: r1377553 - in /incubator/ooo/trunk/main/test/testuno/source: testcase/uno/sc/cell/CellColor.java testlib/uno/TestUtil.java

Author: liuzhe
Date: Mon Aug 27 02:42:45 2012
New Revision: 1377553

URL: http://svn.apache.org/viewvc?rev=1377553&view=rev
Log:
#120689 - [testUNO patch]Add random method in TestUtil, create test cases to check cell background color and font color.
Patch by: Zhu Shan <sh...@gmail.com>
Review by: Liu Zhe <al...@gmail.com>

Added:
    incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sc/cell/CellColor.java
Modified:
    incubator/ooo/trunk/main/test/testuno/source/testlib/uno/TestUtil.java

Added: incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sc/cell/CellColor.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sc/cell/CellColor.java?rev=1377553&view=auto
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sc/cell/CellColor.java (added)
+++ incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sc/cell/CellColor.java Mon Aug 27 02:42:45 2012
@@ -0,0 +1,168 @@
+/**************************************************************
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ * 
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * 
+ *************************************************************/
+
+
+package testcase.uno.sc.cell;
+
+import static org.junit.Assert.assertArrayEquals;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+import org.openoffice.test.uno.UnoApp;
+
+import testlib.uno.SCUtil;
+import testlib.uno.TestUtil;
+import testlib.uno.CellInfo;
+
+import com.sun.star.lang.XComponent;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.table.XCell;
+
+
+/**
+ *  Check the cell background color and font color setting can be applied and saved
+ * 
+ */
+@RunWith(value = Parameterized.class)
+public class CellColor {
+
+	private int[] expected;
+	private String inputType;
+	private int[] inputData;
+	private String fileType;
+	
+	private static final UnoApp unoApp = new UnoApp();
+	
+	XComponent scComponent = null;
+	XSpreadsheetDocument scDocument = null;
+	
+	@Parameters
+	public static Collection<Object[]> data() throws Exception {
+		int[] list1 = TestUtil.randColorList(30);
+		int[] list2 = TestUtil.randColorList(56);
+		int[] list3 = TestUtil.randColorList(5);
+		return Arrays.asList(new Object[][] {
+			{list1, "CellBackColor", list1, "ods"},
+			{list2, "CellBackColor", list2, "ods"},
+			{list3, "CellBackColor", list3, "ods"},
+			{list1, "CellBackColor", list1, "xls"},
+//			{list2, "CellBackColor", list2, "xls"},   Bug 120679
+			{list3, "CellBackColor", list3, "xls"},
+			
+			{list1, "CharColor", list1, "ods"},
+			{list2, "CharColor", list2, "ods"},
+			{list3, "CharColor", list3, "ods"},
+			{list1, "CharColor", list1, "xls"},
+//			{list2, "CharColor", list2, "xls"},   Bug 120679
+			{list3, "CharColor", list3, "xls"}
+		});
+	}
+	
+	public CellColor(int[] expected, String inputType, int[] inputData, String fileType) {
+		this.expected = expected;
+		this.inputType = inputType;
+		this.inputData = inputData;
+		this.fileType = fileType;
+	}
+	
+	
+	@Before
+	public void setUp() throws Exception {
+		scComponent = unoApp.newDocument("scalc");
+		scDocument = SCUtil.getSCDocument(scComponent);
+	}
+
+	@After
+	public void tearDown() throws Exception {
+		unoApp.closeDocument(scComponent);
+		
+	}
+	
+	@BeforeClass
+	public static void setUpConnection() throws Exception {
+		unoApp.start();
+	}
+
+	@AfterClass
+	public static void tearDownConnection() throws InterruptedException, Exception {
+		unoApp.close();
+		SCUtil.clearTempDir();	
+	}
+	
+	/**
+	 * Check the cell background color and font color
+	 * 1. Create a spreadsheet file.
+	 * 2. Input number, text, formula into many cell.
+	 * 3a. Set cell background color.
+	 * 3b. Set cell font color.
+	 * 4. Save file as ODF/MSBinary format.
+	 * 5. Close and reopen file.  -> Check the color setting.
+	 * @throws Exception
+	 */
+	@Test
+	public void testCellColor() throws Exception {
+		String fileName = "testCellColor";
+		
+		int cellNum = inputData.length;
+		XCell[] cells = new XCell[cellNum];
+		int[] results = new int[cellNum];
+		CellInfo cInfo = TestUtil.randCell(256, 100);
+		
+		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
+		
+		for (int i = 0; i < cellNum; i++) {
+			cells[i] = sheet.getCellByPosition(cInfo.getCol(), cInfo.getRow() + i);
+		}
+		
+		cells[0].setValue(inputData[0]);
+		SCUtil. setTextToCell(cells[1], inputType);
+		cells[2].setFormula("=100*23/5");
+		cells[3].setValue(-0.0003424);
+
+		for (int i = 0; i < cellNum; i++) {
+			SCUtil.setCellProperties(cells[i], inputType, inputData[i]);
+		}
+		
+		SCUtil.saveFileAs(scComponent, fileName, fileType);
+		scDocument = SCUtil.reloadFile(unoApp, scDocument, fileName + "." + fileType);
+		sheet = SCUtil.getCurrentSheet(scDocument);
+		
+		for (int i = 0; i < cellNum; i++) {
+			cells[i] = sheet.getCellByPosition(cInfo.getCol(), cInfo.getRow() + i);
+			results[i] = ((Integer) SCUtil.getCellProperties(cells[i], inputType)).intValue();
+		}
+		SCUtil.closeFile(scDocument);
+
+		assertArrayEquals("Incorrect cell background color(" + inputType + ") value got in ." + fileType + " file.", expected, results);
+			
+	}	
+
+}

Modified: incubator/ooo/trunk/main/test/testuno/source/testlib/uno/TestUtil.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testlib/uno/TestUtil.java?rev=1377553&r1=1377552&r2=1377553&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testlib/uno/TestUtil.java (original)
+++ incubator/ooo/trunk/main/test/testuno/source/testlib/uno/TestUtil.java Mon Aug 27 02:42:45 2012
@@ -79,6 +79,40 @@ public class TestUtil {
 	}
 	
 	/**
+	 * Generate a font size number in limited range
+	 * @param max  The font size in Excel2003 is [1,409]
+	 * @return
+	 * @throws Exception
+	 */
+	public static double randFontSize(int max) throws Exception {
+		double basic = random.nextInt(max * 2);
+		double size = 1;
+		if (basic < 2) {
+			size = 1;
+		}
+		else {
+			size = basic / 2;
+		}
+
+		return size;
+	}
+	
+	/**
+	 * Generate a series of font size number 
+	 * @param listSize
+	 * @param max
+	 * @return
+	 * @throws Exception
+	 */
+	public static double[] randFontSizeList(int listSize, int max) throws Exception {
+		double[] sizeList = new double[listSize];
+		for (int i =0; i < listSize; i++) {
+			sizeList[i] = randFontSize(max);
+		}
+		return sizeList;
+	}
+	
+	/**
 	 * Generate a random decimal RGB color number
 	 * @return
 	 * @throws Exception