Skip to content

Ghidra is a software reverse engineering (SRE) framework

Test fixes

dragonmacher975893212cf8
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeProvider.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeProvider.java
index 190091f6b5..d0376311fa 100644
--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeProvider.java
+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/symboltree/SymbolTreeProvider.java
@@ -604,13 +604,13 @@ public class SymbolTreeProvider extends ComponentProviderAdapter {
}
void readConfigState(SaveState saveState) {
- navigateIncomingAction.setSelected(saveState.getBoolean("NAVIGTE_INCOMING", false));
- navigateOutgoingAction.setSelected(saveState.getBoolean("NAVIGTE_OUTGOING", true));
+ navigateIncomingAction.setSelected(saveState.getBoolean("NAVIGATE_INCOMING", false));
+ navigateOutgoingAction.setSelected(saveState.getBoolean("NAVIGATE_OUTGOING", true));
}
void writeConfigState(SaveState saveState) {
- saveState.putBoolean("NAVIGTE_INCOMING", navigateIncomingAction.isSelected());
- saveState.putBoolean("NAVIGTE_OUTGOING", navigateOutgoingAction.isSelected());
+ saveState.putBoolean("NAVIGATE_INCOMING", navigateIncomingAction.isSelected());
+ saveState.putBoolean("NAVIGATE_OUTGOING", navigateOutgoingAction.isSelected());
}
void dispose() {
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/console/ConsolePluginTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/console/ConsolePluginTest.java
index 04dbf57fc5..a8470228be 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/console/ConsolePluginTest.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/console/ConsolePluginTest.java
@@ -407,18 +407,25 @@ public class ConsolePluginTest extends AbstractGhidraHeadedIntegrationTest {
private void next() {
pressButtonByText(findDialog, "Next");
- waitForTasks();
+ waitForNotBusy();
}
private void previous() {
pressButtonByText(findDialog, "Previous");
- waitForTasks();
+ waitForNotBusy();
}
private void findAll(String text) {
runSwing(() -> findDialog.setSearchText(text));
pressButtonByText(findDialog, "Find All");
- waitForTasks();
+ waitForNotBusy();
+ }
+
+ private void waitForNotBusy() {
+ TextComponentSearcher searcher = (TextComponentSearcher) findDialog.getSearcher();
+ waitForSwing();
+ waitFor(() -> !searcher.isBusy());
+ waitForSwing();
}
private void assertSearchModelHasNoSearchResults() {
@@ -489,6 +496,7 @@ public class ConsolePluginTest extends AbstractGhidraHeadedIntegrationTest {
private void selectRow(FindDialogResultsProvider resultsProvider, int row) {
GTable table = resultsProvider.getTable();
runSwing(() -> table.selectRow(row));
+ waitForSwing();
}
private void verfiyHighlightColor(List<TestTextMatch> matches)
@@ -523,7 +531,6 @@ public class ConsolePluginTest extends AbstractGhidraHeadedIntegrationTest {
}
private List<TestTextMatch> getExpectedMatches() {
-
String searchText = findDialog.getSearchText();
assertFalse(searchText.isEmpty());
return getExpectedMatches(searchText);
@@ -541,7 +548,7 @@ public class ConsolePluginTest extends AbstractGhidraHeadedIntegrationTest {
int index = text.indexOf(searchText);
while (index != -1) {
- results.add(new TestTextMatch(index, index + searchText.length()));
+ results.add(new TestTextMatch(searchText, index, index + searchText.length()));
index = text.indexOf(searchText, index + 1);
}
@@ -559,7 +566,7 @@ public class ConsolePluginTest extends AbstractGhidraHeadedIntegrationTest {
return waitForDialogComponent(FindDialog.class);
}
- private record TestTextMatch(int start, int end) {
+ private record TestTextMatch(String searchText, int start, int end) {
boolean contains(int caret) {
return start <= caret && caret <= end;
@@ -567,7 +574,7 @@ public class ConsolePluginTest extends AbstractGhidraHeadedIntegrationTest {
@Override
public String toString() {
- return "[" + start + ',' + end + ']';
+ return searchText + ": [" + start + ',' + end + ']';
}
}
}
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin3Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin3Test.java
index 3733786018..8eb06534b5 100644
--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin3Test.java
+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/symboltree/SymbolTreePlugin3Test.java
@@ -27,6 +27,7 @@ import javax.swing.tree.TreePath;
import org.junit.*;
+import docking.DefaultActionContext;
import docking.action.DockingActionIf;
import docking.action.ToggleDockingAction;
import docking.widgets.tree.GTree;
@@ -334,15 +335,15 @@ public class SymbolTreePlugin3Test extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testSaveState() throws Exception {
- final ToggleDockingAction navigateIncomingAction =
+ ToggleDockingAction navigateIncomingAction =
(ToggleDockingAction) getAction(plugin, NavigateOnIncomingAction.NAME);
assertNotNull(navigateIncomingAction);
- runSwing(() -> navigateIncomingAction.setSelected(true));
+ setToggleActionSelected(navigateIncomingAction, new DefaultActionContext(), true);
SaveState saveState = new SaveState("Test");
plugin.writeConfigState(saveState);
- assertTrue(saveState.getBoolean("GO_TO_TOGGLE_STATE", false));
+ assertTrue(saveState.getBoolean("NAVIGATE_INCOMING", false));
runSwing(() -> {
tool.removePlugins(List.of(plugin));
@@ -357,13 +358,13 @@ public class SymbolTreePlugin3Test extends AbstractGhidraHeadedIntegrationTest {
assertNotNull(plugin);
util.setPlugin(plugin);
- ToggleDockingAction goToToggleAction2 =
- (ToggleDockingAction) getAction(plugin, "Navigation");
- assertNotNull(goToToggleAction2);
- assertFalse(goToToggleAction2.isSelected());
+ navigateIncomingAction =
+ (ToggleDockingAction) getAction(plugin, NavigateOnIncomingAction.NAME);
+ assertNotNull(navigateIncomingAction);
+ assertFalse(navigateIncomingAction.isSelected());
plugin.readConfigState(saveState);
- assertTrue(goToToggleAction2.isSelected());
+ assertTrue(navigateIncomingAction.isSelected());
}
@Test
diff --git a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java
index 0f5011f2dc..bb9c5eb729 100644
--- a/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java
+++ b/Ghidra/Features/Decompiler/src/main/java/ghidra/app/decompiler/component/DecompilerPanel.java
@@ -1405,7 +1405,7 @@ public class DecompilerPanel extends JPanel implements FieldMouseListener, Field
Map<Integer, List<DecompilerSearchLocation>> locationsByLine =
currentSearchResults.getLocationsByLine();
List<DecompilerSearchLocation> locationsOnLine = locationsByLine.get(lineNumber);
- if (locationsOnLine.isEmpty()) {
+ if (locationsOnLine == null) {
return new Highlight[0];
}
diff --git a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/AbstractDecompilerTest.java b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/AbstractDecompilerTest.java
index 33550e2724..61d6cd920e 100644
--- a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/AbstractDecompilerTest.java
+++ b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/AbstractDecompilerTest.java
@@ -152,6 +152,11 @@ public abstract class AbstractDecompilerTest extends AbstractProgramBasedTest {
* @return the token under the cursor
*/
protected ClangToken getToken() {
+ waitForDecompiler();
+ return getToken(provider);
+ }
+
+ protected ClangToken getCursorToken() {
return getToken(provider);
}
diff --git a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerFindDialogTest.java b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerFindDialogTest.java
index 8ec79f64d4..5c87206a44 100644
--- a/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerFindDialogTest.java
+++ b/Ghidra/Features/Decompiler/src/test.slow/java/ghidra/app/plugin/core/decompile/DecompilerFindDialogTest.java
@@ -23,18 +23,19 @@ import org.junit.After;
import org.junit.Test;
import docking.action.DockingActionIf;
+import docking.widgets.FindDialogResultsProvider;
+import docking.widgets.SearchLocation;
import docking.widgets.dialogs.InputDialog;
import docking.widgets.fieldpanel.support.FieldLocation;
import docking.widgets.table.GTable;
+import docking.widgets.table.RowObjectFilterModel;
import ghidra.app.decompiler.ClangToken;
import ghidra.app.decompiler.component.DecompilerFindDialog;
import ghidra.app.decompiler.component.DecompilerPanel;
import ghidra.app.plugin.core.decompile.actions.DecompilerSearchLocation;
-import ghidra.app.plugin.core.table.TableComponentProvider;
import ghidra.program.model.listing.Program;
import ghidra.test.ClassicSampleX86ProgramBuilder;
-import ghidra.util.table.GhidraProgramTableModel;
-import ghidra.util.table.GhidraThreadedTablePanel;
+import util.CollectionUtils;
public class DecompilerFindDialogTest extends AbstractDecompilerTest {
@@ -306,20 +307,16 @@ public class DecompilerFindDialogTest extends AbstractDecompilerTest {
}
private GTable getResultsTable() {
- @SuppressWarnings("unchecked")
- TableComponentProvider<DecompilerSearchLocation> tableProvider =
- waitForComponentProvider(TableComponentProvider.class);
- GhidraThreadedTablePanel<DecompilerSearchLocation> panel =
- tableProvider.getThreadedTablePanel();
- return panel.getTable();
+ FindDialogResultsProvider tableProvider =
+ waitForComponentProvider(FindDialogResultsProvider.class);
+ return tableProvider.getTable();
}
+ @SuppressWarnings("unchecked")
private List<DecompilerSearchLocation> getResults(GTable table) {
- @SuppressWarnings("unchecked")
- GhidraProgramTableModel<DecompilerSearchLocation> model =
- (GhidraProgramTableModel<DecompilerSearchLocation>) table.getModel();
- waitForTableModel(model);
- return model.getModelData();
+ RowObjectFilterModel<SearchLocation> model =
+ (RowObjectFilterModel<SearchLocation>) table.getModel();
+ return CollectionUtils.asList(model.getModelData(), DecompilerSearchLocation.class);
}
private void next() {
@@ -331,7 +328,7 @@ public class DecompilerFindDialogTest extends AbstractDecompilerTest {
}
private void searchAll() {
- pressButtonByText(findDialog, "Search All");
+ pressButtonByText(findDialog, "Find All");
}
private void assertSearchHit(int line, int column, int length) {
diff --git a/Ghidra/Framework/Docking/src/main/java/docking/widgets/search/TextComponentSearcher.java b/Ghidra/Framework/Docking/src/main/java/docking/widgets/search/TextComponentSearcher.java
index 3fe9efbe03..d7c4ea1633 100644
--- a/Ghidra/Framework/Docking/src/main/java/docking/widgets/search/TextComponentSearcher.java
+++ b/Ghidra/Framework/Docking/src/main/java/docking/widgets/search/TextComponentSearcher.java
@@ -74,6 +74,10 @@ public class TextComponentSearcher implements FindDialogSearcher {
this.maxContextChars = max;
}
+ public boolean isBusy() {
+ return worker.isBusy();
+ }
+
@Override
public void dispose() {
diff --git a/Ghidra/Framework/Docking/src/test.slow/java/docking/widgets/search/TextComponentSearcherTest.java b/Ghidra/Framework/Docking/src/test.slow/java/docking/widgets/search/TextComponentSearcherTest.java
index 80648ad5a6..ce7ed5050e 100644
--- a/Ghidra/Framework/Docking/src/test.slow/java/docking/widgets/search/TextComponentSearcherTest.java
+++ b/Ghidra/Framework/Docking/src/test.slow/java/docking/widgets/search/TextComponentSearcherTest.java
@@ -197,7 +197,7 @@ public class TextComponentSearcherTest extends AbstractDockingTest {
results.activate();
assertActive(results);
- results.dispose();
+ runSwing(() -> results.dispose());
assertInactive(results);
// make sure active() does not work once disposed