Line 0
Link Here
|
|
|
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 |
package testcase.uno.sc.data; |
22 |
import static org.junit.Assert.*; |
23 |
|
24 |
import java.util.Arrays; |
25 |
import java.util.Collection; |
26 |
import org.junit.After; |
27 |
import org.junit.AfterClass; |
28 |
import org.junit.Before; |
29 |
import org.junit.BeforeClass; |
30 |
import org.junit.Test; |
31 |
import org.junit.runner.RunWith; |
32 |
import org.junit.runners.Parameterized; |
33 |
import org.junit.runners.Parameterized.Parameters; |
34 |
import org.openoffice.test.common.Testspace; |
35 |
import org.openoffice.test.uno.UnoApp; |
36 |
import testlib.uno.SCUtil; |
37 |
import com.sun.star.beans.XPropertySet; |
38 |
import com.sun.star.lang.XComponent; |
39 |
import com.sun.star.sheet.FilterOperator; |
40 |
import com.sun.star.sheet.TableFilterField; |
41 |
import com.sun.star.sheet.XSheetFilterDescriptor; |
42 |
import com.sun.star.sheet.XSheetFilterable; |
43 |
import com.sun.star.sheet.XSpreadsheetDocument; |
44 |
import com.sun.star.table.XCellRange; |
45 |
import com.sun.star.table.XColumnRowRange; |
46 |
import com.sun.star.table.XTableRows; |
47 |
import com.sun.star.uno.Enum; |
48 |
import com.sun.star.uno.UnoRuntime; |
49 |
|
50 |
|
51 |
@RunWith(value = Parameterized.class) |
52 |
public class StardarFilterTest { |
53 |
private static final UnoApp app = new UnoApp(); |
54 |
UnoApp unoApp = new UnoApp(); |
55 |
XSpreadsheetDocument scDocument = null; |
56 |
XComponent scComponent = null; |
57 |
private String filename = "FilterTest.xls"; |
58 |
private Enum operator; |
59 |
private int column; |
60 |
private boolean[] rowshow; |
61 |
private int value; |
62 |
|
63 |
@Parameters |
64 |
public static Collection<Object[]> data() throws Exception { |
65 |
boolean[] rowshow1 ={true,true,false,true,false,false}; |
66 |
boolean[] rowshow2 ={true,true,true,true,true,false}; |
67 |
boolean[] rowshow3 ={true,false,false,true,false,false}; |
68 |
boolean[] rowshow4 ={true,false,true,true,false,false}; |
69 |
boolean[] rowshow5 ={true,false,false,false,false,true}; |
70 |
boolean[] rowshow6 ={true,false,true,true,false,true}; |
71 |
boolean[] rowshow7 ={true,false,true,false,false,false}; |
72 |
boolean[] rowshow8 ={true,false,true,true,false,true}; |
73 |
boolean[] rowshow9 ={true,true,true,false,true,true}; |
74 |
boolean[] rowshow10 ={true,true,false,false,true,true}; |
75 |
boolean[] rowshow11 ={true,true,false,false,false,false}; |
76 |
boolean[] rowshow12 ={true,true,true,true,false,false}; |
77 |
|
78 |
return Arrays.asList(new Object[][] { |
79 |
{FilterOperator.BOTTOM_PERCENT, 1, 30,rowshow1}, |
80 |
{FilterOperator.BOTTOM_VALUES, 2, 4,rowshow2}, |
81 |
{FilterOperator.EMPTY, 5,1 ,rowshow3}, |
82 |
{FilterOperator.EQUAL,2,44,rowshow4}, |
83 |
{FilterOperator.GREATER, 2,44,rowshow5}, |
84 |
{FilterOperator.GREATER_EQUAL, 2,44,rowshow6}, |
85 |
{FilterOperator.LESS, 3,155,rowshow7}, |
86 |
{FilterOperator.LESS_EQUAL,3, 155,rowshow8}, |
87 |
{FilterOperator.NOT_EMPTY,5,44, rowshow9}, |
88 |
{FilterOperator.NOT_EQUAL,4, 85,rowshow10}, |
89 |
{FilterOperator.TOP_PERCENT,4, 30,rowshow11}, |
90 |
{FilterOperator.TOP_VALUES, 4,3,rowshow12}, |
91 |
}); |
92 |
} |
93 |
|
94 |
|
95 |
|
96 |
@Before |
97 |
public void setUpDocument() throws Exception { |
98 |
unoApp.start(); |
99 |
} |
100 |
|
101 |
@After |
102 |
public void tearDownDocument() { |
103 |
unoApp.close(); |
104 |
unoApp.closeDocument(scComponent); |
105 |
|
106 |
} |
107 |
|
108 |
@BeforeClass |
109 |
public static void setUpConnection() throws Exception { |
110 |
|
111 |
} |
112 |
|
113 |
@AfterClass |
114 |
public static void tearDownConnection() throws InterruptedException, |
115 |
Exception { |
116 |
|
117 |
} |
118 |
|
119 |
public StardarFilterTest(Enum operator, int column,int value, boolean[] rowshow) { |
120 |
this.operator = operator; |
121 |
this.column = column; |
122 |
this.rowshow = rowshow; |
123 |
this.value = value; |
124 |
} |
125 |
|
126 |
@Test |
127 |
public void testStandardFilter() throws Exception { |
128 |
// Prepare test data |
129 |
Testspace.prepareData(filename); |
130 |
String sample = Testspace.getPath("output/../data/" + filename); |
131 |
|
132 |
// Open document |
133 |
scDocument = SCUtil.openFile(sample, unoApp); |
134 |
|
135 |
// Get cell range |
136 |
XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface( |
137 |
XCellRange.class, SCUtil.getCurrentSheet(scDocument)); |
138 |
|
139 |
// Set filter property and filter the cell range |
140 |
XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime |
141 |
.queryInterface(XSheetFilterable.class, |
142 |
xdataRange.getCellRangeByName("A1:F6")); |
143 |
XSheetFilterDescriptor xFilterDesc = xFilter |
144 |
.createFilterDescriptor(true); |
145 |
TableFilterField[] aFilterFields = new TableFilterField[1]; |
146 |
aFilterFields[0] = new TableFilterField(); |
147 |
aFilterFields[0].Field = column; |
148 |
aFilterFields[0].IsNumeric = true; |
149 |
aFilterFields[0].Operator = (FilterOperator) operator; |
150 |
aFilterFields[0].NumericValue = value; |
151 |
xFilterDesc.setFilterFields(aFilterFields); |
152 |
XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface( |
153 |
XPropertySet.class, xFilterDesc); |
154 |
xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true)); |
155 |
xFilter.filter(xFilterDesc); |
156 |
|
157 |
// Verify filter result |
158 |
XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime |
159 |
.queryInterface(XColumnRowRange.class, |
160 |
xdataRange.getCellRangeByName("A1:F6")); |
161 |
XTableRows Rows = ColRowRange.getRows(); |
162 |
for (int i = 0; i < Rows.getCount() - 1; i++) { |
163 |
Object aRowObj = Rows.getByIndex(i); |
164 |
XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface( |
165 |
XPropertySet.class, aRowObj); |
166 |
assertEquals(rowshow[i],(boolean) PropSet.getPropertyValue("IsVisible")); |
167 |
} |
168 |
|
169 |
// Save and reload the document |
170 |
SCUtil.save(scDocument); |
171 |
SCUtil.closeFile(scDocument); |
172 |
scDocument = SCUtil.openFile(sample, unoApp); |
173 |
|
174 |
// Verify the result agains |
175 |
xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, |
176 |
SCUtil.getCurrentSheet(scDocument)); |
177 |
ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface( |
178 |
XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6")); |
179 |
Rows = ColRowRange.getRows(); |
180 |
for (int i = 0; i < Rows.getCount() - 1; i++) { |
181 |
Object aRowObj = Rows.getByIndex(i); |
182 |
XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface( |
183 |
XPropertySet.class, aRowObj); |
184 |
assertEquals(rowshow[i],(boolean) PropSet.getPropertyValue("IsVisible")); |
185 |
} |
186 |
SCUtil.save(scDocument); |
187 |
} |
188 |
} |