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:
|
* Contributors:
|
||||||
* Anna Dushistova (MontaVista) - adapted from FileServiceTest
|
* Anna Dushistova (MontaVista) - adapted from FileServiceTest
|
||||||
|
* Anna Dushistova (MontaVista) - [249102][testing] Improve ShellService Unittests
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.rse.tests.subsystems.shells;
|
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.core.subsystems.ISubSystem;
|
||||||
import org.eclipse.rse.services.shells.IHostOutput;
|
import org.eclipse.rse.services.shells.IHostOutput;
|
||||||
import org.eclipse.rse.services.shells.IHostShell;
|
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.services.shells.IShellService;
|
||||||
import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.IShellServiceSubSystem;
|
import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.IShellServiceSubSystem;
|
||||||
import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.ShellServiceSubSystem;
|
import org.eclipse.rse.subsystems.shells.core.subsystems.servicesubsystem.ShellServiceSubSystem;
|
||||||
import org.eclipse.rse.tests.core.connection.RSEBaseConnectionTestCase;
|
import org.eclipse.rse.tests.core.connection.RSEBaseConnectionTestCase;
|
||||||
|
|
||||||
public class ShellServiceTest extends RSEBaseConnectionTestCase implements
|
public class ShellServiceTest extends RSEBaseConnectionTestCase {
|
||||||
IHostShellOutputListener {
|
|
||||||
|
|
||||||
private String fPropertiesFileName;
|
private String fPropertiesFileName;
|
||||||
// For testing the test: verify methods on Local
|
// For testing the test: verify methods on Local
|
||||||
|
@ -42,7 +40,7 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase implements
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor with specific test name.
|
* Constructor with specific test name.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* test to execute
|
* test to execute
|
||||||
*/
|
*/
|
||||||
|
@ -52,7 +50,7 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase implements
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor with connection type and specific test name.
|
* Constructor with connection type and specific test name.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* test to execute
|
* test to execute
|
||||||
* @param propertiesFileName
|
* @param propertiesFileName
|
||||||
|
@ -130,27 +128,46 @@ public class ShellServiceTest extends RSEBaseConnectionTestCase implements
|
||||||
mon);
|
mon);
|
||||||
assertNotNull(hostShell);
|
assertNotNull(hostShell);
|
||||||
assertNotNull(hostShell.getStandardOutputReader());
|
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 {
|
public void testRunCommand() throws Exception {
|
||||||
IHostShell hostShell = null;
|
IHostShell hostShell = null;
|
||||||
if (!isWindows()) {
|
hostShell = shellService.runCommand("", "echo test", new String[] {},
|
||||||
hostShell = shellService.runCommand("", "echo test",
|
mon);
|
||||||
new String[] {}, mon);
|
ShellOutputListener outputListener = new ShellOutputListener();
|
||||||
hostShell.addOutputListener(this);
|
hostShell.addOutputListener(outputListener);
|
||||||
assertNotNull(hostShell);
|
hostShell.writeToShell("exit");
|
||||||
assertNotNull(hostShell.getStandardOutputReader());
|
assertNotNull(hostShell);
|
||||||
while (hostShell.isActive()) {
|
assertNotNull(hostShell.getStandardOutputReader());
|
||||||
Thread.sleep(200);
|
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