Ghidra is a software reverse engineering (SRE) framework
Test fixes
dragonmacher4ee2d81c4913
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/programtree/ProgramTreePlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/programtree/ProgramTreePlugin.javaindex 8f4b99f393..da862ee2bb 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/programtree/ProgramTreePlugin.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/programtree/ProgramTreePlugin.java@@ -990,5 +990,4 @@ public class ProgramTreePlugin extends ProgramPlugincurrentProvider.selectPathsForLocation(currentLocation);}}-}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramSelection.java b/Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramSelection.javaindex 28e39e0978..f9e74ed4af 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramSelection.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramSelection.java@@ -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;diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/select/qualified/QualifiedSelectionPluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/select/qualified/QualifiedSelectionPluginTest.javaindex 7232b609f8..ace0c391d5 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/select/qualified/QualifiedSelectionPluginTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/select/qualified/QualifiedSelectionPluginTest.java@@ -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 AbstractGhidraHeadedIntegratioprivate 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 AbstractGhidraHeadedIntegratioprivate 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 AbstractGhidraHeadedIntegratiopublic 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 .rsrcselectTreeNodeByText(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 .rsrcselectTreeNodeByText(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 AbstractGhidraHeadedIntegratioassertFalse(rsrcDataSet.isEmpty());// Change to program viewselectTreeNodeByText(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 .rsrcselectTreeNodeByText(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 AbstractGhidraHeadedIntegratioassertFalse(rsrcUndefinedSet.isEmpty());// Change to program viewselectTreeNodeByText(tree, "Test", true);- performAction(replaceView, provider, true);+ performAction(setView, programTree, true);+ProgramSelection undefinedSet = getCurrentSelection();assertFalse(undefinedSet.isEmpty());diff --git a/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DiffTest.java b/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DiffTest.javaindex 8a0c84d8aa..df55b0b01e 100644--- a/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DiffTest.java+++ b/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DiffTest.java@@ -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 .dataselectTreeNodeByText(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 viewselectTreeNodeByText(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());diff --git a/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DiffTestAdapter.java b/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DiffTestAdapter.javaindex 855186fda0..9b5de8d40c 100644--- a/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DiffTestAdapter.java+++ b/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DiffTestAdapter.java@@ -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;diff --git a/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DualProgramTest.java b/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DualProgramTest.javaindex 11a8cf5f91..4183ce36d2 100644--- a/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DualProgramTest.java+++ b/Ghidra/Features/ProgramDiff/src/test.slow/java/ghidra/app/plugin/core/diff/DualProgramTest.java@@ -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);