From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14630 invoked by alias); 24 Nov 2007 22:37:22 -0000 Received: (qmail 14619 invoked by uid 22791); 24 Nov 2007 22:37:20 -0000 X-Spam-Check-By: sourceware.org Received: from smtp-out26.alice.it (HELO smtp-out26.alice.it) (85.33.2.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Sat, 24 Nov 2007 22:37:08 +0000 Received: from FBCMMO03.fbc.local ([192.168.68.197]) by smtp-out26.alice.it with Microsoft SMTPSVC(6.0.3790.1830); Sat, 24 Nov 2007 23:37:04 +0100 Received: from FBCMCL01B03.fbc.local ([192.168.69.84]) by FBCMMO03.fbc.local with Microsoft SMTPSVC(6.0.3790.1830); Sat, 24 Nov 2007 23:37:04 +0100 Received: from [192.168.0.154] ([87.11.18.105]) by FBCMCL01B03.fbc.local with Microsoft SMTPSVC(6.0.3790.1830); Sat, 24 Nov 2007 23:37:04 +0100 Subject: FYI: Mauve tests for CopyOnWriteArrayList From: Mario Torre To: mauve-patches@sources.redhat.com Content-Type: multipart/mixed; boundary="=-2EYR9Dyv1K2H34beIc61" Date: Sat, 24 Nov 2007 22:37:00 -0000 Message-Id: <1195943823.3233.8.camel@nirvana.limasoftware.net> Mime-Version: 1.0 X-Mailer: Evolution 2.12.1 (2.12.1-3.fc8) X-IsSubscribed: yes Mailing-List: contact mauve-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: mauve-patches-owner@sourceware.org X-SW-Source: 2007/txt/msg00058.txt.bz2 --=-2EYR9Dyv1K2H34beIc61 Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-length: 1206 I've added these few tests to mauve. Thanks, Mario 2007-11-24 Mario Torre * gnu/testlet/java/util/concurrent/CopyOnWriteArrayList: new package. * gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveAllTest.java: test. * gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RemoveTest.java: likewise. * gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllAbsentTest.java: likewise. * gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/SubListTest.java: likewise. * gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/RetainAllTest.java: likewise. * gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/TestIterators.java: likewise. * gnu/testlet/java/util/concurrent/CopyOnWriteArrayList/AddAllTest.java: likewise. -- Lima Software - http://www.limasoftware.net/ GNU Classpath Developer - http://www.classpath.org/ Fedora Ambassador - http://fedoraproject.org/wiki/MarioTorre Jabber: neugens@jabber.org pgp key: http://subkeys.pgp.net/ PGP Key ID: 80F240CF Fingerprint: BA39 9666 94EC 8B73 27FA FC7C 4086 63E3 80F2 40CF Please, support open standards: http://opendocumentfellowship.org/petition/ http://www.nosoftwarepatents.com/ --=-2EYR9Dyv1K2H34beIc61 Content-Disposition: attachment; filename=2007-11-24-copy-on-write-array-list-mauve.patch Content-Type: text/x-patch; name=2007-11-24-copy-on-write-array-list-mauve.patch; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-length: 20051 ### 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++; + } + } +} --=-2EYR9Dyv1K2H34beIc61--