Skip to content

Commit 6d7ac95

Browse files
committed
GP-0 Additional test fixes
1 parent 1be7007 commit 6d7ac95

File tree

3 files changed

+63
-20
lines changed

3 files changed

+63
-20
lines changed

Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/app/plugin/core/script/WindowsResourceReferenceScriptTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ private void openProgram(Program program) {
5454
pm.openProgram(program.getDomainFile());
5555
}
5656

57-
private void closeProgram() {
58-
ProgramManager pm = env.getTool().getService(ProgramManager.class);
59-
pm.closeProgram();
60-
waitForSwing();
61-
}
62-
6357
@After
6458
public void tearDown() throws Exception {
6559
env.dispose();
@@ -102,7 +96,6 @@ public void testWinmineNormalCases() throws Exception {
10296
//Check the reference type created is of type DATA
10397
assertTrue(type.equals(RefType.DATA));
10498
}
105-
closeProgram();
10699
}
107100

108101
@Test
@@ -135,8 +128,6 @@ public void testMIPNormalCases() throws Exception {
135128
//check the reference type created is of type DATA
136129
assertTrue(type.equals(RefType.DATA));
137130
}
138-
139-
closeProgram();
140131
}
141132

142133
private Address addr(long offset, Program program) {

Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/framework/main/ByteViewerToolConnectionTest.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@
2828
import docking.DefaultActionContext;
2929
import docking.action.DockingActionIf;
3030
import docking.test.AbstractDockingTest;
31+
import ghidra.app.events.OpenProgramPluginEvent;
3132
import ghidra.app.plugin.core.byteviewer.ByteViewerPlugin;
33+
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
3234
import ghidra.app.services.ProgramManager;
3335
import ghidra.framework.plugintool.Plugin;
3436
import ghidra.framework.plugintool.PluginTool;
3537
import ghidra.framework.plugintool.util.PluginException;
3638
import ghidra.program.database.ProgramBuilder;
39+
import ghidra.program.model.address.Address;
3740
import ghidra.program.model.listing.Program;
41+
import ghidra.program.util.ProgramLocation;
3842
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
3943
import ghidra.test.TestEnv;
4044

@@ -61,8 +65,9 @@ public void tearDown() throws Exception {
6165
pressButtonByText(dialog, "OK");
6266
}
6367

64-
closeAllWindows();
6568
env.dispose();
69+
70+
closeAllWindows();
6671
}
6772

6873
@Test
@@ -83,17 +88,39 @@ public void testConnectToolsDialog() throws Exception {
8388

8489
producerList.setSelectedIndex(0);
8590
consumerList.setSelectedIndex(1);
86-
clickRow(eventList, 1);
91+
int eventCount = eventList.getModel().getSize();
92+
for (int i = 0; i < eventCount; i++) {
93+
clickRow(eventList, i);
94+
}
8795

8896
Program p = buildProgram();
8997

9098
ProgramManager pm = cbTool.getService(ProgramManager.class);
91-
SwingUtilities.invokeAndWait(() -> pm.openProgram(p.getDomainFile()));
99+
runSwing(() -> pm.openProgram(p.getDomainFile()));
100+
101+
waitForSwing();
92102

93103
ProgramManager pm2 = cbTool2.getService(ProgramManager.class);
104+
assertNull(pm2.getCurrentProgram());
105+
106+
// open same program in second tool - cannot rely on tool connection for this
107+
cbTool2.firePluginEvent(new OpenProgramPluginEvent("Test", p));
108+
109+
waitForSwing();
110+
94111
assertEquals(p, pm2.getCurrentProgram());
95112

96-
env.release(p);
113+
Address a = p.getAddressFactory().getDefaultAddressSpace().getAddress(0x1001010);
114+
115+
CodeBrowserPlugin cb1 = getPlugin(cbTool, CodeBrowserPlugin.class);
116+
cb1.goTo(new ProgramLocation(p, a), true);
117+
118+
waitForSwing();
119+
120+
CodeBrowserPlugin cb2 = getPlugin(cbTool2, CodeBrowserPlugin.class);
121+
ProgramLocation loc = cb2.getCurrentLocation();
122+
assertNotNull(loc);
123+
assertEquals(a, loc.getAddress());
97124
}
98125

99126
private void clickRow(JList<?> list, int row) {

Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/framework/main/ToolConnectionTest.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@
2727

2828
import docking.DefaultActionContext;
2929
import docking.action.DockingActionIf;
30+
import ghidra.app.events.OpenProgramPluginEvent;
3031
import ghidra.app.plugin.core.byteviewer.ByteViewerPlugin;
32+
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
3133
import ghidra.app.services.ProgramManager;
3234
import ghidra.framework.plugintool.Plugin;
3335
import ghidra.framework.plugintool.PluginTool;
3436
import ghidra.framework.plugintool.util.PluginException;
3537
import ghidra.program.database.ProgramBuilder;
38+
import ghidra.program.model.address.Address;
3639
import ghidra.program.model.listing.Program;
40+
import ghidra.program.util.ProgramLocation;
3741
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
3842
import ghidra.test.TestEnv;
3943

@@ -75,31 +79,52 @@ public void tearDown() throws Exception {
7579
close(dialog);
7680
}
7781

78-
closeAllWindows();
79-
8082
env.dispose();
83+
84+
closeAllWindows();
8185
}
8286

8387
@Test
8488
public void testConnectToolsDialog() throws Exception {
8589

8690
connectTools();
8791

88-
clickListRow(eventList, 1);
92+
int eventCount = eventList.getModel().getSize();
93+
for (int i = 0; i < eventCount; i++) {
94+
clickListRow(eventList, i);
95+
}
96+
8997
pressButtonByText(dialog, "OK");
9098

9199
Program p = buildNotepad();
92100

93101
ProgramManager pm = tool1.getService(ProgramManager.class);
94-
ProgramManager pm2 = tool2.getService(ProgramManager.class);
95102
runSwing(() -> pm.openProgram(p.getDomainFile()));
96103

97-
waitForCondition(() -> pm2.getCurrentProgram() != null,
98-
"Tool 2 did not open a proagram when one was opened in tool1");
104+
waitForSwing();
105+
106+
ProgramManager pm2 = tool2.getService(ProgramManager.class);
107+
assertNull(pm2.getCurrentProgram());
108+
109+
// open same program in second tool - cannot rely on tool connection for this
110+
tool2.firePluginEvent(new OpenProgramPluginEvent("Test", p));
111+
112+
waitForSwing();
99113

100114
assertEquals(p, pm2.getCurrentProgram());
101115

102-
env.release(p);
116+
Address a = p.getAddressFactory().getDefaultAddressSpace().getAddress(0x1001010);
117+
118+
CodeBrowserPlugin cb1 = getPlugin(tool1, CodeBrowserPlugin.class);
119+
cb1.goTo(new ProgramLocation(p, a), true);
120+
121+
waitForSwing();
122+
123+
CodeBrowserPlugin cb2 = getPlugin(tool2, CodeBrowserPlugin.class);
124+
ProgramLocation loc = cb2.getCurrentLocation();
125+
assertNotNull(loc);
126+
assertEquals(a, loc.getAddress());
127+
103128
}
104129

105130
@Test

0 commit comments

Comments
 (0)