Merge remote-tracking branch 'origin/GT-0-dragonmacher-test-fixes'

This commit is contained in:
ghidravore 2020-03-10 17:50:28 -04:00
commit 83e0ce4091
9 changed files with 55 additions and 43 deletions

View File

@ -31,9 +31,7 @@ import docking.widgets.OptionDialog;
import docking.widgets.dialogs.InputDialog;
import docking.widgets.pathmanager.PathnameTablePanel;
import generic.jar.ResourceFile;
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
import ghidra.app.plugin.core.datamgr.DataTypeManagerPlugin;
import ghidra.app.plugin.core.programtree.ProgramTreePlugin;
import ghidra.framework.Application;
import ghidra.framework.plugintool.PluginTool;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
@ -59,19 +57,19 @@ public class ParseDialogTest extends AbstractGhidraHeadedIntegrationTest {
public void setUp() throws Exception {
env = new TestEnv();
tool = env.getTool();
tool.addPlugin(ProgramTreePlugin.class.getName());
tool.addPlugin(CodeBrowserPlugin.class.getName());
tool.addPlugin(DataTypeManagerPlugin.class.getName());
tool.addPlugin(CParserPlugin.class.getName());
plugin = getPlugin(tool, CParserPlugin.class);
env.showTool();
String tempPath = createTempFilePath(getClass().getSimpleName());
plugin.setUserProfileDir(tempPath);
parseAction = getAction(plugin, CParserPlugin.PARSE_ACTION_NAME);
readDefaultParseProfileFile();
removeAllProfiles();
dialog = getDialog();
dialog = showDialog();
profilesComboBox = findComponent(dialog, JComboBox.class);
assertNotNull(profilesComboBox);
profilesComboBoxModel = (DefaultComboBoxModel<?>) profilesComboBox.getModel();
@ -339,7 +337,7 @@ public class ParseDialogTest extends AbstractGhidraHeadedIntegrationTest {
runSwing(() -> pathPanel.setPaths(new String[] { paths.get(0), path }));
}
private ParseDialog getDialog() {
private ParseDialog showDialog() {
performAction(parseAction, true);
return waitForDialogComponent(ParseDialog.class);
}

View File

@ -206,14 +206,13 @@ public class KeyBindingUtilsTest extends AbstractGhidraHeadedIntegrationTest {
debug("d");
// now repeat the above test with changing some values before writing
// out
// now repeat the above test with changing some values before writing out
invokeInstanceMethod("putObject", defaultKeyBindings,
new Class[] { String.class, Object.class },
new Object[] { "test1", KeyStroke.getKeyStroke(65, 0) });
new Object[] { "TestAction1 (Owner1)", KeyStroke.getKeyStroke(65, 0) });
invokeInstanceMethod("putObject", defaultKeyBindings,
new Class[] { String.class, Object.class },
new Object[] { "test2", KeyStroke.getKeyStroke(66, 0) });
new Object[] { "TestAction2 (Owner 2)", KeyStroke.getKeyStroke(66, 0) });
debug("e");

View File

@ -1199,10 +1199,20 @@ public class DialogComponentProvider
dialogActions.add(action);
addToolbarAction(action);
popupManager.addAction(action);
addKeyBindingAction(action);
}
private void addKeyBindingAction(DockingActionIf action) {
// add the action to the tool in order get key event management (key bindings
// options and key event processing)
DockingWindowManager dwm = DockingWindowManager.getActiveInstance();
if (dwm == null) {
// This implies the client dialog has been shown outside of the plugin framework. In
// that case, the client will not get key event processing for dialog actions.
return;
}
Tool tool = dwm.getTool();
tool.addAction(new DialogActionProxy(action));
}

View File

@ -226,6 +226,6 @@ public class DockingActionProxy
@Override
public String toString() {
return dockingAction.getName();
return dockingAction.toString();
}
}

View File

@ -1710,10 +1710,10 @@ public class DockingWindowManager implements PropertyChangeListener, Placeholder
};
if (provider.isModal()) {
SystemUtilities.runSwingNow(r);
Swing.runNow(r);
}
else {
SystemUtilities.runIfSwingOrPostSwingLater(r);
Swing.runIfSwingOrRunLater(r);
}
}

View File

@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -18,29 +17,35 @@ package docking;
import docking.action.DockingActionIf;
import docking.action.ToggleDockingActionIf;
import generic.json.Json;
public class ExecutableKeyActionAdapter {
DockingActionIf action;
ActionContext context;
public ExecutableKeyActionAdapter( DockingActionIf action, ActionContext context ) {
this.action = action;
this.context = context;
}
DockingActionIf action;
ActionContext context;
public void execute() {
// Toggle actions do not toggle its state directly therefor we have to do it for
// them before we execute the action.
if ( action instanceof ToggleDockingActionIf ) {
ToggleDockingActionIf toggleAction = (ToggleDockingActionIf) action;
toggleAction.setSelected( !toggleAction.isSelected() );
}
action.actionPerformed( context );
}
public ExecutableKeyActionAdapter(DockingActionIf action, ActionContext context) {
this.action = action;
this.context = context;
}
public DockingActionIf getAction() {
return action;
}
public void execute() {
// Toggle actions do not toggle its state directly therefor we have to do it for
// them before we execute the action.
if (action instanceof ToggleDockingActionIf) {
ToggleDockingActionIf toggleAction = (ToggleDockingActionIf) action;
toggleAction.setSelected(!toggleAction.isSelected());
}
action.actionPerformed(context);
}
public DockingActionIf getAction() {
return action;
}
@Override
public String toString() {
return Json.toString(action);
}
}

View File

@ -1188,7 +1188,7 @@ public abstract class AbstractDockingTest extends AbstractGenericTest {
if (actions.size() > 1) {
// This shouldn't happen
throw new AssertionFailedError(
"Found more than one action for name '" + name + " (" + owner + ")'");
"Found more than one action for name '" + name + " (" + owner + ")'\n\t" + actions);
}
return CollectionUtils.any(actions);

View File

@ -110,7 +110,7 @@ public class ManagePluginsDialog extends DialogComponentProvider implements Chan
addAction(configureAllPluginsAction);
if (addSaveActions) {
saveAction = new DockingAction("Save Tool", ToolConstants.TOOL_OWNER) {
saveAction = new DockingAction("Save New Tool", ToolConstants.TOOL_OWNER) {
@Override
public void actionPerformed(ActionContext context) {
save();
@ -125,7 +125,7 @@ public class ManagePluginsDialog extends DialogComponentProvider implements Chan
saveAction.setDescription("Save tool to tool chest");
addAction(saveAction);
saveAsAction = new DockingAction("Save Tool As", ToolConstants.TOOL_OWNER) {
saveAsAction = new DockingAction("Save New Tool As", ToolConstants.TOOL_OWNER) {
@Override
public void actionPerformed(ActionContext context) {
saveAs();

View File

@ -630,17 +630,17 @@ public class ToolActionManagerTest extends AbstractGhidraHeadedIntegrationTest {
tool = runningTools[0];
}
}
assertNotNull("Did not find a single running " + toolName + " tool", tool);
assertEquals("Running tool is not " + toolName, toolName, tool.getName());
return tool;
}
private void initializeToolChestToJustCodeBrowser() {
final ToolServices toolServices = frontEndTool.getToolServices();
final ToolChest toolChest = toolServices.getToolChest();
final AtomicReference<String> failedTool = new AtomicReference<>();
runSwing(() -> {
ToolTemplate[] toolTemplates = toolChest.getToolTemplates();
@ -653,9 +653,9 @@ public class ToolActionManagerTest extends AbstractGhidraHeadedIntegrationTest {
}
}
}
});
String toolName = failedTool.get();
assertNull("Failed to remove tool: " + toolName, toolName);
assertEquals("Did not remove tools as expected", 1, toolChest.getToolCount());
@ -690,7 +690,7 @@ public class ToolActionManagerTest extends AbstractGhidraHeadedIntegrationTest {
DockingActionIf createAction = getAction("Create Tool");
performAction(createAction, true);
PluginTool[] tools = frontEndTool.getProject().getToolManager().getRunningTools();
final PluginTool tool = (PluginTool) tools[0];
final PluginTool tool = tools[0];
runSwing(() -> {
try {
tool.addPlugin(CodeBrowserPlugin.class.getName());