[cvs] / jsr166 / src / test / tck / ArrayDeque8Test.java Repository:
ViewVC logotype

Annotation of /jsr166/src/test/tck/ArrayDeque8Test.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (view) (download)

1 : jsr166 1.1 /*
2 :     * Written by Doug Lea and Martin Buchholz with assistance from
3 :     * members of JCP JSR-166 Expert Group and released to the public
4 :     * domain, as explained at
5 :     * http://creativecommons.org/publicdomain/zero/1.0/
6 :     */
7 :    
8 :     import java.util.ArrayDeque;
9 :     import java.util.Collections;
10 :     import java.util.Spliterator;
11 :    
12 :     import junit.framework.Test;
13 :     import junit.framework.TestSuite;
14 :    
15 :     public class ArrayDeque8Test extends JSR166TestCase {
16 :     public static void main(String[] args) {
17 :     main(suite(), args);
18 :     }
19 :    
20 :     public static Test suite() {
21 :     return newTestSuite(ArrayDeque8Test.class);
22 :     }
23 :    
24 :     /**
25 :     * Spliterator.getComparator always throws IllegalStateException
26 :     */
27 :     public void testSpliterator_getComparator() {
28 :     assertThrows(IllegalStateException.class,
29 :     () -> new ArrayDeque().spliterator().getComparator());
30 :     }
31 :    
32 :     /**
33 :     * Spliterator characteristics are as advertised
34 :     */
35 :     public void testSpliterator_characteristics() {
36 :     ArrayDeque q = new ArrayDeque();
37 :     Spliterator s = q.spliterator();
38 :     int characteristics = s.characteristics();
39 :     int required = Spliterator.NONNULL
40 :     | Spliterator.ORDERED
41 :     | Spliterator.SIZED
42 :     | Spliterator.SUBSIZED;
43 :     assertEquals(required, characteristics & required);
44 :     assertTrue(s.hasCharacteristics(required));
45 :     assertEquals(0, characteristics
46 :     & (Spliterator.CONCURRENT
47 :     | Spliterator.DISTINCT
48 :     | Spliterator.IMMUTABLE
49 :     | Spliterator.SORTED));
50 :     }
51 :    
52 :     /**
53 :     * Handle capacities near Integer.MAX_VALUE.
54 : jsr166 1.2 * ant -Dvmoptions='-Xms28g -Xmx28g' -Djsr166.expensiveTests=true -Djsr166.tckTestClass=ArrayDeque8Test -Djsr166.methodFilter=testHugeCapacity tck
55 : jsr166 1.1 */
56 : jsr166 1.2 public void testHugeCapacity() {
57 : jsr166 1.1 if (! (testImplementationDetails
58 :     && expensiveTests
59 :     && Runtime.getRuntime().maxMemory() > 24L * (1 << 30)))
60 :     return;
61 :    
62 : jsr166 1.2 final Integer e = 42;
63 :     final int maxArraySize = Integer.MAX_VALUE - 8;
64 : jsr166 1.1
65 :     assertThrows(OutOfMemoryError.class,
66 : jsr166 1.2 () -> new ArrayDeque(Integer.MAX_VALUE));
67 : jsr166 1.1
68 :     {
69 : jsr166 1.2 ArrayDeque q = new ArrayDeque(maxArraySize - 1);
70 : jsr166 1.1 assertEquals(0, q.size());
71 :     assertTrue(q.isEmpty());
72 :     q = null;
73 :     }
74 :    
75 :     {
76 : jsr166 1.2 ArrayDeque q = new ArrayDeque();
77 :     assertTrue(q.addAll(Collections.nCopies(maxArraySize - 3, e)));
78 : jsr166 1.1 assertEquals(e, q.peekFirst());
79 :     assertEquals(e, q.peekLast());
80 : jsr166 1.2 assertEquals(maxArraySize - 3, q.size());
81 : jsr166 1.1 q.addFirst((Integer) 0);
82 :     q.addLast((Integer) 1);
83 :     assertEquals((Integer) 0, q.peekFirst());
84 :     assertEquals((Integer) 1, q.peekLast());
85 : jsr166 1.2 assertEquals(maxArraySize - 1, q.size());
86 : jsr166 1.1
87 :     ArrayDeque qq = q;
88 :     ArrayDeque smallish = new ArrayDeque(
89 : jsr166 1.2 Collections.nCopies(Integer.MAX_VALUE - q.size() + 1, e));
90 : jsr166 1.1 assertThrows(
91 :     IllegalStateException.class,
92 :     () -> qq.addAll(qq),
93 :     () -> qq.addAll(smallish),
94 :     () -> smallish.addAll(qq));
95 :     }
96 :     }
97 :    
98 :     }

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8