public inbox for mauve-patches@sourceware.org
 help / color / mirror / Atom feed
* SpinnerListModel tests
@ 2004-10-12 20:26 Andrew John Hughes
  2004-10-15 21:07 ` Mark Wielaard
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew John Hughes @ 2004-10-12 20:26 UTC (permalink / raw)
  To: mauve-patches


[-- Attachment #1.1: Type: text/plain, Size: 383 bytes --]

Attached is a patch to add tests for the javax.swing.SpinnerListModel
class.  Okay to commit?

Cheers,
-- 
Andrew :-)
 
Please avoid sending me Word or PowerPoint attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html
 
Value your freedom, or you will lose it, teaches history.
`Don't bother us with politics' respond those who don't want to learn.
 


[-- Attachment #1.2: spinner_list_model.diff --]
[-- Type: text/x-patch, Size: 12865 bytes --]

? spinnerlistmodel-tests.diff
Index: ArrayModel.java
===================================================================
RCS file: ArrayModel.java
diff -N ArrayModel.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ArrayModel.java	12 Oct 2004 19:07:14 -0000
@@ -0,0 +1,62 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2004 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.SpinnerListModel;
+
+import gnu.testlet.Testlet;
+import gnu.testlet.TestHarness;
+import javax.swing.SpinnerListModel;
+
+public class ArrayModel implements Testlet
+{
+
+  public void test(TestHarness harness)
+  {
+    SpinnerListModel model;
+    Object[] array;
+    
+    /* Create array */
+    array = new Object[]{"GNU", "Classpath"};
+    /* Create model */
+    model = new SpinnerListModel(array);
+    /* Check retrieval */
+    harness.check(model.getList() != null, "Array model creation check");
+    harness.check(model.getValue(), "GNU", "Array model current value check");
+    harness.check(model.getNextValue(), "Classpath", "Array model next value check");
+    harness.check(model.getValue(), "GNU", "Array model no change of current value after next check");
+    harness.check(model.getPreviousValue(), null, "Array model previous value check");
+    /* Value change check */
+    array[0] = "GNU's Not UNIX";
+    harness.check(model.getValue(), "GNU's Not UNIX", "Array model backing list change check");
+    /* Value setting check */
+    model.setValue("Classpath");
+    harness.check(model.getValue(), "Classpath", "Array model successful set check");
+    try
+      {
+        model.setValue("Sun");
+        harness.fail("Exception not thrown for non-existant value with array model.");
+      }
+    catch (IllegalArgumentException exception)
+      {
+        /* Success */
+      }
+  }
+}
Index: Constructors.java
===================================================================
RCS file: Constructors.java
diff -N Constructors.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Constructors.java	12 Oct 2004 19:07:14 -0000
@@ -0,0 +1,73 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2004 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.SpinnerListModel;
+
+import gnu.testlet.Testlet;
+import gnu.testlet.TestHarness;
+import java.util.ArrayList;
+import javax.swing.SpinnerListModel;
+
+public class Constructors implements Testlet
+{
+
+  public void test(TestHarness harness)
+  {
+    SpinnerListModel model;
+
+    /* Invalid values */
+    try
+      {
+        model = new SpinnerListModel((Object[]) null);
+        harness.fail("Null array supplied to constructor failed to throw an exception.");
+      }
+    catch (IllegalArgumentException exception)
+      {
+        /* Success */
+      }
+    try
+      {
+        model = new SpinnerListModel(new ArrayList());
+        harness.fail("Empty list supplied to constructor failed to throw an exception.");
+      }
+    catch (IllegalArgumentException exception)
+      {
+        /* Success */
+      }
+    try
+      {
+        model = new SpinnerListModel(new Object[]{});
+        harness.fail("Empty array supplied to constructor failed to throw an exception.");
+      }
+    catch (IllegalArgumentException exception)
+      {
+        /* Success */
+      }
+
+    /* Test the default model */
+    model = new SpinnerListModel();
+    harness.check(model.getList() != null, "Default list construction check.");
+    harness.check(model.getValue(), "empty", "Default list current value check.");
+    harness.check(model.getNextValue(), null, "Default list next value check.");
+    harness.check(model.getPreviousValue(), null, "Default list previous value check.");
+
+  }
+}
Index: ListModel.java
===================================================================
RCS file: ListModel.java
diff -N ListModel.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ListModel.java	12 Oct 2004 19:07:14 -0000
@@ -0,0 +1,66 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2004 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.SpinnerListModel;
+
+import gnu.testlet.Testlet;
+import gnu.testlet.TestHarness;
+import java.util.ArrayList;
+import java.util.List;
+import javax.swing.SpinnerListModel;
+
+public class ListModel implements Testlet
+{
+
+  public void test(TestHarness harness)
+  {
+    SpinnerListModel model;
+    List list;
+    
+    /* Create list */
+    list = new ArrayList();
+    list.add("GNU");
+    list.add("Classpath");
+    /* Create model */
+    model = new SpinnerListModel(list);
+    /* Check retrieval */
+    harness.check(model.getList() != null, "List model creation check");
+    harness.check(model.getValue(), "GNU", "List model current value check");
+    harness.check(model.getNextValue(), "Classpath", "List model next value check");
+    harness.check(model.getValue(), "GNU", "List model no change of current value after next check");
+    harness.check(model.getPreviousValue(), null, "List model previous value check");
+    /* Value change check */
+    list.set(0, "GNU's Not UNIX");
+    harness.check(model.getValue(), "GNU's Not UNIX", "List model backing list change check");
+    /* Value setting check */
+    model.setValue("Classpath");
+    harness.check(model.getValue(), "Classpath", "List model successful set check");
+    try
+      {
+        model.setValue("Sun");
+        harness.fail("Exception not thrown for non-existant value with list model.");
+      }
+    catch (IllegalArgumentException exception)
+      {
+        /* Success */
+      }
+  }
+}
Index: Ordering.java
===================================================================
RCS file: Ordering.java
diff -N Ordering.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ Ordering.java	12 Oct 2004 19:07:14 -0000
@@ -0,0 +1,58 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2004 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.SpinnerListModel;
+
+import gnu.testlet.Testlet;
+import gnu.testlet.TestHarness;
+import java.util.ArrayList;
+import java.util.List;
+import javax.swing.SpinnerListModel;
+
+public class Ordering implements Testlet
+{
+
+  public void test(TestHarness harness)
+  {
+    SpinnerListModel model;
+    List list;
+    
+    /* Create list */
+    list = new ArrayList();
+    list.add("a");
+    list.add("z");
+    list.add("a");
+    list.add("b");
+    /* Create model */
+    model = new SpinnerListModel(list);
+    /* Check retrieval */
+    harness.check(model.getList() != null, "Array model ordering creation check");
+    harness.check(model.getValue(), "a", "Array model ordering current value check");
+    harness.check(model.getNextValue(), "z", "Array model ordering next value check");
+    harness.check(model.getValue(), "a", "Array model ordering no change of current value after next check");
+    harness.check(model.getPreviousValue(), null, "Array model ordering previous value check");
+    /* Value ordering of setting check */
+    model.setValue("a");
+    harness.check(model.getValue(), "a", "Array model ordering successful set check");
+    harness.check(model.getPreviousValue(), null, "Array model ordering post-set previous value check");
+    harness.check(model.getNextValue(), "z", "Array model ordering post-set next value check");
+  }
+}
Index: SetList.java
===================================================================
RCS file: SetList.java
diff -N SetList.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ SetList.java	12 Oct 2004 19:07:14 -0000
@@ -0,0 +1,67 @@
+// Tags: JDK1.4
+
+// Copyright (C) 2004 Andrew John Hughes <gnu_andrew@member.fsf.org>
+
+// 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, 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+package gnu.testlet.javax.swing.SpinnerListModel;
+
+import gnu.testlet.Testlet;
+import gnu.testlet.TestHarness;
+import java.util.ArrayList;
+import java.util.List;
+import javax.swing.SpinnerListModel;
+
+public class SetList implements Testlet
+{
+
+public void test(TestHarness harness)
+{
+    SpinnerListModel model;
+    List list;
+
+    /* Create default model */
+    model = new SpinnerListModel();
+    /* Invalid values */
+    try
+      {
+        model.setList((ArrayList) null);
+        harness.fail("Null list supplied to setList failed to throw an exception.");
+      }
+    catch (IllegalArgumentException exception)
+      {
+        /* Success */
+      }
+    try
+      {
+        model.setList(new ArrayList());
+        harness.fail("Empty list supplied to setList failed to throw an exception.");
+      }
+    catch (IllegalArgumentException exception)
+      {
+        /* Success */
+      }
+
+    /* Test a successful change */
+    list = new ArrayList();
+    list.add("GNU");
+    model.setList(list);
+    harness.check(model.getList(), list, "Model allowed successful change of list.");
+  }
+
+}

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: SpinnerListModel tests
  2004-10-12 20:26 SpinnerListModel tests Andrew John Hughes
@ 2004-10-15 21:07 ` Mark Wielaard
  2004-10-16 12:30   ` Andrew John Hughes
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Wielaard @ 2004-10-15 21:07 UTC (permalink / raw)
  To: gnu_andrew; +Cc: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 874 bytes --]

Hi,

On Tue, 2004-10-12 at 22:26, Andrew John Hughes wrote:
> Attached is a patch to add tests for the javax.swing.SpinnerListModel
> class.  Okay to commit?

Thanks! These look fine.
One style point. I like to write checks that check whether an exception
is actually thrown as:

        boolean some_exception_thrown = false;
        try
          {
            some_operation_that_might_throw_some_exception();
          }
        catch (SomeException some_exception)
          {
            some_exception_thrown = true;
          }
        harness.check(some_exception);
        
That way you get a a test result (PASS) even when the exception is
thrown (when running with -verbose or -resultsonly). And not just a
(FAIL) test result if nothing is thrown.

Do you have CVS access already? Or would you like me to apply this?

Cheers,

Mark

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: SpinnerListModel tests
  2004-10-15 21:07 ` Mark Wielaard
@ 2004-10-16 12:30   ` Andrew John Hughes
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew John Hughes @ 2004-10-16 12:30 UTC (permalink / raw)
  To: mauve-patches

[-- Attachment #1: Type: text/plain, Size: 1536 bytes --]

On Fri, 2004-10-15 at 22:07, Mark Wielaard wrote:
> Hi,
> 
> On Tue, 2004-10-12 at 22:26, Andrew John Hughes wrote:
> > Attached is a patch to add tests for the javax.swing.SpinnerListModel
> > class.  Okay to commit?
> 
> Thanks! These look fine.
> One style point. I like to write checks that check whether an exception
> is actually thrown as:
> 
>         boolean some_exception_thrown = false;
>         try
>           {
>             some_operation_that_might_throw_some_exception();
>           }
>         catch (SomeException some_exception)
>           {
>             some_exception_thrown = true;
>           }
>         harness.check(some_exception);
>         
> That way you get a a test result (PASS) even when the exception is
> thrown (when running with -verbose or -resultsonly). And not just a
> (FAIL) test result if nothing is thrown.
> 
> Do you have CVS access already? Or would you like me to apply this?
> 
> Cheers,
> 
> Mark

Thanks, Mark.  I have CVS access, so I'll make the stylistic changes and
commit (they make more sense).

Cheers,
-- 
Andrew :-)

Please avoid sending me Microsoft Office (e.g. Word, PowerPoint) attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

"Value your freedom, or you will lose it, teaches history.
`Don't bother us with politics' respond those who don't want to learn."
-- Richard Stallman

"We've all been part of the biggest beta test the world has ever known --
Windows"
-- Victor Wheatman, Gartner


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-10-16 12:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-12 20:26 SpinnerListModel tests Andrew John Hughes
2004-10-15 21:07 ` Mark Wielaard
2004-10-16 12:30   ` Andrew John Hughes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).