Merge remote-tracking branch 'origin/GP-0-dragonmacher-test-fixes-8-13-24'

This commit is contained in:
Ryan Kurtz 2024-08-13 10:29:04 -04:00
commit 5b29c4d66c
6 changed files with 38 additions and 46 deletions

View File

@ -990,5 +990,4 @@ public class ProgramTreePlugin extends ProgramPlugin
currentProvider.selectPathsForLocation(currentLocation);
}
}
}

View File

@ -41,6 +41,7 @@ public class ProgramSelection implements AddressSetView {
* @param to the end of the selection
*/
public ProgramSelection(Address from, Address to) {
this();
if (to.compareTo(from) < 0) {
Address temp = to;
to = from;

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -25,6 +25,7 @@ import javax.swing.tree.TreePath;
import org.junit.*;
import docking.ComponentProvider;
import docking.action.DockingActionIf;
import ghidra.app.events.ProgramSelectionPluginEvent;
import ghidra.app.plugin.core.codebrowser.CodeBrowserPlugin;
@ -32,7 +33,6 @@ import ghidra.app.plugin.core.codebrowser.CodeViewerProvider;
import ghidra.app.plugin.core.marker.MarkerManagerPlugin;
import ghidra.app.plugin.core.navigation.GoToAddressLabelPlugin;
import ghidra.app.plugin.core.programtree.ProgramTreePlugin;
import ghidra.app.plugin.core.programtree.ViewManagerComponentProvider;
import ghidra.app.plugin.core.select.programtree.ProgramTreeSelectionPlugin;
import ghidra.app.services.ProgramManager;
import ghidra.framework.plugintool.PluginTool;
@ -57,8 +57,7 @@ public class QualifiedSelectionPluginTest extends AbstractGhidraHeadedIntegratio
private DockingActionIf selectInstructionAction;
private DockingActionIf selectUndefinedAction;
private ProgramTreePlugin pt;
private ViewManagerComponentProvider programTreeProvider;
private DockingActionIf replaceView;
private DockingActionIf setView;
private ToyProgramBuilder builder;
@Before
@ -88,17 +87,10 @@ public class QualifiedSelectionPluginTest extends AbstractGhidraHeadedIntegratio
private void setUpProgramTree(PluginTool tool) throws Exception {
tool.addPlugin(ProgramTreePlugin.class.getName());
pt = env.getPlugin(ProgramTreePlugin.class);
replaceView = getAction(pt, "Replace View");
showProgramTree();
setView = getAction(pt, "Set View");
tool.addPlugin(ProgramTreeSelectionPlugin.class.getName());
}
private void showProgramTree() {
programTreeProvider = (ViewManagerComponentProvider) getInstanceField("viewProvider", pt);
tool.showComponentProvider(programTreeProvider, true);
waitForComponentProvider(ViewManagerComponentProvider.class);
}
protected void setUpQualifiedSelection(PluginTool tool) throws Exception {
tool.addPlugin(QualifiedSelectionPlugin.class.getName());
qSelectPlugin = getPlugin(tool, QualifiedSelectionPlugin.class);
@ -219,11 +211,12 @@ public class QualifiedSelectionPluginTest extends AbstractGhidraHeadedIntegratio
public void testSelectWithView() throws Exception {
AddressSet rsrcSet = new AddressSet(addr("0100a000"), addr("0100f3ff"));
ComponentProvider programTree = showProvider(tool, "Program Tree");
JTree tree = waitFor(() -> findComponent(tool.getToolFrame(), JTree.class));
// Replace view with .rsrc
selectTreeNodeByText(tree, ".rsrc", true);
performAction(replaceView, provider, true);
performAction(setView, programTree, true);
ProgramSelection rsrcInstructionSet = getCurrentSelection();
assertTrue(rsrcInstructionSet.isEmpty());
@ -236,7 +229,7 @@ public class QualifiedSelectionPluginTest extends AbstractGhidraHeadedIntegratio
// Change to program view and make sure the previously selected (but not visible in
// the current view) instructions are selected in the new view.
selectTreeNodeByText(tree, "Test", true);
performAction(replaceView, provider, true);
performAction(setView, programTree, true);
ProgramSelection instructionSet = getCurrentSelection();
assertFalse("Instructions selection should have been restored when the view changed",
instructionSet.isEmpty());
@ -248,7 +241,7 @@ public class QualifiedSelectionPluginTest extends AbstractGhidraHeadedIntegratio
// Replace view with .rsrc
selectTreeNodeByText(tree, ".rsrc", true);
performAction(replaceView, provider, true);
performAction(setView, programTree, true);
assertTrue(getCurrentSelection().isEmpty());
// Select All Data.
performAction(selectDataAction, provider, true);
@ -257,7 +250,7 @@ public class QualifiedSelectionPluginTest extends AbstractGhidraHeadedIntegratio
assertFalse(rsrcDataSet.isEmpty());
// Change to program view
selectTreeNodeByText(tree, "Test", true);
performAction(replaceView, provider, true);
performAction(setView, programTree, true);
ProgramSelection dataSet = getCurrentSelection();
assertFalse(dataSet.isEmpty());
@ -268,7 +261,7 @@ public class QualifiedSelectionPluginTest extends AbstractGhidraHeadedIntegratio
// Replace view with .rsrc
selectTreeNodeByText(tree, ".rsrc", true);
performAction(replaceView, provider, true);
performAction(setView, programTree, true);
assertTrue(getCurrentSelection().isEmpty());
// Select All Undefined.
performAction(selectUndefinedAction, provider, true);
@ -277,7 +270,8 @@ public class QualifiedSelectionPluginTest extends AbstractGhidraHeadedIntegratio
assertFalse(rsrcUndefinedSet.isEmpty());
// Change to program view
selectTreeNodeByText(tree, "Test", true);
performAction(replaceView, provider, true);
performAction(setView, programTree, true);
ProgramSelection undefinedSet = getCurrentSelection();
assertFalse(undefinedSet.isEmpty());

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -428,7 +428,7 @@ public class DiffTest extends DiffTestAdapter {
// Replace view with .data
selectTreeNodeByText(tree, ".data");
invokeAndWait(replaceView);
setView();
topOfFile(fp1);
assertEquals(addr("1008000"), cb.getCurrentAddress());
bottomOfFile(fp1);
@ -436,7 +436,7 @@ public class DiffTest extends DiffTestAdapter {
// Replace with program view
selectTreeNodeByText(tree, "DiffTestPgm1");
invokeAndWait(replaceView);
setView();
topOfFile(fp1);
assertEquals(addr("100"), cb.getCurrentAddress());
bottomOfFile(fp1);
@ -455,8 +455,7 @@ public class DiffTest extends DiffTestAdapter {
openDiff(diffTestP1, diffTestP2);
JTree tree = getProgramTree();
selectTreeNodeByText(tree, ".data");
runSwing(() -> replaceView.actionPerformed(new DefaultActionContext()));
setView();
topOfFile(fp1);
assertEquals(addr("1008000"), cb.getCurrentAddress());
@ -482,11 +481,11 @@ public class DiffTest extends DiffTestAdapter {
JTree tree = getProgramTree();
selectTreeNodeByText(tree, ".data");
runSwing(() -> replaceView.actionPerformed(new DefaultActionContext()));
runSwing(() -> setView.actionPerformed(programTreeProvider.getActionContext(null)));
selectTreeNodeByText(tree, ".rsrc");
runSwing(() -> goToView.actionPerformed(new DefaultActionContext()));
runSwing(() -> goToView.actionPerformed(programTreeProvider.getActionContext(null)));
topOfFile(fp1);
assertEquals(addr("1008000"), cb.getCurrentAddress());

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -111,7 +111,7 @@ public class DiffTestAdapter extends AbstractGhidraHeadedIntegrationTest {
ProgramTreePlugin pt;
ComponentProvider programTreeProvider;
DockingActionIf replaceView;
DockingActionIf setView;
DockingActionIf goToView;
DockingActionIf removeView;
@ -484,8 +484,8 @@ public class DiffTestAdapter extends AbstractGhidraHeadedIntegrationTest {
tool.addPlugin(ProgramTreePlugin.class.getName());
pt = env.getPlugin(ProgramTreePlugin.class);
showProgramTree();
replaceView = getAction(pt, "Replace View");
programTreeProvider = showProvider(tool, "Program Tree");
setView = getAction(pt, "Set View");
goToView = getAction(pt, "Go To start of folder/fragment in View");
removeView = getAction(pt, "Remove folder/fragment from View");
@ -511,6 +511,11 @@ public class DiffTestAdapter extends AbstractGhidraHeadedIntegrationTest {
env.dispose();
}
protected void setView() {
ActionContext context = runSwing(() -> programTreeProvider.getActionContext(null));
performAction(setView, context, true);
}
void closeDiff() throws Exception {
closeDiffByAction();
@ -1134,13 +1139,6 @@ public class DiffTestAdapter extends AbstractGhidraHeadedIntegrationTest {
assertEquals(expectedSelection, currentSelection);
}
private void showProgramTree() {
ProgramTreePlugin ptree = env.getPlugin(ProgramTreePlugin.class);
programTreeProvider = (ComponentProvider) getInstanceField("viewProvider", ptree);
tool.showComponentProvider(programTreeProvider, true);
}
JTree getProgramTree() {
JTree tree = findComponent(programTreeProvider.getComponent(), JTree.class);
return tree;

View File

@ -4,9 +4,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -36,6 +36,7 @@ import ghidra.app.services.ProgramManager;
import ghidra.framework.cmd.CompoundCmd;
import ghidra.program.database.ProgramBuilder;
import ghidra.program.database.ProgramDB;
import ghidra.program.model.listing.Program;
import ghidra.program.model.symbol.SourceType;
public class DualProgramTest extends DiffTestAdapter {
@ -349,7 +350,7 @@ public class DualProgramTest extends DiffTestAdapter {
// Modify the active program.
setLocation("100f3ff");
CompoundCmd cmd = new CompoundCmd("test");
CompoundCmd<Program> cmd = new CompoundCmd<>("test");
cmd.add(new AddLabelCmd(addr("100f3ff"), "TestLabel", false, SourceType.USER_DEFINED));
cmd.add(
new AddLabelCmd(addr("100f3ff"), "AnotherTestLabel", false, SourceType.USER_DEFINED));
@ -375,7 +376,7 @@ public class DualProgramTest extends DiffTestAdapter {
openSecondProgram(diffTestP1, diffTestP2);
JTree tree = findComponent(tool.getToolFrame(), JTree.class);
selectTreeNodeByText(tree, "DiffTestPgm1");
performAction(replaceView, true);
setView();
topOfFile(fp1);
assertEquals(addr("00000100"), cb.getCurrentAddress());
bottomOfFile(fp1);
@ -387,7 +388,7 @@ public class DualProgramTest extends DiffTestAdapter {
openSecondProgram(diffTestP1, diffTestP2);
JTree tree = findComponent(tool.getToolFrame(), JTree.class);
selectTreeNodeByText(tree, ".data");
performAction(replaceView, true);
setView();
topOfFile(fp1);
assertEquals(addr("1008000"), cb.getCurrentAddress());
bottomOfFile(fp1);
@ -399,7 +400,7 @@ public class DualProgramTest extends DiffTestAdapter {
openSecondProgram(diffTestP1, diffTestP2);
JTree tree = findComponent(tool.getToolFrame(), JTree.class);
selectTreeNodeByText(tree, ".data");
performAction(replaceView, true);
setView();
selectTreeNodeByText(tree, ".rsrc");
performAction(goToView, true);