This is the mail archive of the mauve-patches@sourceware.org mailing list for the Mauve project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: ComponentSampleModel - new tests


This patch (committed) adds some new tests for the ComponentSampleModel class:

2006-07-17 David Gilbert <david.gilbert@object-refinery.com>

* gnu/testlet/java/awt/image/ComponentSampleModel/constructors.java: New file,
* gnu/testlet/java/awt/image/ComponentSampleModel/createDataBuffer.java: New file
* gnu/testlet/java/awt/image/ComponentSampleModel/equals.java: New file,
* gnu/testlet/java/awt/image/ComponentSampleModel/hashCode.java: New file,
* gnu/testlet/java/awt/image/ComponentSampleModel/MyComponentSampleModel.java: New file.


Regards,

Dave
Index: gnu/testlet/java/awt/image/ComponentSampleModel/MyComponentSampleModel.java
===================================================================
RCS file: gnu/testlet/java/awt/image/ComponentSampleModel/MyComponentSampleModel.java
diff -N gnu/testlet/java/awt/image/ComponentSampleModel/MyComponentSampleModel.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/ComponentSampleModel/MyComponentSampleModel.java	17 Jul 2006 16:30:43 -0000
@@ -0,0 +1,51 @@
+/* MyComponentSampleModel.java -- provides access to protected attributes.
+   Copyright (C) 2006 David Gilbert <david.gilbert@object-refinery.com>
+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: not-a-test
+
+package gnu.testlet.java.awt.image.ComponentSampleModel;
+
+import java.awt.image.ComponentSampleModel;
+
+public class MyComponentSampleModel extends ComponentSampleModel
+{
+  public MyComponentSampleModel(int dataType, int w, int h, int pixelStride, 
+          int scanlineStride, int[] bandOffsets)
+  {
+    super(dataType, w, h, pixelStride, scanlineStride, bandOffsets);
+  }
+  
+  public MyComponentSampleModel(int dataType, int w, int h, int pixelStride, 
+          int scanlineStride, int[] bandOffsets, int[] bankIndices)
+  {
+    super(dataType, w, h, pixelStride, scanlineStride, bandOffsets);
+  }
+  
+  public int[] getBandOffsetsDirect()
+  {
+    return this.bandOffsets;
+  }
+  
+  public int[] getBankIndicesDirect()
+  {
+    return this.bankIndices;
+  }
+}
Index: gnu/testlet/java/awt/image/ComponentSampleModel/constructors.java
===================================================================
RCS file: gnu/testlet/java/awt/image/ComponentSampleModel/constructors.java
diff -N gnu/testlet/java/awt/image/ComponentSampleModel/constructors.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/ComponentSampleModel/constructors.java	17 Jul 2006 16:30:43 -0000
@@ -0,0 +1,171 @@
+/* constructors.java -- some checks for the constructors in the
+       ComponentSampleModel class.
+   Copyright (C) 2006 David Gilbert <david.gilbert@object-refinery.com>
+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.4
+
+package gnu.testlet.java.awt.image.ComponentSampleModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.image.ComponentSampleModel;
+import java.awt.image.DataBuffer;
+import java.util.Arrays;
+
+public class constructors implements Testlet
+{
+  public void test(TestHarness harness)
+  {
+    testConstructor1(harness);
+    testConstructor2(harness);
+    testDefensiveCopies(harness);
+  }
+  
+  public void testConstructor1(TestHarness harness)
+  {
+    harness.checkPoint("testConstructor1()");
+    
+    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_BYTE,
+            10, 20, 3, 30, new int[] {0, 1, 2});
+    harness.check(m.getDataType(), DataBuffer.TYPE_BYTE);
+    harness.check(m.getWidth(), 10);
+    harness.check(m.getHeight(), 20);
+    harness.check(m.getPixelStride(), 3);
+    harness.check(m.getScanlineStride(), 30);
+    harness.check(Arrays.equals(m.getBandOffsets(), new int[] {0, 1, 2}));
+    
+    // try bad type
+    boolean pass = false;
+    try
+    {
+      m = new ComponentSampleModel(DataBuffer.TYPE_UNDEFINED, 10, 20, 3, 30, 
+              new int[] {0, 1, 2});
+    }
+    catch (IllegalArgumentException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // try zero width
+    pass = false;
+    try
+    {
+      m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 0, 20, 3, 30, 
+              new int[] {0, 1, 2});
+    }
+    catch (IllegalArgumentException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+
+    // try zero height
+    pass = false;
+    try
+    {
+      m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 10, 0, 3, 30, 
+              new int[] {0, 1, 2});
+    }
+    catch (IllegalArgumentException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // try negative pixel stride
+    pass = false;
+    try
+    {
+      m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 10, 20, -1, 30, 
+              new int[] {0, 1, 2});
+    }
+    catch (IllegalArgumentException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+
+    // try negative scanline stride
+    pass = false;
+    try
+    {
+      m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 10, 20, 3, -1, 
+              new int[] {0, 1, 2});
+    }
+    catch (IllegalArgumentException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // try width * height > Integer.MAX_VALUE
+    pass = false;
+    try
+    {
+      m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 3, 
+              Integer.MAX_VALUE / 2, 3, 30, new int[] {0, 1, 2});
+    }
+    catch (IllegalArgumentException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // try null band offsets
+    pass = false;
+    try
+    {
+      m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 10, 20, 3, 30, null);
+    }
+    catch (NullPointerException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);    
+  }
+  
+  public void testConstructor2(TestHarness harness)
+  {
+    harness.checkPoint("testConstructor2()");
+    
+  }
+  
+  public void testDefensiveCopies(TestHarness harness)
+  {
+    harness.checkPoint("testDefensiveCopies()");
+    int[] bandOffsets = new int[] {0, 1, 2};
+    MyComponentSampleModel m = new MyComponentSampleModel(DataBuffer.TYPE_BYTE,
+            10, 20, 3, 30, bandOffsets);
+    harness.check(bandOffsets != m.getBandOffsetsDirect());
+    harness.check(Arrays.equals(bandOffsets, m.getBandOffsetsDirect()));
+
+    int[] bankIndices = new int[] {0, 0, 0};
+    MyComponentSampleModel m2 = new MyComponentSampleModel(DataBuffer.TYPE_BYTE,
+            10, 20, 3, 30, bandOffsets, bankIndices);
+    harness.check(bandOffsets != m.getBandOffsetsDirect());
+    harness.check(Arrays.equals(bandOffsets, m.getBandOffsetsDirect()));
+    harness.check(bankIndices != m.getBankIndicesDirect());
+    harness.check(Arrays.equals(bankIndices, m.getBankIndicesDirect()));
+
+  }
+}
Index: gnu/testlet/java/awt/image/ComponentSampleModel/createDataBuffer.java
===================================================================
RCS file: gnu/testlet/java/awt/image/ComponentSampleModel/createDataBuffer.java
diff -N gnu/testlet/java/awt/image/ComponentSampleModel/createDataBuffer.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/ComponentSampleModel/createDataBuffer.java	17 Jul 2006 16:30:43 -0000
@@ -0,0 +1,44 @@
+/* createDataBuffer.java -- some checks for the createDataBuffer() method in 
+       the ComponentSampleModel class.
+   Copyright (C) 2006 David Gilbert <david.gilbert@object-refinery.com>
+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.4
+
+package gnu.testlet.java.awt.image.ComponentSampleModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.image.ComponentSampleModel;
+import java.awt.image.DataBuffer;
+
+public class createDataBuffer implements Testlet
+{
+  public void test(TestHarness harness)
+  {
+    ComponentSampleModel m = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 10, 
+            20, 3, 30, new int[] {0, 1, 2});
+    DataBuffer db = m.createDataBuffer();
+    harness.check(db.getDataType(), DataBuffer.TYPE_BYTE);
+    harness.check(db.getNumBanks(), 1);
+    harness.check(db.getSize(), 600);
+  }
+}
Index: gnu/testlet/java/awt/image/ComponentSampleModel/equals.java
===================================================================
RCS file: gnu/testlet/java/awt/image/ComponentSampleModel/equals.java
diff -N gnu/testlet/java/awt/image/ComponentSampleModel/equals.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/ComponentSampleModel/equals.java	17 Jul 2006 16:30:43 -0000
@@ -0,0 +1,78 @@
+/* equals.java -- some checks for the equals() method in the 
+       ComponentSampleModel class.
+   Copyright (C) 2006 David Gilbert <david.gilbert@object-refinery.com>
+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.4
+
+package gnu.testlet.java.awt.image.ComponentSampleModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.image.ComponentSampleModel;
+import java.awt.image.DataBuffer;
+
+public class equals implements Testlet
+{
+  public void test(TestHarness harness)
+  {
+    ComponentSampleModel m1 = new ComponentSampleModel(DataBuffer.TYPE_INT, 
+            10, 20, 3, 40, new int[] {0, 1, 2});
+    ComponentSampleModel m2 = new ComponentSampleModel(DataBuffer.TYPE_INT, 
+            10, 20, 3, 40, new int[] {0, 1, 2});
+    harness.check(m1.equals(m2));
+    
+    m1 = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 
+            10, 20, 3, 40, new int[] {0, 1, 2});
+    harness.check(!m1.equals(m2));
+    m2 = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 
+            10, 20, 3, 40, new int[] {0, 1, 2});
+    harness.check(m1.equals(m2));
+    
+    m1 = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 
+            9, 20, 3, 40, new int[] {0, 1, 2});
+    harness.check(!m1.equals(m2));
+    m2 = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 
+            9, 20, 3, 40, new int[] {0, 1, 2});
+    harness.check(m1.equals(m2));
+    
+    m1 = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 
+            9, 19, 3, 40, new int[] {0, 1, 2});
+    harness.check(!m1.equals(m2));
+    m2 = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 
+            9, 19, 3, 40, new int[] {0, 1, 2});
+    harness.check(m1.equals(m2));
+    
+    m1 = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 
+            9, 19, 4, 40, new int[] {0, 1, 2});
+    harness.check(!m1.equals(m2));
+    m2 = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 
+            9, 19, 4, 40, new int[] {0, 1, 2});
+    harness.check(m1.equals(m2));
+
+    m1 = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 
+            9, 19, 4, 40, new int[] {0, 2, 1});
+    harness.check(!m1.equals(m2));
+    m2 = new ComponentSampleModel(DataBuffer.TYPE_BYTE, 
+            9, 19, 4, 40, new int[] {0, 2, 1});
+    harness.check(m1.equals(m2));
+  }
+}
Index: gnu/testlet/java/awt/image/ComponentSampleModel/hashCode.java
===================================================================
RCS file: gnu/testlet/java/awt/image/ComponentSampleModel/hashCode.java
diff -N gnu/testlet/java/awt/image/ComponentSampleModel/hashCode.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/awt/image/ComponentSampleModel/hashCode.java	17 Jul 2006 16:30:43 -0000
@@ -0,0 +1,46 @@
+/* hashCode.java -- some checks for the hashCode() method in the
+       ComponentSampleModel class.
+   Copyright (C) 2006 David Gilbert <david.gilbert@object-refinery.com>
+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.4
+
+package gnu.testlet.java.awt.image.ComponentSampleModel;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.image.ComponentSampleModel;
+import java.awt.image.DataBuffer;
+
+public class hashCode implements Testlet
+{
+  public void test(TestHarness harness)
+  {
+    // equal instances should have equal hashCodes...
+    ComponentSampleModel m1 = new ComponentSampleModel(DataBuffer.TYPE_INT, 
+            10, 20, 3, 3, new int[] {0, 1, 2});
+    ComponentSampleModel m2 = new ComponentSampleModel(DataBuffer.TYPE_INT, 
+            10, 20, 3, 3, new int[] {0, 1, 2});
+    harness.check(m1.equals(m2));
+    harness.check(m1.hashCode(), m2.hashCode());
+  }
+
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]