|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2007 Wind River Systems, Inc. and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* Michael Scharf (Wind River) - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.tm.internal.terminal.connector; |
| 12 |
|
| 13 |
import java.io.OutputStream; |
| 14 |
|
| 15 |
import junit.framework.TestCase; |
| 16 |
|
| 17 |
import org.eclipse.swt.widgets.Composite; |
| 18 |
import org.eclipse.swt.widgets.Shell; |
| 19 |
import org.eclipse.tm.internal.terminal.connector.TerminalConnector.Factory; |
| 20 |
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage; |
| 21 |
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore; |
| 22 |
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl; |
| 23 |
import org.eclipse.tm.internal.terminal.provisional.api.TerminalConnectorImpl; |
| 24 |
import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; |
| 25 |
|
| 26 |
public class TerminalConnectorTest extends TestCase { |
| 27 |
public class SettingsMock implements ISettingsStore { |
| 28 |
|
| 29 |
public String get(String key) { |
| 30 |
return null; |
| 31 |
} |
| 32 |
|
| 33 |
public String get(String key, String defaultValue) { |
| 34 |
return null; |
| 35 |
} |
| 36 |
|
| 37 |
public void put(String key, String value) { |
| 38 |
} |
| 39 |
|
| 40 |
} |
| 41 |
public static class TerminalControlMock implements ITerminalControl { |
| 42 |
|
| 43 |
public void displayTextInTerminal(String text) { |
| 44 |
} |
| 45 |
|
| 46 |
public OutputStream getRemoteToTerminalOutputStream() { |
| 47 |
return null; |
| 48 |
} |
| 49 |
|
| 50 |
public Shell getShell() { |
| 51 |
return null; |
| 52 |
} |
| 53 |
|
| 54 |
public TerminalState getState() { |
| 55 |
return null; |
| 56 |
} |
| 57 |
|
| 58 |
public void setMsg(String msg) { |
| 59 |
} |
| 60 |
|
| 61 |
public void setState(TerminalState state) { |
| 62 |
} |
| 63 |
|
| 64 |
public void setTerminalTitle(String title) { |
| 65 |
} |
| 66 |
|
| 67 |
} |
| 68 |
static class ConnectorMock extends TerminalConnectorImpl { |
| 69 |
|
| 70 |
public boolean fEcho; |
| 71 |
public int fWidth; |
| 72 |
public int fHeight; |
| 73 |
public ITerminalControl fControl; |
| 74 |
public ISettingsStore fSaveStore; |
| 75 |
public ISettingsStore fLoadStore; |
| 76 |
public boolean fDisconnect; |
| 77 |
|
| 78 |
public boolean isLocalEcho() { |
| 79 |
return fEcho; |
| 80 |
} |
| 81 |
public void setTerminalSize(int newWidth, int newHeight) { |
| 82 |
fWidth=newWidth; |
| 83 |
fHeight=newHeight; |
| 84 |
} |
| 85 |
public void connect(ITerminalControl control) { |
| 86 |
fControl=control; |
| 87 |
} |
| 88 |
public void disconnect() { |
| 89 |
fDisconnect=true; |
| 90 |
} |
| 91 |
|
| 92 |
public OutputStream getOutputStream() { |
| 93 |
return null; |
| 94 |
} |
| 95 |
|
| 96 |
public String getSettingsSummary() { |
| 97 |
return "Summary"; |
| 98 |
} |
| 99 |
|
| 100 |
public void load(ISettingsStore store) { |
| 101 |
fLoadStore=store; |
| 102 |
} |
| 103 |
|
| 104 |
public ISettingsPage makeSettingsPage() { |
| 105 |
return new ISettingsPage(){ |
| 106 |
public void createControl(Composite parent) { |
| 107 |
} |
| 108 |
public void loadSettings() { |
| 109 |
} |
| 110 |
public void saveSettings() { |
| 111 |
} |
| 112 |
public boolean validateSettings() { |
| 113 |
return false; |
| 114 |
}}; |
| 115 |
} |
| 116 |
|
| 117 |
public void save(ISettingsStore store) { |
| 118 |
fSaveStore=store; |
| 119 |
} |
| 120 |
} |
| 121 |
static class SimpleFactory implements Factory { |
| 122 |
final TerminalConnectorImpl fConnector; |
| 123 |
public SimpleFactory(TerminalConnectorImpl connector) { |
| 124 |
fConnector = connector; |
| 125 |
} |
| 126 |
public TerminalConnectorImpl makeConnector() throws Exception { |
| 127 |
// TODO Auto-generated method stub |
| 128 |
return fConnector; |
| 129 |
} |
| 130 |
} |
| 131 |
public void testGetInitializationErrorMessage() { |
| 132 |
TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName"); |
| 133 |
c.connect(new TerminalControlMock()); |
| 134 |
assertNull(c.getInitializationErrorMessage()); |
| 135 |
|
| 136 |
c=new TerminalConnector(new SimpleFactory(new ConnectorMock(){ |
| 137 |
public void initialize() throws Exception { |
| 138 |
throw new Exception("FAILED"); |
| 139 |
}}),"xID","xName"); |
| 140 |
c.connect(new TerminalControlMock()); |
| 141 |
assertEquals("FAILED",c.getInitializationErrorMessage()); |
| 142 |
|
| 143 |
} |
| 144 |
|
| 145 |
public void testGetIdAndName() { |
| 146 |
TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName"); |
| 147 |
assertEquals("xID", c.getId()); |
| 148 |
assertEquals("xName", c.getName()); |
| 149 |
} |
| 150 |
|
| 151 |
public void testIsInitialized() { |
| 152 |
TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName"); |
| 153 |
assertFalse(c.isInitialized()); |
| 154 |
c.getId(); |
| 155 |
assertFalse(c.isInitialized()); |
| 156 |
c.getName(); |
| 157 |
assertFalse(c.isInitialized()); |
| 158 |
c.getSettingsSummary(); |
| 159 |
assertFalse(c.isInitialized()); |
| 160 |
c.setTerminalSize(10,10); |
| 161 |
assertFalse(c.isInitialized()); |
| 162 |
c.load(null); |
| 163 |
assertFalse(c.isInitialized()); |
| 164 |
c.save(null); |
| 165 |
assertFalse(c.isInitialized()); |
| 166 |
c.getAdapter(ConnectorMock.class); |
| 167 |
assertFalse(c.isInitialized()); |
| 168 |
} |
| 169 |
|
| 170 |
public void testConnect() { |
| 171 |
TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName"); |
| 172 |
assertFalse(c.isInitialized()); |
| 173 |
c.connect(new TerminalControlMock()); |
| 174 |
assertTrue(c.isInitialized()); |
| 175 |
|
| 176 |
} |
| 177 |
|
| 178 |
public void testDisconnect() { |
| 179 |
ConnectorMock mock=new ConnectorMock(); |
| 180 |
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName"); |
| 181 |
TerminalControlMock control=new TerminalControlMock(); |
| 182 |
c.connect(control); |
| 183 |
c.disconnect(); |
| 184 |
assertTrue(mock.fDisconnect); |
| 185 |
} |
| 186 |
|
| 187 |
public void testGetTerminalToRemoteStream() { |
| 188 |
ConnectorMock mock=new ConnectorMock(); |
| 189 |
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName"); |
| 190 |
TerminalControlMock control=new TerminalControlMock(); |
| 191 |
c.connect(control); |
| 192 |
assertSame(mock.fControl,control); |
| 193 |
} |
| 194 |
|
| 195 |
public void testGetSettingsSummary() { |
| 196 |
TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName"); |
| 197 |
assertEquals("Not Initialized", c.getSettingsSummary()); |
| 198 |
c.connect(new TerminalControlMock()); |
| 199 |
assertEquals("Summary", c.getSettingsSummary()); |
| 200 |
} |
| 201 |
|
| 202 |
public void testIsLocalEcho() { |
| 203 |
ConnectorMock mock=new ConnectorMock(); |
| 204 |
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName"); |
| 205 |
assertFalse(c.isLocalEcho()); |
| 206 |
mock.fEcho=true; |
| 207 |
assertTrue(c.isLocalEcho()); |
| 208 |
} |
| 209 |
|
| 210 |
public void testLoad() { |
| 211 |
ConnectorMock mock=new ConnectorMock(); |
| 212 |
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName"); |
| 213 |
ISettingsStore s=new SettingsMock(); |
| 214 |
c.load(s); |
| 215 |
// the load is called after the connect... |
| 216 |
assertNull(mock.fLoadStore); |
| 217 |
c.connect(new TerminalControlMock()); |
| 218 |
assertSame(s,mock.fLoadStore); |
| 219 |
} |
| 220 |
|
| 221 |
public void testSave() { |
| 222 |
ConnectorMock mock=new ConnectorMock(); |
| 223 |
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName"); |
| 224 |
ISettingsStore s=new SettingsMock(); |
| 225 |
c.save(s); |
| 226 |
assertNull(mock.fSaveStore); |
| 227 |
c.connect(new TerminalControlMock()); |
| 228 |
c.save(s); |
| 229 |
assertSame(s,mock.fSaveStore); |
| 230 |
} |
| 231 |
|
| 232 |
public void testMakeSettingsPage() { |
| 233 |
ConnectorMock mock=new ConnectorMock(); |
| 234 |
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName"); |
| 235 |
assertNotNull(c.makeSettingsPage()); |
| 236 |
} |
| 237 |
|
| 238 |
public void testSetTerminalSize() { |
| 239 |
ConnectorMock mock=new ConnectorMock(); |
| 240 |
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName"); |
| 241 |
c.setTerminalSize(100, 200); |
| 242 |
|
| 243 |
} |
| 244 |
|
| 245 |
public void testGetAdapter() { |
| 246 |
ConnectorMock mock=new ConnectorMock(); |
| 247 |
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName"); |
| 248 |
assertNull(c.getAdapter(ConnectorMock.class)); |
| 249 |
// the load is called after the connect... |
| 250 |
c.connect(new TerminalControlMock()); |
| 251 |
|
| 252 |
assertSame(mock, c.getAdapter(ConnectorMock.class)); |
| 253 |
} |
| 254 |
|
| 255 |
} |