/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6207984 6272521 6192552 6269713 6197726 6260652 5073546 4137464
* 4155650 4216399 4294891 6282555 6318622 6355327 6383475 6420753
* 6431845 4802633 6570566 6570575 6570631 6570924 6691185 6691215
* @summary Run many tests on many Collection and Map implementations
* @author Martin Buchholz
* @run main MOAT
*/
/* Mother Of All (Collection) Tests
*
* Testing of collection classes is often spotty, because many tests
* need to be performed on many implementations, but the onus on
* writing the tests falls on the engineer introducing the new
* implementation.
*
* The idea of this mega-test is that:
*
* An engineer adding a new collection implementation could simply add
* their new implementation to a list of implementations in this
* test's main method. Any general purpose Collection<Integer> or
* Map<Integer,Integer> class is appropriate.
*
* An engineer fixing a regression could add their regression test here and
* simultaneously test all other implementations.
*/
public class MOAT {
// Empty collections
THROWS(IndexOutOfBoundsException.class,
// Singleton collections
}
check(c.containsAll(c));
}
}
testEmptyIterator(c.iterator());
}
if (rnd.nextBoolean())
THROWS(NoSuchElementException.class,
catch (IllegalStateException _) { pass(); }
catch (UnsupportedOperationException _) { pass(); }
catch (Throwable t) { unexpected(t); }
if (rnd.nextBoolean())
}
}
if (c instanceof NavigableSet<?>)
}
if (! c.isEmpty()) {
);
}
}
}
testList(c);
if (! c.isEmpty())
new Fun(){void f(){
new Fun(){void f(){
}
try { c.clear(); }
catch (Throwable t) { unexpected(t); }
}
testEmptySet(m.keySet());
testEmptySet(m.entrySet());
testEmptyCollection(m.values());
catch (NullPointerException _) { /* OK */ }
catch (NullPointerException _) { /* OK */ }
}
if (! m.isEmpty()) {
}
testImmutableSet(m.keySet());
//testImmutableSet(m.entrySet());
}
try { m.clear(); }
catch (Throwable t) { unexpected(t); }
testEmptyMap(m);
}
clear(c);
try {
} catch (Throwable t) { unexpected(t); }
}
catch (UnsupportedOperationException t) { return false; }
catch (Throwable t) { unexpected(t); }
try {
} catch (Throwable t) { unexpected(t); }
return true;
}
catch (UnsupportedOperationException t) { return false; }
catch (Throwable t) { unexpected(t); }
return true;
}
try {
{
int size = 0;
}
||
// !!!!
// 6260652: (coll) Arrays.asList(x).toArray().getClass()
// should be Object[].class
);
}
if (c instanceof Serializable) {
//System.out.printf("Serializing %s%n", c.getClass().getName());
try {
equal(c instanceof Serializable,
clone instanceof Serializable);
equal(c instanceof RandomAccess,
clone instanceof RandomAccess);
else
throw xxx;
}
}
}
catch (Throwable t) { unexpected(t); }
}
//----------------------------------------------------------------
// If add(null) succeeds, contains(null) & remove(null) should succeed
//----------------------------------------------------------------
// !!!! 5018849: (coll) TreeSet.contains(null) does not agree with Javadoc
if (c instanceof TreeSet) return;
try {
if (c.size() == 1)
try {
}
catch (Throwable t) { unexpected(t); }
}
catch (NullPointerException e) { /* OK */ }
catch (Throwable t) { unexpected(t); }
}
//----------------------------------------------------------------
// If add("x") succeeds, contains("x") & remove("x") should succeed
//----------------------------------------------------------------
@SuppressWarnings("unchecked")
try {
try {
} catch (Throwable t) { unexpected(t); }
}
catch (ClassCastException e) { /* OK */ }
catch (Throwable t) { unexpected(t); }
}
try {
c.add(1);
clear(c);
}
catch (Throwable t) { unexpected(t); }
}
q.clear();
for (int i = 0; i < 5; i++) {
testQueueAddRemove(q, null);
testQueueAddRemove(q, 537);
q.add(i);
}
q.poll();
if ((q instanceof LinkedBlockingQueue) ||
(q instanceof LinkedBlockingDeque) ||
(q instanceof ConcurrentLinkedDeque) ||
(q instanceof ConcurrentLinkedQueue)) {
}
}
final Integer e) {
try {
q.add(e);
} catch (NullPointerException npe) {
return; // Null elements not supported
}
if (q instanceof Deque<?>) {
// insert, query, remove element at head
if (isEmpty) {
THROWS(NoSuchElementException.class,
} else {
}
if (isList) {
}
default: throw new AssertionError();
}
if (isList) {
}
default: throw new AssertionError();
}
if (isEmpty) {
THROWS(NoSuchElementException.class,
} else {
}
if (isList) {
}
// insert, query, remove element at tail
if (isEmpty) {
THROWS(NoSuchElementException.class,
} else {
}
default: throw new AssertionError();
}
if (isList) {
}
case 7:
break;
default: throw new AssertionError();
}
if (isEmpty) {
THROWS(NoSuchElementException.class,
} else {
}
// Test operations on empty deque
case 1:
}
break;
case 3:
while (lit.hasPrevious()) {
}
break;
default: throw new AssertionError();
}
if (isList) {
THROWS(NoSuchElementException.class,
}
THROWS(NoSuchElementException.class,
}
}
q.getClass().getSimpleName());
q.clear();
for (int i = 0; i < 5; i++)
q.add(i);
for (int i = 3; i >= 0; i--)
q.remove(i);
q.clear();
for (int i = 0; i < 5; i++)
q.add(i);
for (int i = 1; i < 4; i++)
q.remove(i);
}
//----------------------------------------------------------------
// 4802633: (coll) AbstractList.addAll(-1,emptyCollection)
// doesn't throw IndexOutOfBoundsException
//----------------------------------------------------------------
try {
fail("Expected IndexOutOfBoundsException not thrown");
}
catch (UnsupportedOperationException _) {/* OK */}
catch (IndexOutOfBoundsException _) {/* OK */}
catch (Throwable t) { unexpected(t); }
// equal(l instanceof Serializable,
// l.subList(0,0) instanceof Serializable);
check(l instanceof Serializable);
equal(l instanceof RandomAccess,
}
try { testCollection1(c); }
catch (Throwable t) { unexpected(t); }
}
if (! supportsAdd(c)) return;
//System.out.println("add() supported");
if (c instanceof NavigableSet) {
}
if (c instanceof Queue)
if (c instanceof List)
check(supportsRemove(c));
try {
oneElement(c);
}
catch (Throwable t) { unexpected(t); }
clear(c); testNullElement(c);
oneElement(c); testNullElement(c);
clear(c); testStringElement(c);
oneElement(c); testStringElement(c);
//----------------------------------------------------------------
// The "all" operations should throw NPE when passed null
//----------------------------------------------------------------
{
oneElement(c);
try {
fail("Expected NullPointerException");
}
catch (NullPointerException e) { pass(); }
catch (Throwable t) { unexpected(t); }
oneElement(c);
try {
fail("Expected NullPointerException");
}
catch (NullPointerException e) { pass(); }
catch (Throwable t) { unexpected(t); }
oneElement(c);
try {
fail("Expected NullPointerException");
}
catch (NullPointerException e) { pass(); }
catch (Throwable t) { unexpected(t); }
oneElement(c);
try {
c.containsAll(null);
fail("Expected NullPointerException");
}
catch (NullPointerException e) { pass(); }
catch (Throwable t) { unexpected(t); }
}
}
//----------------------------------------------------------------
// Map
//----------------------------------------------------------------
}
if (m instanceof ConcurrentMap)
if (m instanceof NavigableMap) {
}
if (supportsClear(m)) {
try { clear(m); }
catch (Throwable t) { unexpected(t); }
}
if (supportsPut(m)) {
try {
}
catch (Throwable t) { unexpected(t); }
}
}
// We're asking for .equals(...) semantics
if (m instanceof IdentityHashMap) return false;
catch (UnsupportedOperationException t) { return false; }
catch (Throwable t) { unexpected(t); }
try {
} catch (Throwable t) { unexpected(t); }
return true;
}
try { m.clear(); }
catch (UnsupportedOperationException t) { return false; }
catch (Throwable t) { unexpected(t); }
return true;
}
//----------------------------------------------------------------
// ConcurrentMap
//----------------------------------------------------------------
try {
clear(m);
catch (NullPointerException t) { }
catch (NullPointerException t) { }
catch (NullPointerException t) { }
testEmptyMap(m);
}
catch (Throwable t) { unexpected(t); }
}
catch (Throwable t) {
}
}
m.clear();
? (ConcurrentMap<T,Integer>) m
: null;
}
}
//----------------------------------------------------------------
// NavigableMap
//----------------------------------------------------------------
private static void
Integer i,
}
private static void
Integer i,
}
if (rnd.nextBoolean())
}
}
{
abstract class NavigableMapView {
}
NavigableMapView[] views = {
return m; }},
return m.headMap(99, true); }},
return m.tailMap(-99, false); }},
};
abstract class Remover {
}
.remove(k)); }},
.remove(k)); }},
};
try {
m.clear();
equalMaps(m, singletonMap);
} catch (Throwable t) { unexpected(t); }
}
}
}
{
clear(m);
new Iterator<?>[] {
m.descendingKeySet().iterator(),
m.navigableKeySet().descendingIterator()}) {
THROWS(NoSuchElementException.class,
}
{
THROWS(NoSuchElementException.class,
}
}
clear(s);
new Iterator<?>[] {
s.descendingIterator(),
s.descendingSet().iterator()}) {
THROWS(NoSuchElementException.class,
}
}
//--------------------- Infrastructure ---------------------------
}
catch (Throwable t) {
else unexpected(t);}}
try {
return baos.toByteArray();
} catch (IOException e) { throw new Error(e); }}
throws IOException, ClassNotFoundException {
@SuppressWarnings("unchecked")
}