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:33:42 UTC
svn commit: r1379274 - in
/incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data:
AdvanceFilter.java StandardFilterOption.java
Author: liuzhe
Date: Fri Aug 31 03:33:41 2012
New Revision: 1379274
URL: http://svn.apache.org/viewvc?rev=1379274&view=rev
Log:
#120763 - [testuno patch]Advance filter and Filter option
Patch By: Terry Yang <po...@hotmail.com>
Review By: Liu Zhe <al...@gmail.com>
Added:
incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/AdvanceFilter.java
incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/StandardFilterOption.java
Added: incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/AdvanceFilter.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/AdvanceFilter.java?rev=1379274&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/AdvanceFilter.java (added)
+++ incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/AdvanceFilter.java Fri Aug 31 03:33:41 2012
@@ -0,0 +1,155 @@
+/**************************************************************
+ *
+ * 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 org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openoffice.test.common.Testspace;
+import org.openoffice.test.uno.UnoApp;
+import testlib.uno.SCUtil;
+import testlib.uno.TestUtil;
+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.XCellRangeData;
+import com.sun.star.sheet.XSheetFilterDescriptor;
+import com.sun.star.sheet.XSheetFilterable;
+import com.sun.star.sheet.XSheetFilterableEx;
+import com.sun.star.sheet.XSpreadsheet;
+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.UnoRuntime;
+
+public class AdvanceFilter {
+ private static final UnoApp app = new UnoApp();
+
+ UnoApp unoApp = new UnoApp();
+ XSpreadsheetDocument scDocument = null;
+ XComponent scComponent = null;
+ private String filename = "FilterTest.xls";
+
+ @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 {
+
+ }
+
+ @Test
+ public void testStandardFilterForString() 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));
+ XSpreadsheet currentsheet = SCUtil.getCurrentSheet(scDocument);
+
+ // Get the FilterCrit range and set the filter Critvalue
+ XCellRange FilterCritRange = currentsheet.getCellRangeByName("A15:F16");
+ XCellRangeData FilterCritData = (XCellRangeData) UnoRuntime
+ .queryInterface(XCellRangeData.class, FilterCritRange);
+ Object[][] aCritValues = {
+ { "Name", "Age", "Weight", "Height", "Score", "Graduate" },
+ { "", "", ">= 44", "", "", "" } };
+ FilterCritData.setDataArray(aCritValues);
+
+ // Filter the date
+ XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime
+ .queryInterface(XSheetFilterable.class,
+ xdataRange.getCellRangeByName("A1:F6"));
+
+ XSheetFilterableEx xCriteria = (XSheetFilterableEx) UnoRuntime
+ .queryInterface(XSheetFilterableEx.class,
+ xdataRange.getCellRangeByName("A15:F16"));
+ XSheetFilterDescriptor xFilterDesc = xCriteria
+ .createFilterDescriptorByObject(xFilter);
+ if (xFilterDesc != null)
+ 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(); i++) {
+ Object aRowObj = Rows.getByIndex(i);
+ XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, aRowObj);
+ if (i == 1 | i == 4) {
+ assertFalse("Expect should be false",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertTrue("Expect should be true",
+ (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(); i++) {
+ Object aRowObj = Rows.getByIndex(i);
+ XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, aRowObj);
+ if (i == 1 | i == 4) {
+ assertFalse("Expect should be false",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertTrue("Expect should be true",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+ }
+}
Added: incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/StandardFilterOption.java
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/StandardFilterOption.java?rev=1379274&view=auto
==============================================================================
--- incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/StandardFilterOption.java (added)
+++ incubator/ooo/trunk/test/testuno/source/testcase/uno/sc/data/StandardFilterOption.java Fri Aug 31 03:33:41 2012
@@ -0,0 +1,621 @@
+/**************************************************************
+ *
+ * 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 org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+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.XCellAddressable;
+import com.sun.star.sheet.XSheetFilterDescriptor;
+import com.sun.star.sheet.XSheetFilterable;
+import com.sun.star.sheet.XSpreadsheet;
+import com.sun.star.sheet.XSpreadsheetDocument;
+import com.sun.star.table.CellAddress;
+import com.sun.star.table.CellRangeAddress;
+import com.sun.star.table.TableOrientation;
+import com.sun.star.table.XCell;
+import com.sun.star.table.XCellRange;
+import com.sun.star.table.XColumnRowRange;
+import com.sun.star.table.XTableRows;
+import com.sun.star.text.XTextDocument;
+import com.sun.star.uno.UnoRuntime;
+
+public class StandardFilterOption {
+ private static final UnoApp app = new UnoApp();
+
+ UnoApp unoApp = new UnoApp();
+ XSpreadsheetDocument scDocument = null;
+ XComponent scComponent = null;
+ private String filename = "FilterTest.xls";
+
+ @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 {
+
+ }
+
+ @Test
+ public void testStandardFilterForString() 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 = 0;
+ aFilterFields[0].IsNumeric = false;
+ aFilterFields[0].Operator = FilterOperator.EQUAL;
+ aFilterFields[0].StringValue = "Tom";
+ 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:E6"));
+ 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);
+ if (i == 0 | i == 5) {
+ assertTrue("Verify row is invisible.",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertFalse("Verify row is invisible.",
+ (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:E6"));
+ 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);
+ if (i == 0 | i == 5) {
+ assertTrue("Verify row is invisible.",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertFalse("Verify row is invisible.",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+ }
+
+ @Test
+ public void testStandardFilterOptionCaseSensitive() 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 = 5;
+ aFilterFields[0].IsNumeric = false;
+ aFilterFields[0].Operator = FilterOperator.EQUAL;
+ aFilterFields[0].StringValue = "No";
+ xFilterDesc.setFilterFields(aFilterFields);
+ XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, xFilterDesc);
+ xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true));
+ xFilterProp.setPropertyValue("IsCaseSensitive", false);
+ 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);
+ if (i == 0|i==1|i==5) {
+ assertTrue("Expect should be True",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertFalse("Expect should be false",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+ //Change to CaseSenstive
+ xFilterProp.setPropertyValue("IsCaseSensitive", true);
+ xFilter.filter(xFilterDesc);
+
+ //Verify result
+ for (int i = 0; i < Rows.getCount() - 1; i++) {
+ Object aRowObj = Rows.getByIndex(i);
+ XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, aRowObj);
+ if (i == 0|i==5) {
+ assertTrue("Expect should be True",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertFalse("Expect should be false",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+
+ // Save and reload the document
+ SCUtil.save(scDocument);
+ SCUtil.closeFile(scDocument);
+ scDocument = SCUtil.openFile(sample, unoApp);
+
+ // Verify the result again
+ 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);
+ if (i == 0|i==5) {
+ assertTrue("Expect should be True",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertFalse("Expect should be false",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+ }
+
+ @Test
+ public void testStandardFilterOptionContainsHeader() 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 = 2;
+ aFilterFields[0].IsNumeric = true;
+ aFilterFields[0].Operator = FilterOperator.LESS;
+ aFilterFields[0].NumericValue = 44;
+ 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:E6"));
+ 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);
+ if (i == 0 | i == 1 | i == 4) {
+ assertTrue("Expect result should be True",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertFalse("Expect result should be false",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+ //Change to not contain header
+ xFilterProp.setPropertyValue("ContainsHeader", new Boolean(false));
+ xFilter.filter(xFilterDesc);
+
+ //Verify result
+ for (int i = 0; i < Rows.getCount() - 1; i++) {
+ Object aRowObj = Rows.getByIndex(i);
+ XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, aRowObj);
+ if (i == 1 | i == 4) {
+ assertTrue("Expect result should be True",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertFalse("Expect result should be false",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+ // Save the document
+ SCUtil.save(scDocument);
+ SCUtil.closeFile(scDocument);
+ scDocument = SCUtil.openFile(sample, unoApp);
+
+ // Verify filter result again
+ 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);
+ if (i == 1 | i == 4) {
+ assertTrue("Expect result should be True",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertFalse("Expect result should be false",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+ }
+
+ @Test
+ public void testStandardFilterOptionCopyOutput() 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));
+ XSpreadsheet currentSheet = SCUtil.getCurrentSheet(scDocument);
+ //Get the value before filter
+ String[][] souce =SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 5);
+
+ //Copy to cell postion
+ XCell cell = currentSheet.getCellByPosition(7, 7);
+ XCellAddressable xCellAddr = (XCellAddressable)
+ UnoRuntime.queryInterface(XCellAddressable.class, cell);
+ CellAddress copytoAddress = xCellAddr.getCellAddress();
+
+ // 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 = 3;
+ aFilterFields[0].IsNumeric = true;
+ aFilterFields[0].Operator = FilterOperator.GREATER;
+ aFilterFields[0].NumericValue = 155;
+ xFilterDesc.setFilterFields(aFilterFields);
+ XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, xFilterDesc);
+ xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true));
+ xFilterProp.setPropertyValue("CopyOutputData",new Boolean(true));
+ xFilterProp.setPropertyValue("OutputPosition",copytoAddress);
+ xFilter.filter(xFilterDesc);
+
+ // Verify source range not changed
+ XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime
+ .queryInterface(XColumnRowRange.class,
+ xdataRange.getCellRangeByName("A1:F6"));
+ XTableRows Rows = ColRowRange.getRows();
+ for (int i = 0; i < Rows.getCount(); i++) {
+ Object aRowObj = Rows.getByIndex(i);
+ XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, aRowObj);
+ assertTrue("Expect should be True",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+ //Get the data after filter
+ String[][] dataafterFilter = SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 5);
+ assertArrayEquals(souce,dataafterFilter);
+
+ //Get the copyto filter result, verify it
+ ColRowRange = (XColumnRowRange) UnoRuntime
+ .queryInterface(XColumnRowRange.class,
+ xdataRange.getCellRangeByName("H8:M10"));
+ for (int i = 0; i < Rows.getCount(); i++) {
+ Object aRowObj = Rows.getByIndex(i);
+ XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, aRowObj);
+ assertTrue("Expect should be True",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+ //Verify the first filter line data
+ assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 0),SCUtil.getTextFromCellRange(currentSheet, 7, 7, 12, 7));
+
+ //Verify the Second filter line data
+ assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 1, 5, 1),SCUtil.getTextFromCellRange(currentSheet, 7, 8, 12, 8));
+
+ //Verify the Last filter line data
+ assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 4, 5, 4),SCUtil.getTextFromCellRange(currentSheet, 7, 9, 12, 9));
+
+ // Save the document
+ SCUtil.save(scDocument);
+ SCUtil.closeFile(scDocument);
+ scDocument = SCUtil.openFile(sample, unoApp);
+
+ // Verify filter result again
+ 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(); i++) {
+ Object aRowObj = Rows.getByIndex(i);
+ XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, aRowObj);
+ assertTrue("Expect should be true",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+ //Get the data after filter
+ currentSheet = SCUtil.getCurrentSheet(scDocument);
+ dataafterFilter = SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 5);
+ assertArrayEquals(souce,dataafterFilter);
+
+
+ //Get the copyto filter result, verify it
+ ColRowRange = (XColumnRowRange) UnoRuntime
+ .queryInterface(XColumnRowRange.class,
+ xdataRange.getCellRangeByName("H8:M10"));
+ for (int i = 0; i < Rows.getCount(); i++) {
+ Object aRowObj = Rows.getByIndex(i);
+ XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, aRowObj);
+ assertTrue("Expect should be True",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+ //Verify the first filter line data
+ assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 0),SCUtil.getTextFromCellRange(currentSheet, 7, 7, 12, 7));
+
+ //Verify the Second filter line data
+ assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 1, 5, 1),SCUtil.getTextFromCellRange(currentSheet, 7, 8, 12, 8));
+
+ //Verify the Last filter line data
+ assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 4, 5, 4),SCUtil.getTextFromCellRange(currentSheet, 7, 9, 12, 9));
+ }
+
+ @Test
+ public void testStandardFilterOptionSkipDuplicates() 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:E6"));
+ XSheetFilterDescriptor xFilterDesc = xFilter
+ .createFilterDescriptor(true);
+ TableFilterField[] aFilterFields = new TableFilterField[1];
+ aFilterFields[0] = new TableFilterField();
+ aFilterFields[0].Field = 3;
+ aFilterFields[0].IsNumeric = true;
+ aFilterFields[0].Operator = FilterOperator.GREATER_EQUAL;
+ aFilterFields[0].NumericValue = 155;
+ xFilterDesc.setFilterFields(aFilterFields);
+ XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, xFilterDesc);
+ xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true));
+ xFilterProp.setPropertyValue("SkipDuplicates", new Boolean(true));
+ xFilter.filter(xFilterDesc);
+
+ // Verify filter result
+ XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime
+ .queryInterface(XColumnRowRange.class,
+ xdataRange.getCellRangeByName("A1:E6"));
+ XTableRows Rows = ColRowRange.getRows();
+ for (int i = 0; i < Rows.getCount(); i++) {
+ Object aRowObj = Rows.getByIndex(i);
+ XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, aRowObj);
+ if (i == 2) {
+ assertFalse("Verify row is invisible.",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertTrue("Verify row is invisible.",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+ //Change to skip Dulicates
+ xFilterProp.setPropertyValue("SkipDuplicates", new Boolean(false));
+ xFilter.filter(xFilterDesc);
+
+ // Verify filter result
+ ColRowRange = (XColumnRowRange) UnoRuntime
+ .queryInterface(XColumnRowRange.class,
+ xdataRange.getCellRangeByName("A1:E6"));
+ Rows = ColRowRange.getRows();
+ for (int i = 0; i < Rows.getCount(); i++) {
+ Object aRowObj = Rows.getByIndex(i);
+ XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, aRowObj);
+ if (i == 2|i==6) {
+ assertFalse("Expect should be false",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertTrue("Expect should be True",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+ // Save the document
+ SCUtil.save(scDocument);
+ SCUtil.closeFile(scDocument);
+ scDocument = SCUtil.openFile(sample, unoApp);
+
+ // Verify filter result again
+ xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class,
+ SCUtil.getCurrentSheet(scDocument));
+ ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(
+ XColumnRowRange.class, xdataRange.getCellRangeByName("A1:E6"));
+ 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);
+ if (i == 2|i==6 ) {
+ assertFalse("Expect should be false",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertTrue("Expect should be true",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+ }
+
+ @Test
+ public void testStandardFilterOptionUseRegularExpressions() 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 = 0;
+ aFilterFields[0].IsNumeric = false;
+ aFilterFields[0].Operator = FilterOperator.EQUAL;
+ aFilterFields[0].StringValue = "^.{3}$";
+ xFilterDesc.setFilterFields(aFilterFields);
+ XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, xFilterDesc);
+ xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true));
+ xFilterProp.setPropertyValue("UseRegularExpressions", 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(); i++) {
+ Object aRowObj = Rows.getByIndex(i);
+ XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, aRowObj);
+ if (i==2|i==4) {
+ assertFalse("Expect should be false",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertTrue("Expect should be true",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+ // Save the document
+ SCUtil.save(scDocument);
+ SCUtil.closeFile(scDocument);
+ scDocument = SCUtil.openFile(sample, unoApp);
+
+ // Verify filter result again
+ 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(); i++) {
+ Object aRowObj = Rows.getByIndex(i);
+ XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(
+ XPropertySet.class, aRowObj);
+ if (i==2|i==4 ) {
+ assertFalse("Expect should be false",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ } else
+ assertTrue("Expect should be true",
+ (Boolean) PropSet.getPropertyValue("IsVisible"));
+ }
+
+ }
+
+}