diff --git a/icu4j/src/com/ibm/richtext/test/TestTextPanel.java b/icu4j/src/com/ibm/richtext/test/TestTextPanel.java index e1ded9a660d..7118a2baf9a 100755 --- a/icu4j/src/com/ibm/richtext/test/TestTextPanel.java +++ b/icu4j/src/com/ibm/richtext/test/TestTextPanel.java @@ -1,5 +1,5 @@ /* - * @(#)$RCSfile: TestTextPanel.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:46:57 $ + * @(#)$RCSfile: TestTextPanel.java,v $ $Revision: 1.2 $ $Date: 2000/04/21 22:11:24 $ * * (C) Copyright IBM Corp. 1998-1999. All Rights Reserved. * @@ -14,6 +14,8 @@ */ package com.ibm.richtext.tests; +import com.ibm.test.TestFmwk; + import java.util.Random; import java.awt.Color; import java.awt.Frame; @@ -41,7 +43,12 @@ import com.ibm.textlayout.attributes.AttributeSet; import com.ibm.textlayout.attributes.TextAttribute; import com.ibm.textlayout.attributes.AttributeMap; -public final class TestTextPanel { +public final class TestTextPanel extends TestFmwk { + + public static void main(String[] args) throws Exception { + + new TestTextPanel().run(args); + } private final class TestListener implements TextPanelListener { @@ -96,7 +103,7 @@ public final class TestTextPanel { } } if (e) { - throw new Error("Some events pending"); + errln("Some events pending"); } } @@ -104,7 +111,7 @@ public final class TestTextPanel { int index = event.getID() - TextPanelEvent.TEXT_PANEL_FIRST; if (status[index] == NO_WAY) { - throw new Error("Unexpected event: " + event); + errln("Unexpected event: " + event); } else if (status[index] == DEFINITELY) { status[index] = NO_WAY; @@ -193,18 +200,18 @@ public final class TestTextPanel { } } - public static void main(String[] args) { - - new TestTextPanel().test(); - System.out.println("TextPanelTest PASSED"); - } - public TestTextPanel() { fClipboard = new Clipboard("TestTextPanel"); incRandSeed(); } + // For inner class accessibility + protected void errln(String message) { + + super.errln(message); + } + public TestTextPanel(MTextPanel panel) { this(); @@ -275,11 +282,11 @@ public final class TestTextPanel { setTextPanel(new TextPanel(text, fClipboard)); for (int i=0; i < TEST_ITERS; i++) { - testSetSelection(); + _testSetSelection(); testModifications(MOD_TEXT, true); testEditMenuOperations(fClipboard); testModFlag(fTextPanel.getCommandLogSize()); - testCommandLogControl(); + _testCommandLogControl(); } } @@ -340,10 +347,10 @@ public final class TestTextPanel { } if (fTextPanel.getSelectionStart() != start) { - throw new Error("getSelectionStart is incorrect after set"); + errln("getSelectionStart is incorrect after set"); } if (fTextPanel.getSelectionEnd() != limit) { - throw new Error("getSelectionEnd is incorrect after set"); + errln("getSelectionEnd is incorrect after set"); } fListener.assertNotExpectingEvents(); fListener.allowAll(); @@ -371,11 +378,11 @@ public final class TestTextPanel { testSelection(SET_END, start, selEnd); } - public void testSetSelection() { + public void _testSetSelection() { int textLength = fTextPanel.getTextLength(); if (textLength != fTextPanel.getText().length()) { - throw new Error("Text panel length is not correct"); + errln("Text panel length is not correct"); } setAndTestSelection(0, textLength / 2); @@ -414,7 +421,7 @@ public final class TestTextPanel { fListener.assertNotExpectingEvents(); if (fTextPanel.getSelectionStart() != oldText.length() + insLength) { - throw new Error("Append didn't result in correct selection"); + errln("Append didn't result in correct selection"); } fListener.expectEvent(TextPanelEvent.TEXT_CHANGED); @@ -424,27 +431,27 @@ public final class TestTextPanel { fListener.allowAll(); if (fTextPanel.getSelectionStart() != insLength) { - throw new Error("Insert didn't result in correct selection"); + errln("Insert didn't result in correct selection"); } fTextPanel.replaceRange(insertionText, insLength, insLength+oldText.length()); if (fTextPanel.getSelectionStart() != insLength*2) { - throw new Error("Replace didn't result in correct selection"); + errln("Replace didn't result in correct selection"); } if (fTextPanel.getSelectionEnd() != insLength*2) { - throw new Error("Replace didn't result in correct selection"); + errln("Replace didn't result in correct selection"); } if (fTextPanel.getTextLength() != insLength*3) { - throw new Error("textLength is incorrect"); + errln("textLength is incorrect"); } if (restoreOldText) { fTextPanel.setText(oldText); if (fTextPanel.getSelectionStart() != oldText.length()) { - throw new Error("setText didn't result in correct selection"); + errln("setText didn't result in correct selection"); } if (fTextPanel.getTextLength() != oldText.length()) { - throw new Error("length incorrect after setText"); + errln("length incorrect after setText"); } } @@ -452,7 +459,7 @@ public final class TestTextPanel { } private static int iterationCount = 0; - public void testCommandLogControl() { + public void _testCommandLogControl() { fListener.refuseAll(); iterationCount++; @@ -465,7 +472,7 @@ public final class TestTextPanel { fTextPanel.setCommandLogSize(BIG_COMMAND_LOG_SIZE); if (fTextPanel.canRedo()) { - throw new Error("canRedo after setCommandLogSize"); + errln("canRedo after setCommandLogSize"); } fListener.assertNotExpectingEvents(); } @@ -502,17 +509,17 @@ public final class TestTextPanel { fListener.assertNotExpectingEvents(); } if (!fTextPanel.canUndo()) { - throw new Error("Command log is too small"); + errln("Command log is too small"); } fListener.allowAll(); fTextPanel.undo(); if (fTextPanel.canUndo()) { - throw new Error("Command log is too large"); + errln("Command log is too large"); } if (fTextPanel.getTextLength() != origLength * insText.length()) { - throw new Error("Text length was not restored"); + errln("Text length was not restored"); } for (int i=0; i < BIG_COMMAND_LOG_SIZE; i++) { @@ -520,11 +527,11 @@ public final class TestTextPanel { } if (fTextPanel.getTextLength() != origLength+BIG_COMMAND_LOG_SIZE) { - throw new Error("Text length was not restored after redo"); + errln("Text length was not restored after redo"); } if (fTextPanel.canRedo()) { - throw new Error("Should not be able to redo"); + errln("Should not be able to redo"); } fTextPanel.undo(); @@ -532,27 +539,27 @@ public final class TestTextPanel { fTextPanel.setCommandLogSize(SMALL_COMMAND_LOG_SIZE); if (fTextPanel.canRedo()) { - throw new Error("canRedo after setCommandLogSize(small)"); + errln("canRedo after setCommandLogSize(small)"); } for (int i=0; i < SMALL_COMMAND_LOG_SIZE; i++) { if (!fTextPanel.canUndo()) { - throw new Error("should be able to undo"); + errln("should be able to undo"); } fTextPanel.undo(); } if (fTextPanel.canUndo()) { - throw new Error("should not be able to undo after setCommandLogSize(small)"); + errln("should not be able to undo after setCommandLogSize(small)"); } if (!fTextPanel.canRedo()) { - throw new Error("why can't this redo???"); + errln("why can't this redo???"); } fTextPanel.redo(); fTextPanel.clearCommandLog(); if (fTextPanel.canUndo() || fTextPanel.canRedo()) { - throw new Error("Command log wasn't cleared"); + errln("Command log wasn't cleared"); } } @@ -570,29 +577,29 @@ public final class TestTextPanel { } }); if (!fTextPanel.clipboardNotEmpty()) { - throw new Error("MTextPanel doesn't recognize string content."); + errln("MTextPanel doesn't recognize string content."); } fTextPanel.setCaretPosition(fTextPanel.getSelectionStart()); int oldLength = fTextPanel.getTextLength(); fTextPanel.paste(); if (fTextPanel.getTextLength() != oldLength + STRING_CONTENT.length()) { - throw new Error("Text length is wrong after paste."); + errln("Text length is wrong after paste."); } if (!fTextPanel.canUndo()) { - throw new Error("canUndo should be true"); + errln("canUndo should be true"); } fTextPanel.undo(); if (fTextPanel.getTextLength() != oldLength) { - throw new Error("Length is wrong after undo"); + errln("Length is wrong after undo"); } if (!fTextPanel.canRedo()) { - throw new Error("canRedo should be true"); + errln("canRedo should be true"); } fTextPanel.redo(); if (fTextPanel.getTextLength() != oldLength + STRING_CONTENT.length()) { - throw new Error("Text length is wrong after redo."); + errln("Text length is wrong after redo."); } } @@ -600,14 +607,14 @@ public final class TestTextPanel { fTextPanel.selectAll(); fTextPanel.clear(); if (fTextPanel.getTextLength() != 0) { - throw new Error("Length is nonzero after clear"); + errln("Length is nonzero after clear"); } if (!fTextPanel.canUndo()) { - throw new Error("canUndo should be true"); + errln("canUndo should be true"); } fTextPanel.undo(); if (fTextPanel.getTextLength() != origLength) { - throw new Error("Old text not restored"); + errln("Old text not restored"); } if (origLength > 0) { @@ -615,22 +622,22 @@ public final class TestTextPanel { fTextPanel.select(0, 1); fTextPanel.cut(); if (fTextPanel.getTextLength() != origLength-1) { - throw new Error("Length wrong after cut"); + errln("Length wrong after cut"); } fTextPanel.paste(); if (fTextPanel.getTextLength() != origLength) { - throw new Error("Length wrong after paste"); + errln("Length wrong after paste"); } fTextPanel.select(0, origLength); fTextPanel.copy(); fTextPanel.setCaretPosition(0); fTextPanel.paste(); if (fTextPanel.getTextLength() != 2*origLength) { - throw new Error("Length wrong after paste"); + errln("Length wrong after paste"); } fTextPanel.undo(); if (fTextPanel.getTextLength() != origLength) { - throw new Error("Length wrong after undo"); + errln("Length wrong after undo"); } } } @@ -641,7 +648,7 @@ public final class TestTextPanel { fTextPanel.setModified(modified); for (int i=0; i < depth; i++) { if (!fTextPanel.canUndo()) { - throw new Error("Panel cannot undo at valid depth. Depth=" + i); + errln("Panel cannot undo at valid depth. Depth=" + i); } fTextPanel.undo(); fTextPanel.setModified(modified); @@ -649,13 +656,13 @@ public final class TestTextPanel { // check that all mod flags are false: if (fTextPanel.isModified() != modified) { - throw new Error("isModified is not correct"); + errln("isModified is not correct"); } for (int i=0; i < depth; i++) { fTextPanel.redo(); if (fTextPanel.isModified() != modified) { - throw new Error("isModified is not correct"); + errln("isModified is not correct"); } } } @@ -681,7 +688,7 @@ public final class TestTextPanel { } if (fTextPanel.getTextLength() != oldLength) { - throw new Error("Undo did not restore old text."); + errln("Undo did not restore old text."); } } @@ -743,7 +750,7 @@ public final class TestTextPanel { break; default: - throw new Error("Invalid operation!"); + errln("Invalid operation!"); } fListener.assertNotExpectingEvents(); fListener.allowAll(); diff --git a/icu4j/src/com/ibm/richtext/tests/TestAttributeMap.java b/icu4j/src/com/ibm/richtext/tests/TestAttributeMap.java index c16499692ff..bfbe326793d 100755 --- a/icu4j/src/com/ibm/richtext/tests/TestAttributeMap.java +++ b/icu4j/src/com/ibm/richtext/tests/TestAttributeMap.java @@ -1,5 +1,5 @@ /* - * @(#)$RCSfile: TestAttributeMap.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:46:57 $ + * @(#)$RCSfile: TestAttributeMap.java,v $ $Revision: 1.2 $ $Date: 2000/04/21 22:11:24 $ * * (C) Copyright IBM Corp. 1998-1999. All Rights Reserved. * @@ -14,7 +14,7 @@ */ package com.ibm.richtext.tests; -//import java.util.Hashtable; +import com.ibm.test.TestFmwk; import com.ibm.textlayout.attributes.AttributeSet; import com.ibm.textlayout.attributes.TextAttribute; @@ -22,10 +22,31 @@ import com.ibm.textlayout.attributes.Map; import com.ibm.textlayout.attributes.AttributeMap; import java.util.Enumeration; -public class TestAttributeMap { +// Java2 imports +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; +import java.util.Map.Entry; + + +public class TestAttributeMap extends TestFmwk { static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved"; + + + // There are JDK 1.1 versions of AttributeMap and AttributeSet. + // Some of the tests in this class require Java 2 API's. I have + // tried to isolate these tests by conditionalizing them on + // this static variable. If you are back-porting to 1.1, remove + // the Java 2 tests ONLY. + private static final boolean gJDK11 = false; + + public static void main(String[] args) throws Exception { + + new TestAttributeMap().run(args); + } + private AttributeSet maps; // A Set of AttributeMaps private AttributeSet sets; // A Set of Sets @@ -44,28 +65,19 @@ public class TestAttributeMap { "Hello world", new Float(-42), new Object(), new AttributeMap(new TestAttribute("3"), "HH") }; - /** - * If the test fails an exception will propogate out of main. - */ - public static void main(String[] args) { - - new TestAttributeMap().test(); - System.out.println("PASSED"); - } - /** * Returns lhs.equals(rhs) - but also checks for symmetry, and * consistency with hashCode(). */ - private static boolean equalMaps(AttributeMap lhs, Object rhs) { + private boolean equalMaps(AttributeMap lhs, Object rhs) { boolean equal = lhs.equals(rhs); if (equal != (rhs.equals(lhs))) { - throw new Error("AttributeMap.equals is not symetric"); + errln("AttributeMap.equals is not symetric"); } if (equal) { if (lhs.hashCode() != rhs.hashCode()) { - throw new Error("AttributeMaps are equal but hashCodes differ"); + errln("AttributeMaps are equal but hashCodes differ"); } } return equal; @@ -114,26 +126,25 @@ public class TestAttributeMap { public void test() { easyTests(); - //onlyAttributeKeyTests(); Enumeration mapIter = maps.elements(); while (mapIter.hasMoreElements()) { AttributeMap testMap = (AttributeMap) mapIter.nextElement(); - testModifiers(testMap); - testViews(testMap); + _testModifiers(testMap); + _testViews(testMap); Enumeration unionIter = maps.elements(); while (unionIter.hasMoreElements()) { - testUnionWith(testMap, (AttributeMap) unionIter.nextElement()); + _testUnionWith(testMap, (AttributeMap) unionIter.nextElement()); } Enumeration setIter = sets.elements(); while (setIter.hasMoreElements()) { AttributeSet testSet = (AttributeSet) setIter.nextElement(); - testIntersectWith(testMap, testSet); - testRemoveAttributes(testMap, testSet); + _testIntersectWith(testMap, testSet); + _testRemoveAttributes(testMap, testSet); } } } @@ -142,13 +153,17 @@ public class TestAttributeMap { * Invoke modifiers on map. All should throw * UnsupportedOperationException, and leave map unmodified. */ - public static void testModifiers(AttributeMap map) { -/* + void _testModifiers(AttributeMap map) { + + if (gJDK11) { + return; + } + AttributeMap originalMap = new AttributeMap(map); try { map.put(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); - throw new Error("Put should throw UnsupportedOperationException."); + errln("Put should throw UnsupportedOperationException."); } catch(UnsupportedOperationException e) { } @@ -160,36 +175,35 @@ public class TestAttributeMap { key = iter.next(); } map.remove(key); - throw new Error("Set should throw UnsupportedOperationException."); + errln("Set should throw UnsupportedOperationException."); } catch(UnsupportedOperationException e) { } try { map.putAll(map); - throw new Error("putAll should throw UnsupportedOperationException."); + errln("putAll should throw UnsupportedOperationException."); } catch(UnsupportedOperationException e) { } try { map.clear(); - throw new Error("clear should throw UnsupportedOperationException."); + errln("clear should throw UnsupportedOperationException."); } catch(UnsupportedOperationException e) { } if (!originalMap.equals(map)) { - throw new Error("Modifiers changed map."); + errln("Modifiers changed map."); } -*/ } /** * Ensure that map.addAttributes(addMap) is equivalent to calling * map.add on all of addMap's entries. */ - public static void testUnionWith(AttributeMap map, AttributeMap addMap) { + void _testUnionWith(AttributeMap map, AttributeMap addMap) { AttributeMap lhs = map.addAttributes(addMap); @@ -203,7 +217,7 @@ public class TestAttributeMap { } if (!equalMaps(lhs, rhs)) { - throw new Error("Maps are not equal."); + errln("Maps are not equal."); } } @@ -211,7 +225,7 @@ public class TestAttributeMap { * Ensure that map.removeAttributes(remove) is equivalent to calling * map.removeAttribute on remove's elements. */ - public static void testRemoveAttributes(AttributeMap map, AttributeSet remove) { + void _testRemoveAttributes(AttributeMap map, AttributeSet remove) { AttributeMap lhs = map.removeAttributes(remove); @@ -224,7 +238,7 @@ public class TestAttributeMap { } if (!equalMaps(lhs, rhs)) { - throw new Error("Maps are not equal."); + errln("Maps are not equal."); } } @@ -232,7 +246,7 @@ public class TestAttributeMap { * Ensure that map.intersectWith(intersect) is equivalent to * map.removeAttributes(map.keySet() - intersect); */ - public static void testIntersectWith(AttributeMap map, AttributeSet intersect) { + void _testIntersectWith(AttributeMap map, AttributeSet intersect) { AttributeMap lhs = map.intersectWith(intersect); @@ -248,7 +262,7 @@ public class TestAttributeMap { System.out.println("map: " + map); System.out.println("lhs: " + lhs); System.out.println("rhs: " + rhs); - throw new Error("Maps are not equal."); + errln("Maps are not equal."); } } @@ -261,29 +275,34 @@ public class TestAttributeMap { * map.get() is consistent with entry's key, value; * sum of hashcodes of entries equals map.hashCode(). */ - public static void testViews(AttributeMap map) { + void _testViews(AttributeMap map) { AttributeSet keySet = map.getKeySet(); - //Collection values = map.values(); - //Set entrySet = map.entrySet(); - - if (keySet.size() != map.size() /*|| entrySet.size() != map.size()*/) { - throw new Error("Set sizes are inconsistent with map size."); - } - - int hashCode = 0; Enumeration keyIter = keySet.elements(); while (keyIter.hasMoreElements()) { if (!map.containsKey(keyIter.nextElement())) { - throw new Error("keySet contains key not in map"); + errln("keySet contains key not in map"); } } -/* + + if (gJDK11) { + return; + } + + Collection values = map.values(); + Set entrySet = map.entrySet(); + + if (keySet.size() != map.size() || entrySet.size() != map.size()) { + errln("Set sizes are inconsistent with map size."); + } + + int hashCode = 0; + Iterator valueIter = values.iterator(); while (valueIter.hasNext()) { if (!map.containsValue(valueIter.next())) { - throw new Error("value set contains value not in map"); + errln("value set contains value not in map"); } } @@ -294,77 +313,76 @@ public class TestAttributeMap { Object key = entry.getKey(); if (!keySet.contains(key)) { - throw new Error("Entry key is not in key set."); + errln("Entry key is not in key set."); } Object value = map.get(entry.getKey()); if (!values.contains(value)) { - throw new Error("Entry value is not in value set."); + errln("Entry value is not in value set."); } if (map.get(key) != value) { - throw new Error("map.get did not return entry value."); + errln("map.get did not return entry value."); } hashCode += entry.hashCode(); } if (hashCode != map.hashCode()) { - throw new Error("map hashcode is not sum of entry hashcodes."); + errln("map hashcode is not sum of entry hashcodes."); } -*/ } /** * Look for correct behavior in obvious cases. */ - private void easyTests() { + void easyTests() { AttributeMap map = new AttributeMap(); if (!map.equals(AttributeMap.EMPTY_ATTRIBUTE_MAP)) { - throw new Error("Default-constructed map is not equal to empty map."); + errln("Default-constructed map is not equal to empty map."); } map = map.addAttribute(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); Object otherMap = new AttributeMap(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE); if (!map.equals(otherMap)) { - throw new Error("Maps are inconsistent after map.add"); + errln("Maps are inconsistent after map.add"); } otherMap = map.addAttributes(map); if (!equalMaps(map,otherMap)) { - throw new Error("Maps are inconsistent after addAttributes"); + errln("Maps are inconsistent after addAttributes"); } map = map.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); if (map.size() != 2) { - throw new Error("Map size is wrong. map="+map); + errln("Map size is wrong. map="+map); } if (equalMaps(map,otherMap)) { - throw new Error("Maps should not be equal"); + errln("Maps should not be equal"); } Object posture = new Float(0); map = map.addAttribute(TextAttribute.POSTURE, posture); if (map.size() != 2) { - throw new Error("Map size is wrong"); + errln("Map size is wrong"); } if (!map.get(TextAttribute.POSTURE).equals(posture)) { - throw new Error("Map element is wrong"); + errln("Map element is wrong"); } map = map.removeAttribute(TextAttribute.UNDERLINE); if (map.size() != 1) { - throw new Error("Map size is wrong"); + errln("Map size is wrong"); } if (map.get(TextAttribute.UNDERLINE) != null) { - throw new Error("Map should not have element"); + errln("Map should not have element"); } // map has POSTURE_REGULAR. If we addAttributes a map with @@ -372,11 +390,11 @@ public class TestAttributeMap { map = map.addAttributes(new AttributeMap(TextAttribute.POSTURE, TextAttribute.POSTURE_OBLIQUE)); if (map.get(TextAttribute.POSTURE) != TextAttribute.POSTURE_OBLIQUE) { - throw new Error("Map element is wrong"); + errln("Map element is wrong"); } - testModifiers(map); - testViews(map); + _testModifiers(map); + _testViews(map); Enumeration mapIter = maps.elements(); while (mapIter.hasMoreElements()) { @@ -384,29 +402,8 @@ public class TestAttributeMap { Object newValue = new Object(); AttributeMap newMap = testMap.addAttribute(attributes[0], newValue); if (newMap.get(attributes[0]) != newValue) { - throw new Error("Did not get expected value back. map=" + map); + errln("Did not get expected value back. map=" + map); } } } - -/* private void onlyAttributeKeyTests() { - - Hashtable ht = new Hashtable(); - ht.put("Not an attribute!", "Shouldn't work!"); - - try { - new AttributeMap(ht); - throw new Error("No exception from non-Attribute key in constructor"); - } - catch(ClassCastException e) { - } - - try { - AttributeMap.EMPTY_ATTRIBUTE_MAP.addAttributes(ht); - throw new Error("No exception from non-Attribute key in addAttributes"); - } - catch(ClassCastException e) { - } - } -*/ } \ No newline at end of file diff --git a/icu4j/src/com/ibm/richtext/tests/TestAttributeSet.java b/icu4j/src/com/ibm/richtext/tests/TestAttributeSet.java index 1196749d6d7..d77105256c0 100755 --- a/icu4j/src/com/ibm/richtext/tests/TestAttributeSet.java +++ b/icu4j/src/com/ibm/richtext/tests/TestAttributeSet.java @@ -1,5 +1,5 @@ /* - * @(#)$RCSfile: TestAttributeSet.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:46:57 $ + * @(#)$RCSfile: TestAttributeSet.java,v $ $Revision: 1.2 $ $Date: 2000/04/21 22:11:24 $ * * (C) Copyright IBM Corp. 1998-1999. All Rights Reserved. * @@ -14,17 +14,18 @@ */ package com.ibm.richtext.tests; +import com.ibm.test.TestFmwk; import com.ibm.textlayout.attributes.AttributeSet; import java.util.Enumeration; -public class TestAttributeSet { +public class TestAttributeSet extends TestFmwk { static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved"; - public static void main(String[] args) { + + public static void main(String[] args) throws Exception { - new TestAttributeSet().test(); - System.out.println("PASSED"); + new TestAttributeSet().run(args); } public void test() { @@ -36,55 +37,55 @@ public class TestAttributeSet { AttributeSet set1 = new AttributeSet(new Object[] {elem1, elem2, elem3}); if (set1.size() != 3) { - throw new Error("Size is wrong."); + errln("Size is wrong."); } if (set1.contains(elem4)){ - throw new Error("Set contents are wrong."); + errln("Set contents are wrong."); } if (!set1.contains(elem1)) { - throw new Error("Set contents are wrong."); + errln("Set contents are wrong."); } AttributeSet set2 = new AttributeSet(elem4); if (set2.size() != 1) { - throw new Error("Size is wrong."); + errln("Size is wrong."); } if (!set2.contains(elem4)){ - throw new Error("Set contents are wrong."); + errln("Set contents are wrong."); } if (set2.contains(elem1)) { - throw new Error("Set contents are wrong."); + errln("Set contents are wrong."); } Enumeration iter = set2.elements(); if (!iter.nextElement().equals(elem4)) { - throw new Error("Invalid object in iterator."); + errln("Invalid object in iterator."); } AttributeSet union = set2.unionWith(set1); if (!set1.unionWith(set2).equals(union)) { - throw new Error("unionWith is not commutative."); + errln("unionWith is not commutative."); } if (!union.contains(elem1) || !union.contains(elem4)) { - throw new Error("Set contents are wrong."); + errln("Set contents are wrong."); } if (!set1.addElement(elem4).equals(union)) { - throw new Error("addElement is wrong."); + errln("addElement is wrong."); } if (!union.intersectWith(set1).equals(set1)) { - throw new Error("intersectWith is wrong."); + errln("intersectWith is wrong."); } if (!union.subtract(set1).equals(set2)) { - throw new Error("subtract is wrong."); + errln("subtract is wrong."); } } } \ No newline at end of file diff --git a/icu4j/src/com/ibm/richtext/tests/TestFormatter.java b/icu4j/src/com/ibm/richtext/tests/TestFormatter.java index 3d38d6ac97b..ea7ec960b6e 100755 --- a/icu4j/src/com/ibm/richtext/tests/TestFormatter.java +++ b/icu4j/src/com/ibm/richtext/tests/TestFormatter.java @@ -1,5 +1,5 @@ /* - * @(#)$RCSfile: TestFormatter.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:46:57 $ + * @(#)$RCSfile: TestFormatter.java,v $ $Revision: 1.2 $ $Date: 2000/04/21 22:11:24 $ * * (C) Copyright IBM Corp. 1998-1999. All Rights Reserved. * @@ -14,6 +14,8 @@ */ package com.ibm.richtext.tests; +import com.ibm.test.TestFmwk; + import com.ibm.textlayout.attributes.AttributeMap; import com.ibm.textlayout.attributes.TextAttribute; import com.ibm.richtext.styledtext.MText; @@ -31,14 +33,19 @@ import java.awt.Image; import java.awt.Point; import java.awt.Rectangle; import java.awt.Toolkit; -import java.awt.image.MemoryImageSource; +import java.awt.image.BufferedImage; import java.util.Hashtable; -public final class TestFormatter { +public final class TestFormatter extends TestFmwk { static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved"; + public static void main(String[] args) throws Exception { + + new TestFormatter().run(args); + } + private static final Point ORIGIN = new Point(0, 0); private static final AttributeMap DEFAULTS; @@ -71,21 +78,14 @@ public final class TestFormatter { private Graphics fGraphics; - public static void main(String[] args) { - - new TestFormatter().test(); - System.out.println("Formatter test PASSED"); - } - public TestFormatter() { - //MemoryImageSource mis = new MemoryImageSource(10, 10, new int[100], 0, 10); - //Image img = Toolkit.getDefaultToolkit().createImage(mis); - //img = img.getScaledInstance(10, 10, 0); - - Frame f = new Frame(); - f.show(); - fGraphics = f.getGraphics(); + fGraphics = new BufferedImage(100, 100, BufferedImage.TYPE_3BYTE_BGR).getGraphics(); + + //JDK 1.1: + //Frame f = new Frame(); + //f.show(); + //fGraphics = f.getGraphics(); } private String fiveLines = "a\nb\nc\nd\ne"; @@ -94,18 +94,18 @@ public final class TestFormatter { public void test() { - //MConstText text = new StyledText(fiveLines, PLAIN); - //testLineExceptions(makeFormatter(text, 100, true), 5); - //testLineAccess(makeFormatter(text, 100, true), 5); + MConstText text = new StyledText(fiveLines, PLAIN); + _testLineExceptions(makeFormatter(text, 100, true), 5); + _testLineAccess(makeFormatter(text, 100, true), 5); - //text = new StyledText(twelveLines, PLAIN); - //testLineExceptions(makeFormatter(text, 3, false), 12); - //testLineAccess(makeFormatter(text, 100, true), 12); + text = new StyledText(twelveLines, PLAIN); + _testLineExceptions(makeFormatter(text, 3, false), 12); + _testLineAccess(makeFormatter(text, 100, true), 12); - testWithModification(); + _testWithModification(); } - private void testWithModification() { + private void _testWithModification() { MText text = new StyledText(fiveLines, PLAIN); MFormatter formatter = makeFormatter(text, 100, true); @@ -115,19 +115,19 @@ public final class TestFormatter { text.append(new StyledText("\n", PLAIN)); formatter.updateFormat(text.length()-1, 1, viewRect, ORIGIN); - testLineAccess(formatter, 6); + _testLineAccess(formatter, 6); formatter.stopBackgroundFormatting(); text.append(new StyledText("ad", PLAIN)); formatter.updateFormat(text.length()-2, 2, viewRect, ORIGIN); - testLineAccess(formatter, 6); - testLineExceptions(formatter, 6); + _testLineAccess(formatter, 6); + _testLineExceptions(formatter, 6); formatter.stopBackgroundFormatting(); text.remove(0, 1); formatter.updateFormat(0, 0, viewRect, ORIGIN); - testLineAccess(formatter, 6); - testLineExceptions(formatter, 6); + _testLineAccess(formatter, 6); + _testLineExceptions(formatter, 6); } @@ -142,7 +142,7 @@ public final class TestFormatter { fGraphics); } - private void testLineExceptions(MFormatter formatter, + private void _testLineExceptions(MFormatter formatter, int numLines) { if (numLines == UNKNOWN) { @@ -159,7 +159,7 @@ public final class TestFormatter { } if (!caught) { - throw new Error("Didn't get exception"); + errln("Didn't get exception"); } caught = false; @@ -171,7 +171,7 @@ public final class TestFormatter { } if (!caught) { - throw new Error("Didn't get exception"); + errln("Didn't get exception"); } caught = false; @@ -183,23 +183,23 @@ public final class TestFormatter { } if (!caught) { - throw new Error("Didn't get exception"); + errln("Didn't get exception"); } caught = false; } - private void testLineAccess(MFormatter formatter, - int numLines) { + private void _testLineAccess(MFormatter formatter, + int numLines) { if (numLines == UNKNOWN) { numLines = formatter.getLineCount(); } if (formatter.lineGraphicStart(0) != 0) { - throw new Error("Line 0 doesn't start at height 0"); + errln("Line 0 doesn't start at height 0"); } if (formatter.lineRangeLow(0) != 0) { - throw new Error("Line 0 doesn't start at character 0"); + errln("Line 0 doesn't start at character 0"); } int lastLimit = formatter.lineRangeLimit(0); @@ -212,34 +212,34 @@ public final class TestFormatter { int height = formatter.lineGraphicStart(i); if (lastLimit != formatter.lineRangeLow(i)) { - throw new Error("lastLine limit is not current line start"); + errln("lastLine limit is not current line start"); } int limit = formatter.lineRangeLimit(i); if (limit < lastLimit || (limit == lastLimit && i != numLines-1)) { - throw new Error("line has negative or 0 length"); + errln("line has negative or 0 length"); } int nextHeight = formatter.lineGraphicStart(i+1); if (nextHeight <= height) { - throw new Error("0-height line"); + errln("0-height line"); } int incAmount = Math.max((nextHeight-height)/4, 1); for (int hitY = height; hitY < nextHeight; hitY += incAmount) { if (formatter.lineAtHeight(hitY) != i) { - throw new Error("lineAtHeight is wrong"); + errln("lineAtHeight is wrong"); } for (int j=0; j < hitX.length; j++) { offset = formatter.pointToTextOffset(offset, hitX[j], hitY, ORIGIN, null, false); if (offset.fOffset < lastLimit || offset.fOffset > limit) { - throw new Error("Inconsistent offset from pointToTextOffset"); + errln("Inconsistent offset from pointToTextOffset"); } //if (formatter.lineContaining(offset) != i) { // int debug = formatter.lineContaining(offset); - // throw new Error("lineContaining is incorrect"); + // errln("lineContaining is incorrect"); //} } } diff --git a/icu4j/src/com/ibm/richtext/tests/TestMText.java b/icu4j/src/com/ibm/richtext/tests/TestMText.java index 1993f7c065a..67a8b7757fd 100755 --- a/icu4j/src/com/ibm/richtext/tests/TestMText.java +++ b/icu4j/src/com/ibm/richtext/tests/TestMText.java @@ -1,5 +1,5 @@ /* - * @(#)$RCSfile: TestMText.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:46:57 $ + * @(#)$RCSfile: TestMText.java,v $ $Revision: 1.2 $ $Date: 2000/04/21 22:11:24 $ * * (C) Copyright IBM Corp. 1998-1999. All Rights Reserved. * @@ -14,6 +14,8 @@ */ package com.ibm.richtext.tests; +import com.ibm.test.TestFmwk; + import com.ibm.textlayout.attributes.AttributeMap; import com.ibm.textlayout.attributes.TextAttribute; @@ -27,14 +29,23 @@ import java.util.Random; import java.io.*; -public class TestMText { +public class TestMText extends TestFmwk { static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved"; + public static void main(String[] args) throws Exception { + + new TestMText().run(args); + } + private static final int TEST_ITERATIONS = 5000; private static final int STYLE_TEST_ITERATIONS = 5000; private static final long RAND_SEED = 598436; + private static final int NOT_IN_MONKEY_TEST = -5000; + private int testIteration = NOT_IN_MONKEY_TEST; + private int theCase = NOT_IN_MONKEY_TEST; + private static StyleModifier createMinusModifier(final Object attr) { return new StyleModifier() { public AttributeMap modifyStyle(AttributeMap style) { @@ -43,28 +54,13 @@ public class TestMText { }; } - private static final String NO_STREAMING_ARG = "-nostreaming"; - - public static void main(String[] args) { - - TestMText t = new TestMText(); - boolean streaming = true; - - if (args.length > 0) { - if (args.length == 1 && args[0].equals(NO_STREAMING_ARG)) { - streaming = false; - } - else { - throw new Error("USAGE: java TestMText [" + NO_STREAMING_ARG + "]"); - } - } - - t.simpleTest(); - t.styleTest(); - t.monkeyTest(streaming); - System.out.println("MText test PASSED"); + public void test() { + + simpleTest(); + styleTest(); + monkeyTest(true); } - + public void simpleTest() { AttributeMap boldStyle = new AttributeMap(TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD); @@ -81,13 +77,13 @@ public class TestMText { buf.append(allItalic); if (ts == buf.getTimeStamp()) { - throw new Error("Time stamp not incremented"); + errln("Time stamp not incremented"); } // should be bbbbbiii now if (buf.length() != allBold.length() + allItalic.length()) { - throw new Error("Length is wrong."); + errln("Length is wrong."); } for (int i=0; i < buf.length(); i++) { @@ -105,29 +101,29 @@ public class TestMText { } if (buf.at(i) != rightChar) { - throw new Error("Character is wrong."); + errln("Character is wrong."); } if (!buf.characterStyleAt(i).equals(rightStyle)) { - throw new Error("Style is wrong."); + errln("Style is wrong."); } } int pos = 0; if (!buf.characterStyleAt(pos).equals(boldStyle)) { - throw new Error("First style is wrong."); + errln("First style is wrong."); } if (buf.characterStyleLimit(pos) != allBold.length()) { - throw new Error("Run length is wrong."); + errln("Run length is wrong."); } pos = allBold.length(); if (!buf.characterStyleAt(pos).equals(italicStyle)) { - throw new Error("Second style is wrong."); + errln("Second style is wrong."); } if (buf.characterStyleLimit(pos) != buf.length()) { - throw new Error("Run length is wrong."); + errln("Run length is wrong."); } { @@ -137,10 +133,10 @@ public class TestMText { // bbbbbiiibbbbb if (buf.damagedRangeStart() != oldLength) { - throw new Error("Damaged range start is incorrect"); + errln("Damaged range start is incorrect"); } if (buf.damagedRangeLimit() != buf.length()) { - throw new Error("Damaged range limit is incorrect"); + errln("Damaged range limit is incorrect"); } } @@ -150,34 +146,34 @@ public class TestMText { // bbbbbbbbbb if (buf.length() != 2 * allBold.length()) { - throw new Error("Text should be twice the length of bold text."); + errln("Text should be twice the length of bold text."); } pos = buf.length() / 2; if (buf.characterStyleStart(pos) != 0 || buf.characterStyleLimit(pos) != buf.length()) { - throw new Error("Run range is wrong."); + errln("Run range is wrong."); } if (!buf.characterStyleAt(pos).equals(boldStyle)) { - throw new Error("Run style is wrong."); + errln("Run style is wrong."); } ts = buf.getTimeStamp(); CharacterIterator cIter = buf.createCharacterIterator(); for (char ch = cIter.first(); ch != cIter.DONE; ch = cIter.next()) { if (ch != allBold.at(0)) { - throw new Error("Character is wrong."); + errln("Character is wrong."); } } if (ts != buf.getTimeStamp()) { - throw new Error("Time stamp should not have changed"); + errln("Time stamp should not have changed"); } buf.replace(0, 1, plain, 0, plain.length()); if (ts == buf.getTimeStamp()) { - throw new Error("Time stamp not incremented"); + errln("Time stamp not incremented"); } // ppppppbbbbbbbbb @@ -185,17 +181,17 @@ public class TestMText { // ppppppiii if (buf.length() != allItalic.length()+plain.length()) { - throw new Error("Length is wrong."); + errln("Length is wrong."); } pos = 0; if (buf.characterStyleLimit(pos) != plain.length()) { - throw new Error("Run limit is wrong."); + errln("Run limit is wrong."); } pos = plain.length(); if (buf.characterStyleLimit(pos) != buf.length()) { - throw new Error("Run limit is wrong."); + errln("Run limit is wrong."); } buf.replace(plain.length(), plain.length(), allBold, 0, allBold.length()); @@ -203,22 +199,22 @@ public class TestMText { AttributeMap st = buf.characterStyleAt(1); if (!st.equals(AttributeMap.EMPTY_ATTRIBUTE_MAP)) { - throw new Error("Style is wrong."); + errln("Style is wrong."); } if (buf.characterStyleStart(1) != 0 || buf.characterStyleLimit(1) != plain.length()) { - throw new Error("Style start is wrong."); + errln("Style start is wrong."); } st = buf.characterStyleAt(buf.length() - 1); if (!st.equals(italicStyle)) { - throw new Error("Style is wrong."); + errln("Style is wrong."); } if (buf.characterStyleStart(buf.length() - 1) != plain.length()+allBold.length()) { - throw new Error("Style start is wrong."); + errln("Style start is wrong."); } if (buf.characterStyleLimit(buf.length() - 1) != buf.length()) { - throw new Error("Style limit is wrong."); + errln("Style limit is wrong."); } } } @@ -305,24 +301,24 @@ public class TestMText { AttributeMap currentStyle = text.characterStyleAt(runStart); int runLimit = text.characterStyleLimit(runStart); if (runStart >= runLimit) { - throw new Error("Run length is not positive"); + errln("Run length is not positive"); } if (currentStyle.equals(oldStyle)) { - throw new Error("Styles didn't merge"); + errln("Styles didn't merge"); } for (int pos=runStart; pos < runLimit; pos++) { AttributeMap charStyleAtPos = text.characterStyleAt(pos); if (currentStyle != charStyleAtPos) { - throw new Error("Iterator style is not equal to text style at " + pos + "."); + errln("Iterator style is not equal to text style at " + pos + "."); } AttributeMap expected = styles[pos]; if (!currentStyle.equals(expected)) { - throw new Error("Iterator style doesn't match expected style at " + pos + "."); + errln("Iterator style doesn't match expected style at " + pos + "."); } if (!(text.characterStyleStart(pos) == runStart) || !(text.characterStyleLimit(pos) == runLimit)) { - throw new Error("style run start / limit is not consistent"); + errln("style run start / limit is not consistent"); } } runStart = runLimit; @@ -330,7 +326,7 @@ public class TestMText { if (textLength > 0) { if (text.characterStyleAt(textLength) != text.characterStyleAt(textLength-1)) { - throw new Error("Character styles at end aren't the same"); + errln("Character styles at end aren't the same"); } } @@ -350,16 +346,24 @@ public class TestMText { System.out.println("damageStart: " + damageStart + "; damageLimit: " + damageLimit); System.out.println("text.rangeStart: " + text.damagedRangeStart() + "text.rangeLimit: " + text.damagedRangeLimit()); - throw new Error("Damage range start or limit is not expected value"); + errln("Damage range start or limit is not expected value"); } if ((damageLimit == Integer.MIN_VALUE) != (oldTs == text.getTimeStamp())) { - throw new Error("timeStamp is incorrect"); + errln("timeStamp is incorrect"); } } } + protected void err(String message) { + + if (testIteration != NOT_IN_MONKEY_TEST) { + message = "testIteration="+testIteration+"; testCase="+theCase+message; + } + super.err(message); + } + /** * Perform a random series of operations on an MText and * check the result of each operation against a set of invariants. @@ -404,8 +408,8 @@ public class TestMText { MText buf = new StyledText(); String plainText = new String(); - int testIteration=0; - int theCase=0; + //int testIteration=0; - now instance variables so errln can report it + //int theCase=0; final int NUM_CASES = 14; boolean[] casesExecuted = new boolean[NUM_CASES]; @@ -414,7 +418,6 @@ public class TestMText { final String ALWAYS_DIFFERENT = "\uFEFF"; - try { for (testIteration=0; testIteration < TEST_ITERATIONS; testIteration++) { theCase = randInt(rand, NUM_CASES); @@ -428,7 +431,7 @@ public class TestMText { int timeStamp = buf.getTimeStamp(); String oldPlainText = plainText; if (oldPlainText == null) { - throw new Error("oldPlainText is null!"); + errln("oldPlainText is null!"); } switch (theCase) { @@ -600,13 +603,13 @@ public class TestMText { } if (error != null) { error.printStackTrace(); - throw new Error("Streaming problem: " + error); + errln("Streaming problem: " + error); } } break; default: - throw new Error("Invalid case."); + errln("Invalid case."); } // Check time stamp if oldPlainText != null. @@ -617,18 +620,18 @@ public class TestMText { oldPlainText.equals(plainText)) { System.out.println("plainText hashCode: " + plainText.hashCode()); System.out.println("oldPlainText hashCode: " + oldPlainText.hashCode()); - throw new Error("Time stamp is incorrect"); + errln("Time stamp is incorrect"); } } // now check invariants: if (plainText.length() != buf.length()) { - throw new Error("Lengths don't match"); + errln("Lengths don't match"); } for (int j=0; j < buf.length(); j++) { if (buf.at(j) != plainText.charAt(j)) { - throw new Error("Characters don't match."); + errln("Characters don't match."); } } @@ -636,15 +639,15 @@ public class TestMText { for (start = 0; start < buf.length();) { if (start != buf.characterStyleStart(start)) { - throw new Error("style start is wrong"); + errln("style start is wrong"); } int limit = buf.characterStyleLimit(start); if (start >= limit) { - throw new Error("start >= limit"); + errln("start >= limit"); } char current = plainText.charAt(start); - AttributeMap comp; + AttributeMap comp = null; if (current == 'p') { comp = emptyAttrs; } @@ -655,32 +658,32 @@ public class TestMText { comp = italicAttrs; } else { - throw new Error("An invalid character snuck in!"); + errln("An invalid character snuck in!"); } AttributeMap startStyle = buf.characterStyleAt(start); - if (!startStyle.equals(comp)) { - throw new Error("Style is not expected style."); + if (!comp.equals(startStyle)) { + errln("Style is not expected style."); } for (int j = start; j < limit; j++) { if (plainText.charAt(j) != current) { - throw new Error("Character doesn't match style."); + errln("Character doesn't match style."); } if (buf.characterStyleAt(j) != startStyle) { - throw new Error("Incorrect style in run"); + errln("Incorrect style in run"); } } if (limit < buf.length()) { if (plainText.charAt(limit) == current) { - throw new Error("Style run ends too soon."); + errln("Style run ends too soon."); } } start = limit; } if (start != buf.length()) { - throw new Error("Last limit is not buffer length."); + errln("Last limit is not buffer length."); } // won't try to compute and check damaged range; however, @@ -689,29 +692,26 @@ public class TestMText { int damageLimit = buf.damagedRangeLimit(); if (damageStart == Integer.MAX_VALUE) { if (damageLimit != Integer.MIN_VALUE) { - throw new Error("Invalid empty interval"); + errln("Invalid empty interval"); } } else { if (damageStart > damageLimit) { - throw new Error("Damage range inverted"); + errln("Damage range inverted"); } if (damageStart < 0 || damageLimit > buf.length()) { - throw new Error("Damage range endpoint out of bounds"); + errln("Damage range endpoint out of bounds"); } } } - } - catch(Error e) { - System.out.println("Iteration=" + testIteration + "; case=" + theCase); - throw e; - } + testIteration = NOT_IN_MONKEY_TEST; + boolean allCasesExecuted = true; for (int index=0; index < NUM_CASES; index++) { allCasesExecuted &= casesExecuted[index]; if (casesExecuted[index] == false) { - System.out.println("Case " + index + " not executed."); + logln("Case " + index + " not executed."); } } //if (allCasesExecuted) { diff --git a/icu4j/src/com/ibm/richtext/tests/TestMTextStreaming.java b/icu4j/src/com/ibm/richtext/tests/TestMTextStreaming.java index 9b4fa8b08be..31c6a03350d 100755 --- a/icu4j/src/com/ibm/richtext/tests/TestMTextStreaming.java +++ b/icu4j/src/com/ibm/richtext/tests/TestMTextStreaming.java @@ -1,5 +1,5 @@ /* - * @(#)$RCSfile: TestMTextStreaming.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:46:57 $ + * @(#)$RCSfile: TestMTextStreaming.java,v $ $Revision: 1.2 $ $Date: 2000/04/21 22:11:24 $ * * (C) Copyright IBM Corp. 1998-1999. All Rights Reserved. * @@ -14,6 +14,8 @@ */ package com.ibm.richtext.tests; +import com.ibm.test.TestFmwk; + import java.io.*; import java.awt.Color; @@ -25,15 +27,14 @@ import com.ibm.richtext.styledtext.StyleModifier; import com.ibm.textlayout.attributes.AttributeMap; import com.ibm.textlayout.attributes.TextAttribute; -public class TestMTextStreaming { +public class TestMTextStreaming extends TestFmwk { static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved"; - public static void main(String[] args) { + + public static void main(String[] args) throws Exception { - TestMTextStreaming t = new TestMTextStreaming(); - t.test(); - System.out.println("PASSED"); + new TestMTextStreaming().run(args); } public TestMTextStreaming() { @@ -117,7 +118,7 @@ public class TestMTextStreaming { } } - public static void streamAndCompare(MText text) { + public void streamAndCompare(MText text) { Throwable error = null; @@ -132,7 +133,7 @@ public class TestMTextStreaming { MText streamedText = (MText) objIn.readObject(); if (!isEqual(text, streamedText)) { isEqual(text, streamedText); - throw new Error("Streamed text is not equal"); + errln("Streamed text is not equal"); } } /* catch(OptionalDataException e) { @@ -150,7 +151,7 @@ public class TestMTextStreaming { if (error != null) { error.printStackTrace(); - throw new Error("Serialization failed."); + errln("Serialization failed."); } } diff --git a/icu4j/src/com/ibm/richtext/tests/TestParagraphStyles.java b/icu4j/src/com/ibm/richtext/tests/TestParagraphStyles.java index d8b6205cddb..eb542ea68f6 100755 --- a/icu4j/src/com/ibm/richtext/tests/TestParagraphStyles.java +++ b/icu4j/src/com/ibm/richtext/tests/TestParagraphStyles.java @@ -1,5 +1,5 @@ /* - * @(#)$RCSfile: TestParagraphStyles.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:46:57 $ + * @(#)$RCSfile: TestParagraphStyles.java,v $ $Revision: 1.2 $ $Date: 2000/04/21 22:11:24 $ * * (C) Copyright IBM Corp. 1998-1999. All Rights Reserved. * @@ -14,6 +14,8 @@ */ package com.ibm.richtext.tests; +import com.ibm.test.TestFmwk; + import com.ibm.richtext.styledtext.StyledText; import com.ibm.richtext.styledtext.MConstText; import com.ibm.richtext.styledtext.MText; @@ -21,10 +23,16 @@ import com.ibm.textlayout.attributes.AttributeMap; import com.ibm.richtext.styledtext.StyleModifier; import java.util.Random; -public final class TestParagraphStyles { +public final class TestParagraphStyles extends TestFmwk { static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved"; + + public static void main(String[] args) throws Exception { + + new TestParagraphStyles().run(args); + } + private static final int RAND_SEED = 1234; private static final int NUM_TESTS = 2500; @@ -51,12 +59,6 @@ public final class TestParagraphStyles { private static final StyleModifier E_MOD = StyleModifier.createReplaceModifier(E_STYLE); - public static void main(String[] args) { - - new TestParagraphStyles().test(); - System.out.println("Paragraph Styles test PASSED"); - } - public void test() { easyTests(); @@ -78,12 +80,12 @@ public final class TestParagraphStyles { verifyParagraphCount(temp); for (int i=0; i < text.length(); i++) { if (!temp.paragraphStyleAt(i).equals(text.paragraphStyleAt(i))) { - throw new Error("Paragraph styles are wrong"); + errln("Paragraph styles are wrong"); } } for (int i=0; i < src.length(); i++) { if (!temp.paragraphStyleAt(i+text.length()).equals(src.paragraphStyleAt(i))) { - throw new Error("Paragraph styles are wrong"); + errln("Paragraph styles are wrong"); } } @@ -91,13 +93,13 @@ public final class TestParagraphStyles { temp.replace(0, 1, src, 0, src.length()); verifyParagraphCount(temp); if (temp.paragraphLimit(0) != 4) { - throw new Error("Paragraph limit is wrong"); + errln("Paragraph limit is wrong"); } if (!temp.paragraphStyleAt(0).equals(B_STYLE)) { - throw new Error("First style is wrong"); + errln("First style is wrong"); } if (!temp.paragraphStyleAt(4).equals(A_STYLE)) { - throw new Error("Style after insert is wrong"); + errln("Style after insert is wrong"); } // test append @@ -107,20 +109,20 @@ public final class TestParagraphStyles { initC.append(newSrc); // now initC should be one paragraph with style B if (initC.paragraphLimit(0) != initC.length()) { - throw new Error("Should only be one paragraph"); + errln("Should only be one paragraph"); } if (initC.paragraphStyleAt(0) != initC.paragraphStyleAt(initC.length())) { - throw new Error("Two different paragraph styles"); + errln("Two different paragraph styles"); } if (!initC.paragraphStyleAt(initC.length()/2).equals(B_STYLE)) { - throw new Error("Incorrect paragraph style"); + errln("Incorrect paragraph style"); } text = new StyledText("aaa\n", PLAIN); text.modifyParagraphStyles(0, text.length(), A_MOD); text.modifyParagraphStyles(text.length(), text.length(), B_MOD); if (text.paragraphStyleAt(text.length()) != B_STYLE) { - throw new Error("0-length paragraph at end has incorrect style"); + errln("0-length paragraph at end has incorrect style"); } } @@ -158,10 +160,10 @@ public final class TestParagraphStyles { trailingP2.modifyParagraphStyles(trailingP2.length(), trailingP2.length(), B_MOD); if (!trailingP2.paragraphStyleAt(trailingP2.length()-1).equals(D_STYLE)) { - throw new Error("Style incorrect in trailingP2"); + errln("Style incorrect in trailingP2"); } if (!trailingP2.paragraphStyleAt(trailingP2.length()).equals(B_STYLE)) { - throw new Error("Ending style incorrect in trailingP2"); + errln("Ending style incorrect in trailingP2"); } MConstText[] tests = { noParagraph, twoParagraphs, @@ -198,8 +200,8 @@ public final class TestParagraphStyles { } } - private static void insertAndCheck(MConstText src, int srcStart, int srcLimit, - MText target, int start, int limit) { + private void insertAndCheck(MConstText src, int srcStart, int srcLimit, + MText target, int start, int limit) { // p-style after insertion AttributeMap after; @@ -236,7 +238,7 @@ public final class TestParagraphStyles { if (target.damagedRangeLimit() != damageLimit) { System.out.println("limit: " + damageLimit + "; target.limit: " + target.damagedRangeLimit()); - throw new Error("Damaged range limit is incorrect"); + errln("Damaged range limit is incorrect"); } final int damageStart = (damageLimit==Integer.MIN_VALUE)? Integer.MAX_VALUE : @@ -244,20 +246,20 @@ public final class TestParagraphStyles { if (target.damagedRangeStart() > damageStart) { System.out.println("start: " + damageStart + "; target.start: " + target.damagedRangeStart()); - throw new Error("Damaged range start is incorrect"); + errln("Damaged range start is incorrect"); } verifyParagraphCount(target); // check endpoints if (!before.equals(target.paragraphStyleAt(Math.max(start-1, 0)))) { - throw new Error("Incorrect paragraph style before modified range"); + errln("Incorrect paragraph style before modified range"); } int lengthDelta = (srcLimit-srcStart) - (limit-start); int indexAfterInsert = Math.min(target.length(), limit + lengthDelta); if (!after.equals(target.paragraphStyleAt(indexAfterInsert))) { - throw new Error("Incorrect paragraph style after modified range"); + errln("Incorrect paragraph style after modified range"); } if (srcHasPBreak) { @@ -269,11 +271,11 @@ public final class TestParagraphStyles { while (startP < limitOfTest) { int limitP = target.paragraphLimit(startP); if (src.paragraphLimit(startP-offset) + offset != limitP) { - throw new Error("paragraph limits are not consistent"); + errln("paragraph limits are not consistent"); } if (!src.paragraphStyleAt(startP-offset) .equals(target.paragraphStyleAt(startP))) { - throw new Error("paragraph styles are not consistent"); + errln("paragraph styles are not consistent"); } startP = limitP; } @@ -281,13 +283,13 @@ public final class TestParagraphStyles { else { for (int i=start; i < start+(srcLimit-srcStart); i++) { if (!after.equals(target.paragraphStyleAt(i))) { - throw new Error("paragraph style changed unexpectedly"); + errln("paragraph style changed unexpectedly"); } } } } - private static void verifyParagraphCount(MConstText text) { + private void verifyParagraphCount(MConstText text) { int pCount = 0; int textLength = text.length(); @@ -313,11 +315,11 @@ public final class TestParagraphStyles { if (sepCount + 1 != pCount) { System.out.println("sepCount=" + sepCount + "; pCount=" + pCount); - throw new Error("Paragraph count is not consistent with characters"); + errln("Paragraph count is not consistent with characters"); } } - private static void checkEndpoint(MConstText text) { + private void checkEndpoint(MConstText text) { boolean emptyFinalParagraph; int length = text.length(); @@ -331,7 +333,7 @@ public final class TestParagraphStyles { } if ((text.paragraphStart(length) == length) != emptyFinalParagraph) { - throw new Error("Final paragraph length is incorrect"); + errln("Final paragraph length is incorrect"); } } } \ No newline at end of file diff --git a/icu4j/src/com/ibm/richtext/tests/TestTextPanel.java b/icu4j/src/com/ibm/richtext/tests/TestTextPanel.java index e1ded9a660d..7118a2baf9a 100755 --- a/icu4j/src/com/ibm/richtext/tests/TestTextPanel.java +++ b/icu4j/src/com/ibm/richtext/tests/TestTextPanel.java @@ -1,5 +1,5 @@ /* - * @(#)$RCSfile: TestTextPanel.java,v $ $Revision: 1.1 $ $Date: 2000/04/20 17:46:57 $ + * @(#)$RCSfile: TestTextPanel.java,v $ $Revision: 1.2 $ $Date: 2000/04/21 22:11:24 $ * * (C) Copyright IBM Corp. 1998-1999. All Rights Reserved. * @@ -14,6 +14,8 @@ */ package com.ibm.richtext.tests; +import com.ibm.test.TestFmwk; + import java.util.Random; import java.awt.Color; import java.awt.Frame; @@ -41,7 +43,12 @@ import com.ibm.textlayout.attributes.AttributeSet; import com.ibm.textlayout.attributes.TextAttribute; import com.ibm.textlayout.attributes.AttributeMap; -public final class TestTextPanel { +public final class TestTextPanel extends TestFmwk { + + public static void main(String[] args) throws Exception { + + new TestTextPanel().run(args); + } private final class TestListener implements TextPanelListener { @@ -96,7 +103,7 @@ public final class TestTextPanel { } } if (e) { - throw new Error("Some events pending"); + errln("Some events pending"); } } @@ -104,7 +111,7 @@ public final class TestTextPanel { int index = event.getID() - TextPanelEvent.TEXT_PANEL_FIRST; if (status[index] == NO_WAY) { - throw new Error("Unexpected event: " + event); + errln("Unexpected event: " + event); } else if (status[index] == DEFINITELY) { status[index] = NO_WAY; @@ -193,18 +200,18 @@ public final class TestTextPanel { } } - public static void main(String[] args) { - - new TestTextPanel().test(); - System.out.println("TextPanelTest PASSED"); - } - public TestTextPanel() { fClipboard = new Clipboard("TestTextPanel"); incRandSeed(); } + // For inner class accessibility + protected void errln(String message) { + + super.errln(message); + } + public TestTextPanel(MTextPanel panel) { this(); @@ -275,11 +282,11 @@ public final class TestTextPanel { setTextPanel(new TextPanel(text, fClipboard)); for (int i=0; i < TEST_ITERS; i++) { - testSetSelection(); + _testSetSelection(); testModifications(MOD_TEXT, true); testEditMenuOperations(fClipboard); testModFlag(fTextPanel.getCommandLogSize()); - testCommandLogControl(); + _testCommandLogControl(); } } @@ -340,10 +347,10 @@ public final class TestTextPanel { } if (fTextPanel.getSelectionStart() != start) { - throw new Error("getSelectionStart is incorrect after set"); + errln("getSelectionStart is incorrect after set"); } if (fTextPanel.getSelectionEnd() != limit) { - throw new Error("getSelectionEnd is incorrect after set"); + errln("getSelectionEnd is incorrect after set"); } fListener.assertNotExpectingEvents(); fListener.allowAll(); @@ -371,11 +378,11 @@ public final class TestTextPanel { testSelection(SET_END, start, selEnd); } - public void testSetSelection() { + public void _testSetSelection() { int textLength = fTextPanel.getTextLength(); if (textLength != fTextPanel.getText().length()) { - throw new Error("Text panel length is not correct"); + errln("Text panel length is not correct"); } setAndTestSelection(0, textLength / 2); @@ -414,7 +421,7 @@ public final class TestTextPanel { fListener.assertNotExpectingEvents(); if (fTextPanel.getSelectionStart() != oldText.length() + insLength) { - throw new Error("Append didn't result in correct selection"); + errln("Append didn't result in correct selection"); } fListener.expectEvent(TextPanelEvent.TEXT_CHANGED); @@ -424,27 +431,27 @@ public final class TestTextPanel { fListener.allowAll(); if (fTextPanel.getSelectionStart() != insLength) { - throw new Error("Insert didn't result in correct selection"); + errln("Insert didn't result in correct selection"); } fTextPanel.replaceRange(insertionText, insLength, insLength+oldText.length()); if (fTextPanel.getSelectionStart() != insLength*2) { - throw new Error("Replace didn't result in correct selection"); + errln("Replace didn't result in correct selection"); } if (fTextPanel.getSelectionEnd() != insLength*2) { - throw new Error("Replace didn't result in correct selection"); + errln("Replace didn't result in correct selection"); } if (fTextPanel.getTextLength() != insLength*3) { - throw new Error("textLength is incorrect"); + errln("textLength is incorrect"); } if (restoreOldText) { fTextPanel.setText(oldText); if (fTextPanel.getSelectionStart() != oldText.length()) { - throw new Error("setText didn't result in correct selection"); + errln("setText didn't result in correct selection"); } if (fTextPanel.getTextLength() != oldText.length()) { - throw new Error("length incorrect after setText"); + errln("length incorrect after setText"); } } @@ -452,7 +459,7 @@ public final class TestTextPanel { } private static int iterationCount = 0; - public void testCommandLogControl() { + public void _testCommandLogControl() { fListener.refuseAll(); iterationCount++; @@ -465,7 +472,7 @@ public final class TestTextPanel { fTextPanel.setCommandLogSize(BIG_COMMAND_LOG_SIZE); if (fTextPanel.canRedo()) { - throw new Error("canRedo after setCommandLogSize"); + errln("canRedo after setCommandLogSize"); } fListener.assertNotExpectingEvents(); } @@ -502,17 +509,17 @@ public final class TestTextPanel { fListener.assertNotExpectingEvents(); } if (!fTextPanel.canUndo()) { - throw new Error("Command log is too small"); + errln("Command log is too small"); } fListener.allowAll(); fTextPanel.undo(); if (fTextPanel.canUndo()) { - throw new Error("Command log is too large"); + errln("Command log is too large"); } if (fTextPanel.getTextLength() != origLength * insText.length()) { - throw new Error("Text length was not restored"); + errln("Text length was not restored"); } for (int i=0; i < BIG_COMMAND_LOG_SIZE; i++) { @@ -520,11 +527,11 @@ public final class TestTextPanel { } if (fTextPanel.getTextLength() != origLength+BIG_COMMAND_LOG_SIZE) { - throw new Error("Text length was not restored after redo"); + errln("Text length was not restored after redo"); } if (fTextPanel.canRedo()) { - throw new Error("Should not be able to redo"); + errln("Should not be able to redo"); } fTextPanel.undo(); @@ -532,27 +539,27 @@ public final class TestTextPanel { fTextPanel.setCommandLogSize(SMALL_COMMAND_LOG_SIZE); if (fTextPanel.canRedo()) { - throw new Error("canRedo after setCommandLogSize(small)"); + errln("canRedo after setCommandLogSize(small)"); } for (int i=0; i < SMALL_COMMAND_LOG_SIZE; i++) { if (!fTextPanel.canUndo()) { - throw new Error("should be able to undo"); + errln("should be able to undo"); } fTextPanel.undo(); } if (fTextPanel.canUndo()) { - throw new Error("should not be able to undo after setCommandLogSize(small)"); + errln("should not be able to undo after setCommandLogSize(small)"); } if (!fTextPanel.canRedo()) { - throw new Error("why can't this redo???"); + errln("why can't this redo???"); } fTextPanel.redo(); fTextPanel.clearCommandLog(); if (fTextPanel.canUndo() || fTextPanel.canRedo()) { - throw new Error("Command log wasn't cleared"); + errln("Command log wasn't cleared"); } } @@ -570,29 +577,29 @@ public final class TestTextPanel { } }); if (!fTextPanel.clipboardNotEmpty()) { - throw new Error("MTextPanel doesn't recognize string content."); + errln("MTextPanel doesn't recognize string content."); } fTextPanel.setCaretPosition(fTextPanel.getSelectionStart()); int oldLength = fTextPanel.getTextLength(); fTextPanel.paste(); if (fTextPanel.getTextLength() != oldLength + STRING_CONTENT.length()) { - throw new Error("Text length is wrong after paste."); + errln("Text length is wrong after paste."); } if (!fTextPanel.canUndo()) { - throw new Error("canUndo should be true"); + errln("canUndo should be true"); } fTextPanel.undo(); if (fTextPanel.getTextLength() != oldLength) { - throw new Error("Length is wrong after undo"); + errln("Length is wrong after undo"); } if (!fTextPanel.canRedo()) { - throw new Error("canRedo should be true"); + errln("canRedo should be true"); } fTextPanel.redo(); if (fTextPanel.getTextLength() != oldLength + STRING_CONTENT.length()) { - throw new Error("Text length is wrong after redo."); + errln("Text length is wrong after redo."); } } @@ -600,14 +607,14 @@ public final class TestTextPanel { fTextPanel.selectAll(); fTextPanel.clear(); if (fTextPanel.getTextLength() != 0) { - throw new Error("Length is nonzero after clear"); + errln("Length is nonzero after clear"); } if (!fTextPanel.canUndo()) { - throw new Error("canUndo should be true"); + errln("canUndo should be true"); } fTextPanel.undo(); if (fTextPanel.getTextLength() != origLength) { - throw new Error("Old text not restored"); + errln("Old text not restored"); } if (origLength > 0) { @@ -615,22 +622,22 @@ public final class TestTextPanel { fTextPanel.select(0, 1); fTextPanel.cut(); if (fTextPanel.getTextLength() != origLength-1) { - throw new Error("Length wrong after cut"); + errln("Length wrong after cut"); } fTextPanel.paste(); if (fTextPanel.getTextLength() != origLength) { - throw new Error("Length wrong after paste"); + errln("Length wrong after paste"); } fTextPanel.select(0, origLength); fTextPanel.copy(); fTextPanel.setCaretPosition(0); fTextPanel.paste(); if (fTextPanel.getTextLength() != 2*origLength) { - throw new Error("Length wrong after paste"); + errln("Length wrong after paste"); } fTextPanel.undo(); if (fTextPanel.getTextLength() != origLength) { - throw new Error("Length wrong after undo"); + errln("Length wrong after undo"); } } } @@ -641,7 +648,7 @@ public final class TestTextPanel { fTextPanel.setModified(modified); for (int i=0; i < depth; i++) { if (!fTextPanel.canUndo()) { - throw new Error("Panel cannot undo at valid depth. Depth=" + i); + errln("Panel cannot undo at valid depth. Depth=" + i); } fTextPanel.undo(); fTextPanel.setModified(modified); @@ -649,13 +656,13 @@ public final class TestTextPanel { // check that all mod flags are false: if (fTextPanel.isModified() != modified) { - throw new Error("isModified is not correct"); + errln("isModified is not correct"); } for (int i=0; i < depth; i++) { fTextPanel.redo(); if (fTextPanel.isModified() != modified) { - throw new Error("isModified is not correct"); + errln("isModified is not correct"); } } } @@ -681,7 +688,7 @@ public final class TestTextPanel { } if (fTextPanel.getTextLength() != oldLength) { - throw new Error("Undo did not restore old text."); + errln("Undo did not restore old text."); } } @@ -743,7 +750,7 @@ public final class TestTextPanel { break; default: - throw new Error("Invalid operation!"); + errln("Invalid operation!"); } fListener.assertNotExpectingEvents(); fListener.allowAll();