| 1 |
/* |
| 2 |
* This file is part of the LibreOffice project. |
| 3 |
* |
| 4 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 5 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 6 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 7 |
* |
| 8 |
* This file incorporates work covered by the following license notice: |
| 9 |
* |
| 10 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 11 |
* contributor license agreements. See the NOTICE file distributed |
| 12 |
* with this work for additional information regarding copyright |
| 13 |
* ownership. The ASF licenses this file to you under the Apache |
| 14 |
* License, Version 2.0 (the "License"); you may not use this file |
| 15 |
* except in compliance with the License. You may obtain a copy of |
| 16 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 17 |
*/ |
| 18 |
|
| 19 |
package com.sun.star.lib.uno.helper; |
| 20 |
|
| 21 |
import com.sun.star.uno.XWeak; |
| 22 |
import com.sun.star.lang.XTypeProvider; |
| 23 |
import com.sun.star.lib.uno.environments.java.java_environment; |
| 24 |
|
| 25 |
import java.util.ArrayList; |
| 26 |
import java.util.Iterator; |
| 27 |
import java.util.List; |
| 28 |
import java.util.ListIterator; |
| 29 |
import java.util.NoSuchElementException; |
| 30 |
|
| 31 |
import java.util.logging.Level; |
| 32 |
import java.util.logging.Logger; |
| 33 |
|
| 34 |
import static org.junit.Assert.assertArrayEquals; |
| 35 |
import static org.junit.Assert.assertEquals; |
| 36 |
import static org.junit.Assert.assertFalse; |
| 37 |
import static org.junit.Assert.assertNotNull; |
| 38 |
import static org.junit.Assert.assertSame; |
| 39 |
import static org.junit.Assert.assertTrue; |
| 40 |
import static org.junit.Assert.fail; |
| 41 |
import org.junit.Before; |
| 42 |
import org.junit.Test; |
| 43 |
|
| 44 |
public class InterfaceContainer_Test |
| 45 |
{ |
| 46 |
private static final Logger logger = Logger.getLogger(InterfaceContainer_Test.class.getName()); |
| 47 |
java_environment env= new java_environment(null); |
| 48 |
/** Creates a new instance of InterfaceContainerTest */ |
| 49 |
AWeakBase obj1,obj2,obj3,obj4; |
| 50 |
Object proxyObj1Weak1; |
| 51 |
Object proxyObj3Weak1; |
| 52 |
Object proxyObj3Weak2; |
| 53 |
Object proxyObj3TypeProv; |
| 54 |
Object proxyObj2TypeProv; |
| 55 |
//contains original objects |
| 56 |
List<Object> list1; |
| 57 |
//contains original objects + proxies |
| 58 |
List<Object> list2; |
| 59 |
//contains original object + proxies + null value |
| 60 |
List<Object> list3; |
| 61 |
|
| 62 |
/** Class variables are initialized before each Test method */ |
| 63 |
@Before public void setUp() throws Exception |
| 64 |
{ |
| 65 |
obj1= new AWeakBase(); |
| 66 |
obj2= new AWeakBase(); |
| 67 |
obj3= new AWeakBase(); |
| 68 |
obj4= new AWeakBase(); |
| 69 |
|
| 70 |
proxyObj1Weak1= ProxyProvider.createProxy(obj1, XWeak.class); |
| 71 |
proxyObj3Weak1= ProxyProvider.createProxy(obj3, XWeak.class); |
| 72 |
proxyObj3Weak2= ProxyProvider.createProxy(obj3, XWeak.class); |
| 73 |
assertNotNull(proxyObj1Weak1); |
| 74 |
assertNotNull(proxyObj3Weak1); |
| 75 |
assertNotNull(proxyObj3Weak2); |
| 76 |
|
| 77 |
proxyObj2TypeProv= ProxyProvider.createProxy(obj2, XTypeProvider.class); |
| 78 |
proxyObj3TypeProv= ProxyProvider.createProxy(obj3, XTypeProvider.class); |
| 79 |
assertNotNull(proxyObj2TypeProv); |
| 80 |
assertNotNull(proxyObj3TypeProv); |
| 81 |
|
| 82 |
list1= new ArrayList<Object>(); |
| 83 |
list1.add(obj1); |
| 84 |
list1.add(obj2); |
| 85 |
list1.add(obj3); |
| 86 |
|
| 87 |
list2= new ArrayList<Object>(); |
| 88 |
list2.add(obj1); |
| 89 |
list2.add(proxyObj2TypeProv); |
| 90 |
list2.add(proxyObj3TypeProv); |
| 91 |
|
| 92 |
list3= new ArrayList<Object>(); |
| 93 |
list3.add(obj1); |
| 94 |
list3.add(null); |
| 95 |
list3.add(proxyObj2TypeProv); |
| 96 |
list3.add(proxyObj3Weak1); |
| 97 |
} |
| 98 |
|
| 99 |
/** Tests add(object), size(), clear(); |
| 100 |
*/ |
| 101 |
@Test public void add() throws Exception |
| 102 |
{ |
| 103 |
logger.log(Level.INFO, "Testing List.add(Object), List.size(), List.clear(), List.isEmpty()"); |
| 104 |
InterfaceContainer cont= new InterfaceContainer(); |
| 105 |
|
| 106 |
assertEquals(cont.size(), 0); |
| 107 |
|
| 108 |
assertTrue(cont.add(obj1)); |
| 109 |
assertEquals(cont.size(), 1); |
| 110 |
|
| 111 |
assertTrue(cont.add(obj1)); // add the same object again |
| 112 |
assertEquals(cont.size(), 2); |
| 113 |
|
| 114 |
assertTrue(cont.add(proxyObj3TypeProv)); |
| 115 |
assertEquals(cont.size(), 3); |
| 116 |
|
| 117 |
assertFalse(cont.isEmpty()); |
| 118 |
cont.clear(); |
| 119 |
assertEquals(cont.size(), 0); |
| 120 |
assertTrue(cont.isEmpty()); |
| 121 |
} |
| 122 |
|
| 123 |
/**Tests list.addAll(Collection c), list.addAll(int index, Collection c) |
| 124 |
*/ |
| 125 |
@Test public void listConstructors() throws Exception |
| 126 |
{ |
| 127 |
logger.log(Level.INFO, "Testing Constructors of InterfaceContainer"); |
| 128 |
InterfaceContainer cont= new InterfaceContainer(100); |
| 129 |
|
| 130 |
assertEquals(cont.elementData.length, 100); |
| 131 |
} |
| 132 |
|
| 133 |
@Test public void trimToSize() throws Exception |
| 134 |
{ |
| 135 |
logger.log(Level.INFO, "Testing InterfaceContainer.trimToSize"); |
| 136 |
InterfaceContainer cont= new InterfaceContainer(100); |
| 137 |
|
| 138 |
cont.trimToSize(); |
| 139 |
assertTrue(cont.isEmpty()); |
| 140 |
cont= new InterfaceContainer(10); |
| 141 |
cont.addAll(list1); |
| 142 |
cont.trimToSize(); |
| 143 |
assertEquals(cont.elementData.length, list1.size()); |
| 144 |
} |
| 145 |
|
| 146 |
@Test public void ensureCapacity() throws Exception |
| 147 |
{ |
| 148 |
logger.log(Level.INFO, "Testing InterfaceContainer.ensureCapacity"); |
| 149 |
InterfaceContainer cont= new InterfaceContainer(10); |
| 150 |
|
| 151 |
cont.ensureCapacity(9); |
| 152 |
assertTrue(cont.elementData.length >= 9); |
| 153 |
|
| 154 |
cont.ensureCapacity(11); |
| 155 |
assertTrue(cont.elementData.length >= 11); |
| 156 |
} |
| 157 |
|
| 158 |
@Test public void addAll() throws Exception |
| 159 |
{ |
| 160 |
logger.log(Level.INFO, "Testing List.addAll(Collection c), List.addAll(int index, Collection c)"); |
| 161 |
InterfaceContainer cont= new InterfaceContainer(); |
| 162 |
|
| 163 |
assertTrue(cont.addAll(list1)); |
| 164 |
assertEquals(cont.size(), list1.size()); |
| 165 |
for (int c= 0; c < cont.size(); c++) |
| 166 |
{ |
| 167 |
assertSame(list1.get(c), cont.get(c)); |
| 168 |
} |
| 169 |
assertTrue(cont.add(obj1)); |
| 170 |
assertTrue(cont.addAll(1, list2)); |
| 171 |
assertSame(cont.get(0), list1.get(0)); |
| 172 |
assertSame(cont.get(1), list2.get(0)); |
| 173 |
assertSame(cont.get(2), list2.get(1)); |
| 174 |
assertSame(cont.get(3), list2.get(2)); |
| 175 |
assertSame(cont.get(4), list1.get(1)); |
| 176 |
assertSame(cont.get(5), list1.get(2)); |
| 177 |
assertSame(cont.get(6), obj1); |
| 178 |
|
| 179 |
cont.clear(); |
| 180 |
cont.addAll(list3); |
| 181 |
// the null element in list3 at index 1 is not added to cont |
| 182 |
assertSame(cont.get(0), list3.get(0)); |
| 183 |
assertSame(cont.get(1), list3.get(2)); |
| 184 |
assertSame(cont.get(2), list3.get(3)); |
| 185 |
} |
| 186 |
|
| 187 |
/** Tests List.add(int index, Object element), List.get(int index) |
| 188 |
*/ |
| 189 |
@Test public void get() throws Exception |
| 190 |
{ |
| 191 |
logger.log(Level.INFO, "Testing List.add(int index, Object element), List.get(int index)"); |
| 192 |
InterfaceContainer cont= new InterfaceContainer(); |
| 193 |
|
| 194 |
cont.add(0, obj1); |
| 195 |
cont.add(1, obj2); |
| 196 |
cont.add(1, proxyObj3Weak1); |
| 197 |
cont.add(3, obj3); |
| 198 |
|
| 199 |
assertSame(cont.get(0), obj1); |
| 200 |
assertSame(cont.get(1), proxyObj3Weak1); |
| 201 |
assertSame(cont.get(2), obj2); |
| 202 |
assertSame(cont.get(3), obj3); |
| 203 |
|
| 204 |
try { |
| 205 |
cont.add(5, obj1); |
| 206 |
fail("IndexOutOfBoundsException expected"); |
| 207 |
} catch (IndexOutOfBoundsException indexOutOfBoundsException) { |
| 208 |
logger.log(Level.FINE, "IndexOutOfBoundsException caught"); |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
/** Tests List.contains |
| 213 |
*/ |
| 214 |
@Test public void contains() throws Exception |
| 215 |
{ |
| 216 |
logger.log(Level.INFO, "Testing List.contains()"); |
| 217 |
InterfaceContainer cont= new InterfaceContainer(); |
| 218 |
|
| 219 |
assertFalse(cont.contains(obj1)); // nothing in the list |
| 220 |
|
| 221 |
cont.add(obj1); |
| 222 |
cont.add(proxyObj2TypeProv); |
| 223 |
cont.add(proxyObj3TypeProv); |
| 224 |
|
| 225 |
assertTrue(cont.contains(obj1)); |
| 226 |
assertTrue(cont.contains(obj2)); |
| 227 |
assertTrue(cont.contains(proxyObj3Weak1)); |
| 228 |
assertTrue(cont.contains(proxyObj3Weak2)); |
| 229 |
assertTrue(cont.contains(proxyObj1Weak1)); |
| 230 |
assertTrue(cont.contains(obj3)); |
| 231 |
assertFalse(cont.contains(null)); |
| 232 |
} |
| 233 |
|
| 234 |
/** Tests List.containsAll |
| 235 |
*/ |
| 236 |
@Test public void containsAll() throws Exception |
| 237 |
{ |
| 238 |
logger.log(Level.INFO, "Testing List.containsAll"); |
| 239 |
InterfaceContainer cont= new InterfaceContainer(); |
| 240 |
|
| 241 |
cont.addAll(list1); |
| 242 |
assertTrue(cont.containsAll(list1)); |
| 243 |
|
| 244 |
cont.clear(); |
| 245 |
cont.addAll(list2); |
| 246 |
assertTrue(cont.containsAll(list2)); |
| 247 |
|
| 248 |
cont.clear(); |
| 249 |
cont.addAll(list3); // the null element in list3 is not added to cont |
| 250 |
assertFalse(cont.containsAll(list3)); |
| 251 |
|
| 252 |
cont.clear(); |
| 253 |
for( int x= 0; x < 6; x++) |
| 254 |
cont.add(obj4); |
| 255 |
assertFalse(cont.contains(list1)); |
| 256 |
|
| 257 |
cont.add(1, list1.get(0)); |
| 258 |
cont.add(3, list1.get(1)); |
| 259 |
cont.add(5, list1.get(2)); |
| 260 |
assertFalse(cont.contains(list1)); |
| 261 |
} |
| 262 |
/** Tests List.indexOf, List.lastIndexOf |
| 263 |
*/ |
| 264 |
@Test public void indexOf() throws Exception |
| 265 |
{ |
| 266 |
logger.log(Level.INFO, "Testing List.indexOf(Object element), List.lastIndexOf(Object element)"); |
| 267 |
InterfaceContainer cont= new InterfaceContainer(); |
| 268 |
|
| 269 |
cont.addAll(list1); |
| 270 |
cont.addAll(list1); |
| 271 |
assertEquals(cont.indexOf(obj3), 2); |
| 272 |
assertEquals(cont.lastIndexOf(obj3), 5); |
| 273 |
|
| 274 |
cont.clear(); |
| 275 |
cont.addAll(list2); |
| 276 |
cont.addAll(list2); |
| 277 |
assertEquals(cont.indexOf(proxyObj3Weak1), 2); |
| 278 |
assertEquals(cont.lastIndexOf(proxyObj3Weak2), 5); |
| 279 |
} |
| 280 |
|
| 281 |
/** Tests List.remove(int index), List.remove(Object element), List.removeAll(Collection c) |
| 282 |
*/ |
| 283 |
@Test public void remove() throws Exception |
| 284 |
{ |
| 285 |
logger.log(Level.INFO, "Testing List.remove(int index), List.remove(Object element), List.removeAll(Collection c)"); |
| 286 |
InterfaceContainer cont= new InterfaceContainer(); |
| 287 |
|
| 288 |
cont.addAll(list2); |
| 289 |
assertTrue(proxyObj2TypeProv.equals(cont.remove(1))); |
| 290 |
assertEquals(cont.size(), 2); |
| 291 |
|
| 292 |
cont.clear(); |
| 293 |
cont.addAll(list2); |
| 294 |
assertTrue(cont.remove(obj1)); |
| 295 |
assertTrue(cont.remove(proxyObj2TypeProv)); |
| 296 |
assertTrue(cont.remove(proxyObj3Weak2)); |
| 297 |
assertTrue(cont.isEmpty()); |
| 298 |
|
| 299 |
cont.clear(); |
| 300 |
cont.addAll(list3); |
| 301 |
assertTrue(cont.removeAll(list3)); |
| 302 |
assertTrue(cont.isEmpty()); |
| 303 |
|
| 304 |
cont.addAll(list2); |
| 305 |
List<Object> list= new ArrayList<Object>(); |
| 306 |
list.add(list2.get(0)); |
| 307 |
list.add(list2.get(1)); |
| 308 |
list.add(proxyObj3Weak2); |
| 309 |
assertTrue(cont.removeAll(list)); |
| 310 |
assertTrue(cont.isEmpty()); |
| 311 |
} |
| 312 |
|
| 313 |
/** Tests List.retainAll |
| 314 |
*/ |
| 315 |
@Test public void retainAll() throws Exception |
| 316 |
{ |
| 317 |
logger.log(Level.INFO, "Testing List.retainAll(Collection c)"); |
| 318 |
InterfaceContainer cont= new InterfaceContainer(); |
| 319 |
|
| 320 |
cont.addAll(list1); //obj1, obj2, obj3 |
| 321 |
cont.addAll(list2); //obj1, proxyObj2TypeProv, proxyObj3TypeProv |
| 322 |
List<Object> list = new ArrayList<Object>(); |
| 323 |
list.add(obj1); |
| 324 |
list.add(proxyObj3Weak1); |
| 325 |
|
| 326 |
assertTrue(cont.retainAll(list)); |
| 327 |
assertSame(cont.get(0), obj1); |
| 328 |
assertSame(cont.get(1), obj3); |
| 329 |
assertSame(cont.get(2), obj1); |
| 330 |
assertSame(cont.get(3), proxyObj3TypeProv); |
| 331 |
assertEquals(cont.size(), 4); |
| 332 |
} |
| 333 |
|
| 334 |
/** Tests List.set(int index, Object element) |
| 335 |
**/ |
| 336 |
@Test public void set() throws Exception |
| 337 |
{ |
| 338 |
logger.log(Level.INFO, "Testing List.set(int index, Object element)"); |
| 339 |
InterfaceContainer cont= new InterfaceContainer(); |
| 340 |
|
| 341 |
cont.addAll(list2); |
| 342 |
Object o1= cont.set(0, obj3); |
| 343 |
Object o2= cont.set(2, proxyObj3Weak1); |
| 344 |
|
| 345 |
assertSame(list2.get(0), o1); |
| 346 |
assertSame(list2.get(2), o2); |
| 347 |
assertSame(cont.get(0), obj3); |
| 348 |
assertSame(cont.get(2), proxyObj3Weak1); |
| 349 |
} |
| 350 |
|
| 351 |
/** Tests List.toArray(), List.toArray(Object[] a) |
| 352 |
*/ |
| 353 |
@Test public void toArray() throws Exception |
| 354 |
{ |
| 355 |
logger.log(Level.INFO, "Testing List.toArray(), List.toArray(Object[] a)"); |
| 356 |
InterfaceContainer cont= new InterfaceContainer(); |
| 357 |
|
| 358 |
cont.addAll(list1); |
| 359 |
Object[] ar= cont.toArray(); |
| 360 |
Object[] arOrig= list1.toArray(); |
| 361 |
assertEquals(ar.length, arOrig.length); |
| 362 |
assertArrayEquals(ar, arOrig); |
| 363 |
|
| 364 |
XWeak[] arWeak= new XWeak[3]; |
| 365 |
XWeak[] arWeak2= (XWeak[])cont.toArray(arWeak); |
| 366 |
assertEquals(ar.length, arWeak2.length); |
| 367 |
assertArrayEquals(ar, arWeak2); |
| 368 |
} |
| 369 |
|
| 370 |
@Test public void Iterator_next() throws Exception |
| 371 |
{ |
| 372 |
logger.log(Level.INFO, "Testing InterfaceContainer.iterator, Iterator.next()"); |
| 373 |
InterfaceContainer cont= new InterfaceContainer(); |
| 374 |
|
| 375 |
cont.addAll(list1); |
| 376 |
Iterator it= cont.iterator(); |
| 377 |
assertSame(it.next(), list1.get(0)); |
| 378 |
assertSame(it.next(), list1.get(1)); |
| 379 |
assertSame(it.next(), list1.get(2)); |
| 380 |
|
| 381 |
try { |
| 382 |
it.next(); |
| 383 |
fail("NoSuchElementException expected"); |
| 384 |
} catch (NoSuchElementException noSuchElementException) { |
| 385 |
logger.log(Level.FINE, "NoSuchElementException caught"); |
| 386 |
} |
| 387 |
} |
| 388 |
|
| 389 |
@Test public void Iterator_hasNext() throws Exception |
| 390 |
{ |
| 391 |
logger.log(Level.INFO, "Testing, Iterator.next()"); |
| 392 |
InterfaceContainer cont= new InterfaceContainer(); |
| 393 |
|
| 394 |
Iterator it= cont.iterator(); |
| 395 |
assertFalse(it.hasNext()); |
| 396 |
|
| 397 |
cont.addAll(list1); |
| 398 |
it= cont.iterator(); |
| 399 |
assertTrue(it.hasNext()); |
| 400 |
|
| 401 |
it.next(); |
| 402 |
assertTrue(it.hasNext()); |
| 403 |
|
| 404 |
it.next(); |
| 405 |
assertTrue(it.hasNext()); |
| 406 |
|
| 407 |
it.next(); |
| 408 |
assertFalse(it.hasNext()); |
| 409 |
} |
| 410 |
|
| 411 |
@Test public void Iterator_remove() throws Exception |
| 412 |
{ |
| 413 |
logger.log(Level.INFO, "Testing, Iterator.remove()"); |
| 414 |
InterfaceContainer cont= new InterfaceContainer(); |
| 415 |
|
| 416 |
Iterator it= cont.iterator(); |
| 417 |
try { |
| 418 |
it.remove(); |
| 419 |
fail("IllegalStateException expected"); |
| 420 |
} catch (IllegalStateException illegalStateException) { |
| 421 |
logger.log(Level.FINE, "IllegalStateException caught"); |
| 422 |
} |
| 423 |
|
| 424 |
cont.add(obj1); |
| 425 |
it= cont.iterator(); |
| 426 |
it.next(); |
| 427 |
it.remove(); |
| 428 |
assertTrue(cont.isEmpty()); |
| 429 |
try { |
| 430 |
it.remove(); |
| 431 |
fail("IllegalStateException expected"); |
| 432 |
} catch (IllegalStateException illegalStateException) { |
| 433 |
logger.log(Level.FINE, "IllegalStateException caught"); |
| 434 |
} |
| 435 |
|
| 436 |
cont.clear(); |
| 437 |
cont.addAll(list1); |
| 438 |
it= cont.iterator(); |
| 439 |
while (it.hasNext()) |
| 440 |
{ |
| 441 |
it.next(); |
| 442 |
it.remove(); |
| 443 |
} |
| 444 |
assertTrue(cont.isEmpty()); |
| 445 |
|
| 446 |
// 2 iterators, remove must not impair the other iterator |
| 447 |
cont.clear(); |
| 448 |
cont.addAll(list1); |
| 449 |
int size= cont.size(); |
| 450 |
it= cont.iterator(); |
| 451 |
Iterator it2= cont.iterator(); |
| 452 |
while (it.hasNext()) |
| 453 |
{ |
| 454 |
it.next(); |
| 455 |
it.remove(); |
| 456 |
} |
| 457 |
for( int c= 0; c < size; c++) |
| 458 |
it2.next(); |
| 459 |
assertEquals(cont.size(), 0); |
| 460 |
} |
| 461 |
|
| 462 |
@Test public void ListIterator_next() throws Exception |
| 463 |
{ |
| 464 |
logger.log(Level.INFO, "Testing InterfaceContainer.listIterator, ListIterator.next()"); |
| 465 |
InterfaceContainer cont= new InterfaceContainer(); |
| 466 |
|
| 467 |
cont.addAll(list1); |
| 468 |
Iterator it= cont.listIterator(); |
| 469 |
assertSame(it.next(), list1.get(0)); |
| 470 |
assertSame(it.next(), list1.get(1)); |
| 471 |
assertSame(it.next(), list1.get(2)); |
| 472 |
try { |
| 473 |
it.next(); |
| 474 |
fail("NoSuchElementException expected"); |
| 475 |
} catch (NoSuchElementException noSuchElementException) { |
| 476 |
logger.log(Level.FINE, "NoSuchElementException caught"); |
| 477 |
} |
| 478 |
} |
| 479 |
|
| 480 |
@Test public void ListIterator_hasNext() throws Exception |
| 481 |
{ |
| 482 |
logger.log(Level.INFO, "Testing ListIterator.hasNext()"); |
| 483 |
InterfaceContainer cont= new InterfaceContainer(); |
| 484 |
|
| 485 |
Iterator it= cont.listIterator(); |
| 486 |
assertFalse(it.hasNext()); |
| 487 |
|
| 488 |
cont.addAll(list1); |
| 489 |
it= cont.listIterator(); |
| 490 |
assertTrue(it.hasNext()); |
| 491 |
it.next(); |
| 492 |
assertTrue(it.hasNext()); |
| 493 |
it.next(); |
| 494 |
assertTrue(it.hasNext()); |
| 495 |
it.next(); |
| 496 |
assertFalse(it.hasNext()); |
| 497 |
} |
| 498 |
|
| 499 |
@Test public void ListIterator_remove() throws Exception |
| 500 |
{ |
| 501 |
logger.log(Level.INFO, "Testing ListIterator.remove()"); |
| 502 |
InterfaceContainer cont= new InterfaceContainer(); |
| 503 |
|
| 504 |
ListIterator it= cont.listIterator(); |
| 505 |
try { |
| 506 |
it.remove(); |
| 507 |
fail("IllegalStateException expected"); |
| 508 |
} catch (IllegalStateException illegalStateException) { |
| 509 |
logger.log(Level.FINE, "IllegalStateException caught"); |
| 510 |
} |
| 511 |
|
| 512 |
cont.add(obj1); |
| 513 |
it= cont.listIterator(); |
| 514 |
it.next(); |
| 515 |
it.remove(); |
| 516 |
assertTrue(cont.isEmpty()); |
| 517 |
try { |
| 518 |
it.remove(); |
| 519 |
fail("IllegalStateException expected"); |
| 520 |
} catch (IllegalStateException illegalStateException) { |
| 521 |
logger.log(Level.FINE, "IllegalStateException caught"); |
| 522 |
} |
| 523 |
|
| 524 |
cont.clear(); |
| 525 |
cont.addAll(list1); |
| 526 |
it= cont.listIterator(); |
| 527 |
while (it.hasNext()) |
| 528 |
{ |
| 529 |
it.next(); |
| 530 |
it.remove(); |
| 531 |
} |
| 532 |
assertTrue(cont.isEmpty()); |
| 533 |
|
| 534 |
// 2 iterators, remove must not impair the other iterator |
| 535 |
cont.clear(); |
| 536 |
cont.addAll(list1); |
| 537 |
int size= cont.size(); |
| 538 |
it= cont.listIterator(); |
| 539 |
Iterator it2= cont.listIterator(); |
| 540 |
while (it.hasNext()) |
| 541 |
{ |
| 542 |
it.next(); |
| 543 |
it.remove(); |
| 544 |
} |
| 545 |
for( int c= 0; c < size; c++) |
| 546 |
it2.next(); |
| 547 |
assertEquals(cont.size(), 0); |
| 548 |
} |
| 549 |
|
| 550 |
@Test public void ListIterator_hasPrevious() throws Exception |
| 551 |
{ |
| 552 |
logger.log(Level.INFO, "Testing ListIterator.hasPrevious()"); |
| 553 |
InterfaceContainer cont= new InterfaceContainer(); |
| 554 |
|
| 555 |
ListIterator it= cont.listIterator(); |
| 556 |
assertFalse(it.hasPrevious()); |
| 557 |
cont.addAll(list1); |
| 558 |
it= cont.listIterator(); |
| 559 |
while (it.hasNext()) |
| 560 |
{ |
| 561 |
it.next(); |
| 562 |
assertTrue(it.hasPrevious()); |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
@Test public void ListIterator_previous() throws Exception |
| 567 |
{ |
| 568 |
logger.log(Level.INFO, "Testing ListIterator.previous()"); |
| 569 |
InterfaceContainer cont= new InterfaceContainer(); |
| 570 |
|
| 571 |
cont.addAll(list1); |
| 572 |
// go to the end of our list and list1 |
| 573 |
ListIterator it= cont.listIterator(); |
| 574 |
while (it.hasNext()) { |
| 575 |
it.next(); |
| 576 |
} |
| 577 |
ListIterator it_list1= list1.listIterator(); |
| 578 |
while (it_list1.hasNext()) { |
| 579 |
it_list1.next(); |
| 580 |
} |
| 581 |
|
| 582 |
while (it.hasPrevious()) |
| 583 |
{ |
| 584 |
assertSame(it.previous(), it_list1.previous()); |
| 585 |
} |
| 586 |
try { |
| 587 |
it.previous(); |
| 588 |
fail("NoSuchElementException expected"); |
| 589 |
} catch (NoSuchElementException noSuchElementException) { |
| 590 |
logger.log(Level.FINE, "NoSuchElementException caught"); |
| 591 |
} |
| 592 |
} |
| 593 |
|
| 594 |
@Test public void ListIterator_nextIndex() throws Exception |
| 595 |
{ |
| 596 |
logger.log(Level.INFO, "Testing ListIterator.nextIndex()"); |
| 597 |
InterfaceContainer cont= new InterfaceContainer(); |
| 598 |
|
| 599 |
ListIterator it; |
| 600 |
cont.addAll(list1); |
| 601 |
it= cont.listIterator(); |
| 602 |
assertEquals(it.nextIndex(), 0); |
| 603 |
it.next(); |
| 604 |
assertEquals(it.nextIndex(), 1); |
| 605 |
it.next(); |
| 606 |
assertEquals(it.nextIndex(), 2); |
| 607 |
} |
| 608 |
|
| 609 |
@Test public void ListIterator_previousIndex() throws Exception |
| 610 |
{ |
| 611 |
logger.log(Level.INFO, "Testing ListIterator.previousIndex()"); |
| 612 |
InterfaceContainer cont= new InterfaceContainer(); |
| 613 |
|
| 614 |
ListIterator it; |
| 615 |
cont.addAll(list1); |
| 616 |
it= cont.listIterator(); |
| 617 |
while (it.hasNext()) { |
| 618 |
it.next(); |
| 619 |
} |
| 620 |
|
| 621 |
assertEquals(it.previousIndex(), 2); |
| 622 |
it.previous(); |
| 623 |
assertEquals(it.previousIndex(), 1); |
| 624 |
it.previous(); |
| 625 |
assertEquals(it.previousIndex(), 0); |
| 626 |
it.previous(); |
| 627 |
} |
| 628 |
|
| 629 |
@SuppressWarnings("unchecked") |
| 630 |
@Test public void ListIterator_add() throws Exception |
| 631 |
{ |
| 632 |
logger.log(Level.INFO, "Testing ListIterator.add()"); |
| 633 |
InterfaceContainer cont= new InterfaceContainer(); |
| 634 |
|
| 635 |
ListIterator it= cont.listIterator(); |
| 636 |
it.add(obj1); |
| 637 |
assertEquals(cont.size(), 1); |
| 638 |
it.add(obj2); |
| 639 |
assertEquals(cont.size(), 2); |
| 640 |
it.add(obj3); |
| 641 |
assertSame(it.previous(), obj3); |
| 642 |
assertSame(it.previous(), obj2); |
| 643 |
assertSame(it.previous(), obj1); |
| 644 |
} |
| 645 |
|
| 646 |
@Test public void disposeAndClear() throws Exception |
| 647 |
{ |
| 648 |
logger.log(Level.INFO, "Testing InterfaceContainer.disposeAndClear"); |
| 649 |
InterfaceContainer cont= new InterfaceContainer(10); |
| 650 |
|
| 651 |
cont.add(obj1); |
| 652 |
cont.add(obj2); |
| 653 |
cont.add(obj3); |
| 654 |
cont.add(proxyObj1Weak1); |
| 655 |
cont.add(proxyObj3TypeProv); |
| 656 |
logger.log(Level.FINE, "Two proxies are called. Check the output:"); |
| 657 |
cont.disposeAndClear(new com.sun.star.lang.EventObject()); |
| 658 |
assertEquals(obj1.nDisposingCalled, 1); |
| 659 |
assertEquals(obj2.nDisposingCalled, 1); |
| 660 |
assertEquals(obj3.nDisposingCalled, 1); |
| 661 |
} |
| 662 |
} |