### Eclipse Workspace Patch 1.0 #P mauve Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllTest.java =================================================================== RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllTest.java diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,142 @@ +/* AddAllTest.java -- test for addAll. + Copyright (C) 2007 Mario Torre +This file is part of Mauve. + +Mauve is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +Mauve 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 for more details. + +You should have received a copy of the GNU General Public License +along with Mauve; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +*/ + +// Tags: JDK1.5 + +package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList; + +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; +import java.util.concurrent.CopyOnWriteArrayList; + +import gnu.testlet.TestHarness; +import gnu.testlet.Testlet; + +/** + * @author Mario Torre + */ +public class AddAllTest implements Testlet +{ + public void test(TestHarness harness) + { + testAdd(harness); + testExceptions(harness); + } + + private void testExceptions(TestHarness harness) + { + CopyOnWriteArrayList list = + new CopyOnWriteArrayList(); + + List list2 = new ArrayList(); + list2.add(0); + + harness.checkPoint("addAll - IndexOutOfBoundsException"); + + try + { + // try with index < 0 first + list.addAll(-1, list2); + + // we should not get here + harness.check(false); + } + catch (IndexOutOfBoundsException e) + { + harness.check(true); + } + catch (Exception e) + { + harness.check(false, "Exception of unexpected type: " + e.getMessage()); + } + + list.add(0); + list.add(1); + + try + { + // try with index > list.size() first + list.addAll(list.size() + 1, list2); + + // we should not get here + harness.check(false); + } + catch (IndexOutOfBoundsException e) + { + harness.check(true); + } + catch (Exception e) + { + harness.check(false, "Exception of unexpected type: " + e.getMessage()); + } + + harness.checkPoint("addAll - NullPointerException"); + + try + { + // finally try NullPointerException + list.addAll(null); + + // we should not get here + harness.check(false); + } + catch (NullPointerException e) + { + harness.check(true); + } + catch (Exception e) + { + harness.check(false, "Exception of unexpected type: " + e.getMessage()); + } + } + + private void testAdd(TestHarness harness) + { + harness.checkPoint("addAll"); + + int [] expected = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 + }; + + CopyOnWriteArrayList list = + new CopyOnWriteArrayList(); + + for (int i = 0; i < 10; i++) + list.add(i); + + List list2 = new ArrayList(); + for (int i = 5; i < 15; i++) + list2.add(i); + + list.addAll(list2); + + harness.check(list.size() == 20); + + int i = 0; + for (ListIterator elements = list.listIterator(); + elements.hasNext();) + { + harness.check(elements.next().intValue() == expected[i++]); + } + } +} Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/TestIterators.java =================================================================== RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/TestIterators.java diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/TestIterators.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/TestIterators.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,153 @@ +/* TestIterators.java -- test for the Iterator and ListIterator methods. + Copyright (C) 2007 Mario Torre +This file is part of Mauve. + +Mauve is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +Mauve 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 for more details. + +You should have received a copy of the GNU General Public License +along with Mauve; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +*/ + +// Tags: JDK1.5 + +package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.ListIterator; +import java.util.concurrent.CopyOnWriteArrayList; + +import gnu.testlet.TestHarness; +import gnu.testlet.Testlet; + +/** + * @author Mario Torre + */ +public class TestIterators implements Testlet +{ + public void test(TestHarness harness) + { + iteratorTests(harness); + listIteratorTests(harness); + } + + private void listIteratorTests(TestHarness harness) + { + harness.checkPoint("listIterator"); + + int [] expected = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 6, 7, 8, 9 + }; + + CopyOnWriteArrayList list = + new CopyOnWriteArrayList(); + + java.util.List data = new ArrayList(); + + for (int i = 0; i < 10; i++) + data.add(i); + + // list.add copy the storage array each time is called, adding elements + // that way we avoid all this copying + list.addAll(data); + + ListIterator iterator = list.listIterator(); + int i = 0; + + harness.checkPoint("listIterator - forward"); + + while (iterator.hasNext()) + harness.check(iterator.next().intValue() == expected[i++]); + + harness.checkPoint("listIterator - backward"); + + while (iterator.hasPrevious()) + harness.check(iterator.previous().intValue() == expected[--i]); + + harness.checkPoint("listIterator - forward from element"); + + iterator = list.listIterator(5); + i = 5; + + while (iterator.hasNext()) + harness.check(iterator.next().intValue() == expected[i++]); + + harness.checkPoint("listIterator - backward from element"); + + while (iterator.hasPrevious()) + harness.check(iterator.previous().intValue() == expected[--i]); + } + + private void iteratorTests(TestHarness harness) + { + harness.checkPoint("iterator"); + + int [] expected = + { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 + }; + + CopyOnWriteArrayList list = + new CopyOnWriteArrayList(); + + java.util.List data = new ArrayList(); + + for (int i = 0; i < 10; i++) + data.add(i); + + // list.add copy the storage array each time is called, adding elements + // that way we avoid all this copying + list.addAll(data); + + int i = 0; + for (Iterator iterator = list.iterator(); iterator.hasNext(); ) + { + harness.check(iterator.next().intValue() == expected[i++]); + } + + harness.checkPoint("iterator - snapshot"); + Iterator iterator = list.iterator(); + + list.clear(); + + harness.check(list.size() == 0); + + // the iterator contains a snapshot of the list so resetting the list + // has no effect to the content of the iterator. + + i = 0; + while (iterator.hasNext()) + harness.check(iterator.next().intValue() == expected[i++]); + + harness.checkPoint("iterator - remove"); + + list.addAll(data); + + try + { + for (Iterator iter = list.iterator(); iter.hasNext(); ) + { + iter.remove(); + harness.check(false); + } + + harness.check(false); + } + catch (UnsupportedOperationException e) + { + harness.check(true); + } + } +} Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RetainAllTest.java =================================================================== RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RetainAllTest.java diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RetainAllTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RetainAllTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,65 @@ +/* RetainAllTest.java -- test for retainAll + Copyright (C) 2007 Mario Torre +This file is part of Mauve. + +Mauve is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +Mauve 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 for more details. + +You should have received a copy of the GNU General Public License +along with Mauve; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + + */ + +// Tags: JDK1.5 + + +package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList; + +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; +import java.util.concurrent.CopyOnWriteArrayList; + +import gnu.testlet.TestHarness; +import gnu.testlet.Testlet; + +/** + * @author Mario Torre + */ +public class RetainAllTest + implements Testlet +{ + public void test(TestHarness harness) + { + CopyOnWriteArrayList list = + new CopyOnWriteArrayList(); + + for (int i = 0; i < 10; i++) + list.add(i); + + List list2 = new ArrayList(); + for (int i = 5; i < 15; i++) + list2.add(i); + + list.retainAll(list2); + + harness.check(list.size() == 5); + + int i = 5; + for (ListIterator elements = list.listIterator(); + elements.hasNext();) + { + harness.check(elements.next().intValue() == i); + i++; + } + } +} Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/SubListTest.java =================================================================== RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/SubListTest.java diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/SubListTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/SubListTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,38 @@ +/* SubListTest.java -- Test for subList. + Copyright (C) 2007 Mario Torre +This file is part of Mauve. + +Mauve is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +Mauve 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 for more details. + +You should have received a copy of the GNU General Public License +along with Mauve; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +*/ + +// Tags: JDK1.5 + +package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList; + +import gnu.testlet.TestHarness; +import gnu.testlet.Testlet; + +/** + * @author Mario Torre + */ +public class SubListTest implements Testlet +{ + public void test(TestHarness harness) + { + + } +} Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllAbsentTest.java =================================================================== RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllAbsentTest.java diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllAbsentTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllAbsentTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,64 @@ +/* AddAllAbsentTest.java -- test for addAllAbsent. + Copyright (C) 2007 Mario Torre +This file is part of Mauve. + +Mauve is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +Mauve 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 for more details. + +You should have received a copy of the GNU General Public License +along with Mauve; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +*/ + +// Tags: JDK1.5 + +package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList; + +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; +import java.util.concurrent.CopyOnWriteArrayList; + +import gnu.testlet.TestHarness; +import gnu.testlet.Testlet; + +/** + * @author Mario Torre + */ +public class AddAllAbsentTest implements Testlet +{ + public void test(TestHarness harness) + { + CopyOnWriteArrayList list = new CopyOnWriteArrayList(); + for (int i = 0; i < 10; i++) + { + list.add("#" + i); + } + + List list2 = new ArrayList(); + + for (int i = 9; i < 20; i++) + list2.add("#" + i); + + list.addAllAbsent(list2); + + harness.check(list.size() == 20); + + int i = 0; + for (ListIterator elements = list.listIterator(); + elements.hasNext();) + { + harness.check(elements.next().equals("#" + i)); + i++; + } + } +} Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveTest.java =================================================================== RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveTest.java diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,72 @@ +/* RemoveTest.java -- test for remove. + Copyright (C) 2007 Mario Torre +This file is part of Mauve. + +Mauve is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +Mauve 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 for more details. + +You should have received a copy of the GNU General Public License +along with Mauve; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +*/ + +// Tags: JDK1.5 + +package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; + +import gnu.testlet.TestHarness; +import gnu.testlet.Testlet; + +/** + * @author Mario Torre + */ +public class RemoveTest implements Testlet +{ + public void test(TestHarness harness) + { + CopyOnWriteArrayList list = + new CopyOnWriteArrayList(); + + List data = new ArrayList(); + for (int i = 0; i < 10; i++) + data.add(i); + + list.addAll(data); + + harness.check(list.size() == 10); + + Integer el = list.remove(5); + + harness.check(el.intValue() == 5); + harness.check(list.size() == 9); + + harness.check(list.add(el)); + harness.check(list.size() == 10); + + harness.check(list.remove(el)); + harness.check(list.size() == 9); + + int [] expected = + { + 0, 1, 2, 3, 4, 6, 7, 8, 9 + }; + + int i = 0; + for (Iterator iterator = list.iterator(); iterator.hasNext(); ) + harness.check(iterator.next().intValue() == expected[i++]); + } +} Index: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveAllTest.java =================================================================== RCS file: gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveAllTest.java diff -N gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveAllTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveAllTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,66 @@ +/* RemoveAllTest.java -- test for removeAll. + Copyright (C) 2007 Mario Torre +This file is part of Mauve. + +Mauve is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +Mauve 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 for more details. + +You should have received a copy of the GNU General Public License +along with Mauve; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + + */ + +// Tags: JDK1.5 + + +package gnu.testlet.java.util.concurrent.CopyOnWriteArrayList; + +import java.util.ArrayList; +import java.util.List; +import java.util.ListIterator; +import java.util.concurrent.CopyOnWriteArrayList; + +import gnu.testlet.TestHarness; +import gnu.testlet.Testlet; + +/** + * @author Mario Torre + */ +public class RemoveAllTest + implements Testlet +{ + public void test(TestHarness harness) + { + CopyOnWriteArrayList list = new CopyOnWriteArrayList(); + for (int i = 0; i < 10; i++) + { + list.add("#" + i); + } + + List list2 = new ArrayList(); + + for (int i = 3; i < 20; i++) + list2.add("#" + i); + + list.removeAll(list2); + + harness.check(list.size() == 3); + + int i = 0; + for (ListIterator elements = list.listIterator(); + elements.hasNext();) + { + harness.check(elements.next().equals("#" + i)); + i++; + } + } +}