Test fixes

This commit is contained in:
dragonmacher 2025-04-17 19:16:58 -04:00
parent 92e2b6b5d4
commit fb76362903
7 changed files with 186 additions and 201 deletions

View file

@ -106,7 +106,7 @@ class ParseDialog extends ReusableDialogComponentProvider {
private TableModel parsePathTableModel;
private TableModelListener parsePathTableListener;
private ArrayList<ComboBoxItem> itemList;
private List<ComboBoxItem> itemList;
private ComboBoxItemComparator comparator;
private ResourceFile parentUserFile;
private boolean saveAsInProgress;
@ -122,13 +122,17 @@ class ParseDialog extends ReusableDialogComponentProvider {
}
public void setupForDisplay() {
if (initialBuild) {
if (!initialBuild) {
toFront();
return;
}
itemList = new ArrayList<>();
comparator = new ComboBoxItemComparator();
addWorkPanel(buildMainPanel());
addDismissButton();
createActions();
setActionsEnabled();
notifyContextChanged();
// setup based on save state
if (currentProfileName != null) {
@ -142,10 +146,6 @@ class ParseDialog extends ReusableDialogComponentProvider {
}
}
}
else {
toFront();
}
}
void writeState(SaveState saveState) {
// Get the current state if the dialog has been displayed
@ -257,7 +257,7 @@ class ParseDialog extends ReusableDialogComponentProvider {
tableListener = e -> {
ComboBoxItem item = (ComboBoxItem) comboBox.getSelectedItem();
item.isChanged = !initialBuild;
setActionsEnabled();
notifyContextChanged();
};
tableModel = pathPanel.getTable().getModel();
tableModel.addTableModelListener(tableListener);
@ -272,7 +272,7 @@ class ParseDialog extends ReusableDialogComponentProvider {
parsePathTableListener = e -> {
ComboBoxItem item = (ComboBoxItem) comboBox.getSelectedItem();
item.isChanged = !initialBuild;
setActionsEnabled();
notifyContextChanged();
pathPanel.getTable().repaint();
};
parsePathTableModel = includePathPanel.getTable().getModel();
@ -407,9 +407,22 @@ class ParseDialog extends ReusableDialogComponentProvider {
}
private void selectionChanged(ItemEvent e) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
if (e.getStateChange() == ItemEvent.SELECTED) {
loadProfile();
return;
}
ComboBoxItem item = (ComboBoxItem) e.getItem();
if (item.isChanged && !saveAsInProgress && !initialBuild) {
if (!item.isChanged) {
return;
}
if (saveAsInProgress) {
return;
}
if (initialBuild) {
return;
}
if (item.isUserDefined) {
if (OptionDialog.showOptionDialog(rootPanel, "Save Changes to Profile?",
"Profile " + item.file.getName() +
@ -428,11 +441,6 @@ class ParseDialog extends ReusableDialogComponentProvider {
}
}
}
}
if (e.getStateChange() == ItemEvent.SELECTED) {
loadProfile();
}
}
private void processItemChanged(ComboBoxItem item) {
if (item.isUserDefined) {
@ -482,7 +490,7 @@ class ParseDialog extends ReusableDialogComponentProvider {
return;
}
item.isChanged = true;
setActionsEnabled();
notifyContextChanged();
}
private void createActions() {
@ -491,8 +499,13 @@ class ParseDialog extends ReusableDialogComponentProvider {
public void actionPerformed(ActionContext context) {
save((ComboBoxItem) comboBox.getSelectedItem());
}
@Override
public boolean isEnabledForContext(ActionContext context) {
ComboBoxItem item = (ComboBoxItem) comboBox.getSelectedItem();
return item.isChanged && item.isUserDefined;
}
};
saveAction.setEnabled(false);
Icon icon = Icons.SAVE_ICON;
String saveGroup = "save";
saveAction.setMenuBarData(new MenuData(new String[] { "Save" }, icon, saveGroup));
@ -506,7 +519,6 @@ class ParseDialog extends ReusableDialogComponentProvider {
saveAs((ComboBoxItem) comboBox.getSelectedItem());
}
};
saveAsAction.setEnabled(true);
icon = Icons.SAVE_AS_ICON;
saveAsAction.setMenuBarData(new MenuData(new String[] { "Save As..." }, icon, saveGroup));
saveAsAction.setToolBarData(new ToolBarData(icon, saveGroup));
@ -518,9 +530,13 @@ class ParseDialog extends ReusableDialogComponentProvider {
public void actionPerformed(ActionContext context) {
clear();
}
@Override
public boolean isEnabledForContext(ActionContext context) {
return true;
}
};
clearAction.setEnabled(true);
icon = Icons.CLEAR_ICON;
String clearGroup = "clear";
clearAction
@ -534,8 +550,12 @@ class ParseDialog extends ReusableDialogComponentProvider {
public void actionPerformed(ActionContext context) {
refresh();
}
@Override
public boolean isEnabledForContext(ActionContext context) {
return true;
}
};
refreshAction.setEnabled(true);
icon = Icons.REFRESH_ICON;
String refreshGroup = "refresh";
refreshAction.setMenuBarData(new MenuData(new String[] { "Refresh" }, icon, refreshGroup));
@ -549,8 +569,13 @@ class ParseDialog extends ReusableDialogComponentProvider {
public void actionPerformed(ActionContext context) {
delete();
}
@Override
public boolean isEnabledForContext(ActionContext context) {
ComboBoxItem item = (ComboBoxItem) comboBox.getSelectedItem();
return item.isUserDefined;
}
};
deleteAction.setEnabled(false);
icon = Icons.DELETE_ICON;
String deleteGroup = "Xdelete";
deleteAction.setMenuBarData(new MenuData(new String[] { "Delete" }, icon, deleteGroup));
@ -591,7 +616,7 @@ class ParseDialog extends ReusableDialogComponentProvider {
else {
writeProfile(item.file);
item.isChanged = false;
setActionsEnabled();
notifyContextChanged();
}
}
@ -641,7 +666,7 @@ class ParseDialog extends ReusableDialogComponentProvider {
finally {
saveAsInProgress = false;
}
setActionsEnabled();
notifyContextChanged();
}
}
@ -655,8 +680,8 @@ class ParseDialog extends ReusableDialogComponentProvider {
item.isChanged = false;
StringBuffer sb = new StringBuffer();
ArrayList<String> pathList = new ArrayList<>();
ArrayList<String> includeList = new ArrayList<>();
List<String> pathList = new ArrayList<>();
List<String> includeList = new ArrayList<>();
String langString = null;
String compileString = null;
try {
@ -731,7 +756,7 @@ class ParseDialog extends ReusableDialogComponentProvider {
addDocumentListener();
tableModel.addTableModelListener(tableListener);
parsePathTableModel.addTableModelListener(parsePathTableListener);
setActionsEnabled();
notifyContextChanged();
}
}
@ -836,33 +861,30 @@ class ParseDialog extends ReusableDialogComponentProvider {
}
private String[] expandPaths(String[] paths) {
ArrayList<String> list = new ArrayList<>();
List<String> list = new ArrayList<>();
for (String path : paths) {
File file = new File(path);
// process each header file in the directory
if (file.isDirectory()) {
IncludeFileFinder includeFileFinder = new IncludeFileFinder(file);
if (!file.isDirectory()) {
list.add(path);
continue;
}
IncludeFileFinder finder = new IncludeFileFinder(file);
try {
List<String> includeFileRoots = includeFileFinder.getIncludeFileRoots(true);
for (Object element : includeFileRoots) {
String string = (String) element;
if (string.endsWith(".h")) {
list.add(string);
List<String> roots = finder.getIncludeFileRoots(true);
for (String filePath : roots) {
if (filePath.endsWith(".h")) {
list.add(filePath);
}
}
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
else {
list.add(path);
Msg.error(this, "Exception finding CParser paths", e);
}
}
// convert paths list to String[]
return list.toArray(new String[0]);
}
@ -896,14 +918,6 @@ class ParseDialog extends ReusableDialogComponentProvider {
}
}
private void setActionsEnabled() {
ComboBoxItem item = (ComboBoxItem) comboBox.getSelectedItem();
if (saveAction != null) {
saveAction.setEnabled(item.isChanged && item.isUserDefined);
deleteAction.setEnabled(item.isUserDefined);
}
}
private File getSaveFile() {
GhidraFileChooser fileChooser = new GhidraFileChooser(rootPanel);
@ -914,7 +928,10 @@ class ParseDialog extends ReusableDialogComponentProvider {
File file = fileChooser.getSelectedFile();
fileChooser.dispose();
if (file != null) {
if (file == null) {
return null;
}
File parent = file.getParentFile();
if (parent != null) {
Preferences.setProperty(Preferences.LAST_EXPORT_DIRECTORY,
@ -925,14 +942,20 @@ class ParseDialog extends ReusableDialogComponentProvider {
if (!file.getName().endsWith(FileDataTypeManager.SUFFIX)) {
file = new File(file.getParentFile(), name + FileDataTypeManager.SUFFIX);
}
if (file.exists()) {
if (OptionDialog.showOptionDialog(rootPanel, "Overwrite Existing File?",
if (!file.exists()) {
return file;
}
int choice = OptionDialog.showOptionDialog(rootPanel, "Overwrite Existing File?",
"The file " + file.getAbsolutePath() +
" already exists.\nDo you want to overwrite it?",
"Yes", OptionDialog.QUESTION_MESSAGE) != OptionDialog.OPTION_ONE) {
file = null;
"Yes", OptionDialog.QUESTION_MESSAGE);
if (choice != OptionDialog.OPTION_ONE) {
return null;
}
else {
try {
PackedDatabase.delete(file);
}
@ -940,15 +963,9 @@ class ParseDialog extends ReusableDialogComponentProvider {
Msg.showError(this, mainPanel, "Archive Overwrite Failed", e.getMessage());
return null;
}
}
}
}
return file;
}
/**
* Called when user selects Cancel Button
*/
@Override
protected void dismissCallback() {
close();
@ -1059,7 +1076,7 @@ class ParseDialog extends ReusableDialogComponentProvider {
return this.parseToFileButton;
}
ArrayList<ComboBoxItem> getProfiles() {
List<ComboBoxItem> getProfiles() {
return this.itemList;
}

View file

@ -17,7 +17,6 @@ package docking;
import static org.junit.Assert.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.Set;
@ -622,10 +621,14 @@ public class ComponentProviderActionsTest extends AbstractGhidraHeadedIntegratio
}
private void performLaunchKeyStrokeDialogAction() {
ToolActions toolActions = (ToolActions) ((AbstractDockingTool) tool).getToolActions();
ToolActions toolActions = (ToolActions) tool.getToolActions();
Action action = toolActions.getAction(KeyStroke.getKeyStroke("F4"));
assertNotNull(action);
runSwing(() -> action.actionPerformed(new ActionEvent(this, 0, "")), false);
runSwing(() -> {
SystemKeyBindingAction sysAction = (SystemKeyBindingAction) action;
ExecutableAction executableAction = sysAction.getExecutableAction(null);
executableAction.execute();
}, false);
}
private ToolOptions getKeyBindingOptions() {

View file

@ -17,11 +17,8 @@ package ghidra.app.plugin.core.cparser;
import static org.junit.Assert.*;
import java.awt.Window;
import java.io.File;
import java.util.ArrayList;
import javax.swing.JTextArea;
import java.util.List;
import org.junit.*;
@ -46,8 +43,6 @@ import utilities.util.FileUtilities;
public class ParseDialogParsingAndPromptsTest extends AbstractGhidraHeadedIntegrationTest {
private static final String TITLE = "CParser Results Summary";
private TestEnv env;
private PluginTool tool;
@ -534,57 +529,13 @@ public class ParseDialogParsingAndPromptsTest extends AbstractGhidraHeadedIntegr
}
}
private void startSetLanguage(LanguageID languageID, CompilerSpecID compilerSpecID)
throws Exception {
if (languageID == null) {
throw new RuntimeException("languageID == null not allowed");
}
if (compilerSpecID == null) {
throw new RuntimeException("compilerSpecID == null not allowed");
}
SetLanguageDialog dlg = waitForDialogComponent(SetLanguageDialog.class);
assertNotNull(dlg);
NewLanguagePanel languagePanel =
(NewLanguagePanel) getInstanceField("selectLangPanel", dlg);
assertNotNull(languagePanel);
waitForSwing();
runSwing(() -> {
NewLanguagePanel selectLangPanel =
(NewLanguagePanel) getInstanceField("selectLangPanel", dlg);
selectLangPanel.setSelectedLcsPair(
new LanguageCompilerSpecPair(languageID, compilerSpecID));
}, true);
waitForSwing();
pressButtonByText(dlg, "OK");
}
private void assertResultDialog() {
Window aboutDialog = waitForWindow(TITLE);
assertNotNull(aboutDialog);
pressButtonByText(aboutDialog, "OK");
}
private ParseDialog showParseDialog() {
//ActionContext actionContext = cbPlugin.getProvider().getActionContext(null);
performAction(cparserAction, false);
ParseDialog parseDialog = waitForDialogComponent(ParseDialog.class);
assertNotNull(parseDialog);
return parseDialog;
}
private void setOption(ParseDialog dialog, String options) {
runSwing(() -> {
JTextArea parseOptionsTextField = dialog.getParseOptionsTextField();
parseOptionsTextField.setText(options);
});
}
private void setIncludePaths(ParseDialog dialog, String paths[]) {
runSwing(() -> {
PathnameTablePanel incPaths = dialog.getIncludePaths();
@ -602,7 +553,7 @@ public class ParseDialogParsingAndPromptsTest extends AbstractGhidraHeadedIntegr
private void setSelectedParseProfile(ParseDialog dialog, String profileName) {
runSwing(() -> {
GhidraComboBox<ParseDialog.ComboBoxItem> parseComboBox = dialog.getParseComboBox();
ArrayList<ComboBoxItem> profiles = dialog.getProfiles();
List<ComboBoxItem> profiles = dialog.getProfiles();
int index = 0;
for (ComboBoxItem comboBoxItem : profiles) {
if (profileName.equals(comboBoxItem.getName())) {

View file

@ -344,7 +344,7 @@ public class ParseDialogTest extends AbstractGhidraHeadedIntegrationTest {
private void readDefaultParseProfileFile() throws Exception {
StringBuffer buffy = new StringBuffer();
StringBuilder buffy = new StringBuilder();
List<String> pathList = new ArrayList<>();
ResourceFile profileFile = getPrfFile();
@ -367,7 +367,6 @@ public class ParseDialogTest extends AbstractGhidraHeadedIntegrationTest {
buffy.append(line + "\n");
}
paths = pathList;
defaultPrfOptions = buffy.toString();

View file

@ -17,7 +17,6 @@ package ghidra.app.tablechooser;
import static org.junit.Assert.*;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.*;
import java.util.concurrent.CountDownLatch;
@ -456,10 +455,14 @@ public class TableChooserDialogTest extends AbstractGhidraHeadedIntegrationTest
}
private void performLaunchKeyStrokeDialogAction() {
ToolActions toolActions = (ToolActions) ((AbstractDockingTool) tool).getToolActions();
ToolActions toolActions = (ToolActions) tool.getToolActions();
Action action = toolActions.getAction(KeyStroke.getKeyStroke("F4"));
assertNotNull(action);
runSwing(() -> action.actionPerformed(new ActionEvent(this, 0, "")), false);
runSwing(() -> {
SystemKeyBindingAction sysAction = (SystemKeyBindingAction) action;
ExecutableAction executableAction = sysAction.getExecutableAction(null);
executableAction.execute();
}, false);
}
private void setOptionsKeyStroke(DockingAction action, KeyStroke newKs) {

View file

@ -24,6 +24,7 @@ import javax.swing.table.TableModel;
import org.junit.*;
import docking.action.DockingAction;
import docking.action.DockingActionIf;
import docking.tool.ToolConstants;
import docking.widgets.table.GTableFilterPanel;
@ -95,10 +96,12 @@ public class ManagePluginsTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testActionEnablement() {
performAction(managePluginsDialog.getSaveAction(), true);
DockingAction saveAction = managePluginsDialog.getSaveAction();
performAction(saveAction, true);
assertFalse(saveAction.isEnabledForContext(managePluginsDialog.getActionContext(null)));
assertFalse(managePluginsDialog.getSaveAction().isEnabled());
assertTrue(managePluginsDialog.getSaveAsAction().isEnabled());
DockingAction saveAsAction = managePluginsDialog.getSaveAsAction();
assertTrue(saveAsAction.isEnabledForContext(managePluginsDialog.getActionContext(null)));
}
@Test
@ -144,7 +147,8 @@ public class ManagePluginsTest extends AbstractGhidraHeadedIntegrationTest {
waitForTasks();
assertTrue(tool.hasConfigChanged());
assertTrue(managePluginsDialog.getSaveAction().isEnabled());
DockingAction action = managePluginsDialog.getSaveAction();
assertTrue(action.isEnabledForContext(managePluginsDialog.getActionContext(null)));
assertTrue(
pluginModel.isLoaded(PluginDescription.getPluginDescription(AboutProgramPlugin.class)));
}
@ -152,10 +156,11 @@ public class ManagePluginsTest extends AbstractGhidraHeadedIntegrationTest {
@Test
public void testRemovePlugin() throws Exception {
tool.setConfigChanged(false);
SwingUtilities.invokeLater(() -> pluginManagerComponent.manageAllPlugins());
runSwingLater(() -> pluginManagerComponent.manageAllPlugins());
pluginModel.removePlugin(PluginDescription.getPluginDescription(EquateTablePlugin.class));
assertTrue(tool.hasConfigChanged());
assertTrue(managePluginsDialog.getSaveAction().isEnabled());
DockingAction action = managePluginsDialog.getSaveAction();
assertTrue(action.isEnabledForContext(managePluginsDialog.getActionContext(null)));
assertFalse(
pluginModel.isLoaded(PluginDescription.getPluginDescription(AboutProgramPlugin.class)));

View file

@ -120,8 +120,13 @@ public class ManagePluginsDialog extends ReusableDialogComponentProvider {
public void actionPerformed(ActionContext context) {
save();
}
@Override
public boolean isEnabledForContext(ActionContext context) {
return tool.hasConfigChanged();
}
};
saveAction.setEnabled(tool.hasConfigChanged());
icon = Icons.SAVE_ICON;
String saveGroup = "save";
saveAction.setMenuBarData(new MenuData(new String[] { "Save" }, icon, saveGroup));
@ -135,8 +140,12 @@ public class ManagePluginsDialog extends ReusableDialogComponentProvider {
public void actionPerformed(ActionContext context) {
saveAs();
}
@Override
public boolean isEnabledForContext(ActionContext context) {
return true;
}
};
saveAsAction.setEnabled(true);
icon = Icons.SAVE_AS_ICON;
saveAsAction
.setMenuBarData(new MenuData(new String[] { "Save As..." }, icon, saveGroup));
@ -157,20 +166,18 @@ public class ManagePluginsDialog extends ReusableDialogComponentProvider {
}
else {
tool.getToolServices().saveTool(tool);
saveAction.setEnabled(false);
tool.contextChanged(null);
}
}
private void saveAs() {
tool.saveToolAs();
saveAction.setEnabled(tool.hasConfigChanged());
tool.contextChanged(null);
isNewTool = false;
}
public void stateChanged() {
if (saveAction != null) {
saveAction.setEnabled(tool.hasConfigChanged());
}
tool.contextChanged(null);
}
int getPackageCount() {