GP-0 Additional test fixes

This commit is contained in:
ghidra1 2023-12-20 15:06:28 -05:00
parent 1be700742d
commit 6d7ac958d7
3 changed files with 63 additions and 20 deletions

View file

@ -54,12 +54,6 @@ public class WindowsResourceReferenceScriptTest extends AbstractGhidraHeadedInte
pm.openProgram(program.getDomainFile());
}
private void closeProgram() {
ProgramManager pm = env.getTool().getService(ProgramManager.class);
pm.closeProgram();
waitForSwing();
}
@After
public void tearDown() throws Exception {
env.dispose();
@ -102,7 +96,6 @@ public class WindowsResourceReferenceScriptTest extends AbstractGhidraHeadedInte
//Check the reference type created is of type DATA
assertTrue(type.equals(RefType.DATA));
}
closeProgram();
}
@Test
@ -135,8 +128,6 @@ public class WindowsResourceReferenceScriptTest extends AbstractGhidraHeadedInte
//check the reference type created is of type DATA
assertTrue(type.equals(RefType.DATA));
}
closeProgram();
}
private Address addr(long offset, Program program) {

View file

@ -28,13 +28,17 @@ import org.junit.*;
import docking.DefaultActionContext;
import docking.action.DockingActionIf;
import docking.test.AbstractDockingTest;
import ghidra.app.events.OpenProgramPluginEvent;
import ghidra.app.plugin.core.byteviewer.ByteViewerPlugin;
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
import ghidra.app.services.ProgramManager;
import ghidra.framework.plugintool.Plugin;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.util.PluginException;
import ghidra.program.database.ProgramBuilder;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Program;
import ghidra.program.util.ProgramLocation;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
@ -61,8 +65,9 @@ public class ByteViewerToolConnectionTest extends AbstractGhidraHeadedIntegratio
pressButtonByText(dialog, "OK");
}
closeAllWindows();
env.dispose();
closeAllWindows();
}
@Test
@ -83,17 +88,39 @@ public class ByteViewerToolConnectionTest extends AbstractGhidraHeadedIntegratio
producerList.setSelectedIndex(0);
consumerList.setSelectedIndex(1);
clickRow(eventList, 1);
int eventCount = eventList.getModel().getSize();
for (int i = 0; i < eventCount; i++) {
clickRow(eventList, i);
}
Program p = buildProgram();
ProgramManager pm = cbTool.getService(ProgramManager.class);
SwingUtilities.invokeAndWait(() -> pm.openProgram(p.getDomainFile()));
runSwing(() -> pm.openProgram(p.getDomainFile()));
waitForSwing();
ProgramManager pm2 = cbTool2.getService(ProgramManager.class);
assertNull(pm2.getCurrentProgram());
// open same program in second tool - cannot rely on tool connection for this
cbTool2.firePluginEvent(new OpenProgramPluginEvent("Test", p));
waitForSwing();
assertEquals(p, pm2.getCurrentProgram());
env.release(p);
Address a = p.getAddressFactory().getDefaultAddressSpace().getAddress(0x1001010);
CodeBrowserPlugin cb1 = getPlugin(cbTool, CodeBrowserPlugin.class);
cb1.goTo(new ProgramLocation(p, a), true);
waitForSwing();
CodeBrowserPlugin cb2 = getPlugin(cbTool2, CodeBrowserPlugin.class);
ProgramLocation loc = cb2.getCurrentLocation();
assertNotNull(loc);
assertEquals(a, loc.getAddress());
}
private void clickRow(JList<?> list, int row) {

View file

@ -27,13 +27,17 @@ import org.junit.*;
import docking.DefaultActionContext;
import docking.action.DockingActionIf;
import ghidra.app.events.OpenProgramPluginEvent;
import ghidra.app.plugin.core.byteviewer.ByteViewerPlugin;
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
import ghidra.app.services.ProgramManager;
import ghidra.framework.plugintool.Plugin;
import ghidra.framework.plugintool.PluginTool;
import ghidra.framework.plugintool.util.PluginException;
import ghidra.program.database.ProgramBuilder;
import ghidra.program.model.address.Address;
import ghidra.program.model.listing.Program;
import ghidra.program.util.ProgramLocation;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
@ -75,9 +79,9 @@ public class ToolConnectionTest extends AbstractGhidraHeadedIntegrationTest {
close(dialog);
}
closeAllWindows();
env.dispose();
closeAllWindows();
}
@Test
@ -85,21 +89,42 @@ public class ToolConnectionTest extends AbstractGhidraHeadedIntegrationTest {
connectTools();
clickListRow(eventList, 1);
int eventCount = eventList.getModel().getSize();
for (int i = 0; i < eventCount; i++) {
clickListRow(eventList, i);
}
pressButtonByText(dialog, "OK");
Program p = buildNotepad();
ProgramManager pm = tool1.getService(ProgramManager.class);
ProgramManager pm2 = tool2.getService(ProgramManager.class);
runSwing(() -> pm.openProgram(p.getDomainFile()));
waitForCondition(() -> pm2.getCurrentProgram() != null,
"Tool 2 did not open a proagram when one was opened in tool1");
waitForSwing();
ProgramManager pm2 = tool2.getService(ProgramManager.class);
assertNull(pm2.getCurrentProgram());
// open same program in second tool - cannot rely on tool connection for this
tool2.firePluginEvent(new OpenProgramPluginEvent("Test", p));
waitForSwing();
assertEquals(p, pm2.getCurrentProgram());
env.release(p);
Address a = p.getAddressFactory().getDefaultAddressSpace().getAddress(0x1001010);
CodeBrowserPlugin cb1 = getPlugin(tool1, CodeBrowserPlugin.class);
cb1.goTo(new ProgramLocation(p, a), true);
waitForSwing();
CodeBrowserPlugin cb2 = getPlugin(tool2, CodeBrowserPlugin.class);
ProgramLocation loc = cb2.getCurrentLocation();
assertNotNull(loc);
assertEquals(a, loc.getAddress());
}
@Test