private void testConstructor3(TestHarness harness)
{
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;