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: /**
018: * @author Roman I. Chernyatchik
019: * @version $Revision$
020: */package javax.swing.text;
021:
022: import java.util.Vector;
023: import javax.swing.BasicSwingTestCase;
024: import javax.swing.undo.UndoableEdit;
025:
026: public class StringContentTest_CommonTest extends GapContentTest {
027: @Override
028: protected void setUp() throws Exception {
029: super .setUp();
030: obj = content = new StringContent(30);
031: obj.insertString(0, "This is a test string.");
032: }
033:
034: @Override
035: public void testGetCharsImpliedCharPartial()
036: throws BadLocationException {
037: obj = content = new StringContent();
038: assertEquals(1, content.length());
039: text.setPartialReturn(false);
040: content.getChars(0, 1, text);
041: assertEquals("\n", text.toString());
042: text.setPartialReturn(true);
043: content.getChars(0, 1, text);
044: assertEquals("\n", text.toString());
045: }
046:
047: @Override
048: public void testGetPositionsInRangeVector()
049: throws BadLocationException {
050: Vector<Object> v = new Vector<Object>();
051: v.add(new Object());
052: v.add(new Object());
053: content.createPosition(0);
054: content.createPosition(1);
055: content.createPosition(2);
056: ((StringContent) content).getPositionsInRange(v, 0, 3);
057: if (BasicSwingTestCase.isHarmony()) {
058: // Position at offset 0 WILL NOT be included
059: assertEquals(4, v.size());
060: } else {
061: // Position at offset 0 WILL be included
062: assertEquals(5, v.size());
063: }
064: }
065:
066: /**
067: * Tests that the position at offset of offset + len is included in
068: * the returned vector.
069: */
070: @Override
071: public void testGetPositionsInRangeEnd()
072: throws BadLocationException {
073: content.createPosition(10);
074: Vector<?> v = ((StringContent) content).getPositionsInRange(
075: null, 0, 10);
076: assertEquals(1, v.size());
077: }
078:
079: @Override
080: public void testGetPositionsInRange() throws BadLocationException {
081: Vector<Position> pos = new Vector<Position>();
082: for (int i = 0; i < content.length(); i += 2) {
083: Position p = content.createPosition(i);
084: if (i >= 3 && i <= 3 + 9) {
085: pos.add(p);
086: }
087: }
088: Vector<?> v = ((StringContent) content).getPositionsInRange(
089: null, 3, 9);
090: assertEquals(pos.size(), v.size());
091: int[] offsets = new int[v.size()];
092: for (int i = 0; i < pos.size(); i++) {
093: offsets[i] = pos.get(i).getOffset();
094: }
095: UndoableEdit ue = content.remove(0, 9);
096: ue.undo();
097: for (int i = 0; i < pos.size(); i++) {
098: assertEquals(offsets[i], pos.get(i).getOffset());
099: }
100: }
101:
102: @Override
103: public void testGetCharsNegativeLength() {
104: // Is Already tested in StringContentTest
105: }
106:
107: @Override
108: public void testGetCharsAfterGapNoImplied()
109: throws BadLocationException {
110: // N/A
111: }
112:
113: @Override
114: public void testGetCharsAfterGap() throws BadLocationException {
115: // N/A
116: }
117:
118: @Override
119: public void testGetCharsBeforeGap() throws BadLocationException {
120: // N/A
121: }
122:
123: @Override
124: public void testGetCharsFullLength() throws BadLocationException {
125: // N/A
126: }
127:
128: @Override
129: public void testGetCharsFullActualLength()
130: throws BadLocationException {
131: // N/A
132: }
133:
134: @Override
135: public void testGetCharsImpliedChar() throws BadLocationException {
136: // N/A
137: }
138:
139: @Override
140: public void testGetCharsPartial() throws BadLocationException {
141: // N/A
142: }
143:
144: @Override
145: public void testGetCharsWithGap() throws BadLocationException {
146: // N/A
147: }
148:
149: @Override
150: public void testGetStringNegativeLength() {
151: // Is Already tested in StringContentTest
152: }
153: }
|