001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package javax.swing.text;
018:
019: import static javax.swing.text.VisualPositionHelper.assertNextPosition;
020: import junit.framework.TestCase;
021:
022: /**
023: * Tests <code>View.getNextVisualPositionFrom</code> method on
024: * <code>PlainView</code> which doesn't overrides this method.
025: *
026: * <p>The view is constructed on the <em>root</em> element of
027: * document (<code>PlainDocument</code>).
028: *
029: * <p>Only <code>View.EAST</code> (right) and <code>View.WEST</code> (left)
030: * directions are tested here.
031: */
032: public class View_VisualPositionTest extends TestCase {
033: private Document doc;
034: private View view;
035: private Element root;
036: private int length;
037:
038: @Override
039: protected void setUp() throws Exception {
040: super .setUp();
041: doc = new PlainDocument();
042: doc.insertString(0, "line 1\nthe second line is rather long\n"
043: + "the third line", null);
044: length = doc.getLength();
045:
046: root = doc.getDefaultRootElement();
047: view = new PlainView(root);
048: }
049:
050: public void testGetNextVisualPositionFrom_Right()
051: throws BadLocationException {
052: for (int i = 0; i < length; i++) {
053: assertNextPosition(i + 1, i, View.EAST, view, null);
054: }
055: ;
056: }
057:
058: public void testGetNextVisualPositionFrom_RightAtBeginning()
059: throws BadLocationException {
060:
061: assertNextPosition(0, -1, View.EAST, view, null);
062:
063: assertNextPosition(-1, -2, View.EAST, view, null);
064: assertNextPosition(-2, -3, View.EAST, view, null);
065: assertNextPosition(-3, -4, View.EAST, view, null);
066:
067: assertNextPosition(-9, -10, View.EAST, view, null);
068: }
069:
070: public void testGetNextVisualPositionFrom_RightAtEnd()
071: throws BadLocationException {
072:
073: assertNextPosition(length, length - 1, View.EAST, view, null);
074: assertNextPosition(length, length, View.EAST, view, null);
075:
076: assertNextPosition(length, length + 1, View.EAST, view, null);
077: assertNextPosition(length, length + 2, View.EAST, view, null);
078: assertNextPosition(length, length + 3, View.EAST, view, null);
079:
080: assertNextPosition(length, length + 10, View.EAST, view, null);
081: }
082:
083: public void testGetNextVisualPositionFrom_Left()
084: throws BadLocationException {
085: for (int i = 1; i <= length; i++) {
086: assertNextPosition(i - 1, i, View.WEST, view, null);
087: }
088: ;
089: }
090:
091: public void testGetNextVisualPositionFrom_LeftAtBeginning()
092: throws BadLocationException {
093:
094: assertNextPosition(0, 1, View.WEST, view, null);
095: assertNextPosition(0, 0, View.WEST, view, null);
096:
097: assertNextPosition(length, -1, View.WEST, view, null);
098:
099: assertNextPosition(0, -2, View.WEST, view, null);
100: assertNextPosition(0, -3, View.WEST, view, null);
101:
102: assertNextPosition(0, -10, View.WEST, view, null);
103: }
104:
105: public void testGetNextVisualPositionFrom_LeftAtEnd()
106: throws BadLocationException {
107:
108: assertNextPosition(length - 1, length, View.WEST, view, null);
109: assertNextPosition(length, length + 1, View.WEST, view, null);
110:
111: assertNextPosition(length + 1, length + 2, View.WEST, view,
112: null);
113: assertNextPosition(length + 2, length + 3, View.WEST, view,
114: null);
115:
116: assertNextPosition(length + 9, length + 10, View.WEST, view,
117: null);
118: }
119: }
|