ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ArrayBlockingQueueTest.java
(Generate patch)

Comparing jsr166/src/test/tck/ArrayBlockingQueueTest.java (file contents):
Revision 1.5 by dl, Thu Sep 25 11:02:41 2003 UTC vs.
Revision 1.7 by dl, Sat Dec 27 19:26:42 2003 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
2 > * Written by Doug Lea with assistance from members of JCP JSR-166
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/licenses/publicdomain
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9  
# Line 162 | Line 163 | public class ArrayBlockingQueueTest exte
163      }
164  
165      /**
166 +     *  add(null) throws NPE
167 +     */
168 +    public void testAddNull() {
169 +        try {
170 +            ArrayBlockingQueue q = new ArrayBlockingQueue(1);
171 +            q.add(null);
172 +            shouldThrow();
173 +        } catch (NullPointerException success) { }  
174 +    }
175 +
176 +    /**
177       * Offer succeeds if not full; fails if full
178       */
179      public void testOffer() {
# Line 196 | Line 208 | public class ArrayBlockingQueueTest exte
208          }
209          catch (NullPointerException success) {}
210      }
211 +
212 +    /**
213 +     * addAll(this) throws IAE
214 +     */
215 +    public void testAddAllSelf() {
216 +        try {
217 +            ArrayBlockingQueue q = populatedQueue(SIZE);
218 +            q.addAll(q);
219 +            shouldThrow();
220 +        }
221 +        catch (IllegalArgumentException success) {}
222 +    }
223 +
224 +
225      /**
226       *  addAll of a collection with null elements throws NPE
227       */
# Line 705 | Line 731 | public class ArrayBlockingQueueTest exte
731              unexpectedException();
732          }    
733      }
734 +
735 +    /**
736 +     * toArray(null) throws NPE
737 +     */
738 +    public void testToArray_BadArg() {
739 +        try {
740 +            ArrayBlockingQueue q = populatedQueue(SIZE);
741 +            Object o[] = q.toArray(null);
742 +            shouldThrow();
743 +        } catch(NullPointerException success){}
744 +    }
745 +
746 +    /**
747 +     * toArray with incompatable array type throws CCE
748 +     */
749 +    public void testToArray1_BadArg() {
750 +        try {
751 +            ArrayBlockingQueue q = populatedQueue(SIZE);
752 +            Object o[] = q.toArray(new String[10] );
753 +            shouldThrow();
754 +        } catch(ArrayStoreException  success){}
755 +    }
756 +
757      
758      /**
759       * iterator iterates through all elements
# Line 886 | Line 935 | public class ArrayBlockingQueueTest exte
935          }
936      }
937  
938 +    /**
939 +     * drainTo(null) throws NPE
940 +     */
941 +    public void testDrainToNull() {
942 +        ArrayBlockingQueue q = populatedQueue(SIZE);
943 +        try {
944 +            q.drainTo(null);
945 +            shouldThrow();
946 +        } catch(NullPointerException success) {
947 +        }
948 +    }
949 +
950 +    /**
951 +     * drainTo(this) throws IAE
952 +     */
953 +    public void testDrainToSelf() {
954 +        ArrayBlockingQueue q = populatedQueue(SIZE);
955 +        try {
956 +            q.drainTo(q);
957 +            shouldThrow();
958 +        } catch(IllegalArgumentException success) {
959 +        }
960 +    }
961 +
962 +    /**
963 +     * drainTo(c) empties queue into another collection c
964 +     */
965 +    public void testDrainTo() {
966 +        ArrayBlockingQueue q = populatedQueue(SIZE);
967 +        ArrayList l = new ArrayList();
968 +        q.drainTo(l);
969 +        assertEquals(q.size(), 0);
970 +        assertEquals(l.size(), SIZE);
971 +        for (int i = 0; i < SIZE; ++i)
972 +            assertEquals(l.get(i), new Integer(i));
973 +    }
974 +
975 +    /**
976 +     * drainTo empties full queue, unblocking a waiting put.
977 +     */
978 +    public void testDrainToWithActivePut() {
979 +        final ArrayBlockingQueue q = populatedQueue(SIZE);
980 +        Thread t = new Thread(new Runnable() {
981 +                public void run() {
982 +                    try {
983 +                        q.put(new Integer(SIZE+1));
984 +                    } catch (InterruptedException ie){
985 +                        threadUnexpectedException();
986 +                    }
987 +                }
988 +            });
989 +        try {
990 +            t.start();
991 +            ArrayList l = new ArrayList();
992 +            q.drainTo(l);
993 +            assertTrue(l.size() >= SIZE);
994 +            for (int i = 0; i < SIZE; ++i)
995 +                assertEquals(l.get(i), new Integer(i));
996 +            t.join();
997 +            assertTrue(q.size() + l.size() == SIZE+1);
998 +        } catch(Exception e){
999 +            unexpectedException();
1000 +        }
1001 +    }
1002 +
1003 +    /**
1004 +     * drainTo(null, n) throws NPE
1005 +     */
1006 +    public void testDrainToNullN() {
1007 +        ArrayBlockingQueue q = populatedQueue(SIZE);
1008 +        try {
1009 +            q.drainTo(null, 0);
1010 +            shouldThrow();
1011 +        } catch(NullPointerException success) {
1012 +        }
1013 +    }
1014 +
1015 +    /**
1016 +     * drainTo(this, n) throws IAE
1017 +     */
1018 +    public void testDrainToSelfN() {
1019 +        ArrayBlockingQueue q = populatedQueue(SIZE);
1020 +        try {
1021 +            q.drainTo(q, 0);
1022 +            shouldThrow();
1023 +        } catch(IllegalArgumentException success) {
1024 +        }
1025 +    }
1026 +
1027 +    /**
1028 +     * drainTo(c, n) empties first max {n, size} elements of queue into c
1029 +     */
1030 +    public void testDrainToN() {
1031 +        for (int i = 0; i < SIZE + 2; ++i) {
1032 +            ArrayBlockingQueue q = populatedQueue(SIZE);
1033 +            ArrayList l = new ArrayList();
1034 +            q.drainTo(l, i);
1035 +            int k = (i < SIZE)? i : SIZE;
1036 +            assertEquals(q.size(), SIZE-k);
1037 +            assertEquals(l.size(), k);
1038 +            for (int j = 0; j < k; ++j)
1039 +                assertEquals(l.get(j), new Integer(j));
1040 +        }
1041 +    }
1042 +
1043  
1044   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines