Test fixes for timing issue

This commit is contained in:
dragonmacher 2022-02-01 09:51:03 -05:00
parent d35d496c23
commit 3d0abddbff
3 changed files with 35 additions and 70 deletions

View File

@ -21,7 +21,6 @@ import java.awt.*;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.*;
import javax.swing.table.*;
@ -39,7 +38,6 @@ import docking.widgets.fieldpanel.support.FieldSelection;
import ghidra.app.plugin.core.datamgr.DataTypeManagerPlugin;
import ghidra.app.plugin.core.datamgr.util.DataTypeChooserDialog;
import ghidra.app.plugin.core.stackeditor.StackEditorModel;
import ghidra.app.plugin.core.stackeditor.StackFrameDataType;
import ghidra.app.services.DataTypeManagerService;
import ghidra.app.util.datatype.DataTypeSelectionEditor;
import ghidra.framework.model.*;
@ -48,7 +46,6 @@ import ghidra.framework.plugintool.util.PluginException;
import ghidra.program.database.ProgramBuilder;
import ghidra.program.model.data.*;
import ghidra.program.model.data.Composite;
import ghidra.program.model.data.Enum;
import ghidra.program.model.listing.Program;
import ghidra.test.AbstractGhidraHeadedIntegrationTest;
import ghidra.test.TestEnv;
@ -155,9 +152,6 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration
closeAllWindows();
// this is an attempt to prevent stack traces when take down the environment out from
// under Swing
if (model != null) {
model = null;
}
@ -193,25 +187,6 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration
return compositeDataType.getDisplayName() + " (" + dtmName + ")";
}
@SuppressWarnings("unused")
private String getName(Composite composite) {
if (composite instanceof Structure) {
return "Structure Editor";
}
else if (composite instanceof Union) {
return "Union Editor";
}
else if (composite instanceof Enum) {
return "Enum Editor";
}
else if (composite instanceof StackFrameDataType) {
return "Stack Editor";
}
else {
return "Composite Data Type Editor";
}
}
protected CycleGroupAction getCycleGroup(DataType dt) {
for (CycleGroupAction action : cycles) {
CycleGroup group = action.getCycleGroup();
@ -272,7 +247,7 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration
}
private String arrayToString(int[] values) {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
for (int value : values) {
buf.append(Integer.toString(value) + ", ");
}
@ -301,7 +276,7 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration
if (componentProvider instanceof DataTypeChooserDialog) {
// we must make a selection
Object treePanel = getInstanceField("treePanel", componentProvider);
final JTree tree = (JTree) getInstanceField("tree", treePanel);
JTree tree = (JTree) getInstanceField("tree", treePanel);
DefaultMutableTreeNode root = (DefaultMutableTreeNode) tree.getModel().getRoot();
DefaultMutableTreeNode matchingNode = findFirstLeafNode(root);
TreePath treePath = (TreePath) invokeInstanceMethod("getTreePath", matchingNode);
@ -455,7 +430,7 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration
/**
* Types the indicated string
*
*
* <br>Note: Handles upper and lowercase alphabetic characters,
* numeric characters, and other standard keyboard characters that are
* printable characters. It also handles '\n', '\t', and '\b'.
@ -593,7 +568,7 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration
@SuppressWarnings("unchecked")
private void removeTableCellEditorsFocusLostListener() {
//
//
// Note: black magic code to disable focusLost from cancelling the current editor session
//
@ -813,12 +788,11 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegration
}
protected void checkEnablement(CompositeEditorTableAction action, boolean expectedEnablement) {
AtomicBoolean result = new AtomicBoolean();
runSwing(() -> result.set(action.isEnabledForContext(provider.getActionContext(null))));
boolean actionEnablement = result.get();
assertEquals(action.getName() + " is unexpectedly " +
(actionEnablement ? "enabled" : "disabled") + ".", expectedEnablement,
actionEnablement);
boolean isEnabled =
runSwing(() -> action.isEnabledForContext(provider.getActionContext(null)));
assertEquals(
action.getName() + " is unexpectedly " + (isEnabled ? "enabled" : "disabled") + ".",
expectedEnablement, isEnabled);
}
protected void assertIsPackingEnabled(boolean aligned) {

View File

@ -17,10 +17,12 @@ package ghidra.app.plugin.core.stackeditor;
import static org.junit.Assert.*;
import javax.swing.*;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import org.junit.*;
import org.junit.After;
import org.junit.Before;
import docking.action.DockingAction;
import docking.action.DockingActionIf;
@ -36,6 +38,7 @@ import ghidra.program.model.data.*;
import ghidra.program.model.listing.*;
import ghidra.program.model.symbol.SourceType;
import ghidra.program.util.ProgramLocation;
import ghidra.util.Swing;
public abstract class AbstractStackEditorTest extends AbstractEditorTest {
@ -145,7 +148,7 @@ public abstract class AbstractStackEditorTest extends AbstractEditorTest {
Object editorPanel = getInstanceField("editorPanel", provider);
final JTable table = (JTable) getInstanceField("table", editorPanel);
runSwing(() -> table.editingCanceled(new ChangeEvent(table)));
waitForPostedSwingRunnables();// some editing notifications are in an invokeLater
waitForSwing();// some editing notifications are in an invokeLater
}
@Override
@ -222,16 +225,16 @@ public abstract class AbstractStackEditorTest extends AbstractEditorTest {
finally {
endTransaction(changed);
}
if (provider != null) {
Assert.fail("Provider initialized more than once -- stop it!");
}
assertNull("Provider initialized more than once", provider);
runSwing(() -> {
installProvider(new StackEditorProvider(stackEditorMgr, stackFrame.getFunction()));
assertNotNull(provider);
model = ((StackEditorProvider) provider).getModel();
});
waitForPostedSwingRunnables();
// assertTrue(!model.isLocked());
waitForProgram(program);
getActions();
stackModel = (StackEditorModel) model;
}
@ -247,9 +250,9 @@ public abstract class AbstractStackEditorTest extends AbstractEditorTest {
clearActions();
Object editorPanel = getInstanceField("editorPanel", provider);
final JTable table = (JTable) getInstanceField("table", editorPanel);
JTable table = (JTable) getInstanceField("table", editorPanel);
runSwing(() -> table.editingCanceled(new ChangeEvent(table)));
waitForPostedSwingRunnables();// some editing notifications are in an invokeLater
waitForSwing();// some editing notifications are in an invokeLater
runSwing(() -> provider.dispose(), true);
}
@ -365,7 +368,7 @@ public abstract class AbstractStackEditorTest extends AbstractEditorTest {
}
void closeEditor() {
SwingUtilities.invokeLater(() -> provider.closeComponent());
waitForPostedSwingRunnables();
Swing.runLater(() -> provider.closeComponent());
waitForSwing();
}
}

View File

@ -48,8 +48,7 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {
// Check enablement.
for (CompositeEditorTableAction action : actions) {
if ((action instanceof CycleGroupAction) ||
(action instanceof HexNumbersAction)) {
if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction)) {
checkEnablement(action, true);
}
else {
@ -79,8 +78,7 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {
// Check enablement.
for (CompositeEditorTableAction action : actions) {
if ((action instanceof CycleGroupAction) ||
(action instanceof HexNumbersAction)) {
if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction)) {
checkEnablement(action, true);
}
else {
@ -125,8 +123,6 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {
assertTrue(model.isValidName());// name should be valid
assertEquals(0, model.getNumSelectedComponentRows());
assertEquals(0, model.getNumSelectedRows());
// assertTrue(!model.isLocked());
// assertTrue(!model.isLockable());
assertEquals(function.getName(), stackModel.getCompositeName());
assertEquals(stackModel.getTypeName(), "Stack");
@ -141,8 +137,7 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {
boolean enabled = ((len <= numBytes) && ((favDt instanceof Pointer) || (len > 0)));
checkEnablement(action, enabled);
}
else if ((action instanceof CycleGroupAction) ||
(action instanceof HexNumbersAction) ||
else if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||
(action instanceof ShowComponentPathAction) ||
(action instanceof EditFieldAction) || (action instanceof ClearAction) ||
(action instanceof DeleteAction) || (action instanceof ArrayAction) ||
@ -159,12 +154,9 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {
numBytes = getModel().getMaxReplaceLength(5);
for (CompositeEditorTableAction action : actions) {
if (action instanceof FavoritesAction) {
FavoritesAction fav = (FavoritesAction) action;
DataType favDt = fav.getDataType();
checkEnablement(action, true);
}
else if ((action instanceof CycleGroupAction) ||
(action instanceof HexNumbersAction) ||
else if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||
(action instanceof ShowComponentPathAction) ||
(action instanceof EditFieldAction) || (action instanceof ClearAction) ||
(action instanceof ArrayAction) || (action instanceof PointerAction)) {
@ -191,8 +183,7 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {
boolean enabled = ((len <= numBytes) && ((favDt instanceof Pointer) || (len > 0)));
checkEnablement(action, enabled);
}
else if ((action instanceof CycleGroupAction) ||
(action instanceof HexNumbersAction) ||
else if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||
(action instanceof ShowComponentPathAction) ||
(action instanceof EditFieldAction) || (action instanceof ClearAction) ||
(action instanceof DeleteAction) || (action instanceof ArrayAction) ||
@ -221,8 +212,7 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {
boolean enabled = ((len <= numBytes) && ((favDt instanceof Pointer) || (len > 0)));
checkEnablement(action, enabled);
}
else if ((action instanceof CycleGroupAction) ||
(action instanceof HexNumbersAction) ||
else if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||
(action instanceof ShowComponentPathAction) ||
(action instanceof EditFieldAction) || (action instanceof ClearAction) ||
(action instanceof ArrayAction) || (action instanceof PointerAction)) {
@ -249,8 +239,7 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {
boolean enabled = ((len <= numBytes) && ((favDt instanceof Pointer) || (len > 0)));
checkEnablement(action, enabled);
}
else if ((action instanceof CycleGroupAction) ||
(action instanceof HexNumbersAction) ||
else if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||
(action instanceof ShowComponentPathAction) ||
(action instanceof EditFieldAction) || (action instanceof ClearAction) ||
(action instanceof DeleteAction) || (action instanceof ArrayAction) ||
@ -270,9 +259,8 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {
// Check enablement on a contiguous multi-component selection.
runSwing(() -> model.setSelection(new int[] { 2, 3, 4 }));
for (CompositeEditorTableAction action : actions) {
if ((action instanceof CycleGroupAction) ||
(action instanceof HexNumbersAction) || (action instanceof PointerAction) ||
(action instanceof ClearAction)) {
if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||
(action instanceof PointerAction) || (action instanceof ClearAction)) {
checkEnablement(action, true);
}
else {
@ -288,8 +276,8 @@ public class StackEditorEnablementTest extends AbstractStackEditorTest {
// Check enablement on a non-contiguous multi-component selection.
runSwing(() -> model.setSelection(new int[] { 2, 3, 6, 7 }));
for (CompositeEditorTableAction action : actions) {
if ((action instanceof CycleGroupAction) ||
(action instanceof HexNumbersAction) || (action instanceof ClearAction)) {
if ((action instanceof CycleGroupAction) || (action instanceof HexNumbersAction) ||
(action instanceof ClearAction)) {
checkEnablement(action, true);
}
else {