You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by nd...@apache.org on 2006/11/26 21:15:55 UTC
svn commit: r479418 [21/43] - in
/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common:
javax/swing/ javax/swing/border/ javax/swing/colorchooser/
javax/swing/event/ javax/swing/filechooser/ javax/swing/plaf/
javax/swing/plaf/basic/ j...
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeView_NextNSVisPosTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeView_NextNSVisPosTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeView_NextNSVisPosTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/CompositeView_NextNSVisPosTest.java Sun Nov 26 12:15:43 2006
@@ -24,7 +24,6 @@
import java.awt.Container;
import java.awt.Rectangle;
import java.awt.Shape;
-
import javax.swing.BasicSwingTestCase;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
@@ -35,31 +34,35 @@
import javax.swing.text.ViewTestHelpers.ChildrenFactory;
public class CompositeView_NextNSVisPosTest extends SwingTestCase {
+ private Document doc;
+
+ private Element root;
- private Document doc;
- private Element root;
private CompositeView view;
- private Shape shape;
- private JTextArea area;
- private Bias[] bias;
+ private Shape shape;
+
+ private JTextArea area;
+
+ private Bias[] bias;
+
+ @Override
protected void setUp() throws Exception {
area = new JTextArea() {
- // Change the behavior as if area has our view
- public Rectangle modelToView(final int pos)
- throws BadLocationException {
+ private static final long serialVersionUID = 1L;
- return (Rectangle)view.modelToView(pos, shape, Bias.Forward);
+ // Change the behavior as if area has our view
+ @Override
+ public Rectangle modelToView(final int pos) throws BadLocationException {
+ return (Rectangle) view.modelToView(pos, shape, Bias.Forward);
}
};
area.setSize(100, 150);
-
doc = area.getDocument();
doc.insertString(0, "line1\nline2\n\u05DC\u05DD\nline3\n", null);
// positions: 012345 678901 2 3 4 567890
// 0 1 2
root = doc.getDefaultRootElement();
-
view = new CompositeViewImpl(root) {
private int getY(final ChildView view) {
int result = 0;
@@ -69,17 +72,17 @@
return result;
}
- protected void childAllocation(final int index,
- final Rectangle rc) {
+ @Override
+ protected void childAllocation(final int index, final Rectangle rc) {
// The each view allocation is 16 pixels of height and
// represents a line-like rectangle
- ChildView view = (ChildView)getView(index);
+ ChildView view = (ChildView) getView(index);
rc.y += getY(view);
rc.height = ViewTestHelpers.getHeight(view.getID());
}
- protected View getViewAtPoint(final int x, final int y,
- final Rectangle rc) {
+ @Override
+ protected View getViewAtPoint(final int x, final int y, final Rectangle rc) {
int index = getViewIndex(x, y, rc);
if (index != -1) {
childAllocation(index, rc);
@@ -89,55 +92,40 @@
}
// Link text component (area) with the view
+ @Override
public Container getContainer() {
return area;
}
};
-
view.loadChildren(new ChildrenFactory());
- shape = new Rectangle(100, 200, 190, 560);
-
+ shape = new Rectangle(100, 200, 190, 560);
bias = new Bias[1];
-
super.setUp();
}
-
- public void testGetNextEastWestVisualPositionFrom()
- throws BadLocationException {
-
+ public void testGetNextEastWestVisualPositionFrom() throws BadLocationException {
// EAST
-
- assertEquals(1, view.getNextEastWestVisualPositionFrom(0, Bias.Forward,
- shape, SwingConstants.EAST, bias));
-
- assertEquals(2, view.getNextEastWestVisualPositionFrom(1, Bias.Forward,
- shape, SwingConstants.EAST, bias));
-
+ assertEquals(1, view.getNextEastWestVisualPositionFrom(0, Bias.Forward, shape,
+ SwingConstants.EAST, bias));
+ assertEquals(2, view.getNextEastWestVisualPositionFrom(1, Bias.Forward, shape,
+ SwingConstants.EAST, bias));
// WEST
-
- assertEquals(1, view.getNextEastWestVisualPositionFrom(2, Bias.Forward,
- shape, SwingConstants.WEST, bias));
-
- assertEquals(0, view.getNextEastWestVisualPositionFrom(1, Bias.Forward,
- shape, SwingConstants.WEST, bias));
-
+ assertEquals(1, view.getNextEastWestVisualPositionFrom(2, Bias.Forward, shape,
+ SwingConstants.WEST, bias));
+ assertEquals(0, view.getNextEastWestVisualPositionFrom(1, Bias.Forward, shape,
+ SwingConstants.WEST, bias));
// Invalid offset
-
try {
view.getNextEastWestVisualPositionFrom(-1, Bias.Forward, shape,
SwingConstants.EAST, bias);
-
if (BasicSwingTestCase.isHarmony()) {
fail("BadLocationException must be thrown");
}
- } catch (BadLocationException e) { }
-
+ } catch (BadLocationException e) {
+ }
try {
- view.getNextEastWestVisualPositionFrom(doc.getLength() + 2,
- Bias.Forward, shape,
- SwingConstants.EAST, bias);
-
+ view.getNextEastWestVisualPositionFrom(doc.getLength() + 2, Bias.Forward, shape,
+ SwingConstants.EAST, bias);
if (BasicSwingTestCase.isHarmony()) {
fail("BadLocationException must be thrown");
}
@@ -147,56 +135,40 @@
fail("ArrayIndexOutOfBoundsException must not be thrown");
}
}
-
-
-
// Invalid direction
-
try {
view.getNextEastWestVisualPositionFrom(0, Bias.Backward, shape,
- SwingConstants.NORTH_EAST,
- bias);
-
+ SwingConstants.NORTH_EAST, bias);
fail("IllegalArgumentException must be thrown");
- } catch (IllegalArgumentException e) { }
+ } catch (IllegalArgumentException e) {
+ }
}
- public void testGetNextNorthSouthVisualPositionFrom()
- throws BadLocationException {
-
+ public void testGetNextNorthSouthVisualPositionFrom() throws BadLocationException {
// NORTH
-
- assertEquals(-1, view.getNextNorthSouthVisualPositionFrom(0,
- Bias.Forward, shape, SwingConstants.NORTH, bias));
-
- assertEquals(1, view.getNextNorthSouthVisualPositionFrom(7,
- Bias.Forward, shape, SwingConstants.NORTH, bias));
-
+ assertEquals(-1, view.getNextNorthSouthVisualPositionFrom(0, Bias.Forward, shape,
+ SwingConstants.NORTH, bias));
+ assertEquals(1, view.getNextNorthSouthVisualPositionFrom(7, Bias.Forward, shape,
+ SwingConstants.NORTH, bias));
// SOUTH
-
- assertEquals(8, view.getNextNorthSouthVisualPositionFrom(2,
- Bias.Forward, shape, SwingConstants.SOUTH, bias));
-
- assertEquals(14, view.getNextNorthSouthVisualPositionFrom(8,
- Bias.Forward, shape, SwingConstants.SOUTH, bias));
-
+ assertEquals(8, view.getNextNorthSouthVisualPositionFrom(2, Bias.Forward, shape,
+ SwingConstants.SOUTH, bias));
+ assertEquals(14, view.getNextNorthSouthVisualPositionFrom(8, Bias.Forward, shape,
+ SwingConstants.SOUTH, bias));
try {
view.getNextNorthSouthVisualPositionFrom(-1, Bias.Forward, shape,
SwingConstants.NORTH, bias);
-
if (BasicSwingTestCase.isHarmony()) {
fail("BadLocationException must be thrown");
}
- } catch (BadLocationException e) { }
-
+ } catch (BadLocationException e) {
+ }
// Invalid direction
-
try {
view.getNextNorthSouthVisualPositionFrom(0, Bias.Backward, shape,
SwingConstants.NORTH_EAST, bias);
-
fail("IllegalArgumentException must be thrown");
- } catch (IllegalArgumentException e) { }
+ } catch (IllegalArgumentException e) {
+ }
}
-
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DateFormatterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DateFormatterTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DateFormatterTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DateFormatterTest.java Sun Nov 26 12:15:43 2006
@@ -21,18 +21,17 @@
package javax.swing.text;
import java.text.DateFormat;
-
import javax.swing.SwingTestCase;
public class DateFormatterTest extends SwingTestCase {
DateFormatter formatter;
+ @Override
protected void setUp() throws Exception {
super.setUp();
formatter = new DateFormatter();
}
-
public void testDateFormatterDateFormat() {
DateFormat dateFormat = DateFormat.getInstance();
formatter = new DateFormatter(dateFormat);
@@ -57,7 +56,6 @@
DateFormat dateFormat = DateFormat.getInstance();
formatter.setFormat(dateFormat);
checkBaseProperties(dateFormat);
-
formatter.setFormat(null);
checkBaseProperties(null);
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefStyledDoc_Helpers.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefStyledDoc_Helpers.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefStyledDoc_Helpers.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefStyledDoc_Helpers.java Sun Nov 26 12:15:43 2006
@@ -23,11 +23,9 @@
import java.lang.reflect.Field;
import java.util.List;
import java.util.Vector;
-
import javax.swing.event.DocumentEvent.ElementChange;
import javax.swing.text.AbstractDocument.DefaultDocumentEvent;
import javax.swing.text.DefaultStyledDocument.ElementSpec;
-
import junit.framework.Assert;
/**
@@ -45,6 +43,8 @@
* passed to some methods to <code>stdout</code>.
*/
public static class DefStyledDocWithLogging extends DefaultStyledDocument {
+ private static final long serialVersionUID = 1L;
+
public DefStyledDocWithLogging() {
super();
}
@@ -53,12 +53,12 @@
super(content, new StyleContext());
}
+ @Override
public void insertString(int offset, String text, AttributeSet attrs)
- throws BadLocationException {
-
+ throws BadLocationException {
if (logging) {
- System.out.println(">>>doc.insertString(" + offset + ", '"
- + text + "', " + attrs + ")");
+ System.out.println(">>>doc.insertString(" + offset + ", '" + text + "', "
+ + attrs + ")");
}
super.insertString(offset, text, attrs);
if (logging) {
@@ -66,12 +66,10 @@
}
}
- public void remove(int offset, int length)
- throws BadLocationException {
-
+ @Override
+ public void remove(int offset, int length) throws BadLocationException {
if (logging) {
- System.out.println(">>>doc.remove(" + offset + ", "
- + length + ")");
+ System.out.println(">>>doc.remove(" + offset + ", " + length + ")");
}
super.remove(offset, length);
if (logging) {
@@ -79,6 +77,7 @@
}
}
+ @Override
protected void create(ElementSpec[] spec) {
if (logging) {
System.out.println(">>>doc.create");
@@ -90,9 +89,8 @@
}
}
- protected void insert(int offset, ElementSpec[] spec)
- throws BadLocationException {
-
+ @Override
+ protected void insert(int offset, ElementSpec[] spec) throws BadLocationException {
if (logging) {
System.out.println(">>>doc.insert(" + offset + ", " + ")");
printElementSpecs(spec);
@@ -103,8 +101,8 @@
}
}
- protected void insertUpdate(DefaultDocumentEvent event,
- AttributeSet attrs) {
+ @Override
+ protected void insertUpdate(DefaultDocumentEvent event, AttributeSet attrs) {
if (logging) {
System.out.println(">>>doc.insertUpdate(" + ", " + attrs + ")");
}
@@ -114,6 +112,7 @@
}
}
+ @Override
protected void removeUpdate(DefaultDocumentEvent event) {
if (logging) {
System.out.println(">>>doc.removeUpdate");
@@ -124,6 +123,7 @@
}
}
+ @Override
protected void styleChanged(Style style) {
if (logging) {
System.out.println(">>>styleChanged(" + style + ")");
@@ -134,38 +134,29 @@
}
}
- protected Element createBranchElement(Element parent,
- AttributeSet as) {
+ @Override
+ protected Element createBranchElement(Element parent, AttributeSet as) {
if (logging) {
- System.out.println("createBranch(" + parent.getName()
- + "["
- + (parent.getElementCount() <= 0
- ? "N/A"
- : (parent.getStartOffset() + ", "
- + parent.getEndOffset()))
- + "], "
- + (as == null
- ? "null"
- : new SimpleAttributeSet(as).toString())
- + ")");
+ System.out.println("createBranch("
+ + parent.getName()
+ + "["
+ + (parent.getElementCount() <= 0 ? "N/A" : (parent.getStartOffset()
+ + ", " + parent.getEndOffset())) + "], "
+ + (as == null ? "null" : new SimpleAttributeSet(as).toString()) + ")");
}
return super.createBranchElement(parent, as);
}
- protected Element createLeafElement(Element parent,
- AttributeSet as, int start,
- int end) {
- if (logging) {
- System.out.println("createLeaf(" + parent.getName() + "["
- + (parent.getElementCount() <= 0
- ? "N/A"
- : (parent.getStartOffset() + ", "
- + parent.getEndOffset()))
- + "], "
- + (as == null
- ? "null"
- : new SimpleAttributeSet(as).toString())
- + ", " + start + ", " + end + ")");
+ @Override
+ protected Element createLeafElement(Element parent, AttributeSet as, int start, int end) {
+ if (logging) {
+ System.out.println("createLeaf("
+ + parent.getName()
+ + "["
+ + (parent.getElementCount() <= 0 ? "N/A" : (parent.getStartOffset()
+ + ", " + parent.getEndOffset())) + "], "
+ + (as == null ? "null" : new SimpleAttributeSet(as).toString()) + ", "
+ + start + ", " + end + ")");
}
return super.createLeafElement(parent, as, start, end);
}
@@ -175,19 +166,18 @@
* The version of <code>DefaultStyledDocument.ElementBuffer</code>
* which logs parameters passed to some methods to <code>stdout</code>.
*/
- public static class ElementBufferWithLogging
- extends DefaultStyledDocument.ElementBuffer {
+ public static class ElementBufferWithLogging extends DefaultStyledDocument.ElementBuffer {
+ private static final long serialVersionUID = 1L;
- public ElementBufferWithLogging(final DefaultStyledDocument doc,
- final Element root) {
+ public ElementBufferWithLogging(final DefaultStyledDocument doc, final Element root) {
doc.super(root);
}
- public void change(int offset, int length,
- DefaultDocumentEvent event) {
+ @Override
+ public void change(int offset, int length, DefaultDocumentEvent event) {
if (logging) {
- System.out.println("->buf.change(" + offset + ", " + length
- + ", \n\t" + event + ")");
+ System.out.println("->buf.change(" + offset + ", " + length + ", \n\t" + event
+ + ")");
}
super.change(offset, length, event);
if (logging) {
@@ -195,6 +185,7 @@
}
}
+ @Override
protected void changeUpdate() {
if (logging) {
System.out.println("->buf.changeUpdate");
@@ -205,29 +196,31 @@
}
}
+ @Override
public Element clone(Element parent, Element clonee) {
if (logging) {
- System.out.println("clone(" + parent.getName() + "["
- + (parent.getElementCount() <= 0
- ? "N/A"
- : (parent.getStartOffset() + ", "
- + parent.getEndOffset()))
- + "], " + ", " + clonee.getName() + "["
- + (!clonee.isLeaf()
- && clonee.getElementCount() <= 0
- ? "N/A"
- : (clonee.getStartOffset() + ", "
- + clonee.getEndOffset()))
- + "])");
+ System.out.println("clone("
+ + parent.getName()
+ + "["
+ + (parent.getElementCount() <= 0 ? "N/A" : (parent.getStartOffset()
+ + ", " + parent.getEndOffset()))
+ + "], "
+ + ", "
+ + clonee.getName()
+ + "["
+ + (!clonee.isLeaf() && clonee.getElementCount() <= 0 ? "N/A" : (clonee
+ .getStartOffset()
+ + ", " + clonee.getEndOffset())) + "])");
}
return super.clone(parent, clonee);
}
+ @Override
public void insert(int offset, int length, ElementSpec[] spec,
- DefaultDocumentEvent event) {
+ DefaultDocumentEvent event) {
if (logging) {
- System.out.println("->buf.insert(" + offset + ", " + length
- + ", " + ", " + ")");
+ System.out
+ .println("->buf.insert(" + offset + ", " + length + ", " + ", " + ")");
printElementSpecs(spec);
System.out.println(event);
}
@@ -238,6 +231,7 @@
}
}
+ @Override
protected void insertUpdate(ElementSpec[] spec) {
if (logging) {
System.out.println("->buf.insertUpdate");
@@ -249,11 +243,10 @@
}
}
- public void remove(int offset, int length,
- DefaultDocumentEvent event) {
+ @Override
+ public void remove(int offset, int length, DefaultDocumentEvent event) {
if (logging) {
- System.out.println("->buf.remove(" + offset + ", "
- + length + ")");
+ System.out.println("->buf.remove(" + offset + ", " + length + ")");
}
super.remove(offset, length, event);
if (logging) {
@@ -261,6 +254,7 @@
}
}
+ @Override
protected void removeUpdate() {
if (logging) {
System.out.println("->buf.removeUpdate");
@@ -273,13 +267,12 @@
}
public static final AttributeSet bold;
- public static final AttributeSet italic;
+ public static final AttributeSet italic;
static {
MutableAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setBold(attrs, true);
bold = attrs;
-
attrs = new SimpleAttributeSet();
StyleConstants.setItalic(attrs, true);
italic = attrs;
@@ -296,13 +289,11 @@
* @param added the number of children added
*/
public static void assertChange(final Object object, final Element element,
- final int removed, final int added) {
- ElementChange change = (ElementChange)object;
+ final int removed, final int added) {
+ ElementChange change = (ElementChange) object;
assertSame("change.element", element, change.getElement());
- assertEquals("change.removed.length", removed,
- change.getChildrenRemoved().length);
- assertEquals("change.added.length",
- added, change.getChildrenAdded().length);
+ assertEquals("change.removed.length", removed, change.getChildrenRemoved().length);
+ assertEquals("change.added.length", added, change.getChildrenAdded().length);
}
/**
@@ -314,27 +305,23 @@
* @param addedOffsets the offsets of children added in the same form as
* <code>removedOffsets</code>.
*/
- public static void assertChange(final ElementChange change,
- final int[] removedOffsets,
- final int[] addedOffsets) {
+ public static void assertChange(final ElementChange change, final int[] removedOffsets,
+ final int[] addedOffsets) {
final Element[] removed = change.getChildrenRemoved();
- assertEquals("change.removed.length",
- removedOffsets.length / 2, removed.length);
+ assertEquals("change.removed.length", removedOffsets.length / 2, removed.length);
for (int i = 0, j = 0; i < removed.length; i++, j += 2) {
- assertEquals("change.removed[" + i + "].start",
- removedOffsets[j], removed[i].getStartOffset());
- assertEquals("change.removed[" + i + "].end",
- removedOffsets[j + 1], removed[i].getEndOffset());
+ assertEquals("change.removed[" + i + "].start", removedOffsets[j], removed[i]
+ .getStartOffset());
+ assertEquals("change.removed[" + i + "].end", removedOffsets[j + 1], removed[i]
+ .getEndOffset());
}
-
final Element[] added = change.getChildrenAdded();
- assertEquals("change.added.length",
- addedOffsets.length / 2, added.length);
+ assertEquals("change.added.length", addedOffsets.length / 2, added.length);
for (int i = 0, j = 0; i < added.length; i++, j += 2) {
- assertEquals("change.added[" + i + "].start",
- addedOffsets[j], added[i].getStartOffset());
- assertEquals("change.added[" + i + "].end",
- addedOffsets[j + 1], added[i].getEndOffset());
+ assertEquals("change.added[" + i + "].start", addedOffsets[j], added[i]
+ .getStartOffset());
+ assertEquals("change.added[" + i + "].end", addedOffsets[j + 1], added[i]
+ .getEndOffset());
}
}
@@ -347,15 +334,11 @@
* @param removed offsets of the elements removed
* @param added offsets of the elements added
*/
- public static void assertChange(final Object change,
- final Element element,
- final int index,
- final int[] removed, final int[] added) {
- assertSame("change.element",
- element, ((ElementChange)change).getElement());
- assertEquals("change.index",
- index, ((ElementChange)change).getIndex());
- assertChange((ElementChange)change, removed, added);
+ public static void assertChange(final Object change, final Element element,
+ final int index, final int[] removed, final int[] added) {
+ assertSame("change.element", element, ((ElementChange) change).getElement());
+ assertEquals("change.index", index, ((ElementChange) change).getIndex());
+ assertChange((ElementChange) change, removed, added);
}
/**
@@ -365,17 +348,15 @@
* @param offsets the expected offsets in the form
* <code>{start1, end1, start2, end2, ...}</code>.
*/
- public static void assertChildren(final Element element,
- final int[] offsets) {
+ public static void assertChildren(final Element element, final int[] offsets) {
final int count = element.getElementCount();
- assertEquals("element.children.length",
- offsets.length / 2, count);
+ assertEquals("element.children.length", offsets.length / 2, count);
for (int i = 0, j = 0; i < count; i++, j += 2) {
final Element child = element.getElement(i);
- assertEquals("element.children[" + i + "].start",
- offsets[j], child.getStartOffset());
- assertEquals("element.children[" + i + "].end",
- offsets[j + 1], child.getEndOffset());
+ assertEquals("element.children[" + i + "].start", offsets[j], child
+ .getStartOffset());
+ assertEquals("element.children[" + i + "].end", offsets[j + 1], child
+ .getEndOffset());
}
}
@@ -388,21 +369,18 @@
* @param attributes the expected attributes; <code>null</code> if no
* attributes expected.
*/
- public static void assertChildren(final Element element,
- final int[] offsets,
- final AttributeSet[] attributes) {
+ public static void assertChildren(final Element element, final int[] offsets,
+ final AttributeSet[] attributes) {
assertChildren(element, offsets);
-
- assertEquals("element.attributes.length",
- attributes.length, element.getElementCount());
+ assertEquals("element.attributes.length", attributes.length, element.getElementCount());
for (int i = 0; i < attributes.length; i++) {
final Element child = element.getElement(i);
if (attributes[i] == null) {
- assertEquals("element.children[" + i + "].attributes.count",
- 0, child.getAttributes().getAttributeCount());
+ assertEquals("element.children[" + i + "].attributes.count", 0, child
+ .getAttributes().getAttributeCount());
} else {
- assertTrue("element.child[" + i + "].attributes",
- child.getAttributes().isEqual(attributes[i]));
+ assertTrue("element.child[" + i + "].attributes", child.getAttributes()
+ .isEqual(attributes[i]));
}
}
}
@@ -417,8 +395,7 @@
* @param length the length of the spec.
*/
public static void assertSpec(final ElementSpec spec, final short type,
- final short direction, final int offset,
- final int length, final boolean isNullArray) {
+ final short direction, final int offset, final int length, final boolean isNullArray) {
assertEquals("spec.type", type, spec.getType());
assertEquals("spec.direction", direction, spec.getDirection());
assertEquals("spec.offset", offset, spec.getOffset());
@@ -436,8 +413,7 @@
* @param length the length of the spec.
*/
public static void assertSpec(final ElementSpec spec, final short type,
- final short direction, final int offset,
- final int length) {
+ final short direction, final int offset, final int length) {
assertSpec(spec, type, direction, offset, length, true);
}
@@ -447,10 +423,9 @@
* @param expected the expected spec.
* @param actual the actual spec.
*/
- public static void assertSpec(final ElementSpec expected,
- final ElementSpec actual) {
- assertSpec(actual, expected.getType(), expected.getDirection(),
- expected.getOffset(), expected.getLength());
+ public static void assertSpec(final ElementSpec expected, final ElementSpec actual) {
+ assertSpec(actual, expected.getType(), expected.getDirection(), expected.getOffset(),
+ expected.getLength());
}
/**
@@ -459,8 +434,7 @@
* @param expected array with expected specs.
* @param actual array with the actual specs.
*/
- public static void assertSpecs(final ElementSpec[] expected,
- final ElementSpec[] actual) {
+ public static void assertSpecs(final ElementSpec[] expected, final ElementSpec[] actual) {
assertEquals("specs.length", expected.length, actual.length);
for (int i = 0; i < expected.length; i++) {
assertSpec(expected[i], actual[i]);
@@ -476,12 +450,12 @@
* <code>javax.swing.undo.CompoundEdit</code>, or <code>null</code>
* if something goes wrong.
*/
- public static Vector getEdits(final DefaultDocumentEvent event) {
+ public static Vector<?> getEdits(final DefaultDocumentEvent event) {
try {
- Class eventSuperClass = event.getClass().getSuperclass();
+ Class<?> eventSuperClass = event.getClass().getSuperclass();
Field f = eventSuperClass.getDeclaredField("edits");
f.setAccessible(true);
- return (Vector)(f.get(event));
+ return (Vector<?>) (f.get(event));
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
@@ -509,11 +483,11 @@
* @param edits the list extracted from a <code>DefaultDocumentEvet</code>
* object.
*/
- public static void printChanges(List edits) {
+ public static void printChanges(List<?> edits) {
for (int i = 0; i < edits.size(); i++) {
Object edit = edits.get(i);
if (edit instanceof ElementChange) {
- printChange((ElementChange)edit);
+ printChange((ElementChange) edit);
System.out.println();
}
}
@@ -537,8 +511,7 @@
*/
public static void printElementSpecs(ElementSpec[] spec) {
for (int i = 0; i < spec.length; i++) {
- System.out.println("\t" + spec[i]
- + (i != spec.length - 1 ? "," : ""));
+ System.out.println("\t" + spec[i] + (i != spec.length - 1 ? "," : ""));
}
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultCaretTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultCaretTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultCaretTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultCaretTest.java Sun Nov 26 12:15:43 2006
@@ -30,7 +30,6 @@
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.EventListener;
-
import javax.swing.ExtJTextArea;
import javax.swing.JFrame;
import javax.swing.JTextArea;
@@ -54,7 +53,6 @@
int tCompListenersCount;
//int tmp;
-
Point p;
Highlighter.HighlightPainter pnt;
@@ -115,24 +113,24 @@
int flagMoveDot = 0;
+ @Override
public void setDot(final FilterBypass f, final int i, final Bias b) {
flagSetDot = 1;
super.setDot(f, i, b);
}
+ @Override
public void moveDot(final FilterBypass arg0, final int i, final Bias b) {
flagMoveDot = 1;
super.moveDot(arg0, i, b);
}
-
}
+ @Override
protected void setUp() throws Exception {
super.setUp();
- jta = new ExtJTextArea(
- "JTextArea for DefaultCaret Testing\n***\n*%%%**");
+ jta = new ExtJTextArea("JTextArea for DefaultCaret Testing\n***\n*%%%**");
dc = new DefaultCaret();
-
jf = new JFrame();
p = new Point(5, 16);
bWasException = false;
@@ -145,18 +143,13 @@
r5 = null;
r6 = null;
ad = (AbstractDocument) jta.getDocument();
-
jf.getContentPane().add(jta);
-
jta.getCaret().deinstall(jta);
-
tCompListenersCount = jta.getListeners(MouseListener.class).length
+ jta.getListeners(MouseMotionListener.class).length
+ jta.getListeners(FocusListener.class).length
+ jta.getPropertyChangeListeners().length;
-
jta.setCaret(dc);
-
jf.setLocation(100, 100);
jf.setSize(350, 200);
jf.pack();
@@ -183,6 +176,7 @@
assertFalse("Unexpected exception " + s, bWasException);
}
+ @Override
protected void tearDown() throws Exception {
jf.dispose();
super.tearDown();
@@ -193,11 +187,14 @@
*
*/
boolean findListener(final EventListener[] list, final EventListener elem) {
- if (list == null)
+ if (list == null) {
return false;
- for (int i = 0; i < list.length; i++)
- if (list[i] == elem)
+ }
+ for (int i = 0; i < list.length; i++) {
+ if (list[i] == elem) {
return true;
+ }
+ }
return false;
}
@@ -212,7 +209,6 @@
public void testDefaultCaret() {
assertNotNull(dc);
-
}
public void testGetComponent() {
@@ -229,9 +225,7 @@
+ jta.getListeners(MouseMotionListener.class).length
+ jta.getListeners(FocusListener.class).length
+ jta.getPropertyChangeListeners().length;
-
assertEquals(tCompListenersCount, tCompListenersCountCurrent - 4);
-
}
/*
@@ -243,15 +237,12 @@
int j = jta.getListeners(MouseMotionListener.class).length;
int k = jta.getListeners(FocusListener.class).length;
int l = jta.getPropertyChangeListeners().length;
-
dc.deinstall(jta);
-
assertNull(dc.getComponent());
assertEquals(i, jta.getListeners(MouseListener.class).length + 1);
assertEquals(j, jta.getListeners(MouseMotionListener.class).length + 1);
assertEquals(k, jta.getListeners(FocusListener.class).length + 1);
assertEquals(l, jta.getPropertyChangeListeners().length + 1);
-
assertFalse(findListener(jta.getListeners(MouseListener.class), dc));
assertFalse(findListener(jta.getListeners(MouseListener.class), dc));
assertFalse(findListener(jta.getListeners(FocusListener.class), dc));
@@ -260,29 +251,24 @@
/*
* Tests methods IsVisible and SetVisible
*/
-
public void testIsVisible() throws Exception {
dc.setVisible(true);
- assertTrue("dc.isVisible()= false after" + " dc.setVisible(true)", dc
- .isVisible());
+ assertTrue("dc.isVisible()= false after" + " dc.setVisible(true)", dc.isVisible());
dc.setVisible(false);
- assertFalse("dc.isVisible()= true after" + " dc.setVisible(false)", dc
- .isVisible());
-
+ assertFalse("dc.isVisible()= true after" + " dc.setVisible(false)", dc.isVisible());
}
/*
* Tests methods isSelectionVisible and setSelectionVisible
*/
public void testIsSelectionVisible() throws Exception {
-
assertNotNull(dc);
dc.setSelectionVisible(true);
- assertTrue("dc.isSelectionVisible()= false after"
- + " dc.setSelectionVisible(true)", dc.isSelectionVisible());
+ assertTrue("dc.isSelectionVisible()= false after" + " dc.setSelectionVisible(true)", dc
+ .isSelectionVisible());
dc.setSelectionVisible(false);
- assertFalse("dc.isSelectionVisible()= true after"
- + " dc.setSelectionVisible(false)", dc.isSelectionVisible());
+ assertFalse("dc.isSelectionVisible()= true after" + " dc.setSelectionVisible(false)",
+ dc.isSelectionVisible());
}
public void testEquals() {
@@ -299,54 +285,36 @@
SimpleChangeListener t1 = new SimpleChangeListener();
SimpleChangeListener t2 = new SimpleChangeListener();
SimpleChangeListener t3 = new SimpleChangeListener();
-
dc.addChangeListener(t1);
assertTrue(findListener(dc.getChangeListeners(), t1));
- assertTrue(findListener(dc.listenerList
- .getListeners(ChangeListener.class), t1));
-
+ assertTrue(findListener(dc.listenerList.getListeners(ChangeListener.class), t1));
dc.addChangeListener(t2);
assertTrue(findListener(dc.getChangeListeners(), t1));
- assertTrue(findListener(dc.listenerList
- .getListeners(ChangeListener.class), t1));
+ assertTrue(findListener(dc.listenerList.getListeners(ChangeListener.class), t1));
assertTrue(findListener(dc.getChangeListeners(), t2));
- assertTrue(findListener(dc.listenerList
- .getListeners(ChangeListener.class), t2));
-
+ assertTrue(findListener(dc.listenerList.getListeners(ChangeListener.class), t2));
dc.addChangeListener(t3);
assertTrue(findListener(dc.getChangeListeners(), t1));
- assertTrue(findListener(dc.listenerList
- .getListeners(ChangeListener.class), t1));
+ assertTrue(findListener(dc.listenerList.getListeners(ChangeListener.class), t1));
assertTrue(findListener(dc.getChangeListeners(), t2));
- assertTrue(findListener(dc.listenerList
- .getListeners(ChangeListener.class), t2));
+ assertTrue(findListener(dc.listenerList.getListeners(ChangeListener.class), t2));
assertTrue(findListener(dc.getChangeListeners(), t3));
- assertTrue(findListener(dc.listenerList
- .getListeners(ChangeListener.class), t3));
-
+ assertTrue(findListener(dc.listenerList.getListeners(ChangeListener.class), t3));
dc.removeChangeListener(t1);
assertFalse(findListener(dc.getChangeListeners(), t1));
- assertFalse(findListener(dc.listenerList
- .getListeners(ChangeListener.class), t1));
-
+ assertFalse(findListener(dc.listenerList.getListeners(ChangeListener.class), t1));
dc.removeChangeListener(t2);
assertFalse(findListener(dc.getChangeListeners(), t1));
- assertFalse(findListener(dc.listenerList
- .getListeners(ChangeListener.class), t1));
+ assertFalse(findListener(dc.listenerList.getListeners(ChangeListener.class), t1));
assertFalse(findListener(dc.getChangeListeners(), t2));
- assertFalse(findListener(dc.listenerList
- .getListeners(ChangeListener.class), t2));
-
+ assertFalse(findListener(dc.listenerList.getListeners(ChangeListener.class), t2));
dc.removeChangeListener(t3);
assertFalse(findListener(dc.getChangeListeners(), t1));
- assertFalse(findListener(dc.listenerList
- .getListeners(ChangeListener.class), t1));
+ assertFalse(findListener(dc.listenerList.getListeners(ChangeListener.class), t1));
assertFalse(findListener(dc.getChangeListeners(), t2));
- assertFalse(findListener(dc.listenerList
- .getListeners(ChangeListener.class), t2));
+ assertFalse(findListener(dc.listenerList.getListeners(ChangeListener.class), t2));
assertFalse(findListener(dc.getChangeListeners(), t3));
- assertFalse(findListener(dc.listenerList
- .getListeners(ChangeListener.class), t3));
+ assertFalse(findListener(dc.listenerList.getListeners(ChangeListener.class), t3));
} catch (NullPointerException e) {
bWasException = true;
s = e.getMessage();
@@ -398,45 +366,38 @@
jta.setText(sLTR + sRTL + sLTR + sRTL + sLTR + sRTL + sLTR + sRTL);
//dc.setDot(8);
//dc.moveDot(10);
- dc.positionCaret(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0,
- jta.getX() + r1.x, jta.getY() + r1.y, 0, false));
+ dc.positionCaret(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0, jta.getX() + r1.x,
+ jta.getY() + r1.y, 0, false));
tmp = jta.getUI().viewToModel(jta, new Point(r1.x, r1.y), bias);
checkValues(tmp, bias[0]);
//checkValues(6,6,Position.Bias.Backward);
-
- dc.positionCaret(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0,
- jta.getX() + r5.x, jta.getY() + r5.y, 0, false));
+ dc.positionCaret(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0, jta.getX() + r5.x,
+ jta.getY() + r5.y, 0, false));
tmp = jta.getUI().viewToModel(jta, new Point(r5.x, r5.y), bias);
checkValues(tmp, bias[0]);
//checkValues(4,4,Position.Bias.Forward);
-
- dc.positionCaret(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0,
- jta.getX() + r6.x, jta.getY() + r6.y, 0, false));
+ dc.positionCaret(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0, jta.getX() + r6.x,
+ jta.getY() + r6.y, 0, false));
tmp = jta.getUI().viewToModel(jta, new Point(r6.x, r6.y), bias);
checkValues(tmp, bias[0]);
//checkValues(6,6,Position.Bias.Forward);
-
}
/*
* Tryes to move caret position by Mouse Events (dot = mark)
*/
public void testMoveCaret() throws Exception {
-
- dc.positionCaret(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0,
- jta.getX() + r1.x, jta.getY() + r1.y, 0, false));
- dc.moveCaret(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0, jta
- .getX()
- + r2.x, jta.getY() + r2.y, 0, false));
-
+ dc.positionCaret(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0, jta.getX() + r1.x,
+ jta.getY() + r1.y, 0, false));
+ dc.moveCaret(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0, jta.getX() + r2.x, jta
+ .getY()
+ + r2.y, 0, false));
assertEquals(10, dc.getDot());
assertEquals(6, dc.getMark());
assertEquals(10, jta.getCaretPosition());
-
- dc.moveCaret(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0, jta
- .getX()
- + r3.x, jta.getY() + r3.y, 0, false));
-
+ dc.moveCaret(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0, 0, jta.getX() + r3.x, jta
+ .getY()
+ + r3.y, 0, false));
assertEquals(15, dc.getDot());
assertEquals(6, dc.getMark());
assertEquals(15, jta.getCaretPosition());
@@ -463,10 +424,11 @@
assertTrue(findListener(EvLList, ChL1));
assertTrue(findListener(EvLList, ChL2));
//assertEquals(EvLList.length,2);
- if ((EvLList != null) & (dc.getChangeListeners() != null))
+ if ((EvLList != null) & (dc.getChangeListeners() != null)) {
assertEquals(EvLList.length, dc.getChangeListeners().length);
- //dc.addChangeListener(ChL1);
- //dc.addChangeListener(ChL2);
+ //dc.addChangeListener(ChL1);
+ //dc.addChangeListener(ChL2);
+ }
}
/*
@@ -522,8 +484,9 @@
}
}
assertFalse("Unexpected exception: " + s, bWasException);
- if (pnt == null)
+ if (pnt == null) {
return;
+ }
h = jta.getHighlighter().getHighlights();
assertEquals(1, h.length);
assertEquals(h[0].getPainter(), dc.getSelectionPainter());
@@ -539,7 +502,6 @@
jta.setEditable(false);
dc.focusGained(new FocusEvent(jta, FocusEvent.FOCUS_GAINED));
assertFalse(dc.isVisible());
-
jta.setEditable(true);
jta.setEnabled(false);
dc.focusGained(new FocusEvent(jta, FocusEvent.FOCUS_GAINED));
@@ -553,27 +515,21 @@
public void testMouseDragged() throws Exception {
dc.mousePressed(new MouseEvent(jta, MouseEvent.MOUSE_PRESSED, 0,
- InputEvent.BUTTON1_MASK, jta.getX() + r1.x, jta.getY() + r1.y,
- 0, false, MouseEvent.BUTTON1));
-
+ InputEvent.BUTTON1_MASK, jta.getX() + r1.x, jta.getY() + r1.y, 0, false,
+ MouseEvent.BUTTON1));
dc.mouseDragged(new MouseEvent(jta, MouseEvent.MOUSE_DRAGGED, 0,
- InputEvent.BUTTON1_MASK, jta.getX() + r3.x, jta.getY() + r3.y,
- 0, false, MouseEvent.BUTTON1));
-
+ InputEvent.BUTTON1_MASK, jta.getX() + r3.x, jta.getY() + r3.y, 0, false,
+ MouseEvent.BUTTON1));
assertEquals("rea for D", jta.getSelectedText());
-
/*
* dc.mousePressed(new MouseEvent(jta, MouseEvent.MOUSE_PRESSED, 0,
* InputEvent.BUTTON1_MASK, jta.getX() + r4.x, jta .getY() + r4.y, 0,
* false, MouseEvent.BUTTON1));
*/
-
dc.mouseDragged(new MouseEvent(jta, MouseEvent.MOUSE_DRAGGED, 0,
- InputEvent.BUTTON1_MASK, jta.getX() + r4.x, jta.getY() + r4.y,
- 0, false, MouseEvent.BUTTON1));
-
+ InputEvent.BUTTON1_MASK, jta.getX() + r4.x, jta.getY() + r4.y, 0, false,
+ MouseEvent.BUTTON1));
assertEquals("extA", jta.getSelectedText());
-
/*
* dc.mouseDragged(new MouseEvent(jta, MouseEvent.MOUSE_DRAGGED, 0,
* InputEvent.BUTTON3_MASK, jta.getX() + r2.x, jta .getY() + r2.y, 0,
@@ -585,119 +541,81 @@
* false)); try { assertEquals("JTextArea for D",
* jta.getSelectedText()); } catch (AssertionFailedError e) { e4 = e; }
*/
-
}
public void testMouseClicked() throws Exception {
dc.mouseClicked(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0,
- MouseEvent.BUTTON1_DOWN_MASK, jta.getX() + r1.x, jta.getY() + r1.y,
- 2, false,MouseEvent.BUTTON1));
-
+ InputEvent.BUTTON1_DOWN_MASK, jta.getX() + r1.x, jta.getY() + r1.y, 2, false,
+ MouseEvent.BUTTON1));
assertEquals("JTextArea", jta.getSelectedText());
dc.setDot(5);
dc.mouseClicked(new MouseEvent(jta, MouseEvent.MOUSE_CLICKED, 0,
- InputEvent.BUTTON1_DOWN_MASK, jta.getX() + r1.x, jta.getY() + r1.y,
- 3, false,MouseEvent.BUTTON1));
-
- assertEquals("JTextArea for DefaultCaret Testing", jta
- .getSelectedText());
-
+ InputEvent.BUTTON1_DOWN_MASK, jta.getX() + r1.x, jta.getY() + r1.y, 3, false,
+ MouseEvent.BUTTON1));
+ assertEquals("JTextArea for DefaultCaret Testing", jta.getSelectedText());
}
public void testMousePressed() throws Exception {
-
dc.mousePressed(new MouseEvent(jta, MouseEvent.MOUSE_PRESSED, 0,
- MouseEvent.SHIFT_DOWN_MASK, jta.getX() + r3.x, jta.getY()
- + r3.y, 0, false, MouseEvent.BUTTON1));
-
+ InputEvent.SHIFT_DOWN_MASK, jta.getX() + r3.x, jta.getY() + r3.y, 0, false,
+ MouseEvent.BUTTON1));
assertEquals("JTextArea for D", jta.getSelectedText());
-
}
public void testDocInsChange_DotEqMark() throws Exception {
try {
dc.setDot(5);
-
jta.getDocument().insertString(3, "insert", null);
-
assertFalse("Unexpected exception: " + s, bWasException);
assertEquals(11, dc.getDot());
-
dc.setDot(5);
-
jta.getDocument().insertString(2, "ins", null);
-
assertFalse("Unexpected exception: " + s, bWasException);
assertEquals(8, dc.getDot());
-
dc.setDot(5);
-
jta.getDocument().insertString(5, "inse", null);
-
assertFalse("Unexpected exception: " + s, bWasException);
assertEquals(9, dc.getDot());
-
dc.setDot(5);
-
jta.getDocument().insertString(7, "insert", null);
-
assertEquals(5, dc.getDot());
} catch (BadLocationException e) {
bWasException = true;
s = e.getMessage();
}
assertFalse("Unexpected exception: " + s, bWasException);
-
}
public void testDocInsChange_DotNotEqMark() throws Exception {
try {
dc.setDot(11);
dc.moveDot(6);
-
jta.getDocument().insertString(2, "in", null);
-
assertEquals(8, dc.getDot());
-
assertEquals(13, dc.getMark());
-
dc.setDot(11);
dc.moveDot(6);
-
jta.getDocument().insertString(6, "ins", null);
-
assertEquals(9, dc.getDot());
-
assertEquals(14, dc.getMark());
-
dc.setDot(11);
dc.moveDot(6);
-
jta.getDocument().insertString(7, "inser", null);
-
assertEquals(6, dc.getDot());
-
assertEquals(16, dc.getMark());
-
dc.setDot(6);
dc.moveDot(11);
-
jta.getDocument().insertString(11, "insert", null);
assertEquals(17, dc.getDot());
-
assertEquals(6, dc.getMark());
-
} catch (BadLocationException e) {
bWasException = true;
s = e.getMessage();
}
-
assertFalse("Unexpected exception: " + s, bWasException);
-
}
public void testDocRemoveChange_DotEqMark() throws Exception {
-
dc.setDot(5);
try {
jta.getDocument().remove(3, 1);
@@ -705,9 +623,7 @@
bWasException = true;
s = e.getMessage();
}
-
assertEquals(4, dc.getDot());
-
dc.setDot(5);
try {
jta.getDocument().remove(2, 3);
@@ -715,9 +631,7 @@
bWasException = true;
s = e.getMessage();
}
-
assertEquals(2, dc.getDot());
-
dc.setDot(5);
try {
jta.getDocument().remove(3, 7);
@@ -725,9 +639,7 @@
bWasException = true;
s = e.getMessage();
}
-
assertEquals(3, dc.getDot());
-
dc.setDot(5);
try {
jta.getDocument().remove(5, 8);
@@ -735,9 +647,7 @@
bWasException = true;
s = e.getMessage();
}
-
assertEquals(5, dc.getDot());
-
dc.setDot(5);
try {
jta.getDocument().remove(7, 2);
@@ -745,57 +655,37 @@
bWasException = true;
s = e.getMessage();
}
-
assertEquals(5, dc.getDot());
-
assertFalse("Unexpected exception: " + s, bWasException);
-
}
public void testDocRemoveChange_DotNotEqMark() throws Exception {
-
dc.setDot(11);
dc.moveDot(6);
try {
jta.getDocument().remove(3, 2);
-
assertEquals(4, dc.getDot());
-
assertEquals(9, dc.getMark());
-
dc.setDot(11);
dc.moveDot(6);
-
jta.getDocument().remove(3, 4);
-
assertEquals(3, dc.getDot());
-
assertEquals(7, dc.getMark());
-
dc.setDot(11);
dc.moveDot(6);
-
jta.getDocument().remove(6, 2);
-
assertEquals(6, dc.getDot());
-
assertEquals(9, dc.getMark());
-
dc.setDot(6);
dc.moveDot(11);
-
jta.getDocument().remove(10, 7);
assertEquals(10, dc.getDot());
-
assertEquals(6, dc.getMark());
-
} catch (BadLocationException e) {
bWasException = true;
s = e.getMessage();
}
-
assertFalse("Unexpected exception: " + s, bWasException);
-
}
/*
@@ -803,44 +693,29 @@
*
*/
public void testDocNeverUpdate() throws Exception {
-
dc.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
-
dc.setDot(6);
try {
jta.getDocument().remove(3, 10);
-
assertEquals(6, dc.getDot());
-
dc.setDot(11);
dc.moveDot(6);
-
jta.getDocument().remove(3, 10);
-
assertEquals(6, dc.getDot());
-
assertEquals(11, dc.getMark());
-
dc.setDot(6);
-
jta.getDocument().remove(2, 20);
-
assertEquals(5, dc.getDot());
-
dc.setDot(3);
dc.moveDot(1);
-
jta.getDocument().remove(2, 3);
-
assertEquals(1, dc.getDot());
-
assertEquals(2, dc.getMark());
} catch (BadLocationException e) {
bWasException = true;
s = e.getMessage();
}
assertFalse("Unexpected exception: " + s, bWasException);
-
}
/*
@@ -879,13 +754,10 @@
public void testCaretColor() throws Exception {
//TODO Runnable
-
jta.setSelectionColor(c1);
jta.setCaretColor(c2);
-
assertEquals(c1, jta.getSelectionColor());
assertEquals(c2, jta.getCaretColor());
-
}
void checkFlag(final int i1) {
@@ -894,94 +766,78 @@
}
public void testInvokeFireStateChanged() throws Exception {
-
CHL = new SimpleChangeListener();
dc.addChangeListener(CHL);
dc.setDot(5);
checkFlag(1);
-
dc.moveDot(8);
checkFlag(1);
-
dc.setVisible(true);
checkFlag(0);
-
dc.setVisible(false);
checkFlag(0);
-
dc.setSelectionVisible(true);
checkFlag(0);
-
dc.setSelectionVisible(false);
checkFlag(0);
-
jta.setCaretColor(new Color(235));
checkFlag(0);
-
jta.setCaretColor(new Color(235));
checkFlag(0);
-
jta.setSelectionColor(new Color(235));
checkFlag(0);
-
dc.setBlinkRate(100);
checkFlag(0);
-
jta.setDocument(new PlainDocument());
checkFlag(1);
-
jta.getCaret().deinstall(jta);
checkFlag(0);
-
dc.install(new JTextArea("JTextArea"));
checkFlag(0);
-
}
public void testToString() throws Exception {
-
dc.setDot(4);
dc.moveDot(9);
-
assertEquals("Dot=(9, Forward) Mark=(4, Forward)", dc.toString());
}
+
//Serialization is not supported now by Swing
/*public void testSerialization() throws Exception {
- dc.setDot(4, Position.Bias.Backward);
- dc.setBlinkRate(100);
- dc.setVisible(true);
- dc.setSelectionVisible(true);
- dc.setMagicCaretPosition(new Point(200, 300));
-
- DefaultCaret dc1 = new DefaultCaret();
-
- try {
- FileOutputStream fo = new FileOutputStream("tmp");
- ObjectOutputStream so = new ObjectOutputStream(fo);
- so.writeObject(dc);
- so.flush();
- so.close();
- FileInputStream fi = new FileInputStream("tmp");
- ObjectInputStream si = new ObjectInputStream(fi);
- dc1 = (DefaultCaret) si.readObject();
- si.close();
- } catch (Exception e) {
- assertTrue("seralization failed" + e.getMessage(),false);
- }
-
- assertEquals("Dot=(4, Backward) Mark=(4, Backward)", dc1.toString());
- assertTrue(jta.equals(dc.getComponent()));
- assertTrue(dc1.isSelectionVisible());
- assertEquals(100, dc1.getBlinkRate());
- assertTrue(dc1.getMagicCaretPosition().equals(new Point(200, 300)));
- assertTrue(dc1.getSelectionPainter() instanceof DefaultHighlighter.DefaultHighlightPainter);
- assertTrue(dc1.listenerList.toString().equals(
- dc.listenerList.toString()));
- assertNull(dc1.changeEvent);
-
- } */
+ dc.setDot(4, Position.Bias.Backward);
+ dc.setBlinkRate(100);
+ dc.setVisible(true);
+ dc.setSelectionVisible(true);
+ dc.setMagicCaretPosition(new Point(200, 300));
+
+ DefaultCaret dc1 = new DefaultCaret();
+
+ try {
+ FileOutputStream fo = new FileOutputStream("tmp");
+ ObjectOutputStream so = new ObjectOutputStream(fo);
+ so.writeObject(dc);
+ so.flush();
+ so.close();
+ FileInputStream fi = new FileInputStream("tmp");
+ ObjectInputStream si = new ObjectInputStream(fi);
+ dc1 = (DefaultCaret) si.readObject();
+ si.close();
+ } catch (Exception e) {
+ assertTrue("seralization failed" + e.getMessage(),false);
+ }
+
+ assertEquals("Dot=(4, Backward) Mark=(4, Backward)", dc1.toString());
+ assertTrue(jta.equals(dc.getComponent()));
+ assertTrue(dc1.isSelectionVisible());
+ assertEquals(100, dc1.getBlinkRate());
+ assertTrue(dc1.getMagicCaretPosition().equals(new Point(200, 300)));
+ assertTrue(dc1.getSelectionPainter() instanceof DefaultHighlighter.DefaultHighlightPainter);
+ assertTrue(dc1.listenerList.toString().equals(
+ dc.listenerList.toString()));
+ assertNull(dc1.changeEvent);
+ } */
/*
* for 1.4.2
*/
@@ -991,30 +847,24 @@
* dc.setAsynchronousMovement(true);
* assertTrue(dc.getAsynchronousMovement()); }
*/
-
public void testNavigationFilter() throws Exception {
assertNull(jta.getNavigationFilter());
-
filter = new SimpleNavigationFilter();
jta.setNavigationFilter(filter);
dc.setDot(3);
dc.moveDot(4);
-
assertEquals(1, filter.flagMoveDot);
assertEquals(1, filter.flagSetDot);
}
//TODO
public void testIsActive() throws Exception {
-
dc.setVisible(true);
-
assertTrue(dc.isActive());
-
dc.setVisible(false);
-
assertFalse(dc.isActive());
}
+
public void test3820() {
DefaultCaret dc = new DefaultCaret();
assertEquals(0, dc.getChangeListeners().length);
@@ -1029,7 +879,4 @@
dc.setSelectionVisible(true);
assertEquals(1, jta.getHighlighter().getHighlights().length);
}
-
-
}
-
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultCaret_BidiTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultCaret_BidiTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultCaret_BidiTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultCaret_BidiTest.java Sun Nov 26 12:15:43 2006
@@ -46,20 +46,14 @@
}
void dotTest(final int dot, final Position.Bias bias, final String s) {
-
assertEquals(dot, dc.getDot());
-
assertEquals(bias, dc.getDotBias());
-
assertEquals(s, dc.toString());
-
}
- void insertCase(final int offset, final String ins, final int sDot, final Position.Bias sBias,
- final int gDot, final Position.Bias gBias) {
-
+ void insertCase(final int offset, final String ins, final int sDot,
+ final Position.Bias sBias, final int gDot, final Position.Bias gBias) {
jta.setText(sLTR + sRTL + sLTR + sRTL + sLTR + sRTL);
-
dc.setDot(sDot, sBias);
try {
ad.insertString(offset, ins, null);
@@ -69,15 +63,12 @@
}
assertFalse("Unexpected exception: " + s, bWasException);
assertEquals(gDot, dc.getDot());
-
assertEquals(gBias, dc.getDotBias());
-
}
void removeCase(final String sText, final int offset, final int length, final int sDot,
final Position.Bias sBias, final int gDot, final Position.Bias gBias) {
jta.setText(sText);
-
dc.setDot(sDot, sBias);
try {
ad.remove(offset, length);
@@ -85,191 +76,120 @@
bWasException = true;
s = e.getMessage();
}
-
assertFalse("Unexpected exception: " + s, bWasException);
-
assertEquals(gDot, dc.getDot());
-
assertEquals(gBias, dc.getDotBias());
-
}
void setDotCase(final int dot, final Position.Bias bias, final String s) {
dc.setDot(dot, bias);
-
assertEquals(dot, dc.getDot());
-
assertEquals(bias, dc.getDotBias());
-
- String tmp = "Dot=(" + dc.getDot() + ", " + dc.getDotBias().toString()
- + ") " + "Mark=(" + dc.getMark() + ", ";
+ String tmp = "Dot=(" + dc.getDot() + ", " + dc.getDotBias().toString() + ") "
+ + "Mark=(" + dc.getMark() + ", ";
assertEquals(tmp + s, dc.toString());
-
}
+ @Override
protected void setUp() throws Exception {
super.setUp();
-
jta = new JTextArea(sLTR + sRTL + sLTR + sRTL + sLTR + sRTL);
dc = new DefaultCaret();
-
jf = new JFrame();
-
bWasException = false;
s = null;
-
ad = (AbstractDocument) jta.getDocument();
-
jf.getContentPane().add(jta);
-
jta.getCaret().deinstall(jta);
-
jta.setCaret(dc);
-
jf.setLocation(100, 100);
jf.setSize(350, 200);
jf.pack();
-
}
+ @Override
protected void tearDown() throws Exception {
jf.dispose();
super.tearDown();
}
public void testBidiInsert() throws Exception {
-
insertCase(0, sLTR, 2, Position.Bias.Forward, 3, Position.Bias.Forward);
insertCase(1, sLTR, 2, Position.Bias.Forward, 3, Position.Bias.Forward);
insertCase(2, sLTR, 2, Position.Bias.Forward, 3, Position.Bias.Backward);//b=f
insertCase(3, sLTR, 2, Position.Bias.Forward, 2, Position.Bias.Forward);
-
insertCase(0, sRTL, 2, Position.Bias.Forward, 3, Position.Bias.Forward);
insertCase(1, sRTL, 2, Position.Bias.Forward, 3, Position.Bias.Forward);
insertCase(2, sRTL, 2, Position.Bias.Forward, 3, Position.Bias.Backward);
insertCase(3, sRTL, 2, Position.Bias.Forward, 2, Position.Bias.Forward);
-
- insertCase(0, sLTR, 2, Position.Bias.Backward, 3,
- Position.Bias.Backward);
- insertCase(1, sLTR, 2, Position.Bias.Backward, 3,
- Position.Bias.Backward);
- insertCase(2, sLTR, 2, Position.Bias.Backward, 3,
- Position.Bias.Backward);
- insertCase(3, sLTR, 2, Position.Bias.Backward, 2,
- Position.Bias.Backward);
-
- insertCase(0, sRTL, 2, Position.Bias.Backward, 3,
- Position.Bias.Backward);
- insertCase(1, sRTL, 2, Position.Bias.Backward, 3,
- Position.Bias.Backward);
- insertCase(2, sRTL, 2, Position.Bias.Backward, 3,
- Position.Bias.Backward);
- insertCase(3, sRTL, 2, Position.Bias.Backward, 2,
- Position.Bias.Backward);
-
+ insertCase(0, sLTR, 2, Position.Bias.Backward, 3, Position.Bias.Backward);
+ insertCase(1, sLTR, 2, Position.Bias.Backward, 3, Position.Bias.Backward);
+ insertCase(2, sLTR, 2, Position.Bias.Backward, 3, Position.Bias.Backward);
+ insertCase(3, sLTR, 2, Position.Bias.Backward, 2, Position.Bias.Backward);
+ insertCase(0, sRTL, 2, Position.Bias.Backward, 3, Position.Bias.Backward);
+ insertCase(1, sRTL, 2, Position.Bias.Backward, 3, Position.Bias.Backward);
+ insertCase(2, sRTL, 2, Position.Bias.Backward, 3, Position.Bias.Backward);
+ insertCase(3, sRTL, 2, Position.Bias.Backward, 2, Position.Bias.Backward);
insertCase(1, sLTR, 3, Position.Bias.Forward, 4, Position.Bias.Forward);
insertCase(2, sLTR, 3, Position.Bias.Forward, 4, Position.Bias.Forward);
insertCase(3, sLTR, 3, Position.Bias.Forward, 4, Position.Bias.Backward);
insertCase(4, sLTR, 3, Position.Bias.Forward, 3, Position.Bias.Forward);
-
insertCase(1, sRTL, 3, Position.Bias.Forward, 4, Position.Bias.Forward);
insertCase(2, sRTL, 3, Position.Bias.Forward, 4, Position.Bias.Forward);
insertCase(3, sRTL, 3, Position.Bias.Forward, 4, Position.Bias.Backward);
insertCase(4, sRTL, 3, Position.Bias.Forward, 3, Position.Bias.Forward);
-
- insertCase(1, sLTR, 3, Position.Bias.Backward, 4,
- Position.Bias.Backward);
- insertCase(2, sLTR, 3, Position.Bias.Backward, 4,
- Position.Bias.Backward);
- insertCase(3, sLTR, 3, Position.Bias.Backward, 4,
- Position.Bias.Backward);
- insertCase(4, sLTR, 3, Position.Bias.Backward, 3,
- Position.Bias.Backward);
-
- insertCase(1, sRTL, 3, Position.Bias.Backward, 4,
- Position.Bias.Backward);
- insertCase(2, sRTL, 3, Position.Bias.Backward, 4,
- Position.Bias.Backward);
- insertCase(3, sRTL, 3, Position.Bias.Backward, 4,
- Position.Bias.Backward);
- insertCase(4, sRTL, 3, Position.Bias.Backward, 3,
- Position.Bias.Backward);
-
- insertCase(0, sRTL + sRTL, 2, Position.Bias.Backward, 4,
- Position.Bias.Backward);
- insertCase(1, sRTL + sRTL, 2, Position.Bias.Backward, 4,
- Position.Bias.Backward);
- insertCase(2, sRTL + sRTL, 2, Position.Bias.Backward, 4,
- Position.Bias.Backward);
-
- insertCase(3, sRTL + sRTL, 2, Position.Bias.Backward, 2,
- Position.Bias.Backward);
-
+ insertCase(1, sLTR, 3, Position.Bias.Backward, 4, Position.Bias.Backward);
+ insertCase(2, sLTR, 3, Position.Bias.Backward, 4, Position.Bias.Backward);
+ insertCase(3, sLTR, 3, Position.Bias.Backward, 4, Position.Bias.Backward);
+ insertCase(4, sLTR, 3, Position.Bias.Backward, 3, Position.Bias.Backward);
+ insertCase(1, sRTL, 3, Position.Bias.Backward, 4, Position.Bias.Backward);
+ insertCase(2, sRTL, 3, Position.Bias.Backward, 4, Position.Bias.Backward);
+ insertCase(3, sRTL, 3, Position.Bias.Backward, 4, Position.Bias.Backward);
+ insertCase(4, sRTL, 3, Position.Bias.Backward, 3, Position.Bias.Backward);
+ insertCase(0, sRTL + sRTL, 2, Position.Bias.Backward, 4, Position.Bias.Backward);
+ insertCase(1, sRTL + sRTL, 2, Position.Bias.Backward, 4, Position.Bias.Backward);
+ insertCase(2, sRTL + sRTL, 2, Position.Bias.Backward, 4, Position.Bias.Backward);
+ insertCase(3, sRTL + sRTL, 2, Position.Bias.Backward, 2, Position.Bias.Backward);
}
public void testBidiRemove() throws Exception {
-
- String s1 = sLTR + sRTL + sLTR + sRTL + sLTR + sRTL + sLTR + sRTL
- + sLTR;
- String s2 = sRTL + sRTL + sLTR + sLTR + sRTL + sRTL + sLTR + sLTR
- + sRTL;
-
+ String s1 = sLTR + sRTL + sLTR + sRTL + sLTR + sRTL + sLTR + sRTL + sLTR;
+ String s2 = sRTL + sRTL + sLTR + sLTR + sRTL + sRTL + sLTR + sLTR + sRTL;
//s1 = sLTR + sRTL + sLTR + sRTL + sLTR + sRTL + sLTR + sRTL +
// sLTR;
removeCase(s1, 2, 1, 3, Position.Bias.Forward, 2, Position.Bias.Forward);
//removeCase(s1,2,3,3,Position.Bias.Forward,2,Position.Bias.Forward);//b=f
- removeCase(s1, 2, 1, 3, Position.Bias.Backward, 2,
- Position.Bias.Backward);
- removeCase(s1, 2, 3, 3, Position.Bias.Backward, 2,
- Position.Bias.Backward);
-
+ removeCase(s1, 2, 1, 3, Position.Bias.Backward, 2, Position.Bias.Backward);
+ removeCase(s1, 2, 3, 3, Position.Bias.Backward, 2, Position.Bias.Backward);
//removeCase(s1,1,2,3,Position.Bias.Forward,1,Position.Bias.Backward);//!!!
//removeCase(s1,1,3,3,Position.Bias.Forward,1,Position.Bias.Backward);//b=f
- removeCase(s1, 1, 2, 3, Position.Bias.Backward, 1,
- Position.Bias.Backward);
- removeCase(s1, 1, 3, 3, Position.Bias.Backward, 1,
- Position.Bias.Backward);
-
- removeCase(s1, 3, 1, 3, Position.Bias.Forward, 3,
- Position.Bias.Backward); // b=f
- removeCase(s1, 3, 2, 3, Position.Bias.Forward, 3,
- Position.Bias.Backward); // !!!
- removeCase(s1, 3, 1, 3, Position.Bias.Backward, 3,
- Position.Bias.Backward);
- removeCase(s1, 3, 2, 3, Position.Bias.Backward, 3,
- Position.Bias.Backward);
-
+ removeCase(s1, 1, 2, 3, Position.Bias.Backward, 1, Position.Bias.Backward);
+ removeCase(s1, 1, 3, 3, Position.Bias.Backward, 1, Position.Bias.Backward);
+ removeCase(s1, 3, 1, 3, Position.Bias.Forward, 3, Position.Bias.Backward); // b=f
+ removeCase(s1, 3, 2, 3, Position.Bias.Forward, 3, Position.Bias.Backward); // !!!
+ removeCase(s1, 3, 1, 3, Position.Bias.Backward, 3, Position.Bias.Backward);
+ removeCase(s1, 3, 2, 3, Position.Bias.Backward, 3, Position.Bias.Backward);
//s2 = sRTL + sRTL + sLTR + sLTR + sRTL + sRTL + sLTR + sLTR +
// sRTL;
//removeCase(s2,2,1,3,Position.Bias.Forward,2,Position.Bias.Backward);//b=f
// begin
//removeCase(s2,2,3,3,Position.Bias.Forward,2,Position.Bias.Backward);//
// b=f
- removeCase(s2, 2, 1, 3, Position.Bias.Backward, 2,
- Position.Bias.Backward);
- removeCase(s2, 2, 3, 3, Position.Bias.Backward, 2,
- Position.Bias.Backward);
-
+ removeCase(s2, 2, 1, 3, Position.Bias.Backward, 2, Position.Bias.Backward);
+ removeCase(s2, 2, 3, 3, Position.Bias.Backward, 2, Position.Bias.Backward);
//removeCase(s2,1,2,3,Position.Bias.Forward,1,Position.Bias.Backward);
// //b=f
//removeCase(s2,1,3,3,Position.Bias.Forward,1,Position.Bias.Backward);
// //b=f begin
- removeCase(s2, 1, 2, 3, Position.Bias.Backward, 1,
- Position.Bias.Backward);
- removeCase(s2, 1, 3, 3, Position.Bias.Backward, 1,
- Position.Bias.Backward);
-
+ removeCase(s2, 1, 2, 3, Position.Bias.Backward, 1, Position.Bias.Backward);
+ removeCase(s2, 1, 3, 3, Position.Bias.Backward, 1, Position.Bias.Backward);
//removeCase(s2,3,1,3,Position.Bias.Forward,3,Position.Bias.Backward);//!!!
//removeCase(s2,3,2,3,Position.Bias.Forward,3,Position.Bias.Backward);//b=f
- removeCase(s2, 3, 1, 3, Position.Bias.Backward, 3,
- Position.Bias.Backward);
- removeCase(s2, 3, 2, 3, Position.Bias.Backward, 3,
- Position.Bias.Backward);
-
+ removeCase(s2, 3, 1, 3, Position.Bias.Backward, 3, Position.Bias.Backward);
+ removeCase(s2, 3, 2, 3, Position.Bias.Backward, 3, Position.Bias.Backward);
}
public void testBidiSetDot() throws Exception {
-
setDotCase(0, Position.Bias.Forward, "Forward)");
setDotCase(1, Position.Bias.Backward, "Backward)");
setDotCase(2, Position.Bias.Forward, "Forward)");
@@ -279,21 +199,13 @@
public void testBidiMoveDot() throws Exception {
jta.setText(sLTR + sRTL + sLTR + sRTL + sLTR);
-
dc.setDot(1, Position.Bias.Backward);
- dotTest(1, Position.Bias.Backward,
- "Dot=(1, Backward) Mark=(1, Backward)");
-
+ dotTest(1, Position.Bias.Backward, "Dot=(1, Backward) Mark=(1, Backward)");
dc.moveDot(3);
dotTest(3, Position.Bias.Forward, "Dot=(3, Forward) Mark=(1, Backward)");
-
dc.setDot(2, Position.Bias.Forward);
dotTest(2, Position.Bias.Forward, "Dot=(2, Forward) Mark=(2, Forward)");
-
dc.moveDot(3);
dotTest(3, Position.Bias.Forward, "Dot=(3, Forward) Mark=(2, Forward)");
-
}
-
}
-
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultCaret_MultithreadedTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultCaret_MultithreadedTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultCaret_MultithreadedTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultCaret_MultithreadedTest.java Sun Nov 26 12:15:43 2006
@@ -27,22 +27,27 @@
import javax.swing.SwingWaitTestCase;
public class DefaultCaret_MultithreadedTest extends BasicSwingTestCase {
-
AbstractDocument ad;
+
boolean bWasException = false;
+
DefaultCaret dc = null;
+
JFrame jf = null;
+
JTextArea jta = null;
+
String s = null;
+
int newDot;
-
+
public DefaultCaret_MultithreadedTest(final String name) {
super(name);
}
+ @Override
protected void setUp() throws Exception {
super.setUp();
-
jta = new JTextArea("JTextArea for DefaultCaret Testing\n***\n*%%%**");
dc = new DefaultCaret();
jf = new JFrame();
@@ -57,6 +62,7 @@
jf.setVisible(true);
}
+ @Override
protected void tearDown() throws Exception {
jf.dispose();
super.tearDown();
@@ -82,7 +88,6 @@
waitForIdle();
assertFalse("Unexpected exception: " + s, bWasException);
assertEquals(0, dc.getDot());
-
newDot = 4;
SwingUtilities.invokeAndWait(setDot);
waitForIdle();
@@ -96,14 +101,12 @@
ad.writeUnlock();
waitForIdle();
assertEquals(4, dc.getDot());
-
//dc.setAsynchronousMovement(true); //1.4.2
if (isHarmony()) {
dc.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
} else {
dc.setAsynchronousMovement(true);
}
-
newDot = 0;
SwingUtilities.invokeAndWait(setDot);
waitForIdle();
@@ -119,7 +122,6 @@
SwingWaitTestCase.isRealized(jf);
assertFalse("Unexpected exception: " + s, bWasException);
assertEquals(6, dc.getDot());
-
newDot = 4;
SwingUtilities.invokeAndWait(setDot);
waitForIdle();
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultEditorKitRTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultEditorKitRTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultEditorKitRTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultEditorKitRTest.java Sun Nov 26 12:15:43 2006
@@ -29,27 +29,27 @@
import java.io.Reader;
import java.io.Writer;
import java.lang.reflect.InvocationTargetException;
-
import javax.swing.Action;
import javax.swing.BasicSwingTestCase;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JViewport;
+import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
-
public class DefaultEditorKitRTest extends BasicSwingTestCase {
-
protected DefaultEditorKit kit = null;
protected JFrame frame;
+ @Override
protected void setUp() throws Exception {
super.setUp();
kit = new DefaultEditorKit();
}
+ @Override
protected void tearDown() throws Exception {
kit = null;
if (frame != null) {
@@ -66,14 +66,13 @@
return actions[i];
}
}
-
return null;
}
- protected void performAction(final Object source, final Action action,
- final String command) throws InterruptedException, InvocationTargetException {
-
- final ActionEvent actionEvent = new ActionEvent(source, ActionEvent.ACTION_PERFORMED, command);
+ protected void performAction(final Object source, final Action action, final String command)
+ throws InterruptedException, InvocationTargetException {
+ final ActionEvent actionEvent = new ActionEvent(source, ActionEvent.ACTION_PERFORMED,
+ command);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
action.actionPerformed(actionEvent);
@@ -81,15 +80,14 @@
});
}
- protected JTextArea getInitedComponent(final int startPos,
- final int endPos, final String text) throws InterruptedException, InvocationTargetException {
+ protected JTextArea getInitedComponent(final int startPos, final int endPos,
+ final String text) throws InterruptedException, InvocationTargetException {
JTextArea c = new JTextArea();
return initComponent(c, startPos, endPos, text);
}
- private JTextArea initComponent(final JTextArea c, final int startPos,
- final int endPos, final String text) throws InterruptedException, InvocationTargetException {
-
+ private JTextArea initComponent(final JTextArea c, final int startPos, final int endPos,
+ final String text) throws InterruptedException, InvocationTargetException {
if (frame != null) {
frame.dispose();
}
@@ -98,8 +96,8 @@
JScrollPane scroll = new JScrollPane(c);
((JViewport) c.getParent()).setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
int strHeight = c.getFontMetrics(c.getFont()).getHeight();
- scroll.setPreferredSize(new Dimension(300, strHeight*5));
- scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
+ scroll.setPreferredSize(new Dimension(300, strHeight * 5));
+ scroll.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
frame.getContentPane().add(scroll);
frame.pack();
java.awt.EventQueue.invokeAndWait(new Runnable() {
@@ -118,12 +116,10 @@
JTextArea c = getInitedComponent(2, 7, "0123456789");
performAction(new JTextArea(), action, "command\ncontent");
assertEquals("resulted string", "0123456789", c.getText());
-
c = getInitedComponent(2, 7, "0123456789");
c.setEditable(false);
performAction(c, action, "command\ncontent");
assertEquals("resulted string", "0123456789", c.getText());
-
c = getInitedComponent(2, 7, "0123456789");
performAction(c, action, null);
assertEquals("resulted string", "0123456789", c.getText());
@@ -132,18 +128,26 @@
public void testReadInputStreamDocumentint() throws Exception {
final Marker readerMarker = new Marker();
DefaultEditorKit kit = new DefaultEditorKit() {
- public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void read(Reader in, Document doc, int pos) throws IOException,
+ BadLocationException {
readerMarker.setOccurred();
}
};
kit.read(new ByteArrayInputStream(new byte[10]), new DefaultStyledDocument(), 0);
assertTrue(readerMarker.isOccurred());
}
-
+
public void testWriteOutputStreamDocumentintint() throws Exception {
final Marker writeMarker = new Marker();
DefaultEditorKit kit = new DefaultEditorKit() {
- public void write(Writer out, Document doc, int pos, int len) throws IOException, BadLocationException {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void write(Writer out, Document doc, int pos, int len) throws IOException,
+ BadLocationException {
writeMarker.setOccurred();
}
};
@@ -152,8 +156,9 @@
}
public void testInsertContentActionPerformed_NullEvent() throws Exception {
- final TextAction action = (TextAction)getAction(DefaultEditorKit.insertContentAction);
+ final TextAction action = (TextAction) getAction(DefaultEditorKit.insertContentAction);
final JTextArea c = getInitedComponent(2, 7, "0123456789");
+ assertNotNull(c);
frame.setVisible(true);
final Marker thrown = new Marker();
SwingUtilities.invokeAndWait(new Runnable() {
@@ -172,7 +177,6 @@
String str1 = "Windows line-end\r\nUnix-style\nMacOS\rUnknown\n\r";
String str2 = "Windows line-end\nUnix-style\nMacOS\nUnknown\n\n";
InputStream reader = new ByteArrayInputStream(str1.getBytes());
-
Document doc = new PlainDocument();
kit.read(reader, doc, 0);
assertEquals(str2, doc.getText(0, doc.getLength()));