Test fixes

This commit is contained in:
dragonmacher 2023-08-10 18:58:04 -04:00
parent 2ca66f9505
commit e9931dfeaa
5 changed files with 34 additions and 26 deletions

View File

@ -69,23 +69,23 @@ public class TableComponentProvider<T> extends ComponentProviderAdapter
private HelpLocation helpLoc = new HelpLocation(HelpTopics.SEARCH, "Query_Results");
TableComponentProvider(TableServicePlugin plugin, String title, String name,
GhidraProgramTableModel<T> model, String programName, GoToService gotoService,
GhidraProgramTableModel<T> model, Program program, GoToService gotoService,
String windowSubMenu, Navigatable navigatable) {
this(plugin, title, name, model, programName, gotoService, null, null, null, windowSubMenu,
this(plugin, title, name, model, program, gotoService, null, null, null, windowSubMenu,
navigatable);
}
TableComponentProvider(TableServicePlugin plugin, String title, String name,
GhidraProgramTableModel<T> model, String programName, GoToService gotoService,
GhidraProgramTableModel<T> model, Program program, GoToService gotoService,
MarkerService markerService, Color markerColor, Icon markerIcon, String windowSubMenu,
Navigatable navigatable) {
super(plugin.getTool(), name, plugin.getName());
this.tableServicePlugin = plugin;
this.navigatable = navigatable;
this.program = navigatable.getProgram();
this.program = program;
this.model = model;
this.programName = programName;
this.programName = program.getDomainFile().getName();
this.markerService = markerService;
this.windowSubMenu = windowSubMenu;
setIcon(new GIcon("icon.plugin.table.service"));
@ -130,14 +130,18 @@ public class TableComponentProvider<T> extends ComponentProviderAdapter
tool.contextChanged(TableComponentProvider.this);
});
// only allow global actions through if we are derived from the connect/primary navigatable
table.setActionsEnabled(navigatable.isConnected());
if (navigatable != null) {
// Only allow global actions if we are derived from the connect/primary navigatable.
// This allows the the primary navigatable to process key events without the user having
// to focus first focus the primary navigatable.
table.setActionsEnabled(navigatable.isConnected());
navigatable.addNavigatableListener(this);
table.installNavigation(tool, navigatable);
}
else {
// allow the table to use the default navigation behavior. If the GoToService later
// becomes available, then navigation will work.
table.setActionsEnabled(true); // default navigatable will be used
table.installNavigation(tool);
}
@ -147,11 +151,18 @@ public class TableComponentProvider<T> extends ComponentProviderAdapter
return panel;
}
private void createActions(final Plugin plugin) {
private void createActions(Plugin plugin) {
GhidraTable table = threadedPanel.getTable();
if (navigatable != null) {
selectAction =
new MakeProgramSelectionAction(navigatable, tableServicePlugin.getName(), table);
}
else {
selectAction =
new MakeProgramSelectionAction(tableServicePlugin, table);
}
selectAction.setHelpLocation(new HelpLocation(HelpTopics.SEARCH, "Make_Selection"));
selectionNavigationAction = new SelectionNavigationAction(plugin, table);

View File

@ -140,7 +140,7 @@ public class TableServicePlugin extends ProgramPlugin
GoToService gotoService = tool.getService(GoToService.class);
Program program = model.getProgram();
TableComponentProvider<T> cp = new TableComponentProvider<>(this, title, tableTypeName,
model, program.getDomainFile().getName(), gotoService, windowSubMenu, navigatable);
model, program, gotoService, windowSubMenu, navigatable);
addProvider(program, cp);
return cp;
}
@ -154,8 +154,8 @@ public class TableServicePlugin extends ProgramPlugin
MarkerService markerService = tool.getService(MarkerService.class);
Program program = model.getProgram();
TableComponentProvider<T> cp = new TableComponentProvider<>(this, title, tableTypeName,
model, program.getDomainFile().getName(), gotoService, markerService, markerColor,
markerIcon, windowSubMenu, navigatable);
model, program, gotoService, markerService, markerColor, markerIcon, windowSubMenu,
navigatable);
addProvider(program, cp);
return cp;
}

View File

@ -205,7 +205,8 @@ public interface GoToService {
GoToServiceListener listener, TaskMonitor monitor);
/**
* Returns the default navigatable that is the destination for GoTo events.
* Returns the default navigatable that is the destination for GoTo events. This navigatable
* will not be null.
* @return the navigatable
*/
public Navigatable getDefaultNavigatable();

View File

@ -89,7 +89,7 @@ public class MakeProgramSelectionAction extends DockingAction {
*/
public MakeProgramSelectionAction(Plugin plugin, GhidraTable table) {
super("Make Selection", plugin.getName(), KeyBindingType.SHARED);
this.plugin = plugin;
this.plugin = Objects.requireNonNull(plugin);
this.table = Objects.requireNonNull(table);
init();
}

View File

@ -15,8 +15,7 @@
*/
package ghidra.app.plugin.core.instructionsearch;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.*;
import java.awt.Container;
import java.awt.Window;
@ -66,7 +65,7 @@ public class InstructionSearchTest extends AbstractGhidraHeadedIntegrationTest {
private GhidraTable instructionTable;
private GTable previewTable;
/**
/*
* Test setup. Each test will start with a simple program having a selection
* encompassing the entire range.
*/
@ -98,7 +97,7 @@ public class InstructionSearchTest extends AbstractGhidraHeadedIntegrationTest {
env.dispose();
}
/**
/*
* This builds a small program based on a section of WinHelloCpp.exe. The specific
* section disassembles as follows:
*
@ -112,7 +111,6 @@ public class InstructionSearchTest extends AbstractGhidraHeadedIntegrationTest {
* 004065ef 83 c4 0c ADD ESP,nope
* 004065f2 89 45 fc MOV [EBP + local_8],EAX
*
* @throws Exception
*/
private Program buildProgram() throws Exception {
@ -480,11 +478,10 @@ public class InstructionSearchTest extends AbstractGhidraHeadedIntegrationTest {
assertResultsTableRowCount(1);
}
/**
/*
* Tests that we can perform a search over the entire memory space and return multiple
* results. To do this we're going to have to select the "PUSH EDI" instruction and mask
* out the operand, which should yield 2 matches.
* @throws Exception
*/
@Test
public void testSearchEntireProgramMultipleResults() throws Exception {
@ -821,12 +818,11 @@ public class InstructionSearchTest extends AbstractGhidraHeadedIntegrationTest {
waitForSwing();
}
/**
/*
* Loads the instructions in the given range into the instruction table.
*
* @param addr1 address in the form "0x01234567"
* @param addr2 address in the form "0x01234567"
* @throws Exception
*/
private void loadSelection(String addr1, String addr2) throws Exception {