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 [39/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/View_ChangesTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_ChangesTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_ChangesTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_ChangesTest.java Sun Nov 26 12:15:43 2006
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
/**
* @author Alexey A. Ivanov
* @version $Revision$
@@ -24,7 +23,6 @@
import java.awt.Rectangle;
import java.awt.Shape;
import java.util.ArrayList;
-
import javax.swing.BasicSwingTestCase;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
@@ -35,7 +33,6 @@
import javax.swing.text.ViewTest.DisAbstractedView;
import javax.swing.text.ViewTestHelpers.ElementPartView;
import javax.swing.undo.UndoableEdit;
-
import junit.framework.TestCase;
/**
@@ -43,30 +40,29 @@
*
*/
public class View_ChangesTest extends TestCase {
-
/**
* Class overriding some methods to test View behaviour in respect
* to {insert,remove,changed}Update.
*/
private class ChangeView extends WithChildrenView {
-
/**
* The last allocation returned from
* <code>getChildAllocation</code>.
*/
Shape childAllocation = null;
+
public ChangeView(final Element element) {
super(element);
-
loadChildren(viewFactory);
viewsCreatedElements.clear();
replaceViews = null;
}
+ @Override
public Shape getChildAllocation(final int index, final Shape shape) {
if (!hasChildren) {
- fail("getChildAllocation is not supposed to be " +
- "called when there are no children");
+ fail("getChildAllocation is not supposed to be "
+ + "called when there are no children");
}
return childAllocation = super.getChildAllocation(index, shape);
}
@@ -76,12 +72,12 @@
* to <code>super</code> depending on state of flag
* <code>hasChildren</code>.
*/
+ @Override
public View getView(final int index) {
if (hasChildren) {
return super.getView(index);
- } else {
- return null;
}
+ return null;
}
/**
@@ -89,25 +85,26 @@
* <code>super</code> depending on state of flag
* <code>hasChildren</code>.
*/
+ @Override
public int getViewCount() {
if (hasChildren) {
return super.getViewCount();
- } else {
- return 0;
}
+ return 0;
}
- public void replace(final int index, final int length,
- final View[] views) {
- replaceIndex = index;
+ @Override
+ public void replace(final int index, final int length, final View[] views) {
+ replaceIndex = index;
replaceLength = length;
- replaceViews = views;
+ replaceViews = views;
super.replace(index, length, views);
}
/**
* Just a security check: <code>setParent</code> isn't called.
*/
+ @Override
public void setParent(final View parent) {
super.setParent(parent);
fail("setParent is not supposed to be called");
@@ -118,11 +115,10 @@
* called from <code>insertUpdate</code>,
* <code>removeUpdate</code>, or <code>changedUpdate</code>.
*/
- protected void forwardUpdate(final ElementChange change,
- final DocumentEvent event, final Shape shape,
- final ViewFactory factory) {
- forwardUpdateCalled = true;
-
+ @Override
+ protected void forwardUpdate(final ElementChange change, final DocumentEvent event,
+ final Shape shape, final ViewFactory factory) {
+ forwardUpdateCalled = true;
if (updateChildrenReturn) {
assertSame(event.getChange(root), change);
} else {
@@ -131,7 +127,6 @@
assertSame(docEvent, event);
assertSame(rect, shape);
assertSame(viewFactory, factory);
-
super.forwardUpdate(change, event, shape, factory);
}
@@ -140,17 +135,14 @@
* called from <code>insertUpdate</code>,
* <code>removeUpdate</code>, or <code>changedUpdate</code>.
*/
- protected void forwardUpdateToView(final View view,
- final DocumentEvent event, final Shape shape,
- final ViewFactory factory) {
+ @Override
+ protected void forwardUpdateToView(final View view, final DocumentEvent event,
+ final Shape shape, final ViewFactory factory) {
forwardUpdateToViewCalled = true;
-
viewsForwardedTo.add(view);
-
assertSame(docEvent, event);
assertSame(childAllocation, shape);
assertSame(viewFactory, factory);
-
super.forwardUpdateToView(view, event, shape, factory);
}
@@ -159,19 +151,16 @@
* called from <code>insertUpdate</code>,
* <code>removeUpdate</code>, or <code>changedUpdate</code>.
*/
- protected boolean updateChildren(final ElementChange change,
- final DocumentEvent event, final ViewFactory factory) {
- updateChildrenCalled = true;
-
+ @Override
+ protected boolean updateChildren(final ElementChange change, final DocumentEvent event,
+ final ViewFactory factory) {
+ updateChildrenCalled = true;
assertSame(event.getChange(root), change);
assertSame(docEvent, event);
assertSame(viewFactory, factory);
-
assertTrue(super.updateChildren(change, event, factory));
-
assertFalse(forwardUpdateCalled);
assertFalse(updateLayoutCalled);
-
return updateChildrenReturn;
}
@@ -180,10 +169,10 @@
* from <code>insertUpdate</code>, <code>removeUpdate</code>,
* or <code>changedUpdate</code>.
*/
- protected void updateLayout(final ElementChange change,
- final DocumentEvent event, final Shape shape) {
+ @Override
+ protected void updateLayout(final ElementChange change, final DocumentEvent event,
+ final Shape shape) {
updateLayoutCalled = true;
-
if (updateChildrenReturn) {
assertSame(event.getChange(root), change);
} else {
@@ -191,7 +180,6 @@
}
assertSame(docEvent, event);
assertSame(rect, shape);
-
super.updateLayout(change, event, shape);
}
}
@@ -200,27 +188,35 @@
* View allocation (Shape parameter).
*/
private static final Rectangle rect = new Rectangle(20, 20);
+
private Document doc;
/**
* The event used to test the functionality.
*/
private DocumentEvent docEvent;
+
private boolean forwardUpdateCalled;
+
private boolean forwardUpdateToViewCalled;
+
/**
* Flag which controls whether anonymous test-view has children or not.
*/
private boolean hasChildren;
+
private Element line;
+
/**
* Index of the first child where change happens (in call to replace).
*/
private int replaceIndex;
+
/**
* Number of elements to remove (in call to replace).
*/
private int replaceLength;
+
/**
* Views to add (in call to replace).
*/
@@ -237,22 +233,25 @@
* Return value from updateChildren for anonymous test-view.
*/
private boolean updateChildrenReturn;
+
private boolean updateLayoutCalled;
+
private View view;
/**
* The view factory used in tests.
*/
private ViewFactory viewFactory;
+
/**
* List of elements for which new views were created.
*/
- private ArrayList viewsCreatedElements = new ArrayList();
+ private ArrayList<Element> viewsCreatedElements = new ArrayList<Element>();
/**
* List of views for which forwardUpdateToView was called.
*/
- private ArrayList viewsForwardedTo = new ArrayList();
+ private ArrayList<View> viewsForwardedTo = new ArrayList<View>();
/**
* Creates document event with type of <code>CHANGE</code>.
@@ -260,18 +259,13 @@
public void createChangeEvent() throws BadLocationException {
doc.insertString(doc.getLength(), "one\ntwo\n", null);
view.removeAll();
- ((CompositeView)view).loadChildren(viewFactory);
+ ((CompositeView) view).loadChildren(viewFactory);
viewsCreatedElements.clear();
replaceViews = null;
-
- ElementChange change =
- docEvent.getChange(doc.getDefaultRootElement());
- docEvent = ((AbstractDocument)doc).new DefaultDocumentEvent(
- docEvent.getLength(), docEvent.getOffset(),
- EventType.CHANGE);
-
- ((AbstractDocument.DefaultDocumentEvent)docEvent)
- .addEdit((UndoableEdit)change);
+ ElementChange change = docEvent.getChange(doc.getDefaultRootElement());
+ docEvent = ((AbstractDocument) doc).new DefaultDocumentEvent(docEvent.getLength(),
+ docEvent.getOffset(), EventType.CHANGE);
+ ((AbstractDocument.DefaultDocumentEvent) docEvent).addEdit((UndoableEdit) change);
}
/**
@@ -280,12 +274,9 @@
*/
public void testChangedUpdate01() throws BadLocationException {
createChangeEvent();
-
hasChildren = false;
assertEquals(0, view.getViewCount());
-
view.changedUpdate(docEvent, rect, viewFactory);
-
assertFalse(updateChildrenCalled);
assertFalse(forwardUpdateCalled);
assertFalse(forwardUpdateToViewCalled);
@@ -299,23 +290,17 @@
public void testChangedUpdate02() throws BadLocationException {
hasChildren = true;
createChangeEvent();
-
updateChildrenReturn = false;
assertEquals(4, view.getViewCount());
-
view.changedUpdate(docEvent, rect, viewFactory);
-
assertTrue(updateChildrenCalled);
checkUpdatedChildren(4 + 2, 1);
-
assertTrue(forwardUpdateCalled);
-
assertTrue(forwardUpdateToViewCalled);
assertEquals(3, viewsForwardedTo.size()); // to all children
for (int i = 0; i < viewsForwardedTo.size(); i++) {
assertSame("@ " + i, view.getView(i + 1), viewsForwardedTo.get(i));
}
-
assertTrue(updateLayoutCalled);
}
@@ -327,19 +312,13 @@
hasChildren = true;
createChangeEvent();
assertEquals(1, docEvent.getChange(root).getIndex());
-
updateChildrenReturn = true;
assertEquals(4, view.getViewCount());
-
view.changedUpdate(docEvent, rect, viewFactory);
-
assertTrue(updateChildrenCalled);
checkUpdatedChildren(4 + 2, 1);
-
assertTrue(forwardUpdateCalled);
-
assertFalse(forwardUpdateToViewCalled);
-
assertTrue(updateLayoutCalled);
}
@@ -353,27 +332,18 @@
public void testChangedUpdate04() throws BadLocationException {
hasChildren = true;
changeDocument();
-
updateChildrenReturn = true;
-
Element prevLastLine = root.getElement(root.getElementCount() - 2);
- docEvent = ((AbstractDocument)doc)
- .new DefaultDocumentEvent(line.getStartOffset() + 1,
- prevLastLine.getEndOffset() - 2
- - line.getStartOffset(),
- EventType.CHANGE);
-
+ docEvent = ((AbstractDocument) doc).new DefaultDocumentEvent(line.getStartOffset() + 1,
+ prevLastLine.getEndOffset() - 2 - line.getStartOffset(), EventType.CHANGE);
view.changedUpdate(docEvent, rect, viewFactory);
-
assertFalse(updateChildrenCalled);
assertTrue(forwardUpdateCalled);
-
assertTrue(forwardUpdateToViewCalled);
assertEquals(2, viewsForwardedTo.size());
for (int i = 0; i < viewsForwardedTo.size(); i++) {
assertSame("@ " + i, view.getView(i + 1), viewsForwardedTo.get(i));
}
-
assertTrue(updateLayoutCalled);
}
@@ -387,27 +357,18 @@
public void testChangedUpdate05() throws BadLocationException {
hasChildren = true;
changeDocument();
-
updateChildrenReturn = false;
-
Element prevLastLine = root.getElement(root.getElementCount() - 2);
- docEvent = ((AbstractDocument)doc)
- .new DefaultDocumentEvent(line.getStartOffset() + 1,
- prevLastLine.getEndOffset() - 2
- - line.getStartOffset(),
- EventType.CHANGE);
-
+ docEvent = ((AbstractDocument) doc).new DefaultDocumentEvent(line.getStartOffset() + 1,
+ prevLastLine.getEndOffset() - 2 - line.getStartOffset(), EventType.CHANGE);
view.changedUpdate(docEvent, rect, viewFactory);
-
assertFalse(updateChildrenCalled);
assertTrue(forwardUpdateCalled);
-
assertTrue(forwardUpdateToViewCalled);
assertEquals(2, viewsForwardedTo.size());
for (int i = 0; i < viewsForwardedTo.size(); i++) {
assertSame("@ " + i, view.getView(i + 1), viewsForwardedTo.get(i));
}
-
assertTrue(updateLayoutCalled);
}
@@ -419,68 +380,68 @@
// Class to store which function is called
class Params {
boolean change = false;
+
boolean insert = false;
+
boolean remove = false;
}
final Params params = new Params();
-
view = new DisAbstractedView(line);
View child = new DisAbstractedView(root.getElement(0)) {
- public void changedUpdate(final DocumentEvent event,
- final Shape shape,
- final ViewFactory factory) {
+ @Override
+ public void changedUpdate(final DocumentEvent event, final Shape shape,
+ final ViewFactory factory) {
params.change = true;
}
- public void insertUpdate(final DocumentEvent event,
- final Shape shape,
- final ViewFactory factory) {
+
+ @Override
+ public void insertUpdate(final DocumentEvent event, final Shape shape,
+ final ViewFactory factory) {
params.insert = true;
}
- public void removeUpdate(final DocumentEvent event,
- final Shape shape,
- final ViewFactory factory) {
+
+ @Override
+ public void removeUpdate(final DocumentEvent event, final Shape shape,
+ final ViewFactory factory) {
params.remove = true;
}
};
-
- view.forwardUpdateToView(child,
- ((AbstractDocument)doc).new DefaultDocumentEvent(0, 0,
- EventType.INSERT),
- rect, viewFactory);
-
- assertTrue (params.insert); params.insert = false;
- assertFalse(params.remove); params.remove = false;
- assertFalse(params.change); params.change = false;
-
- view.forwardUpdateToView(child,
- ((AbstractDocument)doc).new DefaultDocumentEvent(0, 0,
- EventType.REMOVE),
- rect, viewFactory);
-
- assertFalse(params.insert); params.insert = false;
- assertTrue (params.remove); params.remove = false;
- assertFalse(params.change); params.change = false;
-
- view.forwardUpdateToView(child,
- ((AbstractDocument)doc).new DefaultDocumentEvent(0, 0,
- EventType.CHANGE),
- rect, viewFactory);
-
- assertFalse(params.insert); params.insert = false;
- assertFalse(params.remove); params.remove = false;
- assertTrue (params.change); params.change = false;
-
- view.forwardUpdateToView(child,
- ((AbstractDocument)doc).new DefaultDocumentEvent(0, 0,
- null),
- rect, viewFactory);
-
- assertFalse(params.insert); params.insert = false;
- assertFalse(params.remove); params.remove = false;
+ view.forwardUpdateToView(child, ((AbstractDocument) doc).new DefaultDocumentEvent(0, 0,
+ EventType.INSERT), rect, viewFactory);
+ assertTrue(params.insert);
+ params.insert = false;
+ assertFalse(params.remove);
+ params.remove = false;
+ assertFalse(params.change);
+ params.change = false;
+ view.forwardUpdateToView(child, ((AbstractDocument) doc).new DefaultDocumentEvent(0, 0,
+ EventType.REMOVE), rect, viewFactory);
+ assertFalse(params.insert);
+ params.insert = false;
+ assertTrue(params.remove);
+ params.remove = false;
+ assertFalse(params.change);
+ params.change = false;
+ view.forwardUpdateToView(child, ((AbstractDocument) doc).new DefaultDocumentEvent(0, 0,
+ EventType.CHANGE), rect, viewFactory);
+ assertFalse(params.insert);
+ params.insert = false;
+ assertFalse(params.remove);
+ params.remove = false;
+ assertTrue(params.change);
+ params.change = false;
+ view.forwardUpdateToView(child, ((AbstractDocument) doc).new DefaultDocumentEvent(0, 0,
+ null), rect, viewFactory);
+ assertFalse(params.insert);
+ params.insert = false;
+ assertFalse(params.remove);
+ params.remove = false;
if (BasicSwingTestCase.isHarmony()) {
- assertFalse(params.change); params.change = false;
+ assertFalse(params.change);
+ params.change = false;
} else {
- assertTrue(params.change); params.change = false;
+ assertTrue(params.change);
+ params.change = false;
}
}
@@ -489,14 +450,10 @@
* is <i>not</i> called.
*/
public void testInsertUpdate01() throws BadLocationException {
- doc.insertString(line.getStartOffset() + 2,
- "one\ntwo\n", null);
-
+ doc.insertString(line.getStartOffset() + 2, "one\ntwo\n", null);
hasChildren = false;
assertEquals(0, view.getViewCount());
-
view.insertUpdate(docEvent, rect, viewFactory);
-
assertFalse(updateChildrenCalled);
assertFalse(forwardUpdateCalled);
assertFalse(forwardUpdateToViewCalled);
@@ -508,25 +465,19 @@
* <code>false</code>. (Views may represent parts of an Element.)
*/
public void testInsertUpdate02() throws BadLocationException {
- doc.insertString(line.getStartOffset() + 2,
- "one\ntwo\n", null);
-
- hasChildren = true;
+ doc.insertString(line.getStartOffset() + 2, "one\ntwo\n", null);
+ hasChildren = true;
updateChildrenReturn = false;
assertEquals(2, view.getViewCount());
-
view.insertUpdate(docEvent, rect, viewFactory);
-
assertTrue(updateChildrenCalled);
checkUpdatedChildren(2 + 2, 1);
-
assertTrue(forwardUpdateCalled);
assertTrue(forwardUpdateToViewCalled);
assertEquals(4 - 1, viewsForwardedTo.size()); // first elem not affected
for (int i = 0; i < viewsForwardedTo.size(); i++) {
assertSame("@ " + i, view.getView(i + 1), viewsForwardedTo.get(i));
}
-
assertTrue(updateLayoutCalled);
}
@@ -536,16 +487,12 @@
*/
public void testInsertUpdate03() throws BadLocationException {
doc.insertString(line.getStartOffset() + 2, "one\ntwo\n", null);
-
- hasChildren = true;
+ hasChildren = true;
updateChildrenReturn = true;
assertEquals(2, view.getViewCount());
-
view.insertUpdate(docEvent, rect, viewFactory);
-
assertTrue(updateChildrenCalled);
checkUpdatedChildren(2 + 2, 1);
-
assertTrue(forwardUpdateCalled);
assertFalse(forwardUpdateToViewCalled);
assertTrue(updateLayoutCalled);
@@ -559,19 +506,14 @@
public void testInsertUpdate04() throws BadLocationException {
hasChildren = true;
changeDocument();
-
// Event method will be tested upon
doc.insertString(doc.getLength(), "insert4", null);
assertEquals(2, docEvent.getChange(root).getIndex());
-
updateChildrenReturn = true;
assertEquals(4, view.getViewCount());
-
view.insertUpdate(docEvent, rect, viewFactory);
-
assertTrue(updateChildrenCalled);
checkUpdatedChildren(4 + 0, 2);
-
assertTrue(forwardUpdateCalled);
assertFalse(forwardUpdateToViewCalled);
assertTrue(updateLayoutCalled);
@@ -585,21 +527,15 @@
doc.insertString(line.getStartOffset() + 2, "one", null);
// This should not cause any line map restructure
assertNull(docEvent.getChange(root));
-
- hasChildren = true;
+ hasChildren = true;
updateChildrenReturn = true;
assertEquals(2, view.getViewCount());
-
view.insertUpdate(docEvent, rect, viewFactory);
-
assertFalse(updateChildrenCalled);
-
assertTrue(forwardUpdateCalled);
-
assertTrue(forwardUpdateToViewCalled);
assertEquals(1, viewsForwardedTo.size());
assertSame(view.getView(1), viewsForwardedTo.get(0));
-
assertTrue(updateLayoutCalled);
}
@@ -608,20 +544,16 @@
*/
public void testInsertUpdate06() throws BadLocationException {
doc.insertString(line.getStartOffset() + 2, "one\ntwo\n", null);
-
- hasChildren = true;
+ hasChildren = true;
updateChildrenReturn = true;
assertEquals(2, view.getViewCount());
-
try {
view.insertUpdate(docEvent, rect, viewFactory = null);
-
// So we should not check for this invalid parameter
// (viewFactory == null)
- fail("Calling insertUpdate with null factory must result " +
- " in exception");
- } catch (NullPointerException e) { }
-
+ fail("Calling insertUpdate with null factory must result " + " in exception");
+ } catch (NullPointerException e) {
+ }
assertTrue(updateChildrenCalled);
// The exception must have occurred in updateChildren
assertFalse(forwardUpdateCalled);
@@ -636,18 +568,13 @@
public void testInsertUpdate07() throws BadLocationException {
hasChildren = true;
changeDocument();
-
doc.insertString(2, "^^^\n", null);
assertEquals(0, docEvent.getChange(root).getIndex());
-
updateChildrenReturn = true;
assertEquals(4, view.getViewCount());
-
view.insertUpdate(docEvent, rect, viewFactory);
-
assertTrue(updateChildrenCalled);
checkUpdatedChildren(4 + 1, 1);
-
assertTrue(forwardUpdateCalled);
assertFalse(forwardUpdateToViewCalled);
assertTrue(updateLayoutCalled);
@@ -660,18 +587,13 @@
public void testInsertUpdate08() throws BadLocationException {
hasChildren = true;
changeDocument();
-
doc.insertString(2, "^^^\n", null);
assertEquals(0, docEvent.getChange(root).getIndex());
-
updateChildrenReturn = false;
assertEquals(4, view.getViewCount());
-
view.insertUpdate(docEvent, rect, viewFactory);
-
assertTrue(updateChildrenCalled);
checkUpdatedChildren(4 + 1, 1);
-
assertTrue(forwardUpdateCalled);
assertTrue(forwardUpdateToViewCalled);
assertEquals(2, viewsForwardedTo.size());
@@ -690,20 +612,15 @@
*/
public void testInsertUpdate09() throws BadLocationException {
createPartialViews();
-
updateChildrenReturn = true;
view.insertUpdate(docEvent, rect, viewFactory);
-
assertFalse(updateChildrenCalled);
-
assertTrue(forwardUpdateCalled);
assertTrue(forwardUpdateToViewCalled);
- assertEquals(BasicSwingTestCase.isHarmony() ? 2 : 1,
- viewsForwardedTo.size());
+ assertEquals(BasicSwingTestCase.isHarmony() ? 2 : 1, viewsForwardedTo.size());
for (int i = 0; i < viewsForwardedTo.size(); i++) {
assertSame("@ " + i, view.getView(i + 1), viewsForwardedTo.get(i));
- assertTrue("@ " + i,
- view.getView(i + 1) instanceof ElementPartView);
+ assertTrue("@ " + i, view.getView(i + 1) instanceof ElementPartView);
}
assertTrue(updateLayoutCalled);
}
@@ -718,20 +635,15 @@
*/
public void testInsertUpdate10() throws BadLocationException {
createPartialViews();
-
updateChildrenReturn = false;
view.insertUpdate(docEvent, rect, viewFactory);
-
assertFalse(updateChildrenCalled);
-
assertTrue(forwardUpdateCalled);
assertTrue(forwardUpdateToViewCalled);
- assertEquals(BasicSwingTestCase.isHarmony() ? 2 : 1,
- viewsForwardedTo.size());
+ assertEquals(BasicSwingTestCase.isHarmony() ? 2 : 1, viewsForwardedTo.size());
for (int i = 0; i < viewsForwardedTo.size(); i++) {
assertSame("@ " + i, view.getView(i + 1), viewsForwardedTo.get(i));
- assertTrue("@ " + i,
- view.getView(i + 1) instanceof ElementPartView);
+ assertTrue("@ " + i, view.getView(i + 1) instanceof ElementPartView);
}
assertTrue(updateLayoutCalled);
}
@@ -739,10 +651,8 @@
private void createPartialViews() throws BadLocationException {
hasChildren = true;
changeDocument();
-
final int offset = (line.getStartOffset() + line.getEndOffset()) / 2;
doc.insertString(offset, "^^^^", null);
-
View[] parts = new View[2];
parts[0] = new ElementPartView(line, line.getStartOffset(), offset + 2);
parts[1] = new ElementPartView(line, offset + 2, line.getEndOffset());
@@ -755,14 +665,10 @@
*/
public void testRemoveUpdate01() throws BadLocationException {
changeDocument();
-
doc.remove(line.getStartOffset(), 9);
-
hasChildren = false;
assertEquals(0, view.getViewCount());
-
view.removeUpdate(docEvent, rect, viewFactory);
-
assertFalse(updateChildrenCalled);
assertFalse(forwardUpdateCalled);
assertFalse(forwardUpdateToViewCalled);
@@ -778,24 +684,17 @@
public void testRemoveUpdate02() throws BadLocationException {
hasChildren = true;
changeDocument();
-
doc.remove(line.getStartOffset(), 9);
-
updateChildrenReturn = false;
assertEquals(4, view.getViewCount());
-
view.removeUpdate(docEvent, rect, viewFactory);
-
assertTrue(updateChildrenCalled);
checkUpdatedChildren(4 - 1, 2);
-
assertTrue(forwardUpdateCalled);
-
assertTrue(forwardUpdateToViewCalled);
assertEquals(2, viewsForwardedTo.size());
assertSame(view.getView(0), viewsForwardedTo.get(0));
assertSame(view.getView(1), viewsForwardedTo.get(1));
-
assertTrue(updateLayoutCalled);
}
@@ -808,22 +707,16 @@
public void testRemoveUpdate03() throws BadLocationException {
hasChildren = true;
changeDocument();
-
doc.remove(line.getStartOffset(), 9);
-
updateChildrenReturn = true;
assertEquals(4, view.getViewCount());
-
view.removeUpdate(docEvent, rect, viewFactory);
-
assertTrue(updateChildrenCalled);
checkUpdatedChildren(4 - 1, 2);
-
assertTrue(forwardUpdateCalled);
assertTrue(forwardUpdateToViewCalled);
assertEquals(1, viewsForwardedTo.size());
assertSame(view.getView(0), viewsForwardedTo.get(0));
-
assertTrue(updateLayoutCalled);
}
@@ -836,22 +729,15 @@
public void testRemoveUpdate04() throws BadLocationException {
hasChildren = true;
changeDocument();
-
doc.remove(line.getStartOffset() + 1, 2);
-
updateChildrenReturn = true;
assertEquals(4, view.getViewCount());
-
view.removeUpdate(docEvent, rect, viewFactory);
-
assertFalse(updateChildrenCalled);
-
assertTrue(forwardUpdateCalled);
-
assertTrue(forwardUpdateToViewCalled);
assertEquals(1, viewsForwardedTo.size());
assertSame(view.getView(1), viewsForwardedTo.get(0));
-
assertTrue(updateLayoutCalled);
}
@@ -864,23 +750,16 @@
public void testRemoveUpdate05() throws BadLocationException {
hasChildren = true;
changeDocument();
-
doc.remove(line.getEndOffset() - 1, 1);
-
updateChildrenReturn = true;
assertEquals(4, view.getViewCount());
-
view.removeUpdate(docEvent, rect, viewFactory);
-
assertTrue(updateChildrenCalled);
checkUpdatedChildren(4 - 1, 2);
-
assertTrue(forwardUpdateCalled);
-
assertFalse(forwardUpdateToViewCalled);
-// assertEquals(1, viewsForwardedTo.size());
-// assertEquals(view.getView(1), viewsForwardedTo.get(0));
-
+ // assertEquals(1, viewsForwardedTo.size());
+ // assertEquals(view.getView(1), viewsForwardedTo.get(0));
assertTrue(updateLayoutCalled);
}
@@ -893,23 +772,16 @@
public void testRemoveUpdate06() throws BadLocationException {
hasChildren = true;
changeDocument();
-
doc.remove(line.getEndOffset() - 1, 1);
-
updateChildrenReturn = false;
assertEquals(4, view.getViewCount());
-
view.removeUpdate(docEvent, rect, viewFactory);
-
assertTrue(updateChildrenCalled);
checkUpdatedChildren(4 - 1, 2);
-
assertTrue(forwardUpdateCalled);
-
assertTrue(forwardUpdateToViewCalled);
assertEquals(1, viewsForwardedTo.size());
assertSame(view.getView(1), viewsForwardedTo.get(0));
-
assertTrue(updateLayoutCalled);
}
@@ -922,23 +794,16 @@
public void testRemoveUpdate07() throws BadLocationException {
hasChildren = true;
changeDocument();
-
doc.remove(0, line.getStartOffset());
-
updateChildrenReturn = false;
assertEquals(4, view.getViewCount());
-
view.removeUpdate(docEvent, rect, viewFactory);
-
assertTrue(updateChildrenCalled);
checkUpdatedChildren(4 - 1, 2);
-
assertTrue(forwardUpdateCalled);
-
assertTrue(forwardUpdateToViewCalled);
assertEquals(1, viewsForwardedTo.size());
assertSame(view.getView(0), viewsForwardedTo.get(0));
-
assertTrue(updateLayoutCalled);
}
@@ -951,17 +816,12 @@
public void testRemoveUpdate08() throws BadLocationException {
hasChildren = true;
changeDocument();
-
doc.remove(0, line.getStartOffset());
-
updateChildrenReturn = true;
assertEquals(4, view.getViewCount());
-
view.removeUpdate(docEvent, rect, viewFactory);
-
assertTrue(updateChildrenCalled);
checkUpdatedChildren(4 - 1, 2);
-
assertTrue(forwardUpdateCalled);
assertFalse(forwardUpdateToViewCalled);
assertTrue(updateLayoutCalled);
@@ -973,26 +833,25 @@
*/
public void testUpdateLayout01() throws BadLocationException {
final class Params {
- View child;
+ View child;
+
boolean height;
+
boolean width;
}
final Params params = new Params();
-
view = new DisAbstractedView(line) {
- public void preferenceChanged(final View child,
- final boolean width,
- final boolean height) {
- params.child = child;
- params.width = width;
+ @Override
+ public void preferenceChanged(final View child, final boolean width,
+ final boolean height) {
+ params.child = child;
+ params.width = width;
params.height = height;
}
};
-
// Insert string to fill docEvent
doc.insertString(line.getStartOffset() + 2, "one\ntwo\n", null);
view.updateLayout(docEvent.getChange(root), docEvent, rect);
-
assertNull(params.child);
assertTrue(params.width);
assertTrue(params.height);
@@ -1005,25 +864,23 @@
*/
public void testUpdateLayout02() throws BadLocationException {
final boolean[] called = new boolean[1];
-
view = new DisAbstractedView(line) {
- public void preferenceChanged(final View child,
- final boolean width,
- final boolean height) {
+ @Override
+ public void preferenceChanged(final View child, final boolean width,
+ final boolean height) {
called[0] = true;
}
};
-
// Insert string to fill docEvent
doc.insertString(line.getStartOffset() + 2, "one\ntwo\n", null);
view.updateLayout(null, docEvent, rect);
-
assertFalse(called[0]);
}
/**
* Sets up the test fixture for changes tests.
*/
+ @Override
protected void setUp() throws Exception {
super.setUp();
doc = new PlainDocument();
@@ -1036,11 +893,9 @@
return new ChildView(element);
}
};
-
// We create anonymous subclass of View where we override
// update methods to assert parameters passed
view = new ChangeView(root);
-
// Document listener to catch events on insert and remove
// (so that they are real but not synthetic). But for event of
// type <code>CHANGE</code> we create it ourselves.
@@ -1048,16 +903,16 @@
public void changedUpdate(final DocumentEvent event) {
docEvent = event;
}
+
public void insertUpdate(final DocumentEvent event) {
docEvent = event;
}
+
public void removeUpdate(final DocumentEvent event) {
docEvent = event;
}
};
-
doc.addDocumentListener(listener);
-
CompositeView_ModelViewTest.shape = rect;
}
@@ -1065,7 +920,7 @@
doc.insertString(doc.getLength(), "one\ntwo\n", null);
line = root.getElement(1);
view.removeAll();
- ((CompositeView)view).loadChildren(viewFactory);
+ ((CompositeView) view).loadChildren(viewFactory);
viewsCreatedElements.clear();
replaceViews = null;
}
@@ -1076,31 +931,24 @@
* @param count the new number of children
* @param length the number of child views removed
*/
- private void checkUpdatedChildren(final int count,
- final int length) {
+ private void checkUpdatedChildren(final int count, final int length) {
Element[] added = docEvent.getChange(root).getChildrenAdded();
- assertEquals("added and created are different",
- added.length, viewsCreatedElements.size());
+ assertEquals("added and created are different", added.length, viewsCreatedElements
+ .size());
for (int i = 0; i < added.length; i++) {
- assertSame("Elemets different @ " + i,
- added[i], viewsCreatedElements.get(i));
+ assertSame("Elemets different @ " + i, added[i], viewsCreatedElements.get(i));
}
- assertEquals("Child view count is unexpected",
- count, view.getViewCount());
- assertEquals("Replace index is unexpected",
- docEvent.getChange(root).getIndex(), replaceIndex);
- assertEquals("Replace length is unexpected",
- length, replaceLength);
- assertEquals("Replace views.length is unexpected",
- added.length, replaceViews.length);
-
+ assertEquals("Child view count is unexpected", count, view.getViewCount());
+ assertEquals("Replace index is unexpected", docEvent.getChange(root).getIndex(),
+ replaceIndex);
+ assertEquals("Replace length is unexpected", length, replaceLength);
+ assertEquals("Replace views.length is unexpected", added.length, replaceViews.length);
}
-
/*public void testUpdateChildren() {
- // tested in testInsertUpdate etc.
- }
+ // tested in testInsertUpdate etc.
+ }
- public void testForwardUpdate() {
- // tested in testInsertUpdate05
- }*/
+ public void testForwardUpdate() {
+ // tested in testInsertUpdate05
+ }*/
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_ChildrenTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_ChildrenTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_ChildrenTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_ChildrenTest.java Sun Nov 26 12:15:43 2006
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
/**
* @author Alexey A. Ivanov
* @version $Revision$
@@ -22,7 +21,6 @@
package javax.swing.text;
import javax.swing.text.ViewTest.DisAbstractedView;
-
import junit.framework.TestCase;
/**
@@ -31,15 +29,20 @@
*/
public class View_ChildrenTest extends TestCase {
private Document doc;
- private Element line;
+
+ private Element line;
+
private boolean replaceIsCalled = false;
- private int replaceLength;
- private int replaceOffset;
- private View[] replaceViews;
- private View view;
+ private int replaceLength;
+
+ private int replaceOffset;
+
+ private View[] replaceViews;
- private View viewToAdd;
+ private View view;
+
+ private View viewToAdd;
public void testAppend() {
view.append(viewToAdd);
@@ -57,8 +60,7 @@
assertEquals(0, replaceLength);
assertEquals(1, replaceViews.length);
assertSame(viewToAdd, replaceViews[0]);
-
- replaceIsCalled = false; // Reset the flag
+ replaceIsCalled = false; // Reset the flag
view.insert(2, viewToAdd);
assertTrue(replaceIsCalled);
assertEquals(2, replaceOffset);
@@ -73,8 +75,7 @@
assertEquals(0, replaceOffset);
assertEquals(1, replaceLength);
assertNull(replaceViews);
-
- replaceIsCalled = false; // Reset the flag
+ replaceIsCalled = false; // Reset the flag
view.remove(2);
assertTrue(replaceIsCalled);
assertEquals(2, replaceOffset);
@@ -101,21 +102,21 @@
assertSame(viewsToAdd, replaceViews);
}
+ @Override
protected void setUp() throws Exception {
super.setUp();
doc = new PlainDocument();
doc.insertString(0, "01234\nabcde", null);
line = doc.getDefaultRootElement().getElement(1);
-
view = new DisAbstractedView(line) {
+ @Override
public void replace(final int offset, final int length, final View[] views) {
replaceIsCalled = true;
- replaceOffset = offset;
- replaceLength = length;
- replaceViews = views;
+ replaceOffset = offset;
+ replaceLength = length;
+ replaceViews = views;
}
};
viewToAdd = ViewTest.getLine1View(doc);
}
-
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_ForwardUpdateRTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_ForwardUpdateRTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_ForwardUpdateRTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_ForwardUpdateRTest.java Sun Nov 26 12:15:43 2006
@@ -24,14 +24,12 @@
import java.awt.Shape;
import java.util.ArrayList;
import java.util.List;
-
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.DocumentEvent.ElementChange;
import javax.swing.text.CompositeView_ModelViewTest.ChildView;
import javax.swing.text.CompositeView_ModelViewTest.WithChildrenView;
import javax.swing.text.Position.Bias;
-
import junit.framework.TestCase;
public class View_ForwardUpdateRTest extends TestCase {
@@ -41,7 +39,6 @@
protected ParentView(Element element, String name) {
super(element);
this.name = name;
-
loadChildren(viewFactory);
}
@@ -49,6 +46,7 @@
return name;
}
+ @Override
public String toString() {
return getName() + " on " + getElement();
}
@@ -61,29 +59,26 @@
return getName() + getModelRange();
}
+ @Override
public int getViewIndex(int pos, Bias bias) {
int result = super.getViewIndex(pos, bias);
- logger.println("\t" + getInfo() + ".getViewIndex("
- + pos + ", " + bias + ") = " + result);
+ logger.println("\t" + getInfo() + ".getViewIndex(" + pos + ", " + bias + ") = "
+ + result);
return result;
}
- protected void forwardUpdate(ElementChange change,
- DocumentEvent event,
- Shape shape,
- ViewFactory factory) {
+ @Override
+ protected void forwardUpdate(ElementChange change, DocumentEvent event, Shape shape,
+ ViewFactory factory) {
logger.println(">>> " + getInfo() + ".forwardUpdate");
-
forwardUpdates.add(this);
super.forwardUpdate(change, event, shape, factory);
-
logger.println("<<< " + getInfo() + ".forwardUpdate");
}
- protected void forwardUpdateToView(View view,
- DocumentEvent event,
- Shape shape,
- ViewFactory factory) {
+ @Override
+ protected void forwardUpdateToView(View view, DocumentEvent event, Shape shape,
+ ViewFactory factory) {
viewsForwardedTo.add(view);
super.forwardUpdateToView(view, event, shape, factory);
}
@@ -106,6 +101,7 @@
super(element);
}
+ @Override
public String toString() {
return "content on " + getElement();
}
@@ -142,15 +138,18 @@
}
private static final Rectangle rect = new Rectangle(200, 100);
+
private static final Logger logger = new Logger(false);
private Document doc;
+
private Element root;
+
private DocumentEvent docEvent;
+
private ViewFactory viewFactory = new ViewFactory() {
public View create(Element element) {
final String name = element.getName();
-
if (AbstractDocument.SectionElementName.equals(name)) {
return new RootView(element);
} else if (AbstractDocument.ParagraphElementName.equals(name)) {
@@ -163,21 +162,19 @@
};
private View view;
- private List forwardUpdates = new ArrayList();
- private List viewsForwardedTo = new ArrayList();
+
+ private List<ParentView> forwardUpdates = new ArrayList<ParentView>();
+
+ private List<View> viewsForwardedTo = new ArrayList<View>();
public void testForwardUpdate01() throws BadLocationException {
doc = new PlainDocument();
-
doc.insertString(doc.getLength(), "line1", null);
doc.insertString(doc.getLength(), "\nline2", null);
-
root = doc.getDefaultRootElement();
view = viewFactory.create(root);
-
assertEquals(2, root.getElementCount());
assertEquals(2, view.getViewCount());
-
docEvent = new DocumentEvent() {
public int getOffset() {
return 0;
@@ -200,7 +197,6 @@
}
};
view.forwardUpdate(null, docEvent, rect, viewFactory);
-
assertEquals(2, viewsForwardedTo.size());
assertSame(view.getView(0), viewsForwardedTo.get(0));
assertSame(view.getView(1), viewsForwardedTo.get(1));
@@ -208,11 +204,9 @@
public void testForwardUpdate02() throws BadLocationException {
initStyledDocument();
-
final MutableAttributeSet fontSize = new SimpleAttributeSet();
StyleConstants.setFontSize(fontSize, 36);
-
- List expected = new ArrayList();
+ List<View> expected = new ArrayList<View>();
logger.print(view);
for (int i = 0; i < view.getViewCount(); i++) {
View child = view.getView(i);
@@ -224,13 +218,8 @@
}
}
logger.println();
-
- ((StyledDocument)doc).setCharacterAttributes(0, doc.getLength() + 1,
- fontSize, false);
-
- view.forwardUpdate(docEvent.getChange(root), docEvent,
- rect, viewFactory);
-
+ ((StyledDocument) doc).setCharacterAttributes(0, doc.getLength() + 1, fontSize, false);
+ view.forwardUpdate(docEvent.getChange(root), docEvent, rect, viewFactory);
logger.println();
assertEquals(expected.size(), viewsForwardedTo.size());
for (int i = 0; i < viewsForwardedTo.size(); i++) {
@@ -241,8 +230,7 @@
public void testForwardUpdate03() throws BadLocationException {
initStyledDocument();
-
- final List expected = new ArrayList();
+ final List<View> expected = new ArrayList<View>();
// We will use the view for the second paragraph
view = view.getView(1);
logger.print(view);
@@ -251,20 +239,13 @@
logger.print("\t" + view.getView(i));
}
logger.println();
-
final MutableAttributeSet fontSize = new SimpleAttributeSet();
StyleConstants.setFontSize(fontSize, 36);
- ((StyledDocument)doc).setCharacterAttributes(0, doc.getLength(),
- fontSize, false);
-
+ ((StyledDocument) doc).setCharacterAttributes(0, doc.getLength(), fontSize, false);
assertEquals(-1, view.getViewIndex(docEvent.getOffset(), Bias.Forward));
- assertEquals(view.getViewCount() - 1,
- view.getViewIndex(docEvent.getOffset()
- + docEvent.getLength(), Bias.Forward));
-
- view.forwardUpdate(docEvent.getChange(view.getElement()),
- docEvent, rect, viewFactory);
-
+ assertEquals(view.getViewCount() - 1, view.getViewIndex(docEvent.getOffset()
+ + docEvent.getLength(), Bias.Forward));
+ view.forwardUpdate(docEvent.getChange(view.getElement()), docEvent, rect, viewFactory);
logger.println();
assertEquals(expected.size(), viewsForwardedTo.size());
for (int i = 0; i < viewsForwardedTo.size(); i++) {
@@ -273,6 +254,7 @@
}
}
+ @Override
protected void setUp() throws Exception {
super.setUp();
CompositeView_ModelViewTest.shape = rect;
@@ -280,17 +262,13 @@
private void initStyledDocument() throws BadLocationException {
doc = new DefaultStyledDocument();
-
final MutableAttributeSet bold = new SimpleAttributeSet();
StyleConstants.setBold(bold, true);
-
doc.insertString(doc.getLength(), "plain", null);
doc.insertString(doc.getLength(), "bold", bold);
doc.insertString(doc.getLength(), "\nline2", null);
-
root = doc.getDefaultRootElement();
view = viewFactory.create(root);
-
doc.addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent e) {
fail("insertUpdate is not expected");
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_GetViewIndexTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_GetViewIndexTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_GetViewIndexTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_GetViewIndexTest.java Sun Nov 26 12:15:43 2006
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
/**
* @author Alexey A. Ivanov
* @version $Revision$
@@ -22,52 +21,41 @@
package javax.swing.text;
import java.awt.Rectangle;
-
import javax.swing.text.CompositeView_ModelViewTest.WithChildrenView;
-
import junit.framework.TestCase;
public class View_GetViewIndexTest extends TestCase {
- private PlainDocument doc; // Document used in tests
- private ViewFactory factory; // View factory used to create new views
- private Element root; // Default root element of the document
- private Rectangle shape; // View allocation (area to render into)
- private CompositeView view; // View object used in tests
+ private PlainDocument doc; // Document used in tests
+
+ private ViewFactory factory; // View factory used to create new views
+
+ private Element root; // Default root element of the document
- private static final int LINE_HEIGHT =
- CompositeView_ModelViewTest.LINE_HEIGHT;
+ private Rectangle shape; // View allocation (area to render into)
+
+ private CompositeView view; // View object used in tests
+
+ private static final int LINE_HEIGHT = CompositeView_ModelViewTest.LINE_HEIGHT;
/**
* Tests int View.getViewIndex(float, float, Shape)
*/
public void testGetViewIndexFloatFloatShape() {
-
assertEquals(-1, view.getViewIndex(0, 0, shape));
assertEquals(0, view.getViewIndex(shape.x, shape.y, shape));
- assertEquals(0, view.getViewIndex(shape.x + shape.width - 1,
- shape.y + LINE_HEIGHT - 1,
- shape));
- assertEquals(-1, view.getViewIndex(shape.x + shape.width,
- shape.y + LINE_HEIGHT, shape));
- assertEquals(-1, view.getViewIndex(shape.x - 1,
- shape.y + LINE_HEIGHT, shape));
-
- assertEquals(1, view.getViewIndex(shape.x,
- shape.y + LINE_HEIGHT,
- shape));
- assertEquals(1, view.getViewIndex(shape.x + shape.width - 1,
- shape.y + LINE_HEIGHT,
- shape));
-
- assertEquals(2, view.getViewIndex(shape.x,
- shape.y + 2 * LINE_HEIGHT,
- shape));
- assertEquals(2, view.getViewIndex(shape.x + shape.width - 1,
- shape.y + 2 * LINE_HEIGHT,
- shape));
-
+ assertEquals(0, view.getViewIndex(shape.x + shape.width - 1, shape.y + LINE_HEIGHT - 1,
+ shape));
+ assertEquals(-1, view.getViewIndex(shape.x + shape.width, shape.y + LINE_HEIGHT, shape));
+ assertEquals(-1, view.getViewIndex(shape.x - 1, shape.y + LINE_HEIGHT, shape));
+ assertEquals(1, view.getViewIndex(shape.x, shape.y + LINE_HEIGHT, shape));
+ assertEquals(1, view.getViewIndex(shape.x + shape.width - 1, shape.y + LINE_HEIGHT,
+ shape));
+ assertEquals(2, view.getViewIndex(shape.x, shape.y + 2 * LINE_HEIGHT, shape));
+ assertEquals(2, view.getViewIndex(shape.x + shape.width - 1, shape.y + 2 * LINE_HEIGHT,
+ shape));
}
+ @Override
protected void setUp() throws Exception {
super.setUp();
doc = new PlainDocument();
@@ -78,7 +66,7 @@
view = new WithChildrenView(root);
factory = new ViewTestHelpers.ChildrenFactory();
view.loadChildren(factory);
- shape = new Rectangle(100, 200, 190, 560);
+ shape = new Rectangle(100, 200, 190, 560);
CompositeView_ModelViewTest.shape = shape;
}
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_NextVisualPositionFromTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_NextVisualPositionFromTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_NextVisualPositionFromTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/View_NextVisualPositionFromTest.java Sun Nov 26 12:15:43 2006
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
/**
* @author Alexey A. Ivanov
* @version $Revision$
@@ -23,7 +22,6 @@
import java.awt.Point;
import java.awt.Shape;
-
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
@@ -40,175 +38,156 @@
* the one has expected value and don't change.
*/
private static class MagicCaret extends DefaultCaret {
- public Point magicPoint;
+ private static final long serialVersionUID = 1L;
+
+ public Point magicPoint;
+ @Override
public Point getMagicCaretPosition() {
return magicPoint;
}
}
private JTextArea area;
+
private MagicCaret caret;
+
private Document doc;
+
private JFrame frame;
private Shape shape;
- private View view;
- private Bias[] bias;
- public void testGetNextVisualPositionFromEast()
- throws BadLocationException {
+ private View view;
- assertEquals(1,
- view.getNextVisualPositionFrom(0, Bias.Forward, shape,
- SwingConstants.EAST, bias));
- assertSame(Bias.Forward, bias[0]); bias[0] = null;
- assertEquals(1,
- view.getNextVisualPositionFrom(0, Bias.Backward, shape,
- SwingConstants.EAST, bias));
- assertSame(Bias.Forward, bias[0]); bias[0] = null;
-
- assertEquals(2,
- view.getNextVisualPositionFrom(1, Bias.Forward, shape,
- SwingConstants.EAST, bias));
- assertSame(Bias.Forward, bias[0]); bias[0] = null;
- assertEquals(2,
- view.getNextVisualPositionFrom(1, Bias.Backward, shape,
- SwingConstants.EAST, bias));
- assertSame(Bias.Forward, bias[0]); bias[0] = null;
+ private Bias[] bias;
+ public void testGetNextVisualPositionFromEast() throws BadLocationException {
+ assertEquals(1, view.getNextVisualPositionFrom(0, Bias.Forward, shape,
+ SwingConstants.EAST, bias));
+ assertSame(Bias.Forward, bias[0]);
+ bias[0] = null;
+ assertEquals(1, view.getNextVisualPositionFrom(0, Bias.Backward, shape,
+ SwingConstants.EAST, bias));
+ assertSame(Bias.Forward, bias[0]);
+ bias[0] = null;
+ assertEquals(2, view.getNextVisualPositionFrom(1, Bias.Forward, shape,
+ SwingConstants.EAST, bias));
+ assertSame(Bias.Forward, bias[0]);
+ bias[0] = null;
+ assertEquals(2, view.getNextVisualPositionFrom(1, Bias.Backward, shape,
+ SwingConstants.EAST, bias));
+ assertSame(Bias.Forward, bias[0]);
+ bias[0] = null;
// End of document: try to go further
- assertEquals(doc.getLength(),
- view.getNextVisualPositionFrom(doc.getLength(),
- Bias.Forward,
- shape,
- SwingConstants.EAST,
- bias));
- }
-
- public void testGetNextVisualPositionFromWest()
- throws BadLocationException {
-
- assertEquals(1, view.getNextVisualPositionFrom(2, Bias.Forward,
- shape, SwingConstants.WEST, bias));
- assertSame(Bias.Forward, bias[0]); bias[0] = null;
- assertEquals(1, view.getNextVisualPositionFrom(2, Bias.Backward,
- shape, SwingConstants.WEST, bias));
- assertSame(Bias.Forward, bias[0]); bias[0] = null;
+ assertEquals(doc.getLength(), view.getNextVisualPositionFrom(doc.getLength(),
+ Bias.Forward, shape, SwingConstants.EAST, bias));
}
- public void testGetNextVisualPositionFromNorth()
- throws BadLocationException {
+ public void testGetNextVisualPositionFromWest() throws BadLocationException {
+ assertEquals(1, view.getNextVisualPositionFrom(2, Bias.Forward, shape,
+ SwingConstants.WEST, bias));
+ assertSame(Bias.Forward, bias[0]);
+ bias[0] = null;
+ assertEquals(1, view.getNextVisualPositionFrom(2, Bias.Backward, shape,
+ SwingConstants.WEST, bias));
+ assertSame(Bias.Forward, bias[0]);
+ bias[0] = null;
+ }
+ public void testGetNextVisualPositionFromNorth() throws BadLocationException {
Shape posRect = view.modelToView(doc.getLength(), shape, Bias.Forward);
caret.magicPoint = posRect.getBounds().getLocation();
-
assertNotNull(caret.getMagicCaretPosition());
- assertEquals(17, view.getNextVisualPositionFrom(doc.getLength(),
- Bias.Forward, shape, SwingConstants.NORTH, bias));
- assertEquals(10, view.getNextVisualPositionFrom(17,
- Bias.Forward, shape, SwingConstants.NORTH, bias));
- assertEquals(6, view.getNextVisualPositionFrom(10,
- Bias.Forward, shape, SwingConstants.NORTH, bias));
+ assertEquals(17, view.getNextVisualPositionFrom(doc.getLength(), Bias.Forward, shape,
+ SwingConstants.NORTH, bias));
+ assertEquals(10, view.getNextVisualPositionFrom(17, Bias.Forward, shape,
+ SwingConstants.NORTH, bias));
+ assertEquals(6, view.getNextVisualPositionFrom(10, Bias.Forward, shape,
+ SwingConstants.NORTH, bias));
// We reached the first line
- assertEquals(-1, view.getNextVisualPositionFrom(6,
- Bias.Forward, shape, SwingConstants.NORTH, bias));
-
+ assertEquals(-1, view.getNextVisualPositionFrom(6, Bias.Forward, shape,
+ SwingConstants.NORTH, bias));
// No magic position
caret.magicPoint = null;
assertNull(area.getCaret().getMagicCaretPosition());
- assertEquals(2, view.getNextVisualPositionFrom(10,
- Bias.Forward, shape, SwingConstants.NORTH, bias));
+ assertEquals(2, view.getNextVisualPositionFrom(10, Bias.Forward, shape,
+ SwingConstants.NORTH, bias));
}
- public void testGetNextVisualPositionFromSouth()
- throws BadLocationException {
-
+ public void testGetNextVisualPositionFromSouth() throws BadLocationException {
Shape posRect = view.modelToView(doc.getLength(), shape, Bias.Forward);
caret.magicPoint = posRect.getBounds().getLocation();
-
assertNotNull(area.getCaret().getMagicCaretPosition());
- assertEquals(10, view.getNextVisualPositionFrom(6, Bias.Forward,
- shape, SwingConstants.SOUTH, bias));
- assertEquals(17, view.getNextVisualPositionFrom(10, Bias.Forward,
- shape, SwingConstants.SOUTH, bias));
+ assertEquals(10, view.getNextVisualPositionFrom(6, Bias.Forward, shape,
+ SwingConstants.SOUTH, bias));
+ assertEquals(17, view.getNextVisualPositionFrom(10, Bias.Forward, shape,
+ SwingConstants.SOUTH, bias));
// 27 == doc.getLength()
- assertEquals(27, view.getNextVisualPositionFrom(17, Bias.Forward,
- shape, SwingConstants.SOUTH, bias));
+ assertEquals(27, view.getNextVisualPositionFrom(17, Bias.Forward, shape,
+ SwingConstants.SOUTH, bias));
// We reached the last line and the last character in document
- assertEquals(27, view.getNextVisualPositionFrom(27, Bias.Forward,
- shape, SwingConstants.SOUTH, bias));
-
+ assertEquals(27, view.getNextVisualPositionFrom(27, Bias.Forward, shape,
+ SwingConstants.SOUTH, bias));
// No magic position
caret.magicPoint = null;
assertNull(area.getCaret().getMagicCaretPosition());
- assertEquals(2, view.getNextVisualPositionFrom(10,
- Bias.Forward, shape, SwingConstants.NORTH, bias));
- assertEquals(13, view.getNextVisualPositionFrom(10,
- Bias.Forward, shape, SwingConstants.SOUTH, bias));
-
+ assertEquals(2, view.getNextVisualPositionFrom(10, Bias.Forward, shape,
+ SwingConstants.NORTH, bias));
+ assertEquals(13, view.getNextVisualPositionFrom(10, Bias.Forward, shape,
+ SwingConstants.SOUTH, bias));
}
- public void testGetNextVisualPositionFromInvalid()
- throws BadLocationException {
-
+ public void testGetNextVisualPositionFromInvalid() throws BadLocationException {
// BadLocation left
try {
int p = view.getNextVisualPositionFrom(-2, Bias.Forward, shape,
- SwingConstants.WEST, bias);
-
+ SwingConstants.WEST, bias);
if (!isHarmony()) {
assertEquals(0, p);
-
// If we go to WEST from -1, we get to document end
p = view.getNextVisualPositionFrom(-1, Bias.Forward, shape,
- SwingConstants.WEST, bias);
+ SwingConstants.WEST, bias);
assertEquals(doc.getLength(), p);
} else {
fail("BadLocationException is expected");
}
- } catch (BadLocationException e) { }
-
+ } catch (BadLocationException e) {
+ }
// BadLocation right
try {
- int p = view.getNextVisualPositionFrom(doc.getLength() + 1,
- Bias.Forward, shape,
- SwingConstants.EAST, bias);
-
+ int p = view.getNextVisualPositionFrom(doc.getLength() + 1, Bias.Forward, shape,
+ SwingConstants.EAST, bias);
if (!isHarmony()) {
assertEquals(doc.getLength(), p);
} else {
fail("BadLocationException is expected");
}
- } catch (BadLocationException e) { }
-
+ } catch (BadLocationException e) {
+ }
// IllegalArgument for direction
try {
- view.getNextVisualPositionFrom(0, Bias.Forward, shape,
- SwingConstants.NORTH_EAST, bias);
-
+ view.getNextVisualPositionFrom(0, Bias.Forward, shape, SwingConstants.NORTH_EAST,
+ bias);
fail("IllegalArgumentException is expected");
- } catch (IllegalArgumentException e) { }
-
+ } catch (IllegalArgumentException e) {
+ }
// ArrayIndexOutOfBounds for bias
try {
- view.getNextVisualPositionFrom(0, Bias.Forward, shape,
- SwingConstants.EAST,
- new Bias[0]);
-
+ view.getNextVisualPositionFrom(0, Bias.Forward, shape, SwingConstants.EAST,
+ new Bias[0]);
fail("ArrayIndexOutOfBoundsException is expected");
- } catch (ArrayIndexOutOfBoundsException e) { }
-
+ } catch (ArrayIndexOutOfBoundsException e) {
+ }
// NullPointerException for bias
try {
- view.getNextVisualPositionFrom(0, Bias.Forward, shape,
- SwingConstants.EAST,
- null);
-
+ view.getNextVisualPositionFrom(0, Bias.Forward, shape, SwingConstants.EAST, null);
fail("NullPointerException is expected");
- } catch (NullPointerException e) { }
+ } catch (NullPointerException e) {
+ }
}
+ @Override
protected void setUp() throws Exception {
super.setUp();
frame = new JFrame("Next Position Test");
@@ -216,25 +195,24 @@
area.setCaret(caret = new MagicCaret());
frame.getContentPane().add(area);
area.setText("1: 0123\n" +
- //01234567
- "2:\n" +
- //890
- "3: 012345\n" +
- //1234567890
- "4: 012");
- //123456
+ //01234567
+ "2:\n" +
+ //890
+ "3: 012345\n" +
+ //1234567890
+ "4: 012");
+ //123456
doc = area.getDocument();
frame.setSize(100, 150);
frame.pack();
-
- view = area.getUI().getRootView(area).getView(0);
+ view = area.getUI().getRootView(area).getView(0);
shape = area.getBounds();
bias = new Bias[1];
-
assertNull(bias[0]);
assertEquals(27, doc.getLength());
}
+ @Override
protected void tearDown() throws Exception {
super.tearDown();
frame.dispose();
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/WrappedPlainViewRTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/WrappedPlainViewRTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/WrappedPlainViewRTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/WrappedPlainViewRTest.java Sun Nov 26 12:15:43 2006
@@ -22,44 +22,47 @@
import java.awt.FontMetrics;
import java.awt.Rectangle;
-
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.SwingTestCase;
import javax.swing.text.Position.Bias;
public class WrappedPlainViewRTest extends SwingTestCase {
- private Document doc;
- private Element root;
+ private Document doc;
+
+ private Element root;
+
private WrappedPlainView view;
- private JTextArea textArea;
- private JFrame frame;
- private Rectangle shape;
- private int width = 145;
+ private JTextArea textArea;
+
+ private JFrame frame;
+
+ private Rectangle shape;
+
+ private int width = 145;
+
private int height = 500;
+ @Override
protected void setUp() throws Exception {
super.setUp();
frame = new JFrame("WrappedPlainView Test");
doc = new PlainDocument();
- doc.insertString(0,
- "one, two, three, four, five\n" +
- "eins, zwei, drei, vier, funf\n" +
- "uno, dos, tres, cuatro, \tcinco", null);
+ doc.insertString(0, "one, two, three, four, five\n" + "eins, zwei, drei, vier, funf\n"
+ + "uno, dos, tres, cuatro, \tcinco", null);
root = doc.getDefaultRootElement();
-
textArea = new JTextArea(doc);
textArea.setLineWrap(true);
frame.getContentPane().add(textArea);
textArea.setSize(width, height);
-
View rootView = textArea.getUI().getRootView(textArea);
- view = (WrappedPlainView)rootView.getView(0);
+ view = (WrappedPlainView) rootView.getView(0);
shape = new Rectangle(width, height);
view.setSize(shape.width, shape.height);
}
+ @Override
protected void tearDown() throws Exception {
super.tearDown();
frame.dispose();
@@ -72,9 +75,8 @@
final Bias[] bias = new Bias[1];
width = getTextWidth(root.getElementCount() - 1) * 3 / 4;
view.setSize(width, height);
- assertEquals(view.getEndOffset() - 1,
- view.viewToModel(width / 2, height - 10,
- new Rectangle(width, height), bias));
+ assertEquals(view.getEndOffset() - 1, view.viewToModel(width / 2, height - 10,
+ new Rectangle(width, height), bias));
}
/**
@@ -86,16 +88,12 @@
textArea.setSize(500, height);
shape = new Rectangle(500, height);
view.setSize(shape.width, shape.height);
-
- assertTrue("The first line must be not wrapped",
- 500 > getTextWidth(0));
+ assertTrue("The first line must be not wrapped", 500 > getTextWidth(0));
FontMetrics metrics = getFontMetrics();
Element line = root.getElement(0);
String text = doc.getText(line.getStartOffset(), 2);
- assertEquals(2,
- view.viewToModel(metrics.stringWidth(text),
- metrics.getHeight() / 2,
- shape, bias));
+ assertEquals(2, view.viewToModel(metrics.stringWidth(text), metrics.getHeight() / 2,
+ shape, bias));
}
/**
@@ -105,7 +103,6 @@
textArea.setText("line1\n\n\n\n");
assertEquals(5, view.getViewCount());
assertSame(doc, textArea.getDocument());
-
doc.insertString(7, "\n", null);
}
@@ -116,15 +113,13 @@
textArea.setText("line1\n\n\n\n");
assertEquals(5, view.getViewCount());
assertSame(doc, textArea.getDocument());
-
doc.remove(6, 1);
}
private int getTextWidth(final int lineNo) throws BadLocationException {
Element line = root.getElement(lineNo);
- String text = doc.getText(line.getStartOffset(),
- line.getEndOffset() - 1
- - line.getStartOffset());
+ String text = doc.getText(line.getStartOffset(), line.getEndOffset() - 1
+ - line.getStartOffset());
FontMetrics metrics = getFontMetrics();
return metrics.stringWidth(text);
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/WrappedPlainViewTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/WrappedPlainViewTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/WrappedPlainViewTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/WrappedPlainViewTest.java Sun Nov 26 12:15:43 2006
@@ -23,7 +23,6 @@
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Rectangle;
-
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.SwingTestCase;
@@ -33,39 +32,43 @@
*
*/
public class WrappedPlainViewTest extends SwingTestCase {
+ private Document doc;
- private Document doc;
private WrappedPlainView view;
- private JTextArea textArea;
- private JFrame frame;
- private Rectangle shape;
+
+ private JTextArea textArea;
+
+ private JFrame frame;
+
+ private Rectangle shape;
private static final int X_AXIS = View.X_AXIS;
+
private static final int Y_AXIS = View.Y_AXIS;
- private int width = 145;
+
+ private int width = 145;
+
private int height = 100;
+ @Override
protected void setUp() throws Exception {
super.setUp();
frame = new JFrame("WrappedPlainView Test");
doc = new PlainDocument();
- doc.insertString(0,
- "one, two, three, four, five\n" +
- "eins, zwei, drei, vier, funf\n" +
- "uno, dos, tres, cuatro, cinco", null);
-
+ doc.insertString(0, "one, two, three, four, five\n" + "eins, zwei, drei, vier, funf\n"
+ + "uno, dos, tres, cuatro, cinco", null);
textArea = new JTextArea(doc);
textArea.setLineWrap(true);
frame.getContentPane().add(textArea);
frame.setSize(width, height);
frame.pack();
-
View rootView = textArea.getUI().getRootView(textArea);
- view = (WrappedPlainView)rootView.getView(0);
+ view = (WrappedPlainView) rootView.getView(0);
shape = textArea.getVisibleRect();
view.setSize(shape.width, shape.height);
}
+ @Override
protected void tearDown() throws Exception {
super.tearDown();
frame.dispose();
@@ -75,27 +78,26 @@
int sum = 0;
for (int i = 0; i < view.getViewCount(); i++) {
View child = view.getView(i);
- sum += (int)child.getPreferredSpan(axis);
+ sum += (int) child.getPreferredSpan(axis);
}
return sum;
}
public void testGetMaximumSpan() {
- assertEquals(Integer.MAX_VALUE, (int)view.getMaximumSpan(X_AXIS));
- assertEquals(getSum(Y_AXIS), (int)view.getMaximumSpan(Y_AXIS));
+ assertEquals(Integer.MAX_VALUE, (int) view.getMaximumSpan(X_AXIS));
+ assertEquals(getSum(Y_AXIS), (int) view.getMaximumSpan(Y_AXIS));
}
public void testGetMinimumSpan() {
- assertEquals(view.getWidth(), (int)view.getMinimumSpan(X_AXIS));
- assertEquals(getSum(Y_AXIS), (int)view.getMinimumSpan(Y_AXIS));
+ assertEquals(view.getWidth(), (int) view.getMinimumSpan(X_AXIS));
+ assertEquals(getSum(Y_AXIS), (int) view.getMinimumSpan(Y_AXIS));
}
public void testGetPreferredSpan() {
- assertEquals(view.getWidth(), (int)view.getPreferredSpan(X_AXIS));
- assertEquals(getSum(Y_AXIS), (int)view.getPreferredSpan(Y_AXIS));
+ assertEquals(view.getWidth(), (int) view.getPreferredSpan(X_AXIS));
+ assertEquals(getSum(Y_AXIS), (int) view.getPreferredSpan(Y_AXIS));
assertEquals(shape.width, view.getWidth());
- assertEquals(shape.width,
- (int)view.getView(0).getPreferredSpan(X_AXIS));
+ assertEquals(shape.width, (int) view.getView(0).getPreferredSpan(X_AXIS));
}
public void testDrawSelectedText() throws BadLocationException {
@@ -103,32 +105,25 @@
Graphics g = textArea.getGraphics();
g.setFont(textArea.getFont());
FontMetrics m = g.getFontMetrics();
-
assertEquals(m.charWidth('l'), view.drawSelectedText(g, 0, 0, 0, 1));
- assertEquals(5 + m.charWidth('l'),
- view.drawSelectedText(g, 5, 0, 0, 1));
- assertEquals(m.stringWidth("line1"),
- view.drawSelectedText(g, 0, 0, 0, 5));
- assertEquals(m.stringWidth("line1\nli"),
- view.drawSelectedText(g, 0, 0, 0, 8));
-
+ assertEquals(5 + m.charWidth('l'), view.drawSelectedText(g, 5, 0, 0, 1));
+ assertEquals(m.stringWidth("line1"), view.drawSelectedText(g, 0, 0, 0, 5));
+ assertEquals(m.stringWidth("line1\nli"), view.drawSelectedText(g, 0, 0, 0, 8));
try {
view.drawSelectedText(g, 0, 0, -1, 1);
-
fail("BadLocationException expected");
- } catch (BadLocationException e) { }
-
+ } catch (BadLocationException e) {
+ }
try {
view.drawUnselectedText(g, 0, 0, 13, 13);
-
fail("BadLocationException expected");
- } catch (BadLocationException e) { }
-
+ } catch (BadLocationException e) {
+ }
try {
view.drawSelectedText(g, 0, 0, 10, 2);
-
fail("BadLocationException expected");
- } catch (BadLocationException e) { }
+ } catch (BadLocationException e) {
+ }
}
public void testDrawUnselectedText() throws BadLocationException {
@@ -136,36 +131,28 @@
Graphics g = textArea.getGraphics();
g.setFont(textArea.getFont());
FontMetrics m = g.getFontMetrics();
-
assertEquals(m.charWidth('l'), view.drawUnselectedText(g, 0, 0, 0, 1));
- assertEquals(5 + m.charWidth('l'),
- view.drawUnselectedText(g, 5, 0, 0, 1));
- assertEquals(m.stringWidth("line1"),
- view.drawUnselectedText(g, 0, 0, 0, 5));
- assertEquals(m.stringWidth("line1\nli"),
- view.drawUnselectedText(g, 0, 0, 0, 8));
-
+ assertEquals(5 + m.charWidth('l'), view.drawUnselectedText(g, 5, 0, 0, 1));
+ assertEquals(m.stringWidth("line1"), view.drawUnselectedText(g, 0, 0, 0, 5));
+ assertEquals(m.stringWidth("line1\nli"), view.drawUnselectedText(g, 0, 0, 0, 8));
try {
view.drawUnselectedText(g, 0, 0, -1, 1);
-
fail("BadLocationException expected");
- } catch (BadLocationException e) { }
-
+ } catch (BadLocationException e) {
+ }
try {
view.drawUnselectedText(g, 0, 0, 13, 13);
-
fail("BadLocationException expected");
- } catch (BadLocationException e) { }
-
+ } catch (BadLocationException e) {
+ }
try {
view.drawUnselectedText(g, 0, 0, 10, 2);
-
fail("BadLocationException expected");
- } catch (BadLocationException e) { }
+ } catch (BadLocationException e) {
+ }
}
-
/*
- public void testPaint() {
- }
- */
+ public void testPaint() {
+ }
+ */
}