1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/* 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);
as.addAttribute(TextAttribute.BACKGROUND, Color.blue, 7, 8);
AttributedCharacterIterator aci = as.getIterator();
harness.check(aci.getRunLimit(), 2);
aci.setIndex(2);
harness.check(aci.getRunLimit(), 4);
aci.setIndex(5);
harness.check(aci.getRunLimit(), 7);
aci.setIndex(7);
harness.check(aci.getRunLimit(), 8);
aci.setIndex(8);
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);
}
}
|