public inbox for mauve-patches@sourceware.org
 help / color / mirror / Atom feed
* FYI: AttributedCharacterIterator/AttributedString - new tests
@ 2006-09-11 11:26 David Gilbert
  0 siblings, 0 replies; only message in thread
From: David Gilbert @ 2006-09-11 11:26 UTC (permalink / raw)
  To: mauve-patches

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

This patch (committed) adds some new checks that I wrote while looking 
at PR29010:

2006-09-11  David Gilbert  <david.gilbert@object-refinery.com>

    * gnu/testlet/java/text/AttributedCharacterIterator/getRunLimit.java:
    New test,
    * gnu/testlet/java/text/AttributedString/constructors.java
    (testConstructor3): Added new checks.

Regards,

Dave

[-- Attachment #2: diff.txt --]
[-- Type: text/plain, Size: 10518 bytes --]

Index: gnu/testlet/java/text/AttributedCharacterIterator/getRunLimit.java
===================================================================
RCS file: gnu/testlet/java/text/AttributedCharacterIterator/getRunLimit.java
diff -N gnu/testlet/java/text/AttributedCharacterIterator/getRunLimit.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gnu/testlet/java/text/AttributedCharacterIterator/getRunLimit.java	11 Sep 2006 11:21:30 -0000
@@ -0,0 +1,158 @@
+/* getRunLimit.java -- some checks for the getRunLimit() methods in the
+       AttributedCharacterIterator interface.
+   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.2
+
+package gnu.testlet.java.text.AttributedCharacterIterator;
+
+import gnu.testlet.TestHarness;
+import gnu.testlet.Testlet;
+
+import java.awt.Color;
+import java.awt.font.TextAttribute;
+import java.text.AttributedCharacterIterator;
+import java.text.AttributedString;
+import java.util.HashSet;
+import java.util.Set;
+
+public class getRunLimit implements Testlet
+{
+  public void test(TestHarness harness)
+  {
+    test1(harness);
+    test2(harness);
+    test3(harness);
+  }
+  
+  public void test1(TestHarness harness)
+  {
+    harness.checkPoint("()");
+    AttributedString as = new AttributedString("ABCDEFGHIJ");
+    as.addAttribute(TextAttribute.LANGUAGE, "English");
+    as.addAttribute(TextAttribute.FOREGROUND, Color.red, 2, 4);
+    AttributedCharacterIterator aci = as.getIterator();
+    harness.check(aci.getRunLimit(), 2);
+    aci.setIndex(2);
+    harness.check(aci.getRunLimit(), 4);
+    aci.setIndex(5);
+    harness.check(aci.getRunLimit(), 10);
+    
+    // try an empty string
+    as = new AttributedString("");
+    aci = as.getIterator();
+    harness.check(aci.getRunLimit(), 0);
+    
+    // try a string with no attributes
+    as = new AttributedString("ABC");
+    aci = as.getIterator();
+    harness.check(aci.getRunLimit(), 3);
+  }
+  
+  public void test2(TestHarness harness)
+  {
+    harness.checkPoint("(AttributedCharacterIterator.Attribute)");
+    AttributedString as = new AttributedString("ABCDEFGHIJ");
+    as.addAttribute(TextAttribute.LANGUAGE, "English");
+    as.addAttribute(TextAttribute.FOREGROUND, Color.red, 2, 4);
+    AttributedCharacterIterator aci = as.getIterator();
+    harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 10);
+    harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 2);
+    harness.check(aci.getRunLimit(TextAttribute.BACKGROUND), 10);
+    aci.setIndex(2);
+    harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 10);
+    harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 4);
+    harness.check(aci.getRunLimit(TextAttribute.BACKGROUND), 10);
+    aci.setIndex(4);
+    harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 10);
+    harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 10);
+    harness.check(aci.getRunLimit(TextAttribute.BACKGROUND), 10);
+    
+    // try an empty string
+    as = new AttributedString("");
+    aci = as.getIterator();
+    harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 0);
+    
+    // try a string with no attributes
+    as = new AttributedString("ABC");
+    aci = as.getIterator();
+    harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 3);
+  }
+  
+  public void test3(TestHarness harness)
+  {
+    harness.checkPoint("(Set)");    
+    AttributedString as = new AttributedString("ABCDEFGHIJ");
+    as.addAttribute(TextAttribute.LANGUAGE, "English");
+    as.addAttribute(TextAttribute.FOREGROUND, Color.red, 2, 4);
+    as.addAttribute(TextAttribute.BACKGROUND, Color.yellow, 3, 5);
+    AttributedCharacterIterator aci = as.getIterator();
+    Set set0 = new HashSet();
+    Set set1 = new HashSet();
+    set1.add(TextAttribute.LANGUAGE);
+    Set set2 = new HashSet();
+    set2.add(TextAttribute.FOREGROUND);
+    set2.add(TextAttribute.BACKGROUND);
+    Set set3 = new HashSet();
+    set3.add(TextAttribute.LANGUAGE);
+    set3.add(TextAttribute.FOREGROUND);
+    set3.add(TextAttribute.BACKGROUND);
+    harness.check(aci.getRunLimit(set0), 10);
+    harness.check(aci.getRunLimit(set1), 10);
+    harness.check(aci.getRunLimit(set2), 2);
+    harness.check(aci.getRunLimit(set3), 2);
+    aci.setIndex(2);
+    harness.check(aci.getRunLimit(set0), 10);
+    harness.check(aci.getRunLimit(set1), 10);
+    harness.check(aci.getRunLimit(set2), 3);
+    harness.check(aci.getRunLimit(set3), 3);
+    aci.setIndex(3);
+    harness.check(aci.getRunLimit(set0), 10);
+    harness.check(aci.getRunLimit(set1), 10);
+    harness.check(aci.getRunLimit(set2), 4);
+    harness.check(aci.getRunLimit(set3), 4);
+    aci.setIndex(4);
+    harness.check(aci.getRunLimit(set0), 10);
+    harness.check(aci.getRunLimit(set1), 10);
+    harness.check(aci.getRunLimit(set2), 5);
+    harness.check(aci.getRunLimit(set3), 5);
+    aci.setIndex(5);
+    harness.check(aci.getRunLimit(set0), 10);
+    harness.check(aci.getRunLimit(set1), 10);
+    harness.check(aci.getRunLimit(set2), 10);
+    harness.check(aci.getRunLimit(set3), 10);
+    // try an empty string
+    as = new AttributedString("");
+    aci = as.getIterator();
+    harness.check(aci.getRunLimit(set0), 0);
+    harness.check(aci.getRunLimit(set1), 0);
+    harness.check(aci.getRunLimit(set2), 0);
+    harness.check(aci.getRunLimit(set3), 0);
+    
+    // try a string with no attributes
+    as = new AttributedString("ABC");
+    aci = as.getIterator();
+    harness.check(aci.getRunLimit(set0), 3);
+    harness.check(aci.getRunLimit(set1), 3);
+    harness.check(aci.getRunLimit(set2), 3);
+    harness.check(aci.getRunLimit(set3), 3);
+  }
+}
Index: gnu/testlet/java/text/AttributedString/constructors.java
===================================================================
RCS file: /cvs/mauve/mauve/gnu/testlet/java/text/AttributedString/constructors.java,v
retrieving revision 1.2
diff -u -r1.2 constructors.java
--- gnu/testlet/java/text/AttributedString/constructors.java	24 Oct 2005 09:06:03 -0000	1.2
+++ gnu/testlet/java/text/AttributedString/constructors.java	11 Sep 2006 11:21:31 -0000
@@ -1,6 +1,6 @@
 // Tags: JDK1.2
 
-// Copyright (C) 2005 David Gilbert <david.gilbert@object-refinery.com>
+// Copyright (C) 2005, 2006, David Gilbert <david.gilbert@object-refinery.com>
 
 // This file is part of Mauve.
 
@@ -24,6 +24,8 @@
 import gnu.testlet.TestHarness;
 import gnu.testlet.Testlet;
 
+import java.awt.Color;
+import java.awt.font.TextAttribute;
 import java.text.AttributedCharacterIterator;
 import java.text.AttributedString;
 import java.util.HashMap;
@@ -116,7 +118,89 @@
 
   private void testConstructor3(TestHarness harness) 
   {
-    harness.checkPoint("AttributedString(AttributedCharacterIterator, int, int, AttributedCharacterIterator.Attribute[]);"); 
+    harness.checkPoint("AttributedString(AttributedCharacterIterator, int, int," +
+                "AttributedCharacterIterator.Attribute[]);");
+    
+    AttributedString as0 = new AttributedString("ABCDEFGHIJ");
+    as0.addAttribute(TextAttribute.LANGUAGE, "English");
+    as0.addAttribute(TextAttribute.FOREGROUND, Color.red, 2, 4);
+    as0.addAttribute(TextAttribute.BACKGROUND, Color.yellow, 3, 5);
+    
+    // try extracting no attributes...
+    AttributedString as = new AttributedString(as0.getIterator(), 1, 8, 
+            new AttributedCharacterIterator.Attribute[] {});
+    AttributedCharacterIterator aci = as.getIterator();
+    harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 7);
+    harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 7);
+    harness.check(aci.getRunLimit(TextAttribute.BACKGROUND), 7);
+    
+    // try extracting just one attribute...
+    as = new AttributedString(as0.getIterator(), 1, 8, 
+            new AttributedCharacterIterator.Attribute[] {TextAttribute.FOREGROUND});
+    aci = as.getIterator();
+    harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 7);
+    harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 1);
+    aci.setIndex(1);
+    harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 7);
+    harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 3);
+    aci.setIndex(3);
+    harness.check(aci.getRunLimit(TextAttribute.LANGUAGE), 7);
+    harness.check(aci.getRunLimit(TextAttribute.FOREGROUND), 7);
+    
+    // null iterator should throw NullPointerException
+    boolean pass = false;
+    try
+    {
+      /*AttributedString as =*/ new AttributedString(null, 0, 3, 
+            new AttributedCharacterIterator.Attribute[] {TextAttribute.FONT});
+    }
+    catch (NullPointerException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // try start > string length
+    AttributedString as1 = new AttributedString("ABC");
+    
+    pass = false;
+    try
+    {
+      /*AttributedString as =*/ new AttributedString(as1.getIterator(), 3, 4, 
+            new AttributedCharacterIterator.Attribute[] {TextAttribute.FONT});
+    }
+    catch (IllegalArgumentException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+
+    // try end > string length
+    pass = false;
+    try
+    {
+      /*AttributedString as =*/ new AttributedString(as1.getIterator(), 1, 4, 
+            new AttributedCharacterIterator.Attribute[] {TextAttribute.FONT});
+    }
+    catch (IllegalArgumentException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+    
+    // try start > end
+    pass = false;
+    try
+    {
+      /*AttributedString as =*/ new AttributedString(as1.getIterator(), 1, 0, 
+            new AttributedCharacterIterator.Attribute[] {TextAttribute.FONT});
+    }
+    catch (IllegalArgumentException e)
+    {
+      pass = true;
+    }
+    harness.check(pass);
+  
   }
 
   private void testConstructor4(TestHarness harness) 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2006-09-11 11:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-11 11:26 FYI: AttributedCharacterIterator/AttributedString - new tests David Gilbert

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).