1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 package ifc.awt; 29 30 31 import lib.MultiMethodTest; 32 import lib.Status; 33 34 import com.sun.star.awt.XListBox; 35 36 /** 37 * Testing <code>com.sun.star.awt.XListBox</code> 38 * interface methods : 39 * <ul> 40 * <li><code> addItemListener()</code></li> 41 * <li><code> removeItemListener()</code></li> 42 * <li><code> addActionListener()</code></li> 43 * <li><code> removeActionListener()</code></li> 44 * <li><code> addItem()</code></li> 45 * <li><code> addItems()</code></li> 46 * <li><code> removeItems()</code></li> 47 * <li><code> getItemCount()</code></li> 48 * <li><code> getItem()</code></li> 49 * <li><code> getItems()</code></li> 50 * <li><code> getSelectedItemPos()</code></li> 51 * <li><code> getSelectedItemsPos()</code></li> 52 * <li><code> getSelectedItem()</code></li> 53 * <li><code> getSelectedItems()</code></li> 54 * <li><code> selectItemPos()</code></li> 55 * <li><code> selectItemsPos()</code></li> 56 * <li><code> selectItem()</code></li> 57 * <li><code> isMutipleMode()</code></li> 58 * <li><code> setMultipleMode()</code></li> 59 * <li><code> getDropDownLineCount()</code></li> 60 * <li><code> setDropDownLineCount()</code></li> 61 * <li><code> makeVisible()</code></li> 62 * </ul> <p> 63 * Test is <b> NOT </b> multithread compilant. <p> 64 * @see com.sun.star.awt.XListBox 65 */ 66 public class _XListBox extends MultiMethodTest { 67 68 public XListBox oObj = null; 69 70 /** 71 * Listener implementation which sets flags on appropriate method calls 72 */ 73 protected class TestActionListener implements com.sun.star.awt.XActionListener { 74 public boolean disposingCalled = false ; 75 public boolean actionPerformedCalled = false ; 76 77 public void disposing(com.sun.star.lang.EventObject e) { 78 disposingCalled = true ; 79 } 80 81 public void actionPerformed(com.sun.star.awt.ActionEvent e) { 82 actionPerformedCalled = true ; 83 } 84 85 } 86 87 TestActionListener actionListener = new TestActionListener() ; 88 89 /** 90 * Listener implementation which sets flags on appropriate method calls 91 */ 92 protected class TestItemListener implements com.sun.star.awt.XItemListener { 93 public boolean disposingCalled = false ; 94 public boolean itemStateChangedCalled = false ; 95 96 public void disposing(com.sun.star.lang.EventObject e) { 97 disposingCalled = true ; 98 } 99 100 public void itemStateChanged(com.sun.star.awt.ItemEvent e) { 101 itemStateChangedCalled = true ; 102 } 103 104 } 105 106 TestItemListener itemListener = new TestItemListener() ; 107 108 short lineCount = 0 ; 109 short itemCount = 0 ; 110 111 /** 112 * Retrieves object relations. 113 * @throws StatusException If one of relations not found. 114 */ 115 public void before() { 116 itemCount = oObj.getItemCount(); 117 } 118 119 /** 120 * !!! Can be checked only interactively !!! 121 */ 122 public void _addItemListener() { 123 124 oObj.addItemListener(itemListener) ; 125 126 tRes.tested("addItemListener()", Status.skipped(true)) ; 127 } 128 129 /** 130 * !!! Can be checked only interactively !!! 131 */ 132 public void _removeItemListener() { 133 requiredMethod("addItemListener()") ; 134 135 oObj.removeItemListener(itemListener) ; 136 137 tRes.tested("removeItemListener()", Status.skipped(true)) ; 138 } 139 140 /** 141 * !!! Can be checked only interactively !!! 142 */ 143 public void _addActionListener() { 144 145 oObj.addActionListener(actionListener) ; 146 147 tRes.tested("addActionListener()", Status.skipped(true)) ; 148 } 149 150 /** 151 * !!! Can be checked only interactively !!! 152 */ 153 public void _removeActionListener() { 154 requiredMethod("addActionListener()") ; 155 156 oObj.removeActionListener(actionListener) ; 157 158 tRes.tested("removeActionListener()", Status.skipped(true)) ; 159 } 160 161 /** 162 * Adds one item to the last position and check the number of 163 * items after addition. <p> 164 * Has <b>OK</b> status if the number of items increased by 1.<p> 165 * The following method tests are to be completed successfully before : 166 * <ul> 167 * <li> <code> getItemCount </code> </li> 168 * </ul> 169 */ 170 public void _addItem() { 171 requiredMethod("getItemCount()") ; 172 173 boolean result = true ; 174 oObj.addItem("Item1", itemCount) ; 175 result = oObj.getItemCount() == itemCount + 1 ; 176 177 tRes.tested("addItem()", result) ; 178 } 179 180 /** 181 * Adds one two items to the last position and check the number of 182 * items after addition. <p> 183 * Has <b>OK</b> status if the number of items increased by 2.<p> 184 * The following method tests are to be executed before : 185 * <ul> 186 * <li> <code> addItem </code> </li> 187 * </ul> 188 */ 189 public void _addItems() { 190 executeMethod("addItem()") ; 191 192 boolean result = true ; 193 short oldCnt = oObj.getItemCount() ; 194 oObj.addItems(new String[] {"Item2", "Item3"}, oldCnt) ; 195 result = oObj.getItemCount() == oldCnt + 2 ; 196 197 tRes.tested("addItems()", result) ; 198 } 199 200 /** 201 * Gets the current number of items and tries to remove them all 202 * then checks number of items. <p> 203 * Has <b>OK</b> status if no items remains. <p> 204 * The following method tests are to be executed before : 205 * <ul> 206 * <li> <code> getItems </code> </li> 207 * <li> <code> getItem </code> </li> 208 * </ul> 209 */ 210 public void _removeItems() { 211 executeMethod("getItems()") ; 212 executeMethod("getItem()") ; 213 executeMethod("getSelectedItemPos()") ; 214 executeMethod("getSelectedItemsPos()") ; 215 executeMethod("getSelectedItem()") ; 216 executeMethod("getSelectedItems()") ; 217 218 boolean result = true ; 219 short oldCnt = oObj.getItemCount() ; 220 oObj.removeItems((short)0, oldCnt) ; 221 result = oObj.getItemCount() == 0 ; 222 223 tRes.tested("removeItems()", result) ; 224 } 225 226 /** 227 * Just retrieves current number of items and stores it. <p> 228 * Has <b>OK</b> status if the count is not less than 0. 229 */ 230 public void _getItemCount() { 231 232 itemCount = oObj.getItemCount() ; 233 234 tRes.tested("getItemCount()", itemCount >= 0) ; 235 } 236 237 /** 238 * After <code>addItem</code> and <code>addItems</code> methods 239 * test the following items must exist {..., "Item1", "Item2", "Item3"} 240 * Retrieves the item from the position which was ititially the last.<p> 241 * Has <b>OK</b> status if the "Item1" was retrieved. <p> 242 * The following method tests are to be executed before : 243 * <ul> 244 * <li> <code> addItems </code> </li> 245 * </ul> 246 */ 247 public void _getItem() { 248 requiredMethod("addItems()") ; 249 250 boolean result = true ; 251 String item = oObj.getItem(itemCount) ; 252 result = "Item1".equals(item) ; 253 254 tRes.tested("getItem()", result) ; 255 } 256 257 /** 258 * After <code>addItem</code> and <code>addItems</code> methods 259 * test the following items must exist {..., "Item1", "Item2", "Item3"} 260 * Retrieves all items. <p> 261 * Has <b>OK</b> status if the last three items retrieved are 262 * "Item1", "Item2" and "Item3". <p> 263 * The following method tests are to be executed before : 264 * <ul> 265 * <li> <code> addItems </code> </li> 266 * </ul> 267 */ 268 public void _getItems() { 269 requiredMethod("addItems()") ; 270 271 boolean result = true ; 272 String[] items = oObj.getItems() ; 273 for (int i = itemCount; i < (itemCount + 3); i++) { 274 result &= ("Item" + (i+1 - itemCount)).equals(items[i]) ; 275 } 276 277 tRes.tested("getItems()", result) ; 278 } 279 280 /** 281 * Gets line count and stores it. <p> 282 * Has <b>OK</b> status if no runtime exceptions occured. 283 */ 284 public void _getDropDownLineCount() { 285 286 boolean result = true ; 287 lineCount = oObj.getDropDownLineCount() ; 288 289 tRes.tested("getDropDownLineCount()", result) ; 290 } 291 292 /** 293 * Sets a new value and then checks get value. <p> 294 * Has <b>OK</b> status if set and get values are equal. <p> 295 * The following method tests are to be completed successfully before : 296 * <ul> 297 * <li> <code> getDropDownLineCount </code> </li> 298 * </ul> 299 */ 300 public void _setDropDownLineCount() { 301 requiredMethod("getDropDownLineCount()") ; 302 303 boolean result = true ; 304 oObj.setDropDownLineCount((short)(lineCount + 1)) ; 305 result = oObj.getDropDownLineCount() == lineCount + 1 ; 306 307 tRes.tested("setDropDownLineCount()", result) ; 308 } 309 310 /** 311 * Selects some item and gets selected item position. <p> 312 * Has <b> OK </b> status if position is equal to position set. <p> 313 * The following method tests are to be completed successfully before : 314 * <ul> 315 * <li> <code> addItems </code> : to have some items </li> 316 * </ul> 317 */ 318 public void _getSelectedItemPos() { 319 requiredMethod("addItems()") ; 320 321 boolean result = true ; 322 oObj.selectItemPos((short)1, true) ; 323 short pos = oObj.getSelectedItemPos() ; 324 325 result = pos == 1 ; 326 327 tRes.tested("getSelectedItemPos()", result) ; 328 } 329 330 /** 331 * Clears all selections, then selects some items and gets selected 332 * item positions. <p> 333 * Has <b> OK </b> status if positions get are the same as were set.<p> 334 * The following method tests are to be completed successfully before : 335 * <ul> 336 * <li> <code> selectItemsPos </code> </li> 337 * </ul> 338 */ 339 public void _getSelectedItemsPos() { 340 requiredMethod("selectItemsPos()") ; 341 342 boolean result = true ; 343 short cnt = oObj.getItemCount() ; 344 for (short i = 0; i < cnt; i++) { 345 oObj.selectItemPos(i, false) ; 346 } 347 oObj.selectItemsPos(new short[] {0, 2}, true) ; 348 349 short[] items = oObj.getSelectedItemsPos() ; 350 351 result = items != null && items.length == 2 && 352 items[0] == 0 && items[1] == 2 ; 353 354 tRes.tested("getSelectedItemsPos()", result) ; 355 } 356 357 /** 358 * Unselects all items, selects some item and then gets selected item. <p> 359 * Has <b> OK </b> status if items selected and get are equal. 360 * The following method tests are to be completed successfully before : 361 * <ul> 362 * <li> <code> addItems </code> : to have some items </li> 363 * </ul> 364 */ 365 public void _getSelectedItem() { 366 requiredMethod("addItems()") ; 367 368 boolean result = true ; 369 short cnt = oObj.getItemCount() ; 370 for (short i = 0; i < cnt; i++) { 371 oObj.selectItemPos(i, false) ; 372 } 373 oObj.selectItem("Item3", true) ; 374 String item = oObj.getSelectedItem() ; 375 376 result = "Item3".equals(item) ; 377 378 tRes.tested("getSelectedItem()", result) ; 379 } 380 381 /** 382 * Clears all selections, then selects some items positions and gets 383 * selected items. <p> 384 * Has <b> OK </b> status if items get are the same as items on 385 * positions which were set.<p> 386 * The following method tests are to be completed successfully before : 387 * <ul> 388 * <li> <code> selectItemsPos </code> </li> 389 * <li> <code> getItem </code>: this method is used here for checking. 390 * </li> 391 * </ul> 392 */ 393 public void _getSelectedItems() { 394 requiredMethod("selectItemsPos()") ; 395 requiredMethod("getItem()") ; 396 397 boolean result = true ; 398 short cnt = oObj.getItemCount() ; 399 for (short i = 0; i < cnt; i++) { 400 oObj.selectItemPos(i, false) ; 401 } 402 oObj.selectItemsPos(new short[] {0, 2}, true) ; 403 404 String[] items = oObj.getSelectedItems() ; 405 result = items != null && items.length == 2 && 406 oObj.getItem((short)0).equals(items[0]) && 407 oObj.getItem((short)2).equals(items[1]) ; 408 409 tRes.tested("getSelectedItems()", result) ; 410 } 411 412 /** 413 * Unselects all items, then selects a single item. <p> 414 * Has <b> OK </b> status if no runtime exceptions occured 415 * The following method tests are to be completed successfully before : 416 * <ul> 417 * <li> <code> addItems </code> : to have some items </li> 418 * </ul> 419 */ 420 public void _selectItemPos() { 421 requiredMethod("addItems()") ; 422 423 boolean result = true ; 424 short cnt = oObj.getItemCount() ; 425 for (short i = 0; i < cnt; i++) { 426 oObj.selectItemPos(i, false) ; 427 } 428 oObj.selectItemPos((short)1, true) ; 429 430 tRes.tested("selectItemPos()", result) ; 431 } 432 433 /** 434 * Just selects some items. <p> 435 * Has <b> OK </b> status if no runtime exceptions occured 436 * The following method tests are to be completed successfully before : 437 * <ul> 438 * <li> <code> addItems </code> : to have some items </li> 439 * </ul> 440 */ 441 public void _selectItemsPos() { 442 requiredMethod("addItems()") ; 443 requiredMethod("setMultipleMode()") ; 444 445 boolean result = true ; 446 oObj.selectItemsPos(new short[] {0, 2}, true) ; 447 448 tRes.tested("selectItemsPos()", result) ; 449 } 450 451 /** 452 * Just selects an item. <p> 453 * Has <b> OK </b> status if no runtime exceptions occured 454 * The following method tests are to be completed successfully before : 455 * <ul> 456 * <li> <code> addItems </code> : to have some items </li> 457 * </ul> 458 */ 459 public void _selectItem() { 460 requiredMethod("addItems()") ; 461 462 boolean result = true ; 463 oObj.selectItem("Item3", true) ; 464 465 tRes.tested("selectItem()", result) ; 466 } 467 468 /** 469 * Checks if multiple mode is set. <p> 470 * Has <b> OK </b> status if multiple mode is set. <p> 471 * The following method tests are to be completed successfully before : 472 * <ul> 473 * <li> <code> setMultipleMode </code> </li> 474 * </ul> 475 */ 476 public void _isMutipleMode() { 477 requiredMethod("setMultipleMode()") ; 478 479 boolean result = true ; 480 result = oObj.isMutipleMode() ; 481 482 tRes.tested("isMutipleMode()", result) ; 483 } 484 485 /** 486 * Sets multiple mode. <p> 487 * Has <b> OK </b> status if no runtime exceptions occured 488 */ 489 public void _setMultipleMode() { 490 491 boolean result = true ; 492 oObj.setMultipleMode(true) ; 493 494 tRes.tested("setMultipleMode()", result) ; 495 } 496 497 /** 498 * Just calls the method to make visible third item. <p> 499 * Has <b> OK </b> status if no runtime exceptions occured.<p> 500 * The following method tests are to be completed successfully before : 501 * <ul> 502 * <li> <code> addItems </code> </li> 503 * </ul> 504 */ 505 public void _makeVisible() { 506 requiredMethod("addItems()") ; 507 508 boolean result = true ; 509 oObj.makeVisible((short)2) ; 510 511 tRes.tested("makeVisible()", result) ; 512 } 513 }