diff options
author | Philippe Marschall | 2014-11-08 20:24:54 +0000 |
---|---|---|
committer | Michael Rennie | 2014-11-12 14:28:26 +0000 |
commit | 0fb2d7b735ddfacbeb71b0e3eb276df73c2996f9 (patch) | |
tree | e9641e9108a34821482b4b0d3e5cdd93eb65b5ee | |
parent | 77ef36de6d2e9af03f0d318b0b0ba458aceefbb2 (diff) | |
download | eclipse.jdt.debug-0fb2d7b735ddfacbeb71b0e3eb276df73c2996f9.tar.gz eclipse.jdt.debug-0fb2d7b735ddfacbeb71b0e3eb276df73c2996f9.tar.xz eclipse.jdt.debug-0fb2d7b735ddfacbeb71b0e3eb276df73c2996f9.zip |
Bug 76936 - [console] Eclipse Console window does not handle \b, \f, and
\r
Add console tests for handling escape characters.
Change-Id: I1bfe3a9c7ba25313358a1a38902b45a75e3c3239
Signed-off-by: Philippe Marschall <philippe.marschall@gmail.com>
-rw-r--r-- | org.eclipse.jdt.debug.tests/console tests/org/eclipse/jdt/debug/tests/console/IOConsoleTests.java | 148 |
1 files changed, 126 insertions, 22 deletions
diff --git a/org.eclipse.jdt.debug.tests/console tests/org/eclipse/jdt/debug/tests/console/IOConsoleTests.java b/org.eclipse.jdt.debug.tests/console tests/org/eclipse/jdt/debug/tests/console/IOConsoleTests.java index 6cce6f969..ba0985298 100644 --- a/org.eclipse.jdt.debug.tests/console tests/org/eclipse/jdt/debug/tests/console/IOConsoleTests.java +++ b/org.eclipse.jdt.debug.tests/console tests/org/eclipse/jdt/debug/tests/console/IOConsoleTests.java @@ -7,6 +7,7 @@ * * Contributors: * IBM Corporation - initial API and implementation + * Philippe Marschall <philippe.marschall@netcetera.ch> - Bug 76936 *******************************************************************************/ package org.eclipse.jdt.debug.tests.console; @@ -27,6 +28,8 @@ public class IOConsoleTests extends AbstractDebugTest implements IPatternMatchLi private int fMatchCount; private boolean fDisconnected = false; + private IConsoleManager fConsoleManager; + private MessageConsole fConsole; /** * Constructor @@ -36,35 +39,136 @@ public class IOConsoleTests extends AbstractDebugTest implements IPatternMatchLi super(name); } + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + fMatchCount = 0; + fConsole = new MessageConsole("Test console", null); + fConsole.addPatternMatchListener(this); + fConsoleManager = ConsolePlugin.getDefault().getConsoleManager(); + fConsoleManager.addConsoles(new IConsole[] { fConsole }); + } + + /* + * (non-Javadoc) + * + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void tearDown() throws Exception { + fConsoleManager.removeConsoles(new IConsole[] { fConsole }); + super.tearDown(); + } + + /** + * Tests the escape characters backspace, carriage return and line feed + * + * @throws Exception + */ + public void testControlCharacters() throws Exception { + MessageConsoleStream stream = fConsole.newMessageStream(); + stream.println("line 1"); + stream.println("fail the test\rwinn"); // winn the test + stream.println("fail not\b\b\b"); // fail not + stream.println("win not\b\b\byes"); // win yes + stream.println("win not\b\b\b\b\b\b\b\b\b\b\b\byes"); // win yes + stream.println("line\findented"); // line + // indented + stream.println("line\f\b\bindented"); // line + // indented + + stream.flush(); + waitUpTo1500Millis(); + + // no newlines at start or end + stream.print("x\b1\nx\b2\nx\b3"); + + waitUpTo1500Millis(); + stream.flush(); + + // newlines at start and end + stream.print("\nx\b1\n\nx\b2\nx\b3\n"); + + waitUpTo1500Millis(); + + // @formatter:off + assertEquals("line 1\n" + + "winn the test\n" + + "fail not\n" + + "win yes\n" + + "yes not\n" + + "line\n" + + " indented\n" + + "line\n" + + " indented\n" + + "1\n2\n3" + + "\n1\n\n2\n3\n", + fConsole.getDocument().get()); + // @formatter:on + } + + /** + * Tests overwriting the last displayed character with backspace + * + * @throws Exception + */ + public void testOverwriteLastCharacter() throws Exception { + MessageConsoleStream stream = fConsole.newMessageStream(); + stream.print("abc"); + stream.flush(); + waitUpTo1500Millis(); + assertEquals("abc", fConsole.getDocument().get()); + stream.print("\b1"); + waitUpTo1500Millis(); + + assertEquals("ab1", fConsole.getDocument().get()); + } + + /** + * Tests overwriting the last displayed line with carriage return + * + * @throws Exception + */ + public void testOverwriteLastLine() throws Exception { + MessageConsoleStream stream = fConsole.newMessageStream(); + stream.print("abc"); + stream.flush(); + waitUpTo1500Millis(); + stream.print("\rxxx"); + waitUpTo1500Millis(); + + assertEquals("xxx", fConsole.getDocument().get()); + } + /** * Tests that the pattern matcher will find a specific pattern * @throws Exception */ public void testPatternMatchListener() throws Exception { - MessageConsole console = new MessageConsole("Test console", null); - fMatchCount = 0; - console.addPatternMatchListener(this); - IConsoleManager consoleManager = ConsolePlugin.getDefault().getConsoleManager(); - consoleManager.addConsoles(new IConsole[]{console}); - try { - MessageConsoleStream stream = console.newMessageStream(); - stream.print("one foo bar"); - stream.println(); - stream.print("two foo bar"); - - long endTime = System.currentTimeMillis() + 1500; - while (!fDisconnected && System.currentTimeMillis() < endTime) { - synchronized(this) { - wait(500); - } - } - - assertEquals("Should be two foo's", 2, fMatchCount); - } finally { - consoleManager.removeConsoles(new IConsole[]{console}); - } + MessageConsoleStream stream = fConsole.newMessageStream(); + stream.print("one foo bar"); + stream.println(); + stream.print("two foo bar"); + + waitUpTo1500Millis(); + + assertEquals("Should be two foo's", 2, fMatchCount); } + private void waitUpTo1500Millis() throws InterruptedException { + long endTime = System.currentTimeMillis() + 1500; + while (!fDisconnected && System.currentTimeMillis() < endTime) { + synchronized (this) { + wait(500); + } + } + } + /** * @see org.eclipse.ui.console.IPatternMatchListener#getPattern() */ |