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/31 05:18:15 UTC

svn commit: r1379272 - in /incubator/ooo/trunk/test/testuno: data/ data/FilterTest.xls source/testcase/uno/sc/data/ source/testcase/uno/sc/data/StardarFilterTest.java source/testlib/uno/SCUtil.java

Author: liuzhe
Date: Fri Aug 31 03:18:15 2012
New Revision: 1379272

URL: http://svn.apache.org/viewvc?rev=1379272&view=rev
Log:
#120755 - [testUNO patch]Standard filter operator
Patch By: Terry Yang <po...@hotmail.com>
Review By: Liu Zhe <al...@gmail.com>

Added:
    incubator/ooo/trunk/test/testuno/data/
    incubator/ooo/trunk/test/testuno/data/FilterTest.xls   (with props)
    incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/
    incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/StardarFilterTest.java
Modified:
    incubator/ooo/trunk/test/testuno/source/testlib/uno/SCUtil.java

Added: incubator/ooo/trunk/test/testuno/data/FilterTest.xls
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/data/FilterTest.xls?rev=1379272&view=auto
==============================================================================
Binary file - no diff available.

Propchange: incubator/ooo/trunk/test/testuno/data/FilterTest.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/StardarFilterTest.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/StardarFilterTest.java?rev=1379272&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/StardarFilterTest.java (added)
+++ incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/StardarFilterTest.java Fri Aug 31 03:18:15 2012
@@ -0,0 +1,188 @@
+/**************************************************************
+ * 
+ * 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.data;
+import static org.junit.Assert.*;
+
+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.common.Testspace;
+import org.openoffice.test.uno.UnoApp;
+import testlib.uno.SCUtil;
+import com.sun.star.beans.XPropertySet;
+import com.sun.star.lang.XComponent;
+import com.sun.star.sheet.FilterOperator;
+import com.sun.star.sheet.TableFilterField;
+import com.sun.star.sheet.XSheetFilterDescriptor;
+import com.sun.star.sheet.XSheetFilterable;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.table.XCellRange;
+import com.sun.star.table.XColumnRowRange;
+import com.sun.star.table.XTableRows;
+import com.sun.star.uno.Enum;
+import com.sun.star.uno.UnoRuntime;
+
+
+@RunWith(value = Parameterized.class)
+public class StardarFilterTest {
+	private static final UnoApp app = new UnoApp();
+	UnoApp unoApp = new UnoApp();
+	XSpreadsheetDocument scDocument = null;
+	XComponent scComponent = null;
+	private String filename = "FilterTest.xls";
+	private Enum operator;
+	private int column;
+	private boolean[] rowshow;
+	private int value;
+	
+	@Parameters
+	public static Collection<Object[]> data() throws Exception {
+		boolean[] rowshow1 ={true,true,false,true,false,false};
+		boolean[] rowshow2 ={true,true,true,true,true,false};
+		boolean[] rowshow3 ={true,false,false,true,false,false};
+		boolean[] rowshow4 ={true,false,true,true,false,false};
+		boolean[] rowshow5 ={true,false,false,false,false,true};
+		boolean[] rowshow6 ={true,false,true,true,false,true};
+		boolean[] rowshow7 ={true,false,true,false,false,false};
+		boolean[] rowshow8 ={true,false,true,true,false,true};
+		boolean[] rowshow9 ={true,true,true,false,true,true};
+		boolean[] rowshow10 ={true,true,false,false,true,true};
+		boolean[] rowshow11 ={true,true,false,false,false,false};
+		boolean[] rowshow12 ={true,true,true,true,false,false};
+		
+		return Arrays.asList(new Object[][] {
+				{FilterOperator.BOTTOM_PERCENT, 1, 30,rowshow1},
+				{FilterOperator.BOTTOM_VALUES, 2, 4,rowshow2},
+				{FilterOperator.EMPTY, 5,1 ,rowshow3},
+				{FilterOperator.EQUAL,2,44,rowshow4},
+				{FilterOperator.GREATER, 2,44,rowshow5},
+				{FilterOperator.GREATER_EQUAL, 2,44,rowshow6},
+				{FilterOperator.LESS, 3,155,rowshow7},
+				{FilterOperator.LESS_EQUAL,3, 155,rowshow8},
+				{FilterOperator.NOT_EMPTY,5,44, rowshow9},
+				{FilterOperator.NOT_EQUAL,4, 85,rowshow10},
+				{FilterOperator.TOP_PERCENT,4, 30,rowshow11},
+				{FilterOperator.TOP_VALUES, 4,3,rowshow12},
+		});
+	    }  
+		
+	
+
+	@Before
+	public void setUpDocument() throws Exception {
+		unoApp.start();
+	}
+
+	@After
+	public void tearDownDocument() {
+		unoApp.close();
+		unoApp.closeDocument(scComponent);
+
+	}
+
+	@BeforeClass
+	public static void setUpConnection() throws Exception {
+
+	}
+
+	@AfterClass
+	public static void tearDownConnection() throws InterruptedException,
+			Exception {
+
+	}
+
+	public StardarFilterTest(Enum operator, int column,int value, boolean[] rowshow) {
+		this.operator = operator;
+		this.column = column;
+		this.rowshow = rowshow;
+		this.value = value;
+	}
+	
+	@Test
+	public void testStandardFilter() throws Exception {
+		// Prepare test data
+		Testspace.prepareData(filename);
+		String sample = Testspace.getPath("output/../data/" + filename);
+		
+		// Open document
+		scDocument = SCUtil.openFile(sample, unoApp);
+		
+		// Get cell range
+		XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface(
+				XCellRange.class, SCUtil.getCurrentSheet(scDocument));
+
+		// Set filter property and filter the cell range
+		XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime
+				.queryInterface(XSheetFilterable.class,
+						xdataRange.getCellRangeByName("A1:F6"));
+		XSheetFilterDescriptor xFilterDesc = xFilter
+				.createFilterDescriptor(true);
+		TableFilterField[] aFilterFields = new TableFilterField[1];
+		aFilterFields[0] = new TableFilterField();
+		aFilterFields[0].Field = column;
+		aFilterFields[0].IsNumeric = true;
+		aFilterFields[0].Operator = (FilterOperator) operator;
+		aFilterFields[0].NumericValue = value;
+		xFilterDesc.setFilterFields(aFilterFields);
+		XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(
+				XPropertySet.class, xFilterDesc);
+		xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true));
+		xFilter.filter(xFilterDesc);
+		
+		// Verify filter result
+		XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime
+				.queryInterface(XColumnRowRange.class,
+						xdataRange.getCellRangeByName("A1:F6"));
+		XTableRows Rows = ColRowRange.getRows();
+		for (int i = 0; i < Rows.getCount() - 1; i++) {
+			Object aRowObj = Rows.getByIndex(i);
+			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+					XPropertySet.class, aRowObj);
+			assertEquals(rowshow[i],(Boolean) PropSet.getPropertyValue("IsVisible"));
+		}
+
+		// Save and reload the document
+		SCUtil.save(scDocument);
+		SCUtil.closeFile(scDocument);
+		scDocument = SCUtil.openFile(sample, unoApp);
+
+		// Verify the result agains
+		xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class,
+				SCUtil.getCurrentSheet(scDocument));
+		ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(
+				XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6"));
+		Rows = ColRowRange.getRows();
+		for (int i = 0; i < Rows.getCount() - 1; i++) {
+			Object aRowObj = Rows.getByIndex(i);
+			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+					XPropertySet.class, aRowObj);
+			assertEquals(rowshow[i],(Boolean) PropSet.getPropertyValue("IsVisible"));
+		}
+		SCUtil.save(scDocument);
+	}
+}

Modified: incubator/ooo/trunk/test/testuno/source/testlib/uno/SCUtil.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testlib/uno/SCUtil.java?rev=1379272&r1=1379271&r2=1379272&view=diff
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/testlib/uno/SCUtil.java (original)
+++ incubator/ooo/trunk/test/testuno/source/testlib/uno/SCUtil.java Fri Aug 31 03:18:15 2012
@@ -526,6 +526,17 @@ public class SCUtil {
 	}
 	
 	/**
+	 * open file in Spreadsheet.
+	 * @param unoApp
+	 * @param filtpath   File path with the extension name. (e.g. "testcase/uno/sc/data/sample.xls")
+	 * @return
+	 * @throws Exception
+	 */
+	public static XSpreadsheetDocument openFile(String filePath, UnoApp app) throws Exception {
+		return (XSpreadsheetDocument) UnoRuntime.queryInterface(XSpreadsheetDocument.class, app.loadDocument(filePath));
+	}
+	
+	/**
 	 * Initial the filter name list
 	 * @throws Exception
 	 */