mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +02:00
[249102] fixed unit tests.
This commit is contained in:
parent
1a52cebfc0
commit
ce6dc5459a
2 changed files with 86 additions and 22 deletions
|
@ -0,0 +1,47 @@
|
|||
/********************************************************************************
|
||||
* Copyright (c) 2008 MontaVista Software, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Anna Dushistova (MontaVista) - [249102][testing] Improve ShellService Unittests
|
||||
********************************************************************************/
|
||||
package org.eclipse.rse.tests.subsystems.shells;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.rse.services.shells.IHostOutput;
|
||||
import org.eclipse.rse.services.shells.IHostShellChangeEvent;
|
||||
import org.eclipse.rse.services.shells.IHostShellOutputListener;
|
||||
|
||||
public class ShellOutputListener implements IHostShellOutputListener {
|
||||
|
||||
private ArrayList outputs;
|
||||
|
||||
public ShellOutputListener() {
|
||||
outputs = new ArrayList();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.rse.services.shells.IHostShellOutputListener#shellOutputChanged
|
||||
* (org.eclipse.rse.services.shells.IHostShellChangeEvent)
|
||||
*/
|
||||
public void shellOutputChanged(IHostShellChangeEvent event) {
|
||||
IHostOutput[] output = event.getLines();
|
||||
for (int i = 0; i < output.length; i++)
|
||||
outputs.add(output[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public Object[] getAllOutput() {
|
||||
return outputs.toArray();
|
||||
}
|
||||
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Anna Dushistova (MontaVista) - adapted from FileServiceTest
|
||||
* Anna Dushistova (MontaVista) - [249102][testing] Improve ShellService Unittests
|
||||
*******************************************************************************/
|
||||
package org.eclipse.rse.tests.subsystems.shells;
|
||||
|
||||
|
@ -22,15 +23,12 @@ import org.eclipse.rse.core.model.IHost;
|
|||
import org.eclipse.rse.core.subsystems.ISubSystem;
|
||||
import org.eclipse.rse.services.shells.IHostOutput;
|
||||
import org.eclipse.rse.services.shells.IHostShell;
|
||||
import org.eclipse.rse.services.shells.IHostShellChangeEvent;
|
||||
import org.eclipse.rse.services.shells.IHostShellOutputListener;
|
||||
import org.eclipse.rse.services.shells.IShellService;
|
||||
import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.IShellServiceSubSystem;
|
||||
import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.ShellServiceSubSystem;
|
||||
import org.eclipse.rse.tests.core.connection.RSEBaseConnectionTestCase;
|
||||
|
||||
public class ShellServiceTest extends RSEBaseConnectionTestCase implements
|
||||
IHostShellOutputListener {
|
||||
public class ShellServiceTest extends RSEBaseConnectionTestCase {
|
||||
|
||||
private String fPropertiesFileName;
|
||||
// For testing the test: verify methods on Local
|
||||
|
@ -42,7 +40,7 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase implements
|
|||
|
||||
/**
|
||||
* Constructor with specific test name.
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* test to execute
|
||||
*/
|
||||
|
@ -52,7 +50,7 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase implements
|
|||
|
||||
/**
|
||||
* Constructor with connection type and specific test name.
|
||||
*
|
||||
*
|
||||
* @param name
|
||||
* test to execute
|
||||
* @param propertiesFileName
|
||||
|
@ -130,27 +128,46 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase implements
|
|||
mon);
|
||||
assertNotNull(hostShell);
|
||||
assertNotNull(hostShell.getStandardOutputReader());
|
||||
|
||||
ShellOutputListener outputListener = new ShellOutputListener();
|
||||
hostShell.addOutputListener(outputListener);
|
||||
// run command
|
||||
hostShell.writeToShell("echo test");
|
||||
hostShell.writeToShell("exit");
|
||||
while (hostShell.isActive()) {
|
||||
Thread.sleep(200);
|
||||
}
|
||||
Object[] allOutput = outputListener.getAllOutput();
|
||||
boolean matchFound = false;
|
||||
for (int i = 0; i < allOutput.length; i++) {
|
||||
matchFound = ((IHostOutput) allOutput[i]).getString()
|
||||
.equals("test");
|
||||
if (matchFound)
|
||||
break;
|
||||
}
|
||||
assertTrue(matchFound);
|
||||
}
|
||||
|
||||
public void testRunCommand() throws Exception {
|
||||
IHostShell hostShell = null;
|
||||
if (!isWindows()) {
|
||||
hostShell = shellService.runCommand("", "echo test",
|
||||
new String[] {}, mon);
|
||||
hostShell.addOutputListener(this);
|
||||
assertNotNull(hostShell);
|
||||
assertNotNull(hostShell.getStandardOutputReader());
|
||||
while (hostShell.isActive()) {
|
||||
Thread.sleep(200);
|
||||
}
|
||||
hostShell = shellService.runCommand("", "echo test", new String[] {},
|
||||
mon);
|
||||
ShellOutputListener outputListener = new ShellOutputListener();
|
||||
hostShell.addOutputListener(outputListener);
|
||||
hostShell.writeToShell("exit");
|
||||
assertNotNull(hostShell);
|
||||
assertNotNull(hostShell.getStandardOutputReader());
|
||||
while (hostShell.isActive()) {
|
||||
Thread.sleep(200);
|
||||
}
|
||||
Object[] allOutput = outputListener.getAllOutput();
|
||||
boolean matchFound = false;
|
||||
for (int i = 0; i < allOutput.length; i++) {
|
||||
matchFound = ((IHostOutput) allOutput[i]).getString()
|
||||
.equals("test");
|
||||
if (matchFound)
|
||||
break;
|
||||
}
|
||||
assertTrue(matchFound);
|
||||
}
|
||||
|
||||
public void shellOutputChanged(IHostShellChangeEvent event) {
|
||||
IHostOutput[] output = event.getLines();
|
||||
if (output.length > 0) {
|
||||
assertEquals(output[0].getString(), "test");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue