incubator-ooo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From liu...@apache.org
Subject svn commit: r1376366 - in /incubator/ooo/trunk/main/test/testuno/source: testcase/uno/sc/AddtionOperatorInFormula.java testcase/uno/sc/cell/ testcase/uno/sc/cell/CellAlignment.java testlib/uno/SCUtil.java testlib/uno/TestUtil.java
Date Thu, 23 Aug 2012 05:10:32 GMT
Author: liuzhe
Date: Thu Aug 23 05:10:32 2012
New Revision: 1376366

URL: http://svn.apache.org/viewvc?rev=1376366&view=rev
Log:
#120671 - [testUNO patch] Add methods in SCUtil and TestUtil, create test case to check cell
alignment.
Patch by: Zhu Shan <shanzhu33@gmail.com>
Review by: Liu Zhe <aliuzhe@gmail.com>

Added:
    incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sc/cell/
    incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sc/cell/CellAlignment.java
Removed:
    incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sc/AddtionOperatorInFormula.java
Modified:
    incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SCUtil.java
    incubator/ooo/trunk/main/test/testuno/source/testlib/uno/TestUtil.java

Added: incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sc/cell/CellAlignment.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sc/cell/CellAlignment.java?rev=1376366&view=auto
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sc/cell/CellAlignment.java (added)
+++ incubator/ooo/trunk/main/test/testuno/source/testcase/uno/sc/cell/CellAlignment.java Thu
Aug 23 05:10:32 2012
@@ -0,0 +1,182 @@
+/**************************************************************
+ * 
+ * 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.assertEquals;
+
+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.CellHoriJustify;
+import com.sun.star.table.CellVertJustify;
+import com.sun.star.table.XCell;
+import com.sun.star.uno.Enum;
+
+/**
+ * Check the cell alignment setting can be applied and saved
+ * 
+ */
+@RunWith(value = Parameterized.class)
+public class CellAlignment {
+
+	private Enum expected;
+	private String inputType;
+	private Enum inputValue;
+	private String fileType;
+	
+	private static final UnoApp unoApp = new UnoApp();
+	
+	XComponent scComponent = null;
+	XSpreadsheetDocument scDocument = null;
+	
+	@Parameters
+	public static Collection<Object[]> data() {
+		return Arrays.asList(new Object[][] {
+				{CellHoriJustify.STANDARD, "HoriJustify", CellHoriJustify.STANDARD, "ods"},
+				{CellHoriJustify.LEFT, "HoriJustify", CellHoriJustify.LEFT, "ods"},
+				{CellHoriJustify.CENTER, "HoriJustify", CellHoriJustify.CENTER, "ods"},
+				{CellHoriJustify.RIGHT, "HoriJustify", CellHoriJustify.RIGHT, "ods"},
+				{CellHoriJustify.BLOCK, "HoriJustify", CellHoriJustify.BLOCK, "ods"},
+				{CellHoriJustify.REPEAT, "HoriJustify", CellHoriJustify.REPEAT, "ods"},
+				{CellVertJustify.STANDARD, "VertJustify", CellVertJustify.STANDARD, "ods"},
+				{CellVertJustify.TOP, "VertJustify", CellVertJustify.TOP, "ods"},
+				{CellVertJustify.CENTER, "VertJustify", CellVertJustify.CENTER, "ods"},
+				{CellVertJustify.BOTTOM, "VertJustify", CellVertJustify.BOTTOM, "ods"},
+				
+				{CellHoriJustify.STANDARD, "HoriJustify", CellHoriJustify.STANDARD, "xls"},
+				{CellHoriJustify.LEFT, "HoriJustify", CellHoriJustify.LEFT, "xls"},
+				{CellHoriJustify.CENTER, "HoriJustify", CellHoriJustify.CENTER, "xls"},
+				{CellHoriJustify.RIGHT, "HoriJustify", CellHoriJustify.RIGHT, "xls"},
+				{CellHoriJustify.BLOCK, "HoriJustify", CellHoriJustify.BLOCK, "xls"},
+				{CellHoriJustify.REPEAT, "HoriJustify", CellHoriJustify.REPEAT, "xls"},
+				{CellVertJustify.STANDARD, "VertJustify", CellVertJustify.STANDARD, "xls"},
+				{CellVertJustify.TOP, "VertJustify", CellVertJustify.TOP, "xls"},
+				{CellVertJustify.CENTER, "VertJustify", CellVertJustify.CENTER, "xls"}//,
+//				{CellVertJustify.BOTTOM, "VertJustify", CellVertJustify.BOTTOM, "xls"}    Bug 120670
+		});
+	}
+	
+	public CellAlignment(Enum expected, String inputType, Enum inputValue, String fileType)
{
+		this.expected = expected;
+		this.inputType = inputType;
+		this.inputValue = inputValue;
+		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 alignment setting can be applied and saved
+	 * 1. Create a spreadsheet file.
+	 * 2. Input number, text, formula into many cell.
+	 * 3. Set cell alignment.
+	 * 4. Save file as ODF/MSBinary format.
+	 * 5. Close and reopen file.  -> Check the alignment setting.
+	 * @throws Exception
+	 */
+	@Test
+	public void testCellAlignment() throws Exception {
+		String fileName = "testCellAlignment";
+		CellInfo cInfo = TestUtil.randCell(20, 50);
+
+		int cellNum = 5; 
+		XCell[] cells = new XCell[cellNum];
+		Enum[] results = new Enum[cellNum];
+				
+		XSpreadsheet sheet = SCUtil.getCurrentSheet(scDocument);
+		
+		//cellNum must be greater than 4
+		if (cellNum < 5) {
+			cellNum = 5;
+		}
+		for (int i = 0; i < cellNum; i++) {
+			cells[i] = sheet.getCellByPosition(cInfo.getCol(), cInfo.getRow() + i);
+		}
+				
+		cells[0].setValue(13.42);
+		SCUtil. setTextToCell(cells[1], "alignment");
+		cells[2].setFormula("=SUM(A100:B100)");
+		cells[3].setValue(-0.2343123);
+		
+		for (int i = 0; i < cellNum; i++) {
+			SCUtil.setCellProperties(cells[i], inputType, inputValue);
+		}
+				
+		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] = (Enum) SCUtil.getCellProperties(cells[i], inputType);
+		}
+		SCUtil.closeFile(scDocument);
+		
+		for (int i = 0; i < cellNum; i++ ) {
+
+			assertEquals("Incorrect cell alignment(" + inputType + ") value got in ." + fileType +
" file.", expected, results[i]);
+			
+		}
+		
+	}
+	
+}

Modified: incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SCUtil.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SCUtil.java?rev=1376366&r1=1376365&r2=1376366&view=diff
==============================================================================
--- incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SCUtil.java (original)
+++ incubator/ooo/trunk/main/test/testuno/source/testlib/uno/SCUtil.java Thu Aug 23 05:10:32
2012
@@ -24,10 +24,12 @@ package testlib.uno;
 
 import java.util.HashMap;
 
+import org.openoffice.test.common.FileUtil;
 import org.openoffice.test.common.Testspace;
 import org.openoffice.test.uno.UnoApp;
 
 import com.sun.star.beans.PropertyValue;
+import com.sun.star.beans.XPropertySet;
 import com.sun.star.container.XIndexAccess;
 import com.sun.star.frame.XController;
 import com.sun.star.frame.XModel;
@@ -49,14 +51,14 @@ import com.sun.star.util.XCloseable;
 
 /**
  * Utilities of Spreadsheet
- * @author test
  *
  */
 
 public class SCUtil {
 	
+	private static final String scTempDir = "output/sc/"; //Spreadsheet temp file directory
 	private static HashMap filterName = new HashMap(); 
-	
+		
 	private SCUtil() {
 		
 	}
@@ -162,6 +164,17 @@ public class SCUtil {
 	}
 
 	/**
+	 * Set text into specific cell
+	 * @param xCell
+	 * @param text
+	 * @throws Exception
+	 */
+	public static void setTextToCell(XCell xCell, String text) throws Exception {
+		XText xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
+		xText.setString(text);
+	}
+	
+	/**
 	 * Set formula into specific cell
 	 * @param xSpreadsheet
 	 * @param column
@@ -306,7 +319,7 @@ public class SCUtil {
 		String[][] cellTexts = new String[end_row - start_row+1][end_col - start_col +1];
 		
 		for (int i = 0; i <= (end_row - start_row); i++ ) {
-			for(int j = 0; j <= (end_col - start_col); j++) {
+			for (int j = 0; j <= (end_col - start_col); j++) {
 				xCell = xCellRange.getCellByPosition(j, i);
 				xText = (XText) UnoRuntime.queryInterface(XText.class, xCell);
 				cellTexts[i][j] = xText.getString();
@@ -345,7 +358,41 @@ public class SCUtil {
 	}
 	
 	/**
-	 * Save file as specific file format into testspace/output folder.
+	 * Set value of specific property from a cell
+	 * @param xCell
+	 * @param propName
+	 * @param value
+	 * @throws Exception
+	 */
+	public static void setCellProperties(XCell xCell, String propName, Object value) throws
Exception {
+		
+		XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
xCell);
+		xPropertySet.setPropertyValue(propName, value);
+	}
+
+	/**
+	 * Get value of specific property from a cell
+	 * @param xCell
+	 * @param propName
+	 * @return
+	 * @throws Exception
+	 */
+	public static Object getCellProperties(XCell xCell, String propName) throws Exception {
+		XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class,
xCell);
+		Object value = xPropertySet.getPropertyValue(propName);
+		
+		return value;
+	}
+	
+	/**
+	 * Clear temp file directory
+	 */
+	public static void clearTempDir() {
+		FileUtil.deleteFile(Testspace.getFile(Testspace.getPath(scTempDir))); 
+	}
+	
+	/**
+	 * Save file as specific file format into spreadsheet temp file folder.
 	 * @param scComponent
 	 * @param fileName  File name string without extension name (e.g. "sampleFile")
 	 * @param extName ("ods", "ots", "xls", "xlt", "csv")
@@ -355,7 +402,7 @@ public class SCUtil {
 		
 		initFilterName();
 
-		String storeUrl = Testspace.getUrl("output/" + fileName + "." + extName);
+		String storeUrl = Testspace.getUrl(scTempDir + fileName + "." + extName);
 		
 		PropertyValue[] storeProps = new PropertyValue[2];
 		storeProps[0] = new PropertyValue();
@@ -381,7 +428,7 @@ public class SCUtil {
 	}
 	
 	/**
-	 * Close a opening file saved in testspace/output direction and reopen it in Spreadsheet.
For save&reload test scenario only.
+	 * Close a opening file saved in spreadsheet temp file direction and reopen it in Spreadsheet.
For save&reload test scenario only.
 	 * @param unoApp
 	 * @param xSpreadsheetDocument
 	 * @param fullFileName   File name with the extension name. (e.g. "sc.ods")
@@ -391,7 +438,7 @@ public class SCUtil {
 	public static XSpreadsheetDocument reloadFile(UnoApp unoApp, XSpreadsheetDocument xSpreadsheetDocument,
String fullFileName) throws Exception {
 		closeFile(xSpreadsheetDocument);
 		
-		String filePath = Testspace.getPath("output/" + fullFileName);
+		String filePath = Testspace.getPath(scTempDir + fullFileName);
 		XSpreadsheetDocument xScDocument = UnoRuntime.queryInterface(XSpreadsheetDocument.class,
unoApp.loadDocument(filePath));
 		
 		return xScDocument;

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=1376366&r1=1376365&r2=1376366&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 Thu Aug 23 05:10:32
2012
@@ -93,20 +93,35 @@ public class TestUtil {
 	
 	/**
 	 * Generate a random decimal RGB color number in limited color space
-	 * @param rMax  The R value limit, [0, rMax)
-	 * @param gMax  The G value limit, [0, gMax)
-	 * @param bMax  The B value limit, [0, bMax)
+	 * @param rMax  The R value limit, get a value in [0, rMax]
+	 * @param gMax  The G value limit, get a value in [0, gMax]
+	 * @param bMax  The B value limit, get a value in [0, bMax]
 	 * @return
 	 * @throws Exception
 	 */
 	public static int randColor(int rMax, int gMax, int bMax) throws Exception {
-		int r = random.nextInt(rMax) % 256;
-		int g = random.nextInt(gMax) % 256;
-		int b = random.nextInt(bMax) % 256;
+		int r = random.nextInt(rMax + 1) % 256;
+		int g = random.nextInt(gMax + 1) % 256;
+		int b = random.nextInt(bMax + 1) % 256;
 
 		return r * 65536 + g * 256 + b; 
 	}
+	
+	/**
+	 * Generate a series of decimal RGB color number
+	 * @param size Set the quantity of random color value generated into the array
+	 * @return
+	 * @throws Exception
+	 */
+	public static int[] randColorList(int size) throws Exception {
+		int[] colorList = new int[size];
+		for (int i = 0; i < size; i++) {
+			colorList[i] = randColor();
+		}
 		
+		return colorList;
+	}
+	
 	/**
 	 * Add "=" before a string
 	 * @param expression



Mime
View raw message