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