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 [22/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/DefaultEditorKitTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultEditorKitTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultEditorKitTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultEditorKitTest.java Sun Nov 26 12:15:43 2006
@@ -31,15 +31,12 @@
import java.io.OutputStreamWriter;
import java.io.StringReader;
import java.io.StringWriter;
-
import javax.swing.Action;
public class DefaultEditorKitTest extends EditorKitTest {
-
@Override
protected void setUp() throws Exception {
super.setUp();
-
kit = new DefaultEditorKit();
}
@@ -52,8 +49,7 @@
assertTrue("document's type", doc instanceof PlainDocument);
assertEquals("document's length", 0, doc.getLength());
assertEquals("number of root elements", 2, doc.getRootElements().length);
- assertNull("document's title", doc
- .getProperty(Document.TitleProperty));
+ assertNull("document's title", doc.getProperty(Document.TitleProperty));
assertNull("document's StreamDescription", doc
.getProperty(Document.StreamDescriptionProperty));
}
@@ -61,30 +57,28 @@
public void testGetActions() {
Action[] actions1 = kit.getActions();
Action[] actions2 = kit.getActions();
- String templateStr = "insert-content, delete-previous, delete-next, " +
- "set-read-only, set-writable, cut-to-clipboard, copy-to-clipboard, " +
- "paste-from-clipboard, page-up, page-down, selection-page-up, " +
- "selection-page-down, selection-page-left, selection-page-right, " +
- "insert-break, beep, caret-forward, caret-backward, selection-forward, " +
- "selection-backward, caret-up, caret-down, selection-up, selection-down, " +
- "caret-begin-word, caret-end-word, selection-begin-word, selection-end-word, " +
- "caret-previous-word, caret-next-word, selection-previous-word, selection-next-word, " +
- "caret-begin-line, caret-end-line, selection-begin-line, selection-end-line, " +
- "caret-begin-paragraph, caret-end-paragraph, selection-begin-paragraph, " +
- "selection-end-paragraph, caret-begin, caret-end, selection-begin, selection-end, " +
- "default-typed, insert-tab, select-word, select-line, select-paragraph, select-all, " +
- "unselect, toggle-componentOrientation, dump-model, ";
-
+ String templateStr = "insert-content, delete-previous, delete-next, "
+ + "set-read-only, set-writable, cut-to-clipboard, copy-to-clipboard, "
+ + "paste-from-clipboard, page-up, page-down, selection-page-up, "
+ + "selection-page-down, selection-page-left, selection-page-right, "
+ + "insert-break, beep, caret-forward, caret-backward, selection-forward, "
+ + "selection-backward, caret-up, caret-down, selection-up, selection-down, "
+ + "caret-begin-word, caret-end-word, selection-begin-word, selection-end-word, "
+ + "caret-previous-word, caret-next-word, selection-previous-word, selection-next-word, "
+ + "caret-begin-line, caret-end-line, selection-begin-line, selection-end-line, "
+ + "caret-begin-paragraph, caret-end-paragraph, selection-begin-paragraph, "
+ + "selection-end-paragraph, caret-begin, caret-end, selection-begin, selection-end, "
+ + "default-typed, insert-tab, select-word, select-line, select-paragraph, select-all, "
+ + "unselect, toggle-componentOrientation, dump-model, ";
assertEquals("number of actions", actions1.length, actions2.length);
for (int i = 0; i < actions1.length; i++) {
assertTrue(i + " action is shared", actions1[i] == actions2[i]);
}
-
assertEquals("number of actions", 53, actions1.length);
for (int i = 0; i < actions1.length; i++) {
- String name = (String)actions1[i].getValue(Action.NAME);
+ String name = (String) actions1[i].getValue(Action.NAME);
name += ", ";
- assertTrue(templateStr.indexOf(name) >=0);
+ assertTrue(templateStr.indexOf(name) >= 0);
templateStr = templateStr.replaceFirst(name, "");
}
assertEquals("", templateStr);
@@ -99,9 +93,15 @@
}
public void testActionSharing() {
- assertTrue("actions are being shared", new DefaultEditorKit().getActions()[0] == new DefaultEditorKit().getActions()[0]);
- assertTrue("actions are being shared", new DefaultEditorKit().getActions()[10] == new DefaultEditorKit().getActions()[10]);
- assertTrue("actions are being shared", new DefaultEditorKit().getActions()[20] == new DefaultEditorKit().getActions()[20]);
+ assertTrue(
+ "actions are being shared",
+ new DefaultEditorKit().getActions()[0] == new DefaultEditorKit().getActions()[0]);
+ assertTrue(
+ "actions are being shared",
+ new DefaultEditorKit().getActions()[10] == new DefaultEditorKit().getActions()[10]);
+ assertTrue(
+ "actions are being shared",
+ new DefaultEditorKit().getActions()[20] == new DefaultEditorKit().getActions()[20]);
}
/*
@@ -109,16 +109,12 @@
*/
public void testReadInputStreamDocumentint() throws Exception {
final ByteArrayOutputStream outFile = new ByteArrayOutputStream();
-
String str = "This is a very short plain-text document.\nIt's to be read only by the test.";
outFile.write(str.getBytes());
-
InputStream inFile = new ByteArrayInputStream(outFile.toByteArray());
-
final Document doc = kit.createDefaultDocument();
kit.read(inFile, doc, 0);
assertEquals("document's length", str.length(), doc.getLength());
-
inFile.close();
inFile = new ByteArrayInputStream(outFile.toByteArray());
kit.read(inFile, doc, 10);
@@ -126,9 +122,7 @@
String head = null;
head = doc.getText(0, 20);
assertEquals("document's head", "This is a This is a ", head);
-
inFile.close();
-
testExceptionalCase(new BadLocationCase() {
@Override
public void exceptionalAction() throws Exception {
@@ -142,29 +136,26 @@
*/
public void testReadReaderDocumentint() throws Exception {
String str = "This is a very short plain-text document.\nIt's to be read only by the test.";
-
final ByteArrayOutputStream outFile = new ByteArrayOutputStream();
outFile.write(str.getBytes());
-
- InputStreamReader inFile = new InputStreamReader(new ByteArrayInputStream(outFile.toByteArray()));
-
+ InputStreamReader inFile = new InputStreamReader(new ByteArrayInputStream(outFile
+ .toByteArray()));
final Document doc = kit.createDefaultDocument();
readKitReader(inFile, doc, 0);
assertEquals("document's length", str.length(), doc.getLength());
-
inFile.close();
inFile = new InputStreamReader(new ByteArrayInputStream(outFile.toByteArray()));
readKitReader(inFile, doc, 10);
assertEquals("document's length", 2 * str.length(), doc.getLength());
String head = doc.getText(0, 20);
assertEquals("document's head", "This is a This is a ", head);
-
inFile.close();
-
testExceptionalCase(new BadLocationCase() {
@Override
public void exceptionalAction() throws Exception {
- kit.read(new InputStreamReader(new ByteArrayInputStream(outFile.toByteArray())), doc, 1000);
+ kit.read(
+ new InputStreamReader(new ByteArrayInputStream(outFile.toByteArray())),
+ doc, 1000);
}
});
}
@@ -176,21 +167,15 @@
String str = "This is a very short plain-text document.It's to be read only by the test.";
final Document doc = kit.createDefaultDocument();
doc.insertString(0, str, doc.getDefaultRootElement().getAttributes());
-
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
writeKitFile(outputStream, str, doc, 0, str.length());
-
String strRead = readStringFromFile(new ByteArrayInputStream(outputStream.toByteArray()));
assertEquals("document", str, strRead);
-
outputStream.reset();
writeKitFile(outputStream, str, doc, 11, str.length() - 13);
-
strRead = readStringFromFile(new ByteArrayInputStream(outputStream.toByteArray()));
assertEquals("document",
- "ery short plain-text document.It's to be read only by the tes",
- strRead);
-
+ "ery short plain-text document.It's to be read only by the tes", strRead);
testExceptionalCase(new BadLocationCase() {
@Override
public void exceptionalAction() throws Exception {
@@ -206,21 +191,15 @@
String str = "This is a very short plain-text document.It's to be read only by the test.";
final Document doc = kit.createDefaultDocument();
doc.insertString(0, str, doc.getDefaultRootElement().getAttributes());
-
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
writeKitWriter(outputStream, str, doc, 0, str.length());
-
String strRead = readStringFromFile(new ByteArrayInputStream(outputStream.toByteArray()));
assertEquals("document", str, strRead);
-
outputStream.reset();
writeKitWriter(outputStream, str, doc, 11, str.length() - 13);
-
strRead = readStringFromFile(new ByteArrayInputStream(outputStream.toByteArray()));
assertEquals("document",
- "ery short plain-text document.It's to be read only by the tes",
- strRead);
-
+ "ery short plain-text document.It's to be read only by the tes", strRead);
testExceptionalCase(new BadLocationCase() {
@Override
public void exceptionalAction() throws Exception {
@@ -228,12 +207,11 @@
}
});
}
-
+
public void testWriteWriterFlush() throws Exception {
final String str = "Test text";
final Document doc = kit.createDefaultDocument();
doc.insertString(0, str, null);
-
final Marker flushMarker = new Marker();
final Marker closeMarker = new Marker();
StringWriter writer = new StringWriter() {
@@ -242,6 +220,7 @@
closeMarker.setOccurred();
super.close();
}
+
@Override
public void flush() {
flushMarker.setOccurred();
@@ -249,16 +228,14 @@
}
};
kit.write(writer, doc, 0, doc.getLength());
-
assertFalse(closeMarker.isOccurred());
assertTrue(flushMarker.isOccurred());
}
-
+
public void testWriteOutputStreamFlush() throws Exception {
final String str = "Test text";
final Document doc = kit.createDefaultDocument();
doc.insertString(0, str, null);
-
final Marker flushMarker = new Marker();
final Marker closeMarker = new Marker();
OutputStream stream = new ByteArrayOutputStream() {
@@ -267,6 +244,7 @@
closeMarker.setOccurred();
super.close();
}
+
@Override
public void flush() throws IOException {
flushMarker.setOccurred();
@@ -274,7 +252,6 @@
}
};
kit.write(stream, doc, 0, doc.getLength());
-
assertFalse(closeMarker.isOccurred());
assertTrue(flushMarker.isOccurred());
}
@@ -283,50 +260,46 @@
String str1 = "This is a very \r\nshort plain-text document.\r\nIt's to be read only by the \r\ntest.";
String str2 = "This is a very \rshort plain-text document.\rIt's to be read only by the test.";
StringReader reader = new StringReader(str1);
-
Document doc = new PlainDocument();
DefaultEditorKit kit = new DefaultEditorKit();
kit.read(reader, doc, 0);
-
String readStr = doc.getText(0, doc.getLength());
assertEquals("no \"\\r\" found", -1, readStr.indexOf("\r"));
assertEquals("string length", str1.length() - 3, readStr.length());
- assertEquals("newLine property", "\r\n", doc.getProperty(DefaultEditorKit.EndOfLineStringProperty));
-
+ assertEquals("newLine property", "\r\n", doc
+ .getProperty(DefaultEditorKit.EndOfLineStringProperty));
reader = new StringReader(str2);
doc = new PlainDocument();
kit = new DefaultEditorKit();
kit.read(reader, doc, 0);
-
readStr = doc.getText(0, doc.getLength());
assertEquals("no \"\\r\" found", -1, readStr.indexOf("\r"));
assertEquals("string length", str2.length(), readStr.length());
- assertEquals("newLine property", "\r", doc.getProperty(DefaultEditorKit.EndOfLineStringProperty));
+ assertEquals("newLine property", "\r", doc
+ .getProperty(DefaultEditorKit.EndOfLineStringProperty));
}
public void testNewLineInputStream() throws IOException, BadLocationException {
String str1 = "This is a very \r\nshort plain-text document.\r\nIt's to be read only by the \r\ntest.";
String str2 = "This is a very \rshort plain-text document.\rIt's to be read only by the test.";
InputStream reader = new ByteArrayInputStream(str1.getBytes());
-
Document doc = new PlainDocument();
DefaultEditorKit kit = new DefaultEditorKit();
kit.read(reader, doc, 0);
-
String readStr = doc.getText(0, doc.getLength());
assertEquals("no \"\\r\" found", -1, readStr.indexOf("\r"));
assertEquals("string length", str1.length() - 3, readStr.length());
- assertEquals("newLine property", "\r\n", doc.getProperty(DefaultEditorKit.EndOfLineStringProperty));
-
+ assertEquals("newLine property", "\r\n", doc
+ .getProperty(DefaultEditorKit.EndOfLineStringProperty));
reader = new ByteArrayInputStream(str2.getBytes());
doc = new PlainDocument();
kit = new DefaultEditorKit();
kit.read(reader, doc, 0);
-
readStr = doc.getText(0, doc.getLength());
assertEquals("no \"\\r\" found", -1, readStr.indexOf("\r"));
assertEquals("string length", str2.length(), readStr.length());
- assertEquals("newLine property", "\r", doc.getProperty(DefaultEditorKit.EndOfLineStringProperty));
+ assertEquals("newLine property", "\r", doc
+ .getProperty(DefaultEditorKit.EndOfLineStringProperty));
}
public void testNewLineWriter() throws IOException, BadLocationException {
@@ -335,14 +308,12 @@
String str3 = "This is a very \nshort plain-text document.\nIt's to be read only by the \ntest.";
StringReader reader = new StringReader(str1);
StringWriter writer = new StringWriter();
-
Document doc = new PlainDocument();
DefaultEditorKit kit = new DefaultEditorKit();
kit.read(reader, doc, 0);
kit.write(writer, doc, 0, doc.getLength());
assertEquals(str1, writer.toString());
assertEquals(str3, doc.getText(0, doc.getLength()));
-
reader = new StringReader(str2);
writer = new StringWriter();
doc = new PlainDocument();
@@ -359,15 +330,12 @@
String str3 = "This is a very \nshort plain-text document.\nIt's to be read only by the \ntest.";
InputStream reader = new ByteArrayInputStream(str1.getBytes());
OutputStream writer = new ByteArrayOutputStream();
-
Document doc = new PlainDocument();
DefaultEditorKit kit = new DefaultEditorKit();
kit.read(reader, doc, 0);
assertEquals(str3, doc.getText(0, doc.getLength()));
kit.write(writer, doc, 0, doc.getLength());
assertEquals(str1, writer.toString());
-
-
reader = new ByteArrayInputStream(str2.getBytes());
writer = new ByteArrayOutputStream();
doc = new PlainDocument();
@@ -378,7 +346,8 @@
assertEquals(str2, writer.toString());
}
- private void readKitReader(final InputStreamReader inFile, final Document doc, final int pos) throws Exception {
+ private void readKitReader(final InputStreamReader inFile, final Document doc, final int pos)
+ throws Exception {
kit.read(inFile, doc, pos);
}
@@ -390,16 +359,14 @@
}
private void writeKitWriter(final OutputStream outputStream, final String str,
- final Document doc, final int pos,
- final int length) throws Exception {
+ final Document doc, final int pos, final int length) throws Exception {
OutputStreamWriter outFile = new OutputStreamWriter(outputStream);
kit.write(outFile, doc, pos, length);
outFile.close();
}
private void writeKitFile(final OutputStream outputStream, final String str,
- final Document doc, final int pos,
- final int length) throws Exception {
+ final Document doc, final int pos, final int length) throws Exception {
kit.write(outputStream, doc, pos, length);
outputStream.close();
}
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultEditorKit_Actions_MultithreadedTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultEditorKit_Actions_MultithreadedTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultEditorKit_Actions_MultithreadedTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultEditorKit_Actions_MultithreadedTest.java Sun Nov 26 12:15:43 2006
@@ -38,7 +38,6 @@
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.util.HashSet;
-
import javax.swing.Action;
import javax.swing.BasicSwingTestCase;
import javax.swing.JComponent;
@@ -47,19 +46,21 @@
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JViewport;
+import javax.swing.ScrollPaneConstants;
import javax.swing.SwingUtilities;
public class DefaultEditorKit_Actions_MultithreadedTest 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) {
@@ -76,14 +77,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);
@@ -91,10 +91,12 @@
});
}
- protected void putStringToClipboard(final String str) throws InterruptedException, InvocationTargetException {
+ protected void putStringToClipboard(final String str) throws InterruptedException,
+ InvocationTargetException {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- final Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+ final Clipboard systemClipboard = Toolkit.getDefaultToolkit()
+ .getSystemClipboard();
if (systemClipboard == null) {
fail("unable to get systemClipboard");
}
@@ -103,17 +105,20 @@
});
}
- protected String getStringFromClipboard() throws InterruptedException, InvocationTargetException {
+ protected String getStringFromClipboard() throws InterruptedException,
+ InvocationTargetException {
class ResultableThread implements Runnable {
public String result;
public void run() {
try {
- final Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
+ final Clipboard systemClipboard = Toolkit.getDefaultToolkit()
+ .getSystemClipboard();
if (systemClipboard == null) {
fail("unable to get systemClipboard");
}
- result = (String)systemClipboard.getContents(null).getTransferData(DataFlavor.stringFlavor);
+ result = (String) systemClipboard.getContents(null).getTransferData(
+ DataFlavor.stringFlavor);
} catch (HeadlessException e) {
fail(e.getMessage());
} catch (UnsupportedFlavorException e) {
@@ -122,20 +127,20 @@
fail(e.getMessage());
}
}
- };
+ }
+ ;
ResultableThread thread = new ResultableThread();
SwingUtilities.invokeAndWait(thread);
-
return thread.result;
}
- protected void performAction(final Object source, final Action action) throws InterruptedException, InvocationTargetException {
+ protected void performAction(final Object source, final Action action)
+ throws InterruptedException, InvocationTargetException {
performAction(source, action, "command");
}
- private JTextArea initComponent(final JTextArea c, final int startPos,
- final int endPos, final String text) throws Exception {
-
+ private JTextArea initComponent(final JTextArea c, final int startPos, final int endPos,
+ final String text) throws Exception {
if (frame != null) {
frame.dispose();
}
@@ -144,8 +149,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();
if (!isHarmony()) {
@@ -163,19 +168,23 @@
return c;
}
- protected JTextArea getInitedComponent(final int startPos,
- final int endPos, final String text) throws Exception {
+ protected JTextArea getInitedComponent(final int startPos, final int endPos,
+ final String text) throws Exception {
JTextArea c = createTextArea();
return initComponent(c, startPos, endPos, text);
}
- protected JTextArea getInitedComponent(final int caretPos, final String text) throws Exception {
+ protected JTextArea getInitedComponent(final int caretPos, final String text)
+ throws Exception {
JTextArea c = createTextArea();
return initComponent(c, caretPos, -1, text);
}
private JTextArea createTextArea() {
return new JTextArea() {
+ private static final long serialVersionUID = 1L;
+
+ @Override
public FontMetrics getFontMetrics(final Font f) {
return DefaultEditorKit_Actions_MultithreadedTest.this.getFontMetrics(f, 6);
};
@@ -195,15 +204,11 @@
String text = "012345 6789\nasfd\nasd asd";
Action action = getAction(DefaultEditorKit.toggleComponentOrientationAction);
JTextArea c = getInitedComponent(10, 15, text);
- assertTrue("component is horizontal", c.getComponentOrientation()
- .isHorizontal());
- assertTrue("component is LR", c.getComponentOrientation()
- .isLeftToRight());
- performAction(c, action);
- assertTrue("component is horizontal", c.getComponentOrientation()
- .isHorizontal());
- assertFalse("component is RL", c.getComponentOrientation()
- .isLeftToRight());
+ assertTrue("component is horizontal", c.getComponentOrientation().isHorizontal());
+ assertTrue("component is LR", c.getComponentOrientation().isLeftToRight());
+ performAction(c, action);
+ assertTrue("component is horizontal", c.getComponentOrientation().isHorizontal());
+ assertFalse("component is RL", c.getComponentOrientation().isLeftToRight());
}
public void testDumpModelActionPerformed() throws Exception {
@@ -215,25 +220,11 @@
Action action = getAction("dump-model");
JTextArea c = getInitedComponent(10, 15, text);
performAction(c, action);
- assertEquals("<paragraph>\n" +
- " <content>\n" +
- " [0,13][012345 6789\n" +
- "]\n" +
- " <content>\n" +
- " [13,18][asfd\n" +
- "]\n" +
- " <content>\n" +
- " [18,27][asd asd\n" +
- "]\n" +
- "<bidi root>\n" +
- " <bidi level\n" +
- " bidiLevel=0\n" +
- " >\n" +
- " [0,27][012345 6789\n" +
- "asfd\n" +
- "asd asd\n" +
- "]\n",
- AbstractDocumentTest.filterNewLines(out.toString()));
+ assertEquals("<paragraph>\n" + " <content>\n" + " [0,13][012345 6789\n"
+ + "]\n" + " <content>\n" + " [13,18][asfd\n" + "]\n" + " <content>\n"
+ + " [18,27][asd asd\n" + "]\n" + "<bidi root>\n" + " <bidi level\n"
+ + " bidiLevel=0\n" + " >\n" + " [0,27][012345 6789\n" + "asfd\n"
+ + "asd asd\n" + "]\n", AbstractDocumentTest.filterNewLines(out.toString()));
} finally {
System.setErr(oldErr);
}
@@ -241,34 +232,29 @@
public void testPageActionPerformed() throws Exception {
String text = "01\n23\n45\n677777777777777777777777777777777777777777777777777\n89\n0-\nqwe\nrty\nasd\n\n\n\n\nzxc\nvbn";
-
Action action = getAction("selection-page-right");
JTextArea c = getInitedComponent(3, 7, text);
performAction(c, action);
assertEquals("selected string",
- "23\n45\n677777777777777777777777777777777777777777777777777\n89",
- c.getSelectedText());
+ "23\n45\n677777777777777777777777777777777777777777777777777\n89", c
+ .getSelectedText());
assertEquals("caret position", 63, c.getCaretPosition());
-
performAction(c, action);
assertEquals("selected string",
- "23\n45\n677777777777777777777777777777777777777777777777777\n89",
- c.getSelectedText());
+ "23\n45\n677777777777777777777777777777777777777777777777777\n89", c
+ .getSelectedText());
assertEquals("caret position", 63, c.getCaretPosition());
-
action = getAction("selection-page-left");
c = getInitedComponent(60, text);
performAction(c, action);
assertEquals("selected string",
- "01\n23\n45\n677777777777777777777777777777777777777777777777777",
- c.getSelectedText());
+ "01\n23\n45\n677777777777777777777777777777777777777777777777777", c
+ .getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
c = getInitedComponent(10, text);
performAction(c, action);
assertEquals("selected string", "01\n23\n45\n6", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
performAction(c, action);
assertEquals("selected string", "01\n23\n45\n6", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
@@ -281,69 +267,54 @@
performAction(c, action, null);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 35, c.getCaretPosition());
-
performAction(c, action, null);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 48, c.getCaretPosition());
-
performAction(c, action, null);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 56, c.getCaretPosition());
-
performAction(c, action, null);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 78, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.pageUpAction);
performAction(c, action, null);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 50, c.getCaretPosition());
-
performAction(c, action, null);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 35, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.pageUpAction);
performAction(c, action, null);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 6, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.pageUpAction);
performAction(c, action, null);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 6, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.pageDownAction);
performAction(c, action, null);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 35, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.pageUpAction);
c = getInitedComponent(0, text);
performAction(c, action, null);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.selectionPageDownAction);
c = getInitedComponent(3, 7, text);
performAction(c, action);
- assertEquals("selected string",
- "111111111111\n2\n3\n44444444\n5555555", c.getSelectedText());
+ assertEquals("selected string", "111111111111\n2\n3\n44444444\n5555555", c
+ .getSelectedText());
assertEquals("caret position", 36, c.getCaretPosition());
-
performAction(c, action);
assertEquals("selected string",
- "111111111111\n2\n3\n44444444\n55555555555\n6\n7\n8\n9", c
- .getSelectedText());
+ "111111111111\n2\n3\n44444444\n55555555555\n6\n7\n8\n9", c.getSelectedText());
assertEquals("caret position", 48, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.selectionPageUpAction);
c = getInitedComponent(19, text);
performAction(c, action);
- assertEquals("selected string", "11111111111111\n2\n3", c
- .getSelectedText());
+ assertEquals("selected string", "11111111111111\n2\n3", c.getSelectedText());
assertEquals("caret position", 1, c.getCaretPosition());
-
c = getInitedComponent(10, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
@@ -376,23 +347,19 @@
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 14, c.getCaretPosition());
-
c = getInitedComponent(16, text);
performAction(c, action);
assertNull("resulted string", c.getSelectedText());
assertEquals("caret position", 19, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.selectionEndParagraphAction);
c = getInitedComponent(6, text);
performAction(c, action);
assertEquals("selected string", "5 6789\n", c.getSelectedText());
assertEquals("caret position", 14, c.getCaretPosition());
-
c = getInitedComponent(16, text);
performAction(c, action);
assertEquals("resulted string", "fd\n", c.getSelectedText());
assertEquals("caret position", 19, c.getCaretPosition());
-
c = getInitedComponent(0, null);
performAction(c, action);
assertNull("resulted string", c.getSelectedText());
@@ -405,23 +372,19 @@
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
c = getInitedComponent(16, text);
performAction(c, action);
assertNull("resulted string", c.getSelectedText());
assertEquals("caret position", 14, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.selectionBeginParagraphAction);
c = getInitedComponent(6, text);
performAction(c, action);
assertEquals("selected string", "\t01234", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
c = getInitedComponent(16, text);
performAction(c, action);
assertEquals("resulted string", "as", c.getSelectedText());
assertEquals("caret position", 14, c.getCaretPosition());
-
c = getInitedComponent(0, null);
performAction(c, action);
assertNull("resulted string", c.getSelectedText());
@@ -434,33 +397,27 @@
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 13, c.getCaretPosition());
-
c = getInitedComponent(1, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
c = getInitedComponent(0, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.selectionBeginWordAction);
c = getInitedComponent(13, 17, text);
performAction(c, action);
assertEquals("selected string", "asfd", c.getSelectedText());
assertEquals("caret position", 17, c.getCaretPosition());
-
c = getInitedComponent(15, 17, text);
performAction(c, action);
assertEquals("selected string", "fd", c.getSelectedText());
assertEquals("caret position", 17, c.getCaretPosition());
-
c = getInitedComponent(2, 1, text);
performAction(c, action);
assertEquals("selected string", "01", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
c = getInitedComponent(0, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
@@ -474,28 +431,23 @@
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 17, c.getCaretPosition());
-
c = getInitedComponent(25, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 26, c.getCaretPosition());
-
c = getInitedComponent(26, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 26, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.selectionEndWordAction);
c = getInitedComponent(14, 16, text);
performAction(c, action);
assertEquals("selected string", "sfd", c.getSelectedText());
assertEquals("caret position", 17, c.getCaretPosition());
-
c = getInitedComponent(24, 25, text);
performAction(c, action);
assertEquals("selected string", "sd", c.getSelectedText());
assertEquals("caret position", 26, c.getCaretPosition());
-
c = getInitedComponent(26, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
@@ -509,33 +461,27 @@
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 13, c.getCaretPosition());
-
c = getInitedComponent(1, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
c = getInitedComponent(0, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.selectionPreviousWordAction);
c = getInitedComponent(13, 17, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 13, c.getCaretPosition());
-
c = getInitedComponent(15, 17, text);
performAction(c, action);
assertEquals("selected string", "as", c.getSelectedText());
assertEquals("caret position", 13, c.getCaretPosition());
-
c = getInitedComponent(2, 1, text);
performAction(c, action);
assertEquals("selected string", "01", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
c = getInitedComponent(0, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
@@ -549,28 +495,23 @@
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 18, c.getCaretPosition());
-
c = getInitedComponent(25, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 26, c.getCaretPosition());
-
c = getInitedComponent(26, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 26, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.selectionNextWordAction);
c = getInitedComponent(14, 16, text);
performAction(c, action);
assertEquals("selected string", "sfd\n", c.getSelectedText());
assertEquals("caret position", 18, c.getCaretPosition());
-
c = getInitedComponent(24, 25, text);
performAction(c, action);
assertEquals("selected string", "sd", c.getSelectedText());
assertEquals("caret position", 26, c.getCaretPosition());
-
c = getInitedComponent(26, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
@@ -584,18 +525,15 @@
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 11, c.getCaretPosition());
-
c = getInitedComponent(8, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.selectionBeginLineAction);
c = getInitedComponent(8, 3, text);
performAction(c, action);
assertEquals("selected string", "01234567", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
c = getInitedComponent(0, null);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
@@ -609,18 +547,15 @@
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 19, c.getCaretPosition());
-
c = getInitedComponent(10, text);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 10, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.selectionEndLineAction);
c = getInitedComponent(3, 8, text);
performAction(c, action);
assertEquals("selected string", "3456789", c.getSelectedText());
assertEquals("caret position", 10, c.getCaretPosition());
-
c = getInitedComponent(0, null);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
@@ -634,19 +569,15 @@
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 28, c.getCaretPosition());
-
c = getInitedComponent(0, null);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.selectionEndAction);
c = getInitedComponent(12, 14, text);
performAction(c, action);
- assertEquals("selected string", "2341234\n12341234", c
- .getSelectedText());
+ assertEquals("selected string", "2341234\n12341234", c.getSelectedText());
assertEquals("caret position", 28, c.getCaretPosition());
-
c = getInitedComponent(0, null);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
@@ -660,19 +591,15 @@
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
c = getInitedComponent(0, null);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
action = getAction(DefaultEditorKit.selectionBeginAction);
c = getInitedComponent(16, 14, text);
performAction(c, action);
- assertEquals("selected string", "0123456789\n12341", c
- .getSelectedText());
+ assertEquals("selected string", "0123456789\n12341", c.getSelectedText());
assertEquals("caret position", 0, c.getCaretPosition());
-
c = getInitedComponent(0, null);
performAction(c, action);
assertNull("selected string", c.getSelectedText());
@@ -685,15 +612,12 @@
JTextArea c = getInitedComponent(15, text);
performAction(c, action);
assertEquals("resulted string", "asfd", c.getSelectedText());
-
c = getInitedComponent(9, text);
performAction(c, action);
assertEquals("resulted string", "6789", c.getSelectedText());
-
c = getInitedComponent(7, text);
performAction(c, action);
assertEquals("resulted string", " ", c.getSelectedText());
-
c = getInitedComponent(0, null);
performAction(c, action);
assertNull("resulted string", c.getSelectedText());
@@ -703,14 +627,11 @@
String text = "0123 456789\nasdf";
Action action = getAction(DefaultEditorKit.selectLineAction);
JTextArea c = getInitedComponent(5, text);
-
performAction(c, action);
assertEquals("resulted string", "0123 456789", c.getSelectedText());
-
c = getInitedComponent(14, text);
performAction(c, action);
assertEquals("resulted string", "asdf", c.getSelectedText());
-
c = getInitedComponent(0, null);
performAction(c, action);
assertNull("resulted string", c.getSelectedText());
@@ -723,17 +644,14 @@
performAction(c, action);
String res = "\t012345 6789" + "\n";
assertEquals("resulted string", res, c.getSelectedText());
-
c = getInitedComponent(15, text);
performAction(c, action);
res = "asfd" + "\n";
assertEquals("resulted string", res, c.getSelectedText());
-
c = getInitedComponent(20, text);
performAction(c, action);
res = "\tasd asd";
assertEquals("resulted string", res, c.getSelectedText());
-
c = getInitedComponent(0, null);
performAction(c, action);
assertNull("resulted string", c.getSelectedText());
@@ -745,7 +663,6 @@
JTextArea c = getInitedComponent(2, 7, text);
performAction(c, action);
assertEquals("resulted string", text, c.getSelectedText());
-
c = getInitedComponent(0, null);
performAction(c, action);
assertNull("resulted string", c.getSelectedText());
@@ -756,15 +673,12 @@
JTextArea c = getInitedComponent(2, 7, "0123456789");
performAction(c, action);
assertEquals("resulted string", "01789", c.getText());
-
c = getInitedComponent(3, "0123456789");
performAction(c, action);
assertEquals("resulted string", "012456789", c.getText());
-
c = getInitedComponent(10, "0123456789");
performAction(c, action);
assertEquals("resulted string", "0123456789", c.getText());
-
c = getInitedComponent(2, 10, "0123456789");
performAction(c, action);
assertEquals("resulted string", "01", c.getText());
@@ -775,15 +689,12 @@
JTextArea c = getInitedComponent(2, 7, "0123456789");
performAction(c, action);
assertEquals("resulted string", "01789", c.getText());
-
c = getInitedComponent(3, "0123456789");
performAction(c, action);
assertEquals("resulted string", "013456789", c.getText());
-
c = getInitedComponent(0, "0123456789");
performAction(c, action);
assertEquals("resulted string", "0123456789", c.getText());
-
c = getInitedComponent(5, 0, "0123456789");
performAction(c, action);
assertEquals("resulted string", "56789", c.getText());
@@ -794,11 +705,9 @@
JTextArea c = getInitedComponent(2, 7, "0123456789");
performAction(c, action, "aaa");
assertEquals("resulted string", "01aaa789", c.getText());
-
c = getInitedComponent(2, 7, "0123456789");
performAction(c, action, null);
assertEquals("resulted string", "0123456789", c.getText());
-
c = getInitedComponent(2, 7, "0123456789");
performAction(c, action, "command\ncontent");
assertEquals("resulted string", "01command\ncontent789", c.getText());
@@ -806,42 +715,42 @@
public void testCopyActionPerformed() throws Exception {
// TODO: Uncomment when Clipboard is fully supported
-// DefaultEditorKit.CopyAction action = new DefaultEditorKit.CopyAction();
-// putStringToClipboard("");
-// JTextArea c = getInitedComponent(2, 7, "0123456789");
-// performAction(c, action);
-// Object result = null;
-// try {
-// result = getStringFromClipboard();
-// } catch (HeadlessException e) {
-// fail(e.getMessage());
-// }
-// assertEquals("selected string", "23456", result);
+ // DefaultEditorKit.CopyAction action = new DefaultEditorKit.CopyAction();
+ // putStringToClipboard("");
+ // JTextArea c = getInitedComponent(2, 7, "0123456789");
+ // performAction(c, action);
+ // Object result = null;
+ // try {
+ // result = getStringFromClipboard();
+ // } catch (HeadlessException e) {
+ // fail(e.getMessage());
+ // }
+ // assertEquals("selected string", "23456", result);
}
public void testCutActionPerformed() throws Exception {
// TODO: Uncomment when Clipboard is fully supported
-// DefaultEditorKit.CutAction action = new DefaultEditorKit.CutAction();
-// putStringToClipboard("");
-// JTextArea c = getInitedComponent(2, 7, "0123456789");
-// performAction(c, action);
-// Object result = null;
-// try {
-// result = getStringFromClipboard();
-// } catch (HeadlessException e) {
-// fail(e.getMessage());
-// }
-// assertEquals("cut string", "23456", result);
-// assertEquals("remained string", "01789", c.getText());
+ // DefaultEditorKit.CutAction action = new DefaultEditorKit.CutAction();
+ // putStringToClipboard("");
+ // JTextArea c = getInitedComponent(2, 7, "0123456789");
+ // performAction(c, action);
+ // Object result = null;
+ // try {
+ // result = getStringFromClipboard();
+ // } catch (HeadlessException e) {
+ // fail(e.getMessage());
+ // }
+ // assertEquals("cut string", "23456", result);
+ // assertEquals("remained string", "01789", c.getText());
}
public void testPasteActionPerformed() throws Exception {
// TODO: Uncomment when Clipboard is fully supported
-// DefaultEditorKit.PasteAction action = new DefaultEditorKit.PasteAction();
-// putStringToClipboard("98765");
-// JTextArea c = getInitedComponent(2, 7, "0123456789");
-// performAction(c, action);
-// assertEquals("resulted string", "0198765789", c.getText());
+ // DefaultEditorKit.PasteAction action = new DefaultEditorKit.PasteAction();
+ // putStringToClipboard("98765");
+ // JTextArea c = getInitedComponent(2, 7, "0123456789");
+ // performAction(c, action);
+ // assertEquals("resulted string", "0198765789", c.getText());
}
public void testInsertTabActionPerformed() throws Exception {
@@ -878,12 +787,10 @@
performAction(c, action, null);
assertEquals("caret position", 9, c.getCaretPosition());
assertNull("selected text ", c.getSelectedText());
-
c = getInitedComponent(text.length(), text);
performAction(c, action, null);
assertEquals("caret position", text.length(), c.getCaretPosition());
assertNull("selected text ", c.getSelectedText());
-
c = getInitedComponent(5, 7, text);
performAction(c, action, null);
assertEquals("caret position", 8, c.getCaretPosition());
@@ -897,12 +804,10 @@
performAction(c, action);
assertEquals("caret position", 7, c.getCaretPosition());
assertNull("selected text ", c.getSelectedText());
-
c = getInitedComponent(0, text);
performAction(c, action);
assertEquals("caret position", 0, c.getCaretPosition());
assertNull("selected text ", c.getSelectedText());
-
c = getInitedComponent(5, 7, text);
performAction(c, action);
assertEquals("caret position", 6, c.getCaretPosition());
@@ -916,12 +821,10 @@
performAction(c, action);
assertEquals("caret position", 9, c.getCaretPosition());
assertEquals("selected text ", "6", c.getSelectedText());
-
c = getInitedComponent(text.length(), text);
performAction(c, action);
assertEquals("caret position", text.length(), c.getCaretPosition());
assertNull("selected text ", c.getSelectedText());
-
c = getInitedComponent(3, 7, text);
performAction(c, action);
assertEquals("caret position", 8, c.getCaretPosition());
@@ -935,12 +838,10 @@
performAction(c, action);
assertEquals("caret position", 7, c.getCaretPosition());
assertEquals("selected text ", " ", c.getSelectedText());
-
c = getInitedComponent(0, text);
performAction(c, action);
assertEquals("caret position", 0, c.getCaretPosition());
assertNull("selected text ", c.getSelectedText());
-
c = getInitedComponent(8, 5, text);
performAction(c, action);
assertEquals("caret position", 4, c.getCaretPosition());
@@ -954,11 +855,9 @@
performAction(c, action);
assertEquals("caret position", 2, c.getCaretPosition());
assertNull("selected text ", c.getSelectedText());
-
performAction(c, action);
assertEquals("caret position", 2, c.getCaretPosition());
assertNull("selected text ", c.getSelectedText());
-
c = getInitedComponent(24, 26, text);
performAction(c, action);
assertEquals("caret position", 17, c.getCaretPosition());
@@ -970,25 +869,19 @@
Action action = getAction(DefaultEditorKit.downAction);
JTextArea c = getInitedComponent(8, text);
performAction(c, action);
- assertEquals("magic caret pos", new Point(48, 0), c.getCaret()
- .getMagicCaretPosition());
+ assertEquals("magic caret pos", new Point(48, 0), c.getCaret().getMagicCaretPosition());
assertEquals("caret position", 17, c.getCaretPosition());
assertNull("selected text ", c.getSelectedText());
-
c = getInitedComponent(text.length(), text);
performAction(c, action);
- assertEquals("magic caret pos", 48, c.getCaret()
- .getMagicCaretPosition().x);
+ assertEquals("magic caret pos", 48, c.getCaret().getMagicCaretPosition().x);
assertEquals("caret position", text.length(), c.getCaretPosition());
assertNull("selected text ", c.getSelectedText());
-
c = getInitedComponent(5, 7, text);
performAction(c, action);
- assertEquals("magic caret pos", new Point(42, 0), c.getCaret()
- .getMagicCaretPosition());
+ assertEquals("magic caret pos", new Point(42, 0), c.getCaret().getMagicCaretPosition());
performAction(c, action);
- assertEquals("magic caret pos", new Point(42, 0), c.getCaret()
- .getMagicCaretPosition());
+ assertEquals("magic caret pos", new Point(42, 0), c.getCaret().getMagicCaretPosition());
assertEquals("caret position", 25, c.getCaretPosition());
assertNull("selected text ", c.getSelectedText());
}
@@ -1000,11 +893,9 @@
performAction(c, action);
assertEquals("caret position", 2, c.getCaretPosition());
assertEquals("selected text ", "2345 6789\nas", c.getSelectedText());
-
performAction(c, action);
assertEquals("caret position", 2, c.getCaretPosition());
assertEquals("selected text ", "2345 6789\nas", c.getSelectedText());
-
c = getInitedComponent(26, 24, text);
performAction(c, action);
assertEquals("caret position", 17, c.getCaretPosition());
@@ -1018,42 +909,36 @@
performAction(c, action);
assertEquals("caret position", 17, c.getCaretPosition());
assertEquals("selected text ", "6789\nasfd", c.getSelectedText());
-
c = getInitedComponent(text.length(), text);
performAction(c, action);
assertEquals("caret position", text.length(), c.getCaretPosition());
assertNull("selected text ", c.getSelectedText());
-
c = getInitedComponent(5, 7, text);
performAction(c, action);
performAction(c, action);
assertEquals("caret position", 25, c.getCaretPosition());
- assertEquals("selected text ", "5 6789\nasfd\nasd as", c
- .getSelectedText());
+ assertEquals("selected text ", "5 6789\nasfd\nasd as", c.getSelectedText());
}
public void testDefaultKeyTypedActionFiltering() throws Exception {
- HashSet nonTypingChars = new HashSet();
+ HashSet<Character> nonTypingChars = new HashSet<Character>();
for (char i = 0; i < 32; i++) {
nonTypingChars.add(new Character(i));
}
- nonTypingChars.add(new Character((char)127));
-
+ nonTypingChars.add(new Character((char) 127));
DefaultEditorKit.DefaultKeyTypedAction action = new DefaultEditorKit.DefaultKeyTypedAction();
JTextArea c = getInitedComponent(4, 5, "0123456789");
-
-
String prevText = c.getText();
- for (char i = 0; i < 255; i++ ) {
+ for (char i = 0; i < 255; i++) {
performAction(c, action, String.valueOf(i));
if (prevText.equals(c.getText())) {
if (!nonTypingChars.contains(new Character(i))) {
- fail("regular character haven't been typed by DEK. code is: " + (int)i);
+ fail("regular character haven't been typed by DEK. code is: " + (int) i);
}
} else {
prevText = c.getText();
if (nonTypingChars.contains(new Character(i))) {
- fail("non-typing character have been typed by DEK. code is: " + (int)i);
+ fail("non-typing character have been typed by DEK. code is: " + (int) i);
}
}
}
@@ -1094,7 +979,8 @@
assertEquals("selection-backward", DefaultEditorKit.selectionBackwardAction);
assertEquals("selection-begin", DefaultEditorKit.selectionBeginAction);
assertEquals("selection-begin-line", DefaultEditorKit.selectionBeginLineAction);
- assertEquals("selection-begin-paragraph", DefaultEditorKit.selectionBeginParagraphAction);
+ assertEquals("selection-begin-paragraph",
+ DefaultEditorKit.selectionBeginParagraphAction);
assertEquals("selection-begin-word", DefaultEditorKit.selectionBeginWordAction);
assertEquals("selection-down", DefaultEditorKit.selectionDownAction);
assertEquals("selection-end", DefaultEditorKit.selectionEndAction);
@@ -1112,7 +998,8 @@
assertEquals("select-line", DefaultEditorKit.selectLineAction);
assertEquals("select-paragraph", DefaultEditorKit.selectParagraphAction);
assertEquals("select-word", DefaultEditorKit.selectWordAction);
- assertEquals("toggle-componentOrientation", DefaultEditorKit.toggleComponentOrientationAction);
+ assertEquals("toggle-componentOrientation",
+ DefaultEditorKit.toggleComponentOrientationAction);
assertEquals("unselect", DefaultEditorKit.unselectAction);
assertEquals("caret-up", DefaultEditorKit.upAction);
assertEquals("set-writable", DefaultEditorKit.writableAction);
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultFormatterFactoryTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultFormatterFactoryTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultFormatterFactoryTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultFormatterFactoryTest.java Sun Nov 26 12:15:43 2006
@@ -25,6 +25,8 @@
public class DefaultFormatterFactoryTest extends SwingTestCase {
class FTF extends JFormattedTextField {
+ private static final long serialVersionUID = 1L;
+
boolean hasFocus;
public FTF(final Object value, final boolean hasFocus) {
@@ -32,6 +34,7 @@
setHasFocus(hasFocus);
}
+ @Override
public boolean hasFocus() {
return hasFocus;
}
@@ -42,29 +45,33 @@
}
DefaultFormatterFactory factory;
+
DefaultFormatter formatter;
+
FTF ftf;
+
DefaultFormatter defaultDormatter;
+
DefaultFormatter editFormatter;
+
DefaultFormatter displayFormatter;
- DefaultFormatter nullFormatter;
+ DefaultFormatter nullFormatter;
+ @Override
protected void setUp() throws Exception {
super.setUp();
factory = new DefaultFormatterFactory();
formatter = new DefaultFormatter();
}
- private void checkFormatter(final JFormattedTextField.AbstractFormatter
- formatter) {
+ private void checkFormatter(final JFormattedTextField.AbstractFormatter formatter) {
assertEquals(formatter, factory.getFormatter(ftf));
}
- private void init(final Object value,
- final boolean hasFocus) {
- ftf = new FTF(value, hasFocus);
- initFormatters();
+ private void init(final Object value, final boolean hasFocus) {
+ ftf = new FTF(value, hasFocus);
+ initFormatters();
}
private void initFormatters() {
@@ -75,35 +82,27 @@
}
public void testGetFormatterNull() {
- init(null, false);
- assertNull(factory.getFormatter(ftf));
-
- factory.setDefaultFormatter(defaultDormatter);
- checkFormatter(defaultDormatter);
-
- factory.setEditFormatter(editFormatter);
- checkFormatter(defaultDormatter);
-
- factory.setDisplayFormatter(displayFormatter);
- checkFormatter(displayFormatter);
-
- factory.setNullFormatter(nullFormatter);
- checkFormatter(nullFormatter);
+ init(null, false);
+ assertNull(factory.getFormatter(ftf));
+ factory.setDefaultFormatter(defaultDormatter);
+ checkFormatter(defaultDormatter);
+ factory.setEditFormatter(editFormatter);
+ checkFormatter(defaultDormatter);
+ factory.setDisplayFormatter(displayFormatter);
+ checkFormatter(displayFormatter);
+ factory.setNullFormatter(nullFormatter);
+ checkFormatter(nullFormatter);
}
public void testGetFormatterNullHasFocus() {
init(null, true);
assertNull(factory.getFormatter(ftf));
-
factory.setDefaultFormatter(defaultDormatter);
checkFormatter(defaultDormatter);
-
factory.setDisplayFormatter(displayFormatter);
checkFormatter(defaultDormatter);
-
factory.setEditFormatter(editFormatter);
checkFormatter(editFormatter);
-
factory.setNullFormatter(nullFormatter);
checkFormatter(nullFormatter);
}
@@ -111,16 +110,12 @@
public void testGetFormatterNotNull_Number() {
init(new Integer(333), false);
assertNull(factory.getFormatter(ftf));
-
factory.setNullFormatter(nullFormatter);
assertNull(factory.getFormatter(ftf));
-
factory.setEditFormatter(editFormatter);
assertNull(factory.getFormatter(ftf));
-
factory.setDefaultFormatter(defaultDormatter);
checkFormatter(defaultDormatter);
-
factory.setDisplayFormatter(displayFormatter);
checkFormatter(displayFormatter);
}
@@ -128,16 +123,12 @@
public void testGetFormatterNotNullHasFocus() {
init(new Integer(333), true);
assertNull(factory.getFormatter(ftf));
-
factory.setNullFormatter(nullFormatter);
assertNull(factory.getFormatter(ftf));
-
factory.setDisplayFormatter(displayFormatter);
assertNull(factory.getFormatter(ftf));
-
factory.setDefaultFormatter(defaultDormatter);
checkFormatter(defaultDormatter);
-
factory.setEditFormatter(editFormatter);
checkFormatter(editFormatter);
}
@@ -169,8 +160,7 @@
public void testDefaultFormatterFactoryDefaultDisplayEdit() {
DefaultFormatter formatter1 = new DefaultFormatter();
DefaultFormatter formatter2 = new DefaultFormatter();
- factory = new DefaultFormatterFactory(formatter, formatter1,
- formatter2);
+ factory = new DefaultFormatterFactory(formatter, formatter1, formatter2);
assertNull(factory.getNullFormatter());
assertEquals(formatter2, factory.getEditFormatter());
assertEquals(formatter1, factory.getDisplayFormatter());
@@ -181,8 +171,7 @@
DefaultFormatter formatter1 = new DefaultFormatter();
DefaultFormatter formatter2 = new DefaultFormatter();
DefaultFormatter formatter3 = new DefaultFormatter();
- factory = new DefaultFormatterFactory(formatter, formatter1,
- formatter2, formatter3);
+ factory = new DefaultFormatterFactory(formatter, formatter1, formatter2, formatter3);
assertEquals(formatter3, factory.getNullFormatter());
assertEquals(formatter2, factory.getEditFormatter());
assertEquals(formatter1, factory.getDisplayFormatter());
Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultFormatterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultFormatterTest.java?view=diff&rev=479418&r1=479417&r2=479418
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultFormatterTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/text/DefaultFormatterTest.java Sun Nov 26 12:15:43 2006
@@ -27,18 +27,20 @@
import javax.swing.JFormattedTextField;
import javax.swing.SwingTestCase;
import javax.swing.SwingUtilities;
-
import junit.framework.AssertionFailedError;
-
public class DefaultFormatterTest extends SwingTestCase {
DefaultFormatter formatter;
+
JFormattedTextField ftf;
+
boolean bWasException;
+
String message;
- AssertionFailedError assertion;
+ AssertionFailedError assertion;
+ @Override
protected void setUp() throws Exception {
super.setUp();
formatter = new DefaultFormatter();
@@ -47,6 +49,7 @@
message = null;
}
+ @Override
protected void tearDown() throws Exception {
super.tearDown();
}
@@ -58,15 +61,13 @@
formatter.setAllowsInvalid(false);
formatter.setCommitsOnValidEdit(true);
formatter.setOverwriteMode(false);
-
try {
clone = formatter.clone();
} catch (CloneNotSupportedException e) {
assertFalse("Unexpected exception: " + e.getMessage(), true);
}
-
assertTrue(clone instanceof DefaultFormatter);
- DefaultFormatter form = (DefaultFormatter)clone;
+ DefaultFormatter form = (DefaultFormatter) clone;
assertEquals(Integer.class, form.getValueClass());
assertFalse(form.getAllowsInvalid());
assertTrue(form.getCommitsOnValidEdit());
@@ -81,10 +82,8 @@
Object value = Color.RED;
try {
assertEquals(value.toString(), formatter.valueToString(value));
-
value = "just value";
assertEquals(value.toString(), formatter.valueToString(value));
-
value = new Integer(123);
assertEquals(value.toString(), formatter.valueToString(value));
} catch (ParseException e) {
@@ -105,7 +104,6 @@
NumberFormatter numFormatter = (NumberFormatter) ftf.getFormatter();
ftf.setText(text);
assertEquals(text, ftf.getText());
-
text = "111222333";
numFormatter.setAllowsInvalid(false);
ftf.setText(text);
@@ -113,9 +111,8 @@
public void run() {
try {
assertEquals(NumberFormat.getNumberInstance()
- .format(new Integer(111222333)),
- ftf.getText());
- } catch(AssertionFailedError e) {
+ .format(new Integer(111222333)), ftf.getText());
+ } catch (AssertionFailedError e) {
assertion = e;
}
}
@@ -130,7 +127,6 @@
formatter = (DefaultFormatter) ftf.getFormatter();
ftf.setText("567");
assertEquals(new Integer(334580), ftf.getValue());
-
formatter.setCommitsOnValidEdit(true);
assertTrue(formatter.getCommitsOnValidEdit());
ftf.setText("123456");
@@ -153,7 +149,6 @@
formatter = (DefaultFormatter) ftf.getFormatter();
ftf.setText("false");
assertEquals(Boolean.TRUE, ftf.getValue());
-
formatter.setCommitsOnValidEdit(true);
assertTrue(formatter.getCommitsOnValidEdit());
ftf.setText("false");
@@ -175,23 +170,19 @@
ftf.setValue(new Integer(334580));
NumberFormatter numFormatter = (NumberFormatter) ftf.getFormatter();
try {
- AbstractDocument doc = (AbstractDocument)ftf.getDocument();
+ AbstractDocument doc = (AbstractDocument) ftf.getDocument();
ftf.setText("00");
-
- doc.insertString(0,"123", null);
+ doc.insertString(0, "123", null);
assertEquals("12300", ftf.getText());
- doc.insertString(0,"456", null);
+ doc.insertString(0, "456", null);
assertEquals("45612300", ftf.getText());
-
numFormatter.setOverwriteMode(true);
-
- doc.insertString(0,"789", null);
+ doc.insertString(0, "789", null);
assertEquals("78912300", ftf.getText());
- doc.insertString(3,"xxx", null);
+ doc.insertString(3, "xxx", null);
assertEquals("789xxx00", ftf.getText());
-
assertEquals(numFormatter, ftf.getFormatter());
- } catch(BadLocationException e) {
+ } catch (BadLocationException e) {
assertTrue("Unexpected exception: " + e.getMessage(), false);
}
}
@@ -200,23 +191,19 @@
ftf.setValue(Boolean.FALSE);
DefaultFormatter formatter = (DefaultFormatter) ftf.getFormatter();
try {
- AbstractDocument doc = (AbstractDocument)ftf.getDocument();
+ AbstractDocument doc = (AbstractDocument) ftf.getDocument();
ftf.setText("00");
- doc.insertString(0,"123", null);
+ doc.insertString(0, "123", null);
assertEquals("123", ftf.getText());
-
- doc.insertString(0,"456", null);
+ doc.insertString(0, "456", null);
assertEquals("456", ftf.getText());
-
formatter.setOverwriteMode(false);
-
- doc.insertString(0,"789", null);
+ doc.insertString(0, "789", null);
assertEquals("789456", ftf.getText());
-
- doc.insertString(3,"xxx", null);
+ doc.insertString(3, "xxx", null);
assertEquals("789xxx456", ftf.getText());
assertEquals(formatter, ftf.getFormatter());
- } catch(BadLocationException e) {
+ } catch (BadLocationException e) {
assertTrue("Unexpected exception: " + e.getMessage(), false);
}
}
@@ -225,26 +212,20 @@
formatter.install(ftf);
assertNull(ftf.getValue());
assertNull(formatter.getValueClass());
-
try {
- assertEquals("java.lang.String",
- formatter.stringToValue("546").getClass().getName());
-
+ assertEquals("java.lang.String", formatter.stringToValue("546").getClass()
+ .getName());
ftf.setValue(Boolean.TRUE);
- assertEquals("java.lang.Boolean",
- formatter.stringToValue("true").getClass().getName());
-
+ assertEquals("java.lang.Boolean", formatter.stringToValue("true").getClass()
+ .getName());
formatter.setValueClass(Float.class);
- assertEquals("java.lang.Float",
- formatter.stringToValue("546").getClass().getName());
-
+ assertEquals("java.lang.Float", formatter.stringToValue("546").getClass().getName());
formatter.setValueClass(Rectangle.class);
- assertEquals("java.lang.String",
- formatter.stringToValue("546").getClass().getName());
+ assertEquals("java.lang.String", formatter.stringToValue("546").getClass()
+ .getName());
} catch (ParseException e) {
assertTrue("Unexpected exception: " + e.getMessage(), false);
}
-
try {
formatter.setValueClass(Integer.class);
formatter.stringToValue("ttt");
@@ -258,7 +239,6 @@
public void testSetGetValueClass() {
assertNull(formatter.getValueClass());
-
formatter.setValueClass(Rectangle.class);
assertEquals(Rectangle.class, formatter.getValueClass());
}