update python & headless tests to manage GhidraScriptUtil resource

This commit is contained in:
Jason P. Leasure 2020-04-29 11:39:05 -04:00
parent 7ee2467016
commit 5f11c9cf7d
6 changed files with 117 additions and 93 deletions

View file

@ -22,6 +22,8 @@ import java.io.ByteArrayOutputStream;
import org.junit.*;
import generic.jar.ResourceFile;
import ghidra.app.plugin.core.osgi.BundleHost;
import ghidra.app.script.GhidraScriptUtil;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
/**
@ -35,6 +37,7 @@ public class PythonInterpreterTest extends AbstractGhidraHeadedIntegrationTest {
@Before
public void setUp() throws Exception {
out = new ByteArrayOutputStream();
GhidraScriptUtil.initialize(new BundleHost(), null);
interpreter = GhidraPythonInterpreter.get();
interpreter.setOut(out);
interpreter.setErr(out);
@ -44,6 +47,7 @@ public class PythonInterpreterTest extends AbstractGhidraHeadedIntegrationTest {
public void tearDown() throws Exception {
out.reset();
interpreter.cleanup();
GhidraScriptUtil.dispose();
}
/**
@ -81,7 +85,7 @@ public class PythonInterpreterTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testPythonCleanupInvalidation() {
interpreter.cleanup();
try {
interpreter.push("pass", null);
fail("Push still worked after interpreter cleanup.");

View file

@ -15,10 +15,12 @@
*/
package ghidra.python;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.*;
import org.junit.*;
import ghidra.app.plugin.core.osgi.BundleHost;
import ghidra.app.script.GhidraScriptUtil;
import ghidra.framework.plugintool.PluginTool;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
@ -36,12 +38,14 @@ public class PythonPluginTest extends AbstractGhidraHeadedIntegrationTest {
public void setUp() throws Exception {
env = new TestEnv();
tool = env.getTool();
GhidraScriptUtil.initialize(new BundleHost(), null);
tool.addPlugin(PythonPlugin.class.getName());
plugin = env.getPlugin(PythonPlugin.class);
}
@After
public void tearDown() throws Exception {
GhidraScriptUtil.dispose();
env.dispose();
}

View file

@ -24,6 +24,8 @@ import org.junit.*;
import generic.jar.ResourceFile;
import ghidra.app.plugin.core.console.ConsolePlugin;
import ghidra.app.plugin.core.osgi.BundleHost;
import ghidra.app.script.GhidraScriptUtil;
import ghidra.app.script.GhidraState;
import ghidra.app.services.ConsoleService;
import ghidra.framework.Application;
@ -45,12 +47,14 @@ public class PythonScriptTest extends AbstractGhidraHeadedIntegrationTest {
public void setUp() throws Exception {
env = new TestEnv();
tool = env.getTool();
GhidraScriptUtil.initialize(new BundleHost(), null);
tool.addPlugin(ConsolePlugin.class.getName());
console = tool.getService(ConsoleService.class);
}
@After
public void tearDown() throws Exception {
GhidraScriptUtil.dispose();
env.dispose();
}