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