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 fvt.uno.sc.data;
22 
23 import static org.junit.Assert.*;
24 
25 import org.junit.After;
26 import org.junit.AfterClass;
27 import org.junit.Before;
28 import org.junit.BeforeClass;
29 import org.junit.Test;
30 import org.openoffice.test.common.Testspace;
31 import org.openoffice.test.uno.UnoApp;
32 
33 import testlib.uno.SCUtil;
34 
35 import com.sun.star.beans.XPropertySet;
36 import com.sun.star.lang.XComponent;
37 import com.sun.star.sheet.FilterOperator;
38 import com.sun.star.sheet.TableFilterField;
39 import com.sun.star.sheet.XCellAddressable;
40 import com.sun.star.sheet.XSheetFilterDescriptor;
41 import com.sun.star.sheet.XSheetFilterable;
42 import com.sun.star.sheet.XSpreadsheet;
43 import com.sun.star.sheet.XSpreadsheetDocument;
44 import com.sun.star.table.CellAddress;
45 import com.sun.star.table.CellRangeAddress;
46 import com.sun.star.table.TableOrientation;
47 import com.sun.star.table.XCell;
48 import com.sun.star.table.XCellRange;
49 import com.sun.star.table.XColumnRowRange;
50 import com.sun.star.table.XTableRows;
51 import com.sun.star.text.XTextDocument;
52 import com.sun.star.uno.UnoRuntime;
53 
54 public class StandardFilterOption {
55 	private static final UnoApp app = new UnoApp();
56 
57 	UnoApp unoApp = new UnoApp();
58 	XSpreadsheetDocument scDocument = null;
59 	XComponent scComponent = null;
60 	private String filename = "FilterTest.xls";
61 
62 	@Before
63 	public void setUpDocument() throws Exception {
64 		unoApp.start();
65 	}
66 
67 	@After
68 	public void tearDownDocument() {
69 		unoApp.close();
70 		unoApp.closeDocument(scComponent);
71 
72 	}
73 
74 	@BeforeClass
75 	public static void setUpConnection() throws Exception {
76 
77 	}
78 
79 	@AfterClass
80 	public static void tearDownConnection() throws InterruptedException, Exception {
81 
82 	}
83 
84 	@Test
85 	public void testStandardFilterForString() throws Exception {
86 		// Prepare test data
87 		String sample = Testspace.prepareData(filename);
88 		// Open document
89 		scDocument = SCUtil.openFile(sample, unoApp);
90 		// Get cell range
91 		XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument));
92 
93 		// Set filter property and filter the cell range
94 		XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime.queryInterface(XSheetFilterable.class, xdataRange.getCellRangeByName("A1:F6"));
95 		XSheetFilterDescriptor xFilterDesc = xFilter.createFilterDescriptor(true);
96 		TableFilterField[] aFilterFields = new TableFilterField[1];
97 		aFilterFields[0] = new TableFilterField();
98 		aFilterFields[0].Field = 0;
99 		aFilterFields[0].IsNumeric = false;
100 		aFilterFields[0].Operator = FilterOperator.EQUAL;
101 		aFilterFields[0].StringValue = "Tom";
102 		xFilterDesc.setFilterFields(aFilterFields);
103 		XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFilterDesc);
104 		xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true));
105 		xFilter.filter(xFilterDesc);
106 
107 		// Verify filter result
108 		XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:E6"));
109 		XTableRows Rows = ColRowRange.getRows();
110 		for (int i = 0; i < Rows.getCount() - 1; i++) {
111 			Object aRowObj = Rows.getByIndex(i);
112 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
113 			if (i == 0 | i == 5) {
114 				assertTrue("Verify row is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible"));
115 			} else
116 				assertFalse("Verify row is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible"));
117 		}
118 
119 		// Save and reload the document
120 		SCUtil.save(scDocument);
121 		SCUtil.closeFile(scDocument);
122 		scDocument = SCUtil.openFile(sample, unoApp);
123 
124 		// Verify the result agains
125 		xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument));
126 		ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:E6"));
127 		Rows = ColRowRange.getRows();
128 		for (int i = 0; i < Rows.getCount() - 1; i++) {
129 			Object aRowObj = Rows.getByIndex(i);
130 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
131 			if (i == 0 | i == 5) {
132 				assertTrue("Verify row is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible"));
133 			} else
134 				assertFalse("Verify row is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible"));
135 		}
136 
137 	}
138 
139 	@Test
140 	public void testStandardFilterOptionCaseSensitive() throws Exception {
141 		// Prepare test data
142 		String sample = Testspace.prepareData(filename);
143 		// Open document
144 		scDocument = SCUtil.openFile(sample, unoApp);
145 		// Get cell range
146 		XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument));
147 
148 		// Set filter property and filter the cell range
149 		XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime.queryInterface(XSheetFilterable.class, xdataRange.getCellRangeByName("A1:F6"));
150 		XSheetFilterDescriptor xFilterDesc = xFilter.createFilterDescriptor(true);
151 		TableFilterField[] aFilterFields = new TableFilterField[1];
152 		aFilterFields[0] = new TableFilterField();
153 		aFilterFields[0].Field = 5;
154 		aFilterFields[0].IsNumeric = false;
155 		aFilterFields[0].Operator = FilterOperator.EQUAL;
156 		aFilterFields[0].StringValue = "No";
157 		xFilterDesc.setFilterFields(aFilterFields);
158 		XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFilterDesc);
159 		xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true));
160 		xFilterProp.setPropertyValue("IsCaseSensitive", false);
161 		xFilter.filter(xFilterDesc);
162 
163 		// Verify filter result
164 		XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6"));
165 		XTableRows Rows = ColRowRange.getRows();
166 		for (int i = 0; i < Rows.getCount() - 1; i++) {
167 			Object aRowObj = Rows.getByIndex(i);
168 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
169 			if (i == 0 | i == 1 | i == 5) {
170 				assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible"));
171 			} else
172 				assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible"));
173 		}
174 
175 		// Change to CaseSenstive
176 		xFilterProp.setPropertyValue("IsCaseSensitive", true);
177 		xFilter.filter(xFilterDesc);
178 
179 		// Verify result
180 		for (int i = 0; i < Rows.getCount() - 1; i++) {
181 			Object aRowObj = Rows.getByIndex(i);
182 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
183 			if (i == 0 | i == 5) {
184 				assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible"));
185 			} else
186 				assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible"));
187 		}
188 
189 		// Save and reload the document
190 		SCUtil.save(scDocument);
191 		SCUtil.closeFile(scDocument);
192 		scDocument = SCUtil.openFile(sample, unoApp);
193 
194 		// Verify the result again
195 		xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument));
196 		ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6"));
197 		Rows = ColRowRange.getRows();
198 		for (int i = 0; i < Rows.getCount() - 1; i++) {
199 			Object aRowObj = Rows.getByIndex(i);
200 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
201 			if (i == 0 | i == 5) {
202 				assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible"));
203 			} else
204 				assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible"));
205 		}
206 	}
207 
208 	@Test
209 	public void testStandardFilterOptionContainsHeader() throws Exception {
210 		// Prepare test data
211 		String sample = Testspace.prepareData(filename);
212 		// Open document
213 		scDocument = SCUtil.openFile(sample, unoApp);
214 		// Get cell range
215 		XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument));
216 
217 		// Set filter property and filter the cell range
218 		XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime.queryInterface(XSheetFilterable.class, xdataRange.getCellRangeByName("A1:F6"));
219 		XSheetFilterDescriptor xFilterDesc = xFilter.createFilterDescriptor(true);
220 		TableFilterField[] aFilterFields = new TableFilterField[1];
221 		aFilterFields[0] = new TableFilterField();
222 		aFilterFields[0].Field = 2;
223 		aFilterFields[0].IsNumeric = true;
224 		aFilterFields[0].Operator = FilterOperator.LESS;
225 		aFilterFields[0].NumericValue = 44;
226 		xFilterDesc.setFilterFields(aFilterFields);
227 		XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFilterDesc);
228 		xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true));
229 		xFilter.filter(xFilterDesc);
230 
231 		// Verify filter result
232 		XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:E6"));
233 		XTableRows Rows = ColRowRange.getRows();
234 		for (int i = 0; i < Rows.getCount() - 1; i++) {
235 			Object aRowObj = Rows.getByIndex(i);
236 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
237 			if (i == 0 | i == 1 | i == 4) {
238 				assertTrue("Expect result should be True", (Boolean) PropSet.getPropertyValue("IsVisible"));
239 			} else
240 				assertFalse("Expect result should be false", (Boolean) PropSet.getPropertyValue("IsVisible"));
241 		}
242 
243 		// Change to not contain header
244 		xFilterProp.setPropertyValue("ContainsHeader", new Boolean(false));
245 		xFilter.filter(xFilterDesc);
246 
247 		// Verify result
248 		for (int i = 0; i < Rows.getCount() - 1; i++) {
249 			Object aRowObj = Rows.getByIndex(i);
250 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
251 			if (i == 1 | i == 4) {
252 				assertTrue("Expect result should be True", (Boolean) PropSet.getPropertyValue("IsVisible"));
253 			} else
254 				assertFalse("Expect result should be false", (Boolean) PropSet.getPropertyValue("IsVisible"));
255 		}
256 
257 		// Save the document
258 		SCUtil.save(scDocument);
259 		SCUtil.closeFile(scDocument);
260 		scDocument = SCUtil.openFile(sample, unoApp);
261 
262 		// Verify filter result again
263 		xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument));
264 		ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6"));
265 		Rows = ColRowRange.getRows();
266 		for (int i = 0; i < Rows.getCount() - 1; i++) {
267 			Object aRowObj = Rows.getByIndex(i);
268 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
269 			if (i == 1 | i == 4) {
270 				assertTrue("Expect result should be True", (Boolean) PropSet.getPropertyValue("IsVisible"));
271 			} else
272 				assertFalse("Expect result should be false", (Boolean) PropSet.getPropertyValue("IsVisible"));
273 		}
274 
275 	}
276 
277 	@Test
278 	public void testStandardFilterOptionCopyOutput() throws Exception {
279 		// Prepare test data
280 		String sample = Testspace.prepareData(filename);
281 		// Open document
282 		scDocument = SCUtil.openFile(sample, unoApp);
283 		// Get cell range
284 		XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument));
285 		XSpreadsheet currentSheet = SCUtil.getCurrentSheet(scDocument);
286 		// Get the value before filter
287 		String[][] souce = SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 5);
288 
289 		// Copy to cell postion
290 		XCell cell = currentSheet.getCellByPosition(7, 7);
291 		XCellAddressable xCellAddr = (XCellAddressable) UnoRuntime.queryInterface(XCellAddressable.class, cell);
292 		CellAddress copytoAddress = xCellAddr.getCellAddress();
293 
294 		// Set filter property and filter the cell range
295 		XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime.queryInterface(XSheetFilterable.class, xdataRange.getCellRangeByName("A1:F6"));
296 		XSheetFilterDescriptor xFilterDesc = xFilter.createFilterDescriptor(true);
297 		TableFilterField[] aFilterFields = new TableFilterField[1];
298 		aFilterFields[0] = new TableFilterField();
299 		aFilterFields[0].Field = 3;
300 		aFilterFields[0].IsNumeric = true;
301 		aFilterFields[0].Operator = FilterOperator.GREATER;
302 		aFilterFields[0].NumericValue = 155;
303 		xFilterDesc.setFilterFields(aFilterFields);
304 		XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFilterDesc);
305 		xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true));
306 		xFilterProp.setPropertyValue("CopyOutputData", new Boolean(true));
307 		xFilterProp.setPropertyValue("OutputPosition", copytoAddress);
308 		xFilter.filter(xFilterDesc);
309 
310 		// Verify source range not changed
311 		XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6"));
312 		XTableRows Rows = ColRowRange.getRows();
313 		for (int i = 0; i < Rows.getCount(); i++) {
314 			Object aRowObj = Rows.getByIndex(i);
315 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
316 			assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible"));
317 		}
318 
319 		// Get the data after filter
320 		String[][] dataafterFilter = SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 5);
321 		assertArrayEquals(souce, dataafterFilter);
322 
323 		// Get the copyto filter result, verify it
324 		ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("H8:M10"));
325 		for (int i = 0; i < Rows.getCount(); i++) {
326 			Object aRowObj = Rows.getByIndex(i);
327 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
328 			assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible"));
329 		}
330 		// Verify the first filter line data
331 		assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 0), SCUtil.getTextFromCellRange(currentSheet, 7, 7, 12, 7));
332 
333 		// Verify the Second filter line data
334 		assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 1, 5, 1), SCUtil.getTextFromCellRange(currentSheet, 7, 8, 12, 8));
335 
336 		// Verify the Last filter line data
337 		assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 4, 5, 4), SCUtil.getTextFromCellRange(currentSheet, 7, 9, 12, 9));
338 
339 		// Save the document
340 		SCUtil.save(scDocument);
341 		SCUtil.closeFile(scDocument);
342 		scDocument = SCUtil.openFile(sample, unoApp);
343 
344 		// Verify filter result again
345 		xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument));
346 		ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6"));
347 		Rows = ColRowRange.getRows();
348 		for (int i = 0; i < Rows.getCount(); i++) {
349 			Object aRowObj = Rows.getByIndex(i);
350 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
351 			assertTrue("Expect should be true", (Boolean) PropSet.getPropertyValue("IsVisible"));
352 		}
353 
354 		// Get the data after filter
355 		currentSheet = SCUtil.getCurrentSheet(scDocument);
356 		dataafterFilter = SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 5);
357 		assertArrayEquals(souce, dataafterFilter);
358 
359 		// Get the copyto filter result, verify it
360 		ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("H8:M10"));
361 		for (int i = 0; i < Rows.getCount(); i++) {
362 			Object aRowObj = Rows.getByIndex(i);
363 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
364 			assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible"));
365 		}
366 		// Verify the first filter line data
367 		assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 0), SCUtil.getTextFromCellRange(currentSheet, 7, 7, 12, 7));
368 
369 		// Verify the Second filter line data
370 		assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 1, 5, 1), SCUtil.getTextFromCellRange(currentSheet, 7, 8, 12, 8));
371 
372 		// Verify the Last filter line data
373 		assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 4, 5, 4), SCUtil.getTextFromCellRange(currentSheet, 7, 9, 12, 9));
374 	}
375 
376 	@Test
377 	public void testStandardFilterOptionSkipDuplicates() throws Exception {
378 		// Prepare test data
379 		String sample = Testspace.prepareData(filename);
380 		// Open document
381 		scDocument = SCUtil.openFile(sample, unoApp);
382 		// Get cell range
383 		XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument));
384 
385 		// Set filter property and filter the cell range
386 		XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime.queryInterface(XSheetFilterable.class, xdataRange.getCellRangeByName("A1:E6"));
387 		XSheetFilterDescriptor xFilterDesc = xFilter.createFilterDescriptor(true);
388 		TableFilterField[] aFilterFields = new TableFilterField[1];
389 		aFilterFields[0] = new TableFilterField();
390 		aFilterFields[0].Field = 3;
391 		aFilterFields[0].IsNumeric = true;
392 		aFilterFields[0].Operator = FilterOperator.GREATER_EQUAL;
393 		aFilterFields[0].NumericValue = 155;
394 		xFilterDesc.setFilterFields(aFilterFields);
395 		XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFilterDesc);
396 		xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true));
397 		xFilterProp.setPropertyValue("SkipDuplicates", new Boolean(true));
398 		xFilter.filter(xFilterDesc);
399 
400 		// Verify filter result
401 		XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:E6"));
402 		XTableRows Rows = ColRowRange.getRows();
403 		for (int i = 0; i < Rows.getCount(); i++) {
404 			Object aRowObj = Rows.getByIndex(i);
405 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
406 			if (i == 2) {
407 				assertFalse("Verify row is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible"));
408 			} else
409 				assertTrue("Verify row is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible"));
410 		}
411 
412 		// Change to skip Dulicates
413 		xFilterProp.setPropertyValue("SkipDuplicates", new Boolean(false));
414 		xFilter.filter(xFilterDesc);
415 
416 		// Verify filter result
417 		ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:E6"));
418 		Rows = ColRowRange.getRows();
419 		for (int i = 0; i < Rows.getCount(); i++) {
420 			Object aRowObj = Rows.getByIndex(i);
421 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
422 			if (i == 2 | i == 6) {
423 				assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible"));
424 			} else
425 				assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible"));
426 		}
427 
428 		// Save the document
429 		SCUtil.save(scDocument);
430 		SCUtil.closeFile(scDocument);
431 		scDocument = SCUtil.openFile(sample, unoApp);
432 
433 		// Verify filter result again
434 		xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument));
435 		ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:E6"));
436 		Rows = ColRowRange.getRows();
437 		for (int i = 0; i < Rows.getCount() - 1; i++) {
438 			Object aRowObj = Rows.getByIndex(i);
439 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
440 			if (i == 2 | i == 6) {
441 				assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible"));
442 			} else
443 				assertTrue("Expect should be true", (Boolean) PropSet.getPropertyValue("IsVisible"));
444 		}
445 
446 	}
447 
448 	@Test
449 	public void testStandardFilterOptionUseRegularExpressions() throws Exception {
450 		// Prepare test data
451 		String sample = Testspace.prepareData(filename);
452 		// Open document
453 		scDocument = SCUtil.openFile(sample, unoApp);
454 		// Get cell range
455 		XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument));
456 
457 		// Set filter property and filter the cell range
458 		XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime.queryInterface(XSheetFilterable.class, xdataRange.getCellRangeByName("A1:F6"));
459 		XSheetFilterDescriptor xFilterDesc = xFilter.createFilterDescriptor(true);
460 		TableFilterField[] aFilterFields = new TableFilterField[1];
461 		aFilterFields[0] = new TableFilterField();
462 		aFilterFields[0].Field = 0;
463 		aFilterFields[0].IsNumeric = false;
464 		aFilterFields[0].Operator = FilterOperator.EQUAL;
465 		aFilterFields[0].StringValue = "^.{3}$";
466 		xFilterDesc.setFilterFields(aFilterFields);
467 		XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFilterDesc);
468 		xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true));
469 		xFilterProp.setPropertyValue("UseRegularExpressions", new Boolean(true));
470 		xFilter.filter(xFilterDesc);
471 
472 		// Verify filter result
473 		XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6"));
474 		XTableRows Rows = ColRowRange.getRows();
475 		for (int i = 0; i < Rows.getCount(); i++) {
476 			Object aRowObj = Rows.getByIndex(i);
477 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
478 			if (i == 2 | i == 4) {
479 				assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible"));
480 			} else
481 				assertTrue("Expect should be true", (Boolean) PropSet.getPropertyValue("IsVisible"));
482 		}
483 
484 		// Save the document
485 		SCUtil.save(scDocument);
486 		SCUtil.closeFile(scDocument);
487 		scDocument = SCUtil.openFile(sample, unoApp);
488 
489 		// Verify filter result again
490 		xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument));
491 		ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6"));
492 		Rows = ColRowRange.getRows();
493 		for (int i = 0; i < Rows.getCount(); i++) {
494 			Object aRowObj = Rows.getByIndex(i);
495 			XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj);
496 			if (i == 2 | i == 4) {
497 				assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible"));
498 			} else
499 				assertTrue("Expect should be true", (Boolean) PropSet.getPropertyValue("IsVisible"));
500 		}
501 
502 	}
503 
504 }
505