mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-21 21:52:10 +02:00
Modernize tm.terminal.test.
Bump BREE to Java 1.8 and fix various warnings as they are seen. Change-Id: I3fb68f164832e6fa28c088c98ba57a7506365590 Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
This commit is contained in:
parent
5e6ca30126
commit
ce7ecf4d04
28 changed files with 376 additions and 319 deletions
|
@ -1,11 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
|
||||
<accessrules>
|
||||
<accessrule kind="accessible" pattern="org/eclipse/tm/internal/terminal/**"/>
|
||||
</accessrules>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="src">
|
||||
<attributes>
|
||||
<attribute name="test" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -9,7 +9,7 @@ Require-Bundle: org.junit,
|
|||
org.eclipse.tm.terminal.control;bundle-version="4.5.0",
|
||||
org.eclipse.core.runtime,
|
||||
org.eclipse.ui
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Export-Package: org.eclipse.tm.internal.terminal.connector;x-internal:=true,
|
||||
org.eclipse.tm.internal.terminal.emulator;x-internal:=true,
|
||||
org.eclipse.tm.internal.terminal.model;x-internal:=true,
|
||||
|
|
|
@ -18,8 +18,6 @@ package org.eclipse.tm.internal.terminal.connector;
|
|||
|
||||
import java.io.OutputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
@ -28,17 +26,22 @@ import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
|
|||
import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TerminalConnectorFactoryTest extends TestCase {
|
||||
public class SettingsMock implements ISettingsStore {
|
||||
|
||||
@Override
|
||||
public String get(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String key, String defaultValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(String key, String value) {
|
||||
}
|
||||
|
||||
|
@ -46,50 +49,64 @@ public class TerminalConnectorFactoryTest extends TestCase {
|
|||
|
||||
public static class TerminalControlMock implements ITerminalControl {
|
||||
|
||||
@Override
|
||||
public void setEncoding(String encoding) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncoding() {
|
||||
return "ISO-8859-1"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayTextInTerminal(String text) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getRemoteToTerminalOutputStream() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shell getShell() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalState getState() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMsg(String msg) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(TerminalState state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTerminalTitle(String title) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupTerminal(Composite parent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectOnEnterIfClosed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConnectOnEnterIfClosed(boolean on) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVT100LineWrapping(boolean enable) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVT100LineWrapping() {
|
||||
return false;
|
||||
}
|
||||
|
@ -105,36 +122,44 @@ public class TerminalConnectorFactoryTest extends TestCase {
|
|||
public ISettingsStore fLoadStore;
|
||||
public boolean fDisconnect;
|
||||
|
||||
@Override
|
||||
public boolean isLocalEcho() {
|
||||
return fEcho;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTerminalSize(int newWidth, int newHeight) {
|
||||
fWidth = newWidth;
|
||||
fHeight = newHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(ITerminalControl control) {
|
||||
super.connect(control);
|
||||
fTerminalControl = control;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doDisconnect() {
|
||||
fDisconnect = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getTerminalToRemoteStream() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSettingsSummary() {
|
||||
return "Summary";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(ISettingsStore store) {
|
||||
fLoadStore = store;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(ISettingsStore store) {
|
||||
fSaveStore = store;
|
||||
}
|
||||
|
@ -146,6 +171,7 @@ public class TerminalConnectorFactoryTest extends TestCase {
|
|||
|
||||
protected TerminalConnector makeTerminalConnector(final TerminalConnectorImpl mock) {
|
||||
TerminalConnector c = new TerminalConnector(new TerminalConnector.Factory() {
|
||||
@Override
|
||||
public TerminalConnectorImpl makeConnector() throws Exception {
|
||||
return mock;
|
||||
}
|
||||
|
@ -159,6 +185,7 @@ public class TerminalConnectorFactoryTest extends TestCase {
|
|||
assertNull(c.getInitializationErrorMessage());
|
||||
|
||||
c = makeTerminalConnector(new ConnectorMock() {
|
||||
@Override
|
||||
public void initialize() throws Exception {
|
||||
throw new Exception("FAILED");
|
||||
}
|
||||
|
|
|
@ -18,8 +18,6 @@ package org.eclipse.tm.internal.terminal.connector;
|
|||
|
||||
import java.io.OutputStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.tm.internal.terminal.connector.TerminalConnector.Factory;
|
||||
|
@ -28,17 +26,22 @@ import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
|
|||
import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
|
||||
import org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TerminalConnectorTest extends TestCase {
|
||||
public class SettingsMock implements ISettingsStore {
|
||||
|
||||
@Override
|
||||
public String get(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(String key, String defaultValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void put(String key, String value) {
|
||||
}
|
||||
|
||||
|
@ -46,50 +49,64 @@ public class TerminalConnectorTest extends TestCase {
|
|||
|
||||
public static class TerminalControlMock implements ITerminalControl {
|
||||
|
||||
@Override
|
||||
public void setEncoding(String encoding) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEncoding() {
|
||||
return "ISO-8859-1"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayTextInTerminal(String text) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getRemoteToTerminalOutputStream() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Shell getShell() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalState getState() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMsg(String msg) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(TerminalState state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTerminalTitle(String title) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setupTerminal(Composite parent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnectOnEnterIfClosed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConnectOnEnterIfClosed(boolean on) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVT100LineWrapping(boolean enable) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVT100LineWrapping() {
|
||||
return false;
|
||||
}
|
||||
|
@ -105,36 +122,44 @@ public class TerminalConnectorTest extends TestCase {
|
|||
public ISettingsStore fLoadStore;
|
||||
public boolean fDisconnect;
|
||||
|
||||
@Override
|
||||
public boolean isLocalEcho() {
|
||||
return fEcho;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTerminalSize(int newWidth, int newHeight) {
|
||||
fWidth = newWidth;
|
||||
fHeight = newHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connect(ITerminalControl control) {
|
||||
super.connect(control);
|
||||
fTerminalControl = control;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doDisconnect() {
|
||||
fDisconnect = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getTerminalToRemoteStream() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSettingsSummary() {
|
||||
return "Summary";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(ISettingsStore store) {
|
||||
fLoadStore = store;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(ISettingsStore store) {
|
||||
fSaveStore = store;
|
||||
}
|
||||
|
@ -147,6 +172,7 @@ public class TerminalConnectorTest extends TestCase {
|
|||
fConnector = connector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalConnectorImpl makeConnector() throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
return fConnector;
|
||||
|
@ -159,6 +185,7 @@ public class TerminalConnectorTest extends TestCase {
|
|||
assertNull(c.getInitializationErrorMessage());
|
||||
|
||||
c = new TerminalConnector(new SimpleFactory(new ConnectorMock() {
|
||||
@Override
|
||||
public void initialize() throws Exception {
|
||||
throw new Exception("FAILED");
|
||||
}
|
||||
|
|
|
@ -15,12 +15,13 @@ package org.eclipse.tm.internal.terminal.connector;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TerminalToRemoteInjectionOutputStreamTest extends TestCase {
|
||||
final static String ENCODING = "UTF-8";
|
||||
final static Charset ENCODING = StandardCharsets.UTF_8;
|
||||
|
||||
/**
|
||||
* This class escapes strings coming on the original
|
||||
|
@ -29,15 +30,18 @@ public class TerminalToRemoteInjectionOutputStreamTest extends TestCase {
|
|||
*/
|
||||
class CleverInterceptor extends TerminalToRemoteInjectionOutputStream.Interceptor {
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
fOriginal.write('[');
|
||||
fOriginal.write(b);
|
||||
fOriginal.write(']');
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
fOriginal.write('[');
|
||||
fOriginal.write(b, off, len);
|
||||
|
@ -49,44 +53,45 @@ public class TerminalToRemoteInjectionOutputStreamTest extends TestCase {
|
|||
class NullInterceptor extends TerminalToRemoteInjectionOutputStream.Interceptor {
|
||||
}
|
||||
|
||||
public void testClose() throws UnsupportedEncodingException, IOException {
|
||||
public void testClose() throws IOException {
|
||||
ByteArrayOutputStream bs = new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs);
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
OutputStream os1 = s.grabOutput();
|
||||
os1.write('x');
|
||||
s.write('A');
|
||||
os1.write('y');
|
||||
s.write('B');
|
||||
os1.close();
|
||||
try (TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs)) {
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
OutputStream os1 = s.grabOutput();
|
||||
os1.write('x');
|
||||
s.write('A');
|
||||
os1.write('y');
|
||||
s.write('B');
|
||||
os1.close();
|
||||
|
||||
s.write('-');
|
||||
OutputStream os = s.grabOutput();
|
||||
// make sure the closed output does not inject anything
|
||||
try {
|
||||
os1.write('k');
|
||||
fail("...");
|
||||
} catch (Exception e) {
|
||||
s.write('-');
|
||||
OutputStream os = s.grabOutput();
|
||||
// make sure the closed output does not inject anything
|
||||
try {
|
||||
os1.write('k');
|
||||
fail("...");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
os.write('X');
|
||||
s.write('a');
|
||||
os.write('Y');
|
||||
// make sure the closed output does not inject anything
|
||||
try {
|
||||
os1.write('l');
|
||||
fail("...");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
s.write('b');
|
||||
os.close();
|
||||
assertEquals("begin:xyAB-XYab", new String(bs.toByteArray(), ENCODING));
|
||||
}
|
||||
os.write('X');
|
||||
s.write('a');
|
||||
os.write('Y');
|
||||
// make sure the closed output does not inject anything
|
||||
try {
|
||||
os1.write('l');
|
||||
fail("...");
|
||||
} catch (Exception e) {
|
||||
}
|
||||
s.write('b');
|
||||
os.close();
|
||||
assertEquals("begin:xyAB-XYab", new String(bs.toByteArray(), ENCODING));
|
||||
}
|
||||
|
||||
public void testFlush() {
|
||||
}
|
||||
|
||||
public void testWriteInt() throws UnsupportedEncodingException, IOException {
|
||||
public void testWriteInt() throws IOException {
|
||||
ByteArrayOutputStream bs = new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs);
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
|
@ -107,78 +112,79 @@ public class TerminalToRemoteInjectionOutputStreamTest extends TestCase {
|
|||
public void testWriteByteArrayIntInt() {
|
||||
}
|
||||
|
||||
public void testGrabOutput() throws UnsupportedEncodingException, IOException {
|
||||
public void testGrabOutput() throws IOException {
|
||||
ByteArrayOutputStream bs = new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs);
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
OutputStream os1 = s.grabOutput();
|
||||
OutputStream os2;
|
||||
try {
|
||||
try (TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs)) {
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
OutputStream os1 = s.grabOutput();
|
||||
OutputStream os2;
|
||||
try {
|
||||
os2 = s.grabOutput();
|
||||
fail("should fail until the foirst output is closed");
|
||||
} catch (IOException e) {
|
||||
}
|
||||
os1.close();
|
||||
os2 = s.grabOutput();
|
||||
fail("should fail until the foirst output is closed");
|
||||
} catch (IOException e) {
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
os2.write("Test".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
s.write(" west".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
os2.write(" the".getBytes(ENCODING));
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING));
|
||||
os2.close();
|
||||
assertEquals("begin:Test the west", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('!');
|
||||
assertEquals("begin:Test the west!", new String(bs.toByteArray(), ENCODING));
|
||||
}
|
||||
os1.close();
|
||||
os2 = s.grabOutput();
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
os2.write("Test".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
s.write(" west".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
os2.write(" the".getBytes(ENCODING));
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING));
|
||||
os2.close();
|
||||
assertEquals("begin:Test the west", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('!');
|
||||
assertEquals("begin:Test the west!", new String(bs.toByteArray(), ENCODING));
|
||||
|
||||
}
|
||||
|
||||
public void testGrabOutputWithCleverInterceptor() throws UnsupportedEncodingException, IOException {
|
||||
public void testGrabOutputWithCleverInterceptor() throws IOException {
|
||||
ByteArrayOutputStream bs = new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs);
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
// the injector escapes the output coming from the main stream
|
||||
OutputStream os = s.grabOutput(new CleverInterceptor());
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
os.write("Test".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
s.write(" west".getBytes(ENCODING));
|
||||
assertEquals("begin:Test[ west]", new String(bs.toByteArray(), ENCODING));
|
||||
os.write(" the".getBytes(ENCODING));
|
||||
assertEquals("begin:Test[ west] the", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('x');
|
||||
assertEquals("begin:Test[ west] the[x]", new String(bs.toByteArray(), ENCODING));
|
||||
os.close();
|
||||
assertEquals("begin:Test[ west] the[x]", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('!');
|
||||
assertEquals("begin:Test[ west] the[x]!", new String(bs.toByteArray(), ENCODING));
|
||||
|
||||
try (TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs)) {
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
// the injector escapes the output coming from the main stream
|
||||
OutputStream os = s.grabOutput(new CleverInterceptor());
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
os.write("Test".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
s.write(" west".getBytes(ENCODING));
|
||||
assertEquals("begin:Test[ west]", new String(bs.toByteArray(), ENCODING));
|
||||
os.write(" the".getBytes(ENCODING));
|
||||
assertEquals("begin:Test[ west] the", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('x');
|
||||
assertEquals("begin:Test[ west] the[x]", new String(bs.toByteArray(), ENCODING));
|
||||
os.close();
|
||||
assertEquals("begin:Test[ west] the[x]", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('!');
|
||||
assertEquals("begin:Test[ west] the[x]!", new String(bs.toByteArray(), ENCODING));
|
||||
}
|
||||
}
|
||||
|
||||
public void testGrabOutputWithNullInterceptor() throws UnsupportedEncodingException, IOException {
|
||||
public void testGrabOutputWithNullInterceptor() throws IOException {
|
||||
ByteArrayOutputStream bs = new ByteArrayOutputStream();
|
||||
TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs);
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
// bytes written to the main stream are ignored while the injector
|
||||
// is active
|
||||
OutputStream os = s.grabOutput(new NullInterceptor());
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
os.write("Test".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
s.write(" west".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
os.write(" the".getBytes(ENCODING));
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('x');
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING));
|
||||
os.close();
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('!');
|
||||
assertEquals("begin:Test the!", new String(bs.toByteArray(), ENCODING));
|
||||
try (TerminalToRemoteInjectionOutputStream s = new TerminalToRemoteInjectionOutputStream(bs)) {
|
||||
s.write("begin:".getBytes(ENCODING));
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
// bytes written to the main stream are ignored while the injector
|
||||
// is active
|
||||
OutputStream os = s.grabOutput(new NullInterceptor());
|
||||
assertEquals("begin:", new String(bs.toByteArray(), ENCODING));
|
||||
os.write("Test".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
s.write(" west".getBytes(ENCODING));
|
||||
assertEquals("begin:Test", new String(bs.toByteArray(), ENCODING));
|
||||
os.write(" the".getBytes(ENCODING));
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('x');
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING));
|
||||
os.close();
|
||||
assertEquals("begin:Test the", new String(bs.toByteArray(), ENCODING));
|
||||
s.write('!');
|
||||
assertEquals("begin:Test the!", new String(bs.toByteArray(), ENCODING));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -11,17 +11,18 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.model;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.tm.terminal.model.ITerminalTextData;
|
||||
import org.eclipse.tm.terminal.model.ITerminalTextDataReadOnly;
|
||||
import org.eclipse.tm.terminal.model.LineSegment;
|
||||
import org.eclipse.tm.terminal.model.Style;
|
||||
import org.eclipse.tm.terminal.model.StyleColor;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
abstract public class AbstractITerminalTextDataTest extends TestCase {
|
||||
abstract protected ITerminalTextData makeITerminalTextData();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
try {
|
||||
assert false;
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.tm.internal.terminal.model;
|
|||
import org.eclipse.tm.terminal.model.ITerminalTextData;
|
||||
|
||||
public class SynchronizedTerminalTextDataTest extends AbstractITerminalTextDataTest {
|
||||
@Override
|
||||
protected ITerminalTextData makeITerminalTextData() {
|
||||
return new SynchronizedTerminalTextData(new TerminalTextData());
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.tm.internal.terminal.model;
|
|||
import org.eclipse.tm.terminal.model.ITerminalTextData;
|
||||
|
||||
public class TerminalTextDataFastScrollTest extends AbstractITerminalTextDataTest {
|
||||
@Override
|
||||
protected ITerminalTextData makeITerminalTextData() {
|
||||
return new TerminalTextDataFastScroll(3);
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.tm.internal.terminal.model;
|
|||
import org.eclipse.tm.terminal.model.ITerminalTextData;
|
||||
|
||||
public class TerminalTextDataFastScrollTestMaxHeigth extends AbstractITerminalTextDataTest {
|
||||
@Override
|
||||
protected ITerminalTextData makeITerminalTextData() {
|
||||
return new TerminalTextDataFastScroll(1);
|
||||
}
|
||||
|
|
|
@ -10,13 +10,13 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.model;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.tm.terminal.model.ITerminalTextData;
|
||||
import org.eclipse.tm.terminal.model.ITerminalTextDataSnapshot;
|
||||
import org.eclipse.tm.terminal.model.Style;
|
||||
import org.eclipse.tm.terminal.model.StyleColor;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TerminalTextDataPerformanceTest extends TestCase {
|
||||
long TIME = 100;
|
||||
|
||||
|
@ -40,11 +40,7 @@ public class TerminalTextDataPerformanceTest extends TestCase {
|
|||
ITerminalTextData term = new TerminalTextData();
|
||||
ITerminalTextDataSnapshot snapshot = term.makeSnapshot();
|
||||
N = 0;
|
||||
snapshot.addListener(new ITerminalTextDataSnapshot.SnapshotOutOfDateListener() {
|
||||
public void snapshotOutOfDate(ITerminalTextDataSnapshot snapshot) {
|
||||
N++;
|
||||
}
|
||||
});
|
||||
snapshot.addListener(snapshot1 -> N++);
|
||||
method0(term, "0b");
|
||||
snapshot.updateSnapshot(true);
|
||||
}
|
||||
|
@ -88,11 +84,7 @@ public class TerminalTextDataPerformanceTest extends TestCase {
|
|||
ITerminalTextData term = new TerminalTextData();
|
||||
ITerminalTextDataSnapshot snapshot = term.makeSnapshot();
|
||||
N = 0;
|
||||
snapshot.addListener(new ITerminalTextDataSnapshot.SnapshotOutOfDateListener() {
|
||||
public void snapshotOutOfDate(ITerminalTextDataSnapshot snapshot) {
|
||||
N++;
|
||||
}
|
||||
});
|
||||
snapshot.addListener(snapshot1 -> N++);
|
||||
method1(term, "1b");
|
||||
snapshot.updateSnapshot(true);
|
||||
}
|
||||
|
@ -185,11 +177,7 @@ public class TerminalTextDataPerformanceTest extends TestCase {
|
|||
TerminalTextData term = new TerminalTextData();
|
||||
ITerminalTextDataSnapshot snapshot = term.makeSnapshot();
|
||||
N = 0;
|
||||
snapshot.addListener(new ITerminalTextDataSnapshot.SnapshotOutOfDateListener() {
|
||||
public void snapshotOutOfDate(ITerminalTextDataSnapshot snapshot) {
|
||||
N++;
|
||||
}
|
||||
});
|
||||
snapshot.addListener(snapshot1 -> N++);
|
||||
Style style = Style.getStyle(StyleColor.getStyleColor("fg"), StyleColor.getStyleColor("bg"), false, false,
|
||||
false, false);
|
||||
initPerformance(term);
|
||||
|
|
|
@ -10,14 +10,14 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.tm.internal.terminal.model;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.tm.terminal.model.ITerminalTextData;
|
||||
import org.eclipse.tm.terminal.model.ITerminalTextDataReadOnly;
|
||||
import org.eclipse.tm.terminal.model.ITerminalTextDataSnapshot;
|
||||
import org.eclipse.tm.terminal.model.Style;
|
||||
import org.eclipse.tm.terminal.model.StyleColor;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class TerminalTextDataSnapshotTest extends TestCase {
|
||||
String toMultiLineText(ITerminalTextDataReadOnly term) {
|
||||
return TerminalTextTestHelper.toMultiLineText(term);
|
||||
|
@ -794,6 +794,7 @@ public class TerminalTextDataSnapshotTest extends TestCase {
|
|||
private final class SnapshotListener implements ITerminalTextDataSnapshot.SnapshotOutOfDateListener {
|
||||
int N;
|
||||
|
||||
@Override
|
||||
public void snapshotOutOfDate(ITerminalTextDataSnapshot snapshot) {
|
||||
N++;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.tm.internal.terminal.model;
|
|||
import org.eclipse.tm.terminal.model.ITerminalTextData;
|
||||
|
||||
public class TerminalTextDataStoreTest extends AbstractITerminalTextDataTest {
|
||||
@Override
|
||||
protected ITerminalTextData makeITerminalTextData() {
|
||||
return new TerminalTextDataStore();
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ package org.eclipse.tm.internal.terminal.model;
|
|||
import org.eclipse.tm.terminal.model.ITerminalTextData;
|
||||
|
||||
public class TerminalTextDataTest extends AbstractITerminalTextDataTest {
|
||||
@Override
|
||||
protected ITerminalTextData makeITerminalTextData() {
|
||||
return new TerminalTextData();
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
fSize = 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ITerminalTextData makeITerminalTextData() {
|
||||
TerminalTextDataWindow term = new TerminalTextDataWindow();
|
||||
term.setWindow(fOffset, fSize);
|
||||
|
@ -40,6 +41,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
* @param expected
|
||||
* @param actual
|
||||
*/
|
||||
@Override
|
||||
protected void assertEqualsTerm(String expected, String actual) {
|
||||
assertEquals(stripMultiLine(expected), stripMultiLine(actual));
|
||||
}
|
||||
|
@ -48,7 +50,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
StringBuffer b = new StringBuffer();
|
||||
// String[] lines=s.split("\n");
|
||||
// <J2ME CDC-1.1 Foundation-1.1 variant>
|
||||
ArrayList<String> l = new ArrayList<String>();
|
||||
ArrayList<String> l = new ArrayList<>();
|
||||
int j = 0;
|
||||
for (int k = 0; k < s.length(); k++) {
|
||||
if (s.charAt(k) == '\n') {
|
||||
|
@ -82,6 +84,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
* @param expected
|
||||
* @param actual
|
||||
*/
|
||||
@Override
|
||||
protected void assertEqualsSimple(String expected, String actual) {
|
||||
assertEquals(stripSimple(expected), stripSimple(actual));
|
||||
}
|
||||
|
@ -97,6 +100,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
return b.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testAddLine() {
|
||||
String s = "111\n" + "222\n" + "333\n" + "444\n" + "555";
|
||||
ITerminalTextData term = makeITerminalTextData();
|
||||
|
@ -105,6 +109,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
assertEqualsTerm("222\n" + "333\n" + "444\n" + "\0\0\0\n" + "\000\000\000", toMultiLineText(term));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testMaxSize() {
|
||||
String s = "111\n" + "222\n" + "333\n" + "444\n" + "555";
|
||||
ITerminalTextData term = makeITerminalTextData();
|
||||
|
@ -130,6 +135,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
+ "\000\000\000\n" + "\000\000\000", toMultiLineText(term));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testGetLineSegments() {
|
||||
Style s1 = getDefaultStyle();
|
||||
Style s2 = s1.setBold(true);
|
||||
|
@ -178,6 +184,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testGetChar() {
|
||||
String s = "12345\n" + "abcde\n" + "ABCDE";
|
||||
ITerminalTextData term = makeITerminalTextData();
|
||||
|
@ -199,6 +206,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
assertEquals('E', term.getChar(2, 4));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testGetStyle() {
|
||||
ITerminalTextData term = makeITerminalTextData();
|
||||
Style style = getDefaultStyle();
|
||||
|
@ -221,6 +229,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testSetChar() {
|
||||
ITerminalTextData term = makeITerminalTextData();
|
||||
term.setDimensions(6, 3);
|
||||
|
@ -240,6 +249,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
assertEqualsTerm("abc\n" + "bcd\n" + "cde\n" + "def\n" + "efg\n" + "fgh", toMultiLineText(term));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testSetChars() {
|
||||
ITerminalTextData term = makeITerminalTextData();
|
||||
term.setDimensions(6, 3);
|
||||
|
@ -268,6 +278,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testSetCharsLen() {
|
||||
ITerminalTextData term = makeITerminalTextData();
|
||||
String s = "ZYXWVU\n" + "abcdef\n" + "ABCDEF";
|
||||
|
@ -295,6 +306,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
fill(term, s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testSetCopyLines() {
|
||||
ITerminalTextData term = new TerminalTextDataStore();
|
||||
String s = "012345";
|
||||
|
@ -337,6 +349,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
assertEqualsSimple("a2345", toSimple(termCopy));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testScrollNegative() {
|
||||
scrollTest(0, 2, -1, " 23 ", " 23 ");
|
||||
scrollTest(0, 1, -1, " 23 ", " 23 ");
|
||||
|
@ -351,6 +364,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
scrollTest(5, 1, -1, " 23 ", " 23 ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testScrollAll() {
|
||||
scrollTest(0, 6, 1, " 2345", " 2 ");
|
||||
scrollTest(0, 6, -1, " 2345", " 3 ");
|
||||
|
@ -358,6 +372,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
scrollTest(0, 6, -2, " 2345", " ");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testCopyLineWithOffset() {
|
||||
ITerminalTextData term = makeITerminalTextData();
|
||||
String s = "111\n" + "222\n" + "333\n" + "444\n" + "555";
|
||||
|
@ -393,6 +408,7 @@ public class TerminalTextDataWindowTest extends AbstractITerminalTextDataTest {
|
|||
term.copy(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testWrappedLines() {
|
||||
ITerminalTextData term = makeITerminalTextData();
|
||||
term.setDimensions(4, 4);
|
||||
|
|
|
@ -34,6 +34,7 @@ public class SpeedTestConnection extends Thread {
|
|||
fSettings = settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
fControl.setState(TerminalState.CONNECTED);
|
||||
|
||||
|
@ -113,11 +114,7 @@ public class SpeedTestConnection extends Thread {
|
|||
}
|
||||
|
||||
private void setTitle(final String title) {
|
||||
Display.getDefault().asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
fControl.setTerminalTitle(title);
|
||||
}
|
||||
});
|
||||
Display.getDefault().asyncExec(() -> fControl.setTerminalTitle(title));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ public class SpeedTestConnector extends TerminalConnectorImpl {
|
|||
public SpeedTestConnector() {
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void connect(ITerminalControl control) {
|
||||
super.connect(control);
|
||||
fControl.setState(TerminalState.CONNECTING);
|
||||
|
@ -52,6 +53,7 @@ public class SpeedTestConnector extends TerminalConnectorImpl {
|
|||
fConnection.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void doDisconnect() {
|
||||
if (fConnection != null) {
|
||||
fConnection.interrupt();
|
||||
|
@ -79,10 +81,12 @@ public class SpeedTestConnector extends TerminalConnectorImpl {
|
|||
return fInputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public OutputStream getTerminalToRemoteStream() {
|
||||
return fOutputStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSettingsSummary() {
|
||||
return fSettings.getInputFile();
|
||||
}
|
||||
|
@ -92,14 +96,17 @@ public class SpeedTestConnector extends TerminalConnectorImpl {
|
|||
fSettings.load(new NullSettingsStore());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(ISettingsStore store) {
|
||||
fSettings.load(store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(ISettingsStore store) {
|
||||
fSettings.save(store);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTerminalSize(int newWidth, int newHeight) {
|
||||
}
|
||||
|
||||
|
|
|
@ -26,9 +26,7 @@ import org.eclipse.swt.graphics.Rectangle;
|
|||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.widgets.Canvas;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.ScrollBar;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
|
@ -49,64 +47,56 @@ public class Snippet48 {
|
|||
final Point origin = new Point(0, 0);
|
||||
final Canvas canvas = new Canvas(shell, SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE | SWT.V_SCROLL | SWT.H_SCROLL);
|
||||
final ScrollBar hBar = canvas.getHorizontalBar();
|
||||
hBar.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
int hSelection = hBar.getSelection();
|
||||
int destX = -hSelection - origin.x;
|
||||
Rectangle rect = image.getBounds();
|
||||
canvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false);
|
||||
origin.x = -hSelection;
|
||||
}
|
||||
hBar.addListener(SWT.Selection, e -> {
|
||||
int hSelection = hBar.getSelection();
|
||||
int destX = -hSelection - origin.x;
|
||||
Rectangle rect = image.getBounds();
|
||||
canvas.scroll(destX, 0, 0, 0, rect.width, rect.height, false);
|
||||
origin.x = -hSelection;
|
||||
});
|
||||
final ScrollBar vBar = canvas.getVerticalBar();
|
||||
vBar.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
int vSelection = vBar.getSelection();
|
||||
int destY = -vSelection - origin.y;
|
||||
Rectangle rect = image.getBounds();
|
||||
canvas.scroll(0, destY, 0, 0, rect.width, rect.height, false);
|
||||
vBar.addListener(SWT.Selection, e -> {
|
||||
int vSelection = vBar.getSelection();
|
||||
int destY = -vSelection - origin.y;
|
||||
Rectangle rect = image.getBounds();
|
||||
canvas.scroll(0, destY, 0, 0, rect.width, rect.height, false);
|
||||
origin.y = -vSelection;
|
||||
});
|
||||
canvas.addListener(SWT.Resize, e -> {
|
||||
Rectangle rect = image.getBounds();
|
||||
Rectangle client = canvas.getClientArea();
|
||||
hBar.setMaximum(rect.width);
|
||||
vBar.setMaximum(rect.height);
|
||||
hBar.setThumb(Math.min(rect.width, client.width));
|
||||
vBar.setThumb(Math.min(rect.height, client.height));
|
||||
int hPage = rect.width - client.width;
|
||||
int vPage = rect.height - client.height;
|
||||
int hSelection = hBar.getSelection();
|
||||
int vSelection = vBar.getSelection();
|
||||
if (hSelection >= hPage) {
|
||||
if (hPage <= 0)
|
||||
hSelection = 0;
|
||||
origin.x = -hSelection;
|
||||
}
|
||||
if (vSelection >= vPage) {
|
||||
if (vPage <= 0)
|
||||
vSelection = 0;
|
||||
origin.y = -vSelection;
|
||||
}
|
||||
canvas.redraw();
|
||||
});
|
||||
canvas.addListener(SWT.Resize, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
Rectangle rect = image.getBounds();
|
||||
Rectangle client = canvas.getClientArea();
|
||||
hBar.setMaximum(rect.width);
|
||||
vBar.setMaximum(rect.height);
|
||||
hBar.setThumb(Math.min(rect.width, client.width));
|
||||
vBar.setThumb(Math.min(rect.height, client.height));
|
||||
int hPage = rect.width - client.width;
|
||||
int vPage = rect.height - client.height;
|
||||
int hSelection = hBar.getSelection();
|
||||
int vSelection = vBar.getSelection();
|
||||
if (hSelection >= hPage) {
|
||||
if (hPage <= 0)
|
||||
hSelection = 0;
|
||||
origin.x = -hSelection;
|
||||
}
|
||||
if (vSelection >= vPage) {
|
||||
if (vPage <= 0)
|
||||
vSelection = 0;
|
||||
origin.y = -vSelection;
|
||||
}
|
||||
canvas.redraw();
|
||||
canvas.addListener(SWT.Paint, e -> {
|
||||
GC gc = e.gc;
|
||||
gc.drawImage(image, origin.x, origin.y);
|
||||
Rectangle rect = image.getBounds();
|
||||
Rectangle client = canvas.getClientArea();
|
||||
int marginWidth = client.width - rect.width;
|
||||
if (marginWidth > 0) {
|
||||
gc.fillRectangle(rect.width, 0, marginWidth, client.height);
|
||||
}
|
||||
});
|
||||
canvas.addListener(SWT.Paint, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
GC gc = e.gc;
|
||||
gc.drawImage(image, origin.x, origin.y);
|
||||
Rectangle rect = image.getBounds();
|
||||
Rectangle client = canvas.getClientArea();
|
||||
int marginWidth = client.width - rect.width;
|
||||
if (marginWidth > 0) {
|
||||
gc.fillRectangle(rect.width, 0, marginWidth, client.height);
|
||||
}
|
||||
int marginHeight = client.height - rect.height;
|
||||
if (marginHeight > 0) {
|
||||
gc.fillRectangle(0, rect.height, client.width, marginHeight);
|
||||
}
|
||||
int marginHeight = client.height - rect.height;
|
||||
if (marginHeight > 0) {
|
||||
gc.fillRectangle(0, rect.height, client.width, marginHeight);
|
||||
}
|
||||
});
|
||||
shell.setSize(200, 150);
|
||||
|
|
|
@ -17,9 +17,7 @@ import org.eclipse.swt.graphics.Point;
|
|||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Canvas;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.ScrollBar;
|
||||
|
||||
public class TerminalTextCanvas extends Canvas {
|
||||
|
@ -31,65 +29,57 @@ public class TerminalTextCanvas extends Canvas {
|
|||
loadImage(parent);
|
||||
|
||||
final ScrollBar hBar = getHorizontalBar();
|
||||
hBar.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
int hSelection = hBar.getSelection();
|
||||
int destX = -hSelection - origin.x;
|
||||
Rectangle rect = image.getBounds();
|
||||
scroll(destX, 0, 0, 0, rect.width, rect.height, false);
|
||||
origin.x = -hSelection;
|
||||
}
|
||||
hBar.addListener(SWT.Selection, e -> {
|
||||
int hSelection = hBar.getSelection();
|
||||
int destX = -hSelection - origin.x;
|
||||
Rectangle rect = image.getBounds();
|
||||
scroll(destX, 0, 0, 0, rect.width, rect.height, false);
|
||||
origin.x = -hSelection;
|
||||
});
|
||||
final ScrollBar vBar = getVerticalBar();
|
||||
vBar.addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
int vSelection = vBar.getSelection();
|
||||
int destY = -vSelection - origin.y;
|
||||
Rectangle rect = image.getBounds();
|
||||
scroll(0, destY, 0, 0, rect.width, rect.height, false);
|
||||
vBar.addListener(SWT.Selection, e -> {
|
||||
int vSelection = vBar.getSelection();
|
||||
int destY = -vSelection - origin.y;
|
||||
Rectangle rect = image.getBounds();
|
||||
scroll(0, destY, 0, 0, rect.width, rect.height, false);
|
||||
origin.y = -vSelection;
|
||||
});
|
||||
addListener(SWT.Resize, e -> {
|
||||
Rectangle rect = image.getBounds();
|
||||
Rectangle client = getClientArea();
|
||||
hBar.setMaximum(rect.width);
|
||||
vBar.setMaximum(rect.height);
|
||||
hBar.setThumb(Math.min(rect.width, client.width));
|
||||
vBar.setThumb(Math.min(rect.height, client.height));
|
||||
int hPage = rect.width - client.width;
|
||||
int vPage = rect.height - client.height;
|
||||
int hSelection = hBar.getSelection();
|
||||
int vSelection = vBar.getSelection();
|
||||
if (hSelection >= hPage) {
|
||||
if (hPage <= 0)
|
||||
hSelection = 0;
|
||||
origin.x = -hSelection;
|
||||
}
|
||||
if (vSelection >= vPage) {
|
||||
if (vPage <= 0)
|
||||
vSelection = 0;
|
||||
origin.y = -vSelection;
|
||||
}
|
||||
redraw();
|
||||
});
|
||||
addListener(SWT.Resize, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
Rectangle rect = image.getBounds();
|
||||
Rectangle client = getClientArea();
|
||||
hBar.setMaximum(rect.width);
|
||||
vBar.setMaximum(rect.height);
|
||||
hBar.setThumb(Math.min(rect.width, client.width));
|
||||
vBar.setThumb(Math.min(rect.height, client.height));
|
||||
int hPage = rect.width - client.width;
|
||||
int vPage = rect.height - client.height;
|
||||
int hSelection = hBar.getSelection();
|
||||
int vSelection = vBar.getSelection();
|
||||
if (hSelection >= hPage) {
|
||||
if (hPage <= 0)
|
||||
hSelection = 0;
|
||||
origin.x = -hSelection;
|
||||
}
|
||||
if (vSelection >= vPage) {
|
||||
if (vPage <= 0)
|
||||
vSelection = 0;
|
||||
origin.y = -vSelection;
|
||||
}
|
||||
redraw();
|
||||
addListener(SWT.Paint, e -> {
|
||||
GC gc = e.gc;
|
||||
System.out.println(gc.getClipping() + " " + origin);
|
||||
gc.drawImage(image, origin.x, origin.y);
|
||||
Rectangle rect = image.getBounds();
|
||||
Rectangle client = getClientArea();
|
||||
int marginWidth = client.width - rect.width;
|
||||
if (marginWidth > 0) {
|
||||
gc.fillRectangle(rect.width, 0, marginWidth, client.height);
|
||||
}
|
||||
});
|
||||
addListener(SWT.Paint, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
GC gc = e.gc;
|
||||
System.out.println(gc.getClipping() + " " + origin);
|
||||
gc.drawImage(image, origin.x, origin.y);
|
||||
Rectangle rect = image.getBounds();
|
||||
Rectangle client = getClientArea();
|
||||
int marginWidth = client.width - rect.width;
|
||||
if (marginWidth > 0) {
|
||||
gc.fillRectangle(rect.width, 0, marginWidth, client.height);
|
||||
}
|
||||
int marginHeight = client.height - rect.height;
|
||||
if (marginHeight > 0) {
|
||||
gc.fillRectangle(0, rect.height, client.width, marginHeight);
|
||||
}
|
||||
int marginHeight = client.height - rect.height;
|
||||
if (marginHeight > 0) {
|
||||
gc.fillRectangle(0, rect.height, client.width, marginHeight);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
package org.eclipse.tm.internal.terminal.test.terminalcanvas;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.DisposeEvent;
|
||||
import org.eclipse.swt.events.DisposeListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
|
@ -20,7 +18,6 @@ import org.eclipse.swt.graphics.Rectangle;
|
|||
import org.eclipse.swt.widgets.Canvas;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.ScrollBar;
|
||||
|
||||
/**
|
||||
|
@ -37,40 +34,26 @@ public abstract class VirtualCanvas extends Canvas {
|
|||
public VirtualCanvas(Composite parent, int style) {
|
||||
super(parent, style | SWT.NO_BACKGROUND | SWT.NO_REDRAW_RESIZE);
|
||||
fPaintGC = new GC(this);
|
||||
addListener(SWT.Paint, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
paint(event.gc);
|
||||
}
|
||||
addListener(SWT.Paint, event -> paint(event.gc));
|
||||
addListener(SWT.Resize, event -> {
|
||||
fClientArea = getClientArea();
|
||||
updateViewRectangle();
|
||||
});
|
||||
addListener(SWT.Resize, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
fClientArea = getClientArea();
|
||||
updateViewRectangle();
|
||||
}
|
||||
});
|
||||
getVerticalBar().addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
scrollY((ScrollBar) e.widget);
|
||||
postScrollEventHandling(e);
|
||||
|
||||
}
|
||||
getVerticalBar().addListener(SWT.Selection, e -> {
|
||||
scrollY((ScrollBar) e.widget);
|
||||
postScrollEventHandling(e);
|
||||
|
||||
});
|
||||
getHorizontalBar().addListener(SWT.Selection, new Listener() {
|
||||
public void handleEvent(Event e) {
|
||||
scrollX((ScrollBar) e.widget);
|
||||
postScrollEventHandling(e);
|
||||
getHorizontalBar().addListener(SWT.Selection, e -> {
|
||||
scrollX((ScrollBar) e.widget);
|
||||
postScrollEventHandling(e);
|
||||
|
||||
}
|
||||
});
|
||||
addDisposeListener(new DisposeListener() {
|
||||
public void widgetDisposed(DisposeEvent e) {
|
||||
if (fPaintGC != null) {
|
||||
fPaintGC.dispose();
|
||||
fPaintGC = null;
|
||||
}
|
||||
addDisposeListener(e -> {
|
||||
if (fPaintGC != null) {
|
||||
fPaintGC.dispose();
|
||||
fPaintGC = null;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ abstract class AbstractLineOrientedDataSource implements IDataSource {
|
|||
|
||||
abstract public void next();
|
||||
|
||||
@Override
|
||||
public int step(ITerminalTextData terminal) {
|
||||
next();
|
||||
char[] chars = dataSource();
|
||||
|
|
|
@ -32,6 +32,7 @@ class DataReader implements Runnable {
|
|||
fThread.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long t0 = System.currentTimeMillis() - 1;
|
||||
long c = 0;
|
||||
|
|
|
@ -19,14 +19,17 @@ final class FastDataSource extends AbstractLineOrientedDataSource {
|
|||
|
||||
int pos;
|
||||
|
||||
@Override
|
||||
public char[] dataSource() {
|
||||
return lines[pos % lines.length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Style getStyle() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next() {
|
||||
pos++;
|
||||
}
|
||||
|
|
|
@ -39,14 +39,17 @@ final class FileDataSource extends AbstractLineOrientedDataSource {
|
|||
fFile = file;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char[] dataSource() {
|
||||
return line.toCharArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Style getStyle() {
|
||||
return style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next() {
|
||||
try {
|
||||
if (reader == null)
|
||||
|
|
|
@ -23,15 +23,18 @@ final class LineCountingDataSource extends AbstractLineOrientedDataSource {
|
|||
|
||||
int pos;
|
||||
|
||||
@Override
|
||||
public char[] dataSource() {
|
||||
return (pos + " 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789")
|
||||
.toCharArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Style getStyle() {
|
||||
return styles[pos % styles.length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void next() {
|
||||
pos++;
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ public class RandomDataSource implements IDataSource {
|
|||
styleNormal.setReverse(true), styleNormal.setReverse(true).setBold(true),
|
||||
styleNormal.setReverse(true).setUnderline(true) };
|
||||
|
||||
@Override
|
||||
public int step(ITerminalTextData terminal) {
|
||||
int N = fRandom.nextInt(1000);
|
||||
int h = terminal.getHeight();
|
||||
|
|
|
@ -16,8 +16,6 @@ import java.util.Iterator;
|
|||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
|
@ -55,13 +53,12 @@ public class TerminalTextUITest {
|
|||
private static Text heightText;
|
||||
|
||||
static class Status implements IStatus {
|
||||
@Override
|
||||
public void setStatus(final String s) {
|
||||
if (!fStatusLabel.isDisposed())
|
||||
Display.getDefault().asyncExec(new Runnable() {
|
||||
public void run() {
|
||||
if (!fStatusLabel.isDisposed())
|
||||
fStatusLabel.setText(s);
|
||||
}
|
||||
Display.getDefault().asyncExec(() -> {
|
||||
if (!fStatusLabel.isDisposed())
|
||||
fStatusLabel.setText(s);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -129,19 +126,17 @@ public class TerminalTextUITest {
|
|||
addLabel(composite, "maxHeight:");
|
||||
final Text maxHeightText = new Text(composite, SWT.BORDER);
|
||||
setLayoutData(maxHeightText, 30);
|
||||
maxHeightText.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
synchronized (fTerminalModel) {
|
||||
int height = textToInt(maxHeightText);
|
||||
if (height < 1)
|
||||
return;
|
||||
if (fTerminalModel.getHeight() > height) {
|
||||
fTerminalModel.scroll(0, fTerminalModel.getHeight(), height - fTerminalModel.getHeight());
|
||||
fTerminalModel.setDimensions(height, fTerminalModel.getWidth());
|
||||
heightText.setText(height + "");
|
||||
}
|
||||
fTerminalModel.setMaxHeight(height);
|
||||
maxHeightText.addModifyListener(e -> {
|
||||
synchronized (fTerminalModel) {
|
||||
int height = textToInt(maxHeightText);
|
||||
if (height < 1)
|
||||
return;
|
||||
if (fTerminalModel.getHeight() > height) {
|
||||
fTerminalModel.scroll(0, fTerminalModel.getHeight(), height - fTerminalModel.getHeight());
|
||||
fTerminalModel.setDimensions(height, fTerminalModel.getWidth());
|
||||
heightText.setText(height + "");
|
||||
}
|
||||
fTerminalModel.setMaxHeight(height);
|
||||
}
|
||||
});
|
||||
maxHeightText.setText(fHeight + "");
|
||||
|
@ -152,16 +147,14 @@ public class TerminalTextUITest {
|
|||
addLabel(composite, "heigth:");
|
||||
heightText = new Text(composite, SWT.BORDER);
|
||||
setLayoutData(heightText, 30);
|
||||
heightText.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
synchronized (fTerminalModel) {
|
||||
int height = textToInt(heightText);
|
||||
if (height < 1)
|
||||
return;
|
||||
maxHeightText.setText("" + height);
|
||||
fTerminalModel.setDimensions(height, fTerminalModel.getWidth());
|
||||
fTerminalModel.setMaxHeight(height);
|
||||
}
|
||||
heightText.addModifyListener(e -> {
|
||||
synchronized (fTerminalModel) {
|
||||
int height = textToInt(heightText);
|
||||
if (height < 1)
|
||||
return;
|
||||
maxHeightText.setText("" + height);
|
||||
fTerminalModel.setDimensions(height, fTerminalModel.getWidth());
|
||||
fTerminalModel.setMaxHeight(height);
|
||||
}
|
||||
});
|
||||
heightText.setText(fHeight + "");
|
||||
|
@ -171,13 +164,11 @@ public class TerminalTextUITest {
|
|||
addLabel(composite, "width:");
|
||||
final Text widthText = new Text(composite, SWT.BORDER);
|
||||
setLayoutData(widthText, 30);
|
||||
widthText.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
synchronized (fTerminalModel) {
|
||||
int width = textToInt(widthText);
|
||||
if (width > 1)
|
||||
fTerminalModel.setDimensions(fTerminalModel.getHeight(), width);
|
||||
}
|
||||
widthText.addModifyListener(e -> {
|
||||
synchronized (fTerminalModel) {
|
||||
int width = textToInt(widthText);
|
||||
if (width > 1)
|
||||
fTerminalModel.setDimensions(fTerminalModel.getHeight(), width);
|
||||
}
|
||||
});
|
||||
widthText.setText(fWidth + "");
|
||||
|
@ -188,12 +179,10 @@ public class TerminalTextUITest {
|
|||
addLabel(composite, "throttle:");
|
||||
final Text throttleText = new Text(composite, SWT.BORDER);
|
||||
setLayoutData(throttleText, 30);
|
||||
throttleText.addModifyListener(new ModifyListener() {
|
||||
public void modifyText(ModifyEvent e) {
|
||||
synchronized (fTerminalModel) {
|
||||
int throttle = textToInt(throttleText);
|
||||
setThrottleForAll(throttle);
|
||||
}
|
||||
throttleText.addModifyListener(e -> {
|
||||
synchronized (fTerminalModel) {
|
||||
int throttle = textToInt(throttleText);
|
||||
setThrottleForAll(throttle);
|
||||
}
|
||||
});
|
||||
return throttleText;
|
||||
|
@ -204,6 +193,7 @@ public class TerminalTextUITest {
|
|||
stopAllButton.setText("Stop ALL");
|
||||
stopAllButton.addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
boolean stop = stopAllButton.getSelection();
|
||||
for (Iterator iterator = fDataReaders.iterator(); iterator.hasNext();) {
|
||||
|
@ -220,6 +210,7 @@ public class TerminalTextUITest {
|
|||
final Button button = new Button(composite, SWT.CHECK);
|
||||
button.setText("ScrollLock");
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
boolean scrollLock = button.getSelection();
|
||||
fgTextCanvas.setScrollLock(scrollLock);
|
||||
|
@ -240,6 +231,7 @@ public class TerminalTextUITest {
|
|||
button.setText(reader.getName());
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
reader.setStart(button.getSelection());
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ import java.io.InputStream;
|
|||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Reader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.eclipse.tm.internal.terminal.control.impl.ITerminalControlForText;
|
||||
import org.eclipse.tm.internal.terminal.emulator.VT100Emulator;
|
||||
|
@ -55,16 +55,19 @@ final class VT100DataSource implements IDataSource {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return fAvailable;
|
||||
}
|
||||
|
||||
private InputStream fInputStream;
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
while (fAvailable == 0) {
|
||||
try {
|
||||
|
@ -87,12 +90,7 @@ final class VT100DataSource implements IDataSource {
|
|||
}
|
||||
|
||||
void init(ITerminalTextData terminal) {
|
||||
final Reader reader;
|
||||
try {
|
||||
reader = new InputStreamReader(new InfiniteFileInputStream(), "ISO-8859-1"); //$NON-NLS-1$
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
final Reader reader = new InputStreamReader(new InfiniteFileInputStream(), StandardCharsets.ISO_8859_1);
|
||||
fEmulator = new VT100Emulator(terminal, new ITerminalControlForText() {
|
||||
|
||||
public void disconnectTerminal() {
|
||||
|
@ -100,29 +98,36 @@ final class VT100DataSource implements IDataSource {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream getOutputStream() {
|
||||
return new ByteArrayOutputStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TerminalState getState() {
|
||||
return TerminalState.CONNECTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITerminalConnector getTerminalConnector() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setState(TerminalState state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTerminalTitle(String title) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableApplicationCursorKeys(boolean enable) {
|
||||
}
|
||||
}, reader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int step(ITerminalTextData terminal) {
|
||||
synchronized (terminal) {
|
||||
if (fEmulator == null) {
|
||||
|
|
|
@ -17,7 +17,7 @@ import java.io.InputStream;
|
|||
import java.io.OutputStream;
|
||||
|
||||
class PipedStreamTest {
|
||||
static class ReadThread extends Thread implements Runnable {
|
||||
static class ReadThread extends Thread {
|
||||
|
||||
InputStream pi = null;
|
||||
|
||||
|
@ -29,6 +29,7 @@ class PipedStreamTest {
|
|||
setDaemon(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
byte[] buffer = new byte[2048];
|
||||
int bytes_read;
|
||||
|
@ -56,6 +57,7 @@ class PipedStreamTest {
|
|||
N = n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
if (N == 0)
|
||||
return -1;
|
||||
|
@ -67,6 +69,7 @@ class PipedStreamTest {
|
|||
return n;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
@ -74,6 +77,7 @@ class PipedStreamTest {
|
|||
/*
|
||||
* available has to be implemented!
|
||||
*/
|
||||
@Override
|
||||
public int available() throws IOException {
|
||||
return N;
|
||||
}
|
||||
|
@ -82,10 +86,12 @@ class PipedStreamTest {
|
|||
static class FakeOutputStream extends OutputStream {
|
||||
long N;
|
||||
|
||||
@Override
|
||||
public void write(int b) throws IOException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
N += len;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue