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: New View tests


I added a couple of tests for javax.swing.text.View.

2006-02-09  Roman Kennke  <kennke@aicas.com>

        * gnu/testlet/javax/swing/text/View/TestView.java: New helper
class.
        * gnu/testlet/javax/swing/text/View/getAlignment.java,
        * gnu/testlet/javax/swing/text/View/getMaximumSpan.java,
        * gnu/testlet/javax/swing/text/View/getMinimumSpan.java,
        * gnu/testlet/javax/swing/text/View/getResizeWeight.java:
        New tests.

/Roman
Index: gnu/testlet/javax/swing/text/View/TestView.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/View/TestView.java
diff -N gnu/testlet/javax/swing/text/View/TestView.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/View/TestView.java	9 Feb 2006 11:57:50 -0000
@@ -0,0 +1,93 @@
+/* TestView.java -- A concrete View implementation for testing
+   Copyright (C) 2006 Roman Kennke (kennke@aicas.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.javax.swing.text.View;
+
+import java.awt.Graphics;
+import java.awt.Shape;
+
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Element;
+import javax.swing.text.PlainDocument;
+import javax.swing.text.View;
+import javax.swing.text.Position.Bias;
+
+/**
+ * A concrete View implementation for testing.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class TestView extends View
+{
+
+  /**
+   * This will be returned by getPreferredSpan for X_AXIS or Y_AXIS.
+   */
+  public float preferred[] = new float[]{ 100F, 100F };
+
+  /**
+   * Creates a new test view by fetching an element from PlainView.
+   */
+  public TestView()
+  {
+    super(createDummyElement());
+  }
+
+  /**
+   * Creates a dummy element for testing.
+   *
+   * @return a dummy element for testing
+   */
+  static Element createDummyElement()
+  {
+    PlainDocument doc = new PlainDocument();
+    return doc.getDefaultRootElement();
+  }
+
+  public void paint(Graphics g, Shape s)
+  {
+    // Not needed in testing.
+  }
+
+  /**
+   * Implemented to return the values in above array.
+   */
+  public float getPreferredSpan(int axis)
+  {
+    return preferred[axis];
+  }
+
+  public Shape modelToView(int pos, Shape a, Bias b)
+      throws BadLocationException
+  {
+    // Not used in testing.
+    return null;
+  }
+
+  public int viewToModel(float x, float y, Shape a, Bias[] b)
+  {
+    // Not used in testing.
+    return 0;
+  }
+
+}
Index: gnu/testlet/javax/swing/text/View/getAlignment.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/View/getAlignment.java
diff -N gnu/testlet/javax/swing/text/View/getAlignment.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/View/getAlignment.java	9 Feb 2006 11:57:50 -0000
@@ -0,0 +1,55 @@
+/* getAlignment.java -- Tests the default getAlignment() implementation
+   Copyright (C) 2006 Roman Kennke (kennke@aicas.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.2
+// Uses: TestView
+
+package gnu.testlet.javax.swing.text.View;
+
+import javax.swing.text.View;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**
+ * Tests the default getAlignment() implementation in View.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class getAlignment implements Testlet
+{
+
+  /**
+   * The entry point for this test.
+   *
+   * @param harness the test harness to use
+   */
+  public void test(TestHarness harness)
+  {
+    TestView v = new TestView();
+    harness.check(v.getAlignment(View.X_AXIS), 0.5F);
+    harness.check(v.getAlignment(View.Y_AXIS), 0.5F);
+    // Try two illegal values.
+    harness.check(v.getAlignment(-1), 0.5F);
+    harness.check(v.getAlignment(123), 0.5F);
+  }
+
+}
Index: gnu/testlet/javax/swing/text/View/getMaximumSpan.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/View/getMaximumSpan.java
diff -N gnu/testlet/javax/swing/text/View/getMaximumSpan.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/View/getMaximumSpan.java	9 Feb 2006 11:57:50 -0000
@@ -0,0 +1,104 @@
+/* getMaxnimumSpan.java -- Tests the maximumSpan default implementation
+   Copyright (C) 2006 Roman Kennke (kennke@aicas.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.2
+// Uses: TestView
+
+package gnu.testlet.javax.swing.text.View;
+
+import javax.swing.text.View;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**
+ * Tests the getMaximumSpan() default implementation.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class getMaximumSpan implements Testlet
+{
+
+  /**
+   * A subclass of TestView that allows to customize the resizeWeight.
+   */
+  private class PositiveResizeWeightView extends TestView {
+
+    int resizeWeight = 0;
+
+    /**
+     * Overridden to return a custom resize weight.
+     *
+     * @return resizeWeight
+     */
+    public int getResizeWeight(int axis) {
+      return resizeWeight;
+    }
+  }
+
+  /**
+   * The entry point into this test.
+   *
+   * @param harness the test harness to use
+   */
+  public void test(TestHarness harness)
+  {
+    testXAxis(harness);
+    testYAxis(harness);
+    testPositiveResizeWeight(harness);
+  }
+
+  /**
+   * Tests the default impl for the X_AXIS. This will forward to
+   * getPreferredSpan().
+   *
+   * @param harness the test harness to use
+   */
+  private void testXAxis(TestHarness harness)
+  {
+    TestView v = new TestView();
+    v.preferred[View.X_AXIS] = 123F;
+    harness.check(v.getMaximumSpan(View.X_AXIS), 123F);
+  }
+
+  /**
+   * Tests the default impl for the Y_AXIS. This will forward to
+   * getPreferredSpan().
+   *
+   * @param harness the test harness to use
+   */
+  private void testYAxis(TestHarness harness)
+  {
+    TestView v = new TestView();
+    v.preferred[View.Y_AXIS] = 123F;
+    harness.check(v.getMaximumSpan(View.Y_AXIS), 123F);
+  }
+
+  private void testPositiveResizeWeight(TestHarness harness)
+  {
+    PositiveResizeWeightView v = new PositiveResizeWeightView();
+    v.resizeWeight = 100;
+    v.preferred[View.X_AXIS] = 123F;
+    v.preferred[View.Y_AXIS] = 123F;
+    harness.check((int) v.getMaximumSpan(View.X_AXIS), Integer.MAX_VALUE);
+    harness.check((int) v.getMaximumSpan(View.Y_AXIS), Integer.MAX_VALUE);
+  }
+}
Index: gnu/testlet/javax/swing/text/View/getMinimumSpan.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/View/getMinimumSpan.java
diff -N gnu/testlet/javax/swing/text/View/getMinimumSpan.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/View/getMinimumSpan.java	9 Feb 2006 11:57:50 -0000
@@ -0,0 +1,110 @@
+/* getMinimumSpan.java -- Tests the minimumSpan default implementation
+   Copyright (C) 2006 Roman Kennke (kennke@aicas.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.2
+// Uses: TestView
+
+package gnu.testlet.javax.swing.text.View;
+
+import javax.swing.text.View;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**
+ * Tests the getMinimumSpan() default implementation.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class getMinimumSpan implements Testlet
+{
+
+  /**
+   * A subclass of TestView that allows to customize the resizeWeight.
+   */
+  private class PositiveResizeWeightView extends TestView {
+
+    int resizeWeight = 0;
+
+    /**
+     * Overridden to return a custom resize weight.
+     *
+     * @return resizeWeight
+     */
+    public int getResizeWeight(int axis) {
+      return resizeWeight;
+    }
+  }
+
+  /**
+   * The entry point into this test.
+   *
+   * @param harness the test harness to use
+   */
+  public void test(TestHarness harness)
+  {
+    testXAxis(harness);
+    testYAxis(harness);
+    testPositiveResizeWeight(harness);
+  }
+
+  /**
+   * Tests the default impl for the X_AXIS. This will forward to
+   * getPreferredSpan().
+   *
+   * @param harness the test harness to use
+   */
+  private void testXAxis(TestHarness harness)
+  {
+    TestView v = new TestView();
+    v.preferred[View.X_AXIS] = 123F;
+    harness.check(v.getMinimumSpan(View.X_AXIS), 123F);
+  }
+
+  /**
+   * Tests the default impl for the Y_AXIS. This will forward to
+   * getPreferredSpan().
+   *
+   * @param harness the test harness to use
+   */
+  private void testYAxis(TestHarness harness)
+  {
+    TestView v = new TestView();
+    v.preferred[View.Y_AXIS] = 123F;
+    harness.check(v.getMinimumSpan(View.Y_AXIS), 123F);
+  }
+
+  /**
+   * Tests the minimumSpan with a positive resizeWeight.
+   *
+   * @param harness the test harness to use
+   */
+  private void testPositiveResizeWeight(TestHarness harness)
+  {
+    PositiveResizeWeightView v = new PositiveResizeWeightView();
+    v.resizeWeight = 100;
+    v.preferred[View.X_AXIS] = 123F;
+    v.preferred[View.Y_AXIS] = 123F;
+    harness.check((int) v.getMinimumSpan(View.X_AXIS), 0);
+    harness.check((int) v.getMinimumSpan(View.Y_AXIS), 0);
+  }
+
+}
Index: gnu/testlet/javax/swing/text/View/getResizeWeight.java
===================================================================
RCS file: gnu/testlet/javax/swing/text/View/getResizeWeight.java
diff -N gnu/testlet/javax/swing/text/View/getResizeWeight.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/javax/swing/text/View/getResizeWeight.java	9 Feb 2006 11:57:50 -0000
@@ -0,0 +1,55 @@
+/* getResizeWeight.java -- Tests the default implementation of getResizeWeight
+   Copyright (C) 2006 Roman Kennke (kennke@aicas.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.2
+// Uses: TestView
+
+package gnu.testlet.javax.swing.text.View;
+
+import javax.swing.text.View;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+/**
+ * Tests the default implementation of getResizeWeight().
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+public class getResizeWeight implements Testlet
+{
+
+  /**
+   * The entry point for this test.
+   *
+   * @param harness the test harness to use
+   */
+  public void test(TestHarness harness)
+  {
+    TestView v = new TestView();
+    harness.check(v.getResizeWeight(View.X_AXIS), 0);
+    harness.check(v.getResizeWeight(View.Y_AXIS), 0);
+    // Try two illegal values.
+    harness.check(v.getResizeWeight(-1), 0);
+    harness.check(v.getResizeWeight(123), 0);
+  }
+
+}

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