Ghidra is a software reverse engineering (SRE) framework
Test fixes
ghidragon0adc91a15621
diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.javaindex 1dd01ba698..8a51db6b82 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/AbstractEditorTest.java@@ -41,6 +41,7 @@ import ghidra.app.plugin.core.stackeditor.StackEditorModel;import ghidra.app.services.DataTypeManagerService;import ghidra.app.util.datatype.DataTypeSelectionEditor;import ghidra.framework.model.*;+import ghidra.framework.options.Options;import ghidra.framework.plugintool.PluginTool;import ghidra.framework.plugintool.util.PluginException;import ghidra.program.database.ProgramBuilder;@@ -819,4 +820,11 @@ public abstract class AbstractEditorTest extends AbstractGhidraHeadedIntegrationassertEquals(value, ((CompEditorModel) model).getLength());}+ protected void setOptions(String optionName, boolean b) {+ runSwing(() -> {+ Options options = tool.getOptions("Editors");+ assertTrue(options.isRegistered(optionName));+ options.setBoolean(optionName, b);+ });+ }}diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorProviderTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorProviderTest.javaindex 6974325e8b..87d7d0da60 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorProviderTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/StructureEditorProviderTest.java@@ -23,12 +23,16 @@ import org.junit.Assert;import org.junit.Test;import docking.ActionContext;+import docking.action.DockingActionIf;+import docking.action.ToggleDockingActionIf;import ghidra.framework.options.Options;import ghidra.program.model.data.*;import ghidra.util.exception.DuplicateNameException;import ghidra.util.exception.UsrException;public class StructureEditorProviderTest extends AbstractStructureEditorTest {+ private static final String HEX_OPTION_NAME =+ "Structure Editor" + Options.DELIMITER + "Show Numbers In Hex";@Overrideprotected void init(Structure dt, final Category cat, final boolean showInHex) {@@ -653,98 +657,61 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {}@Test- public void testChangeHexNumbersOption() throws Exception {- final Options options = tool.getOptions("Editors");- final String hexNumbersName =- "Structure Editor" + Options.DELIMITER + "Show Numbers In Hex";-- runSwing(() -> {- boolean showNumbersInHex = options.getBoolean(hexNumbersName, false);- installProvider(- new StructureEditorProvider(plugin, complexStructure, showNumbersInHex));- model = provider.getModel();- });-- DataType oldDt = model.viewComposite.clone(null);-- // Get the hex option values- boolean hexNumbers = options.getBoolean(hexNumbersName, false);- assertEquals(false, hexNumbers);- // Check the values are in decimal- assertEquals(false, model.isShowingNumbersInHex());- assertEquals("47", model.getValueAt(15, model.getOffsetColumn()));- assertEquals("45", model.getValueAt(15, model.getLengthColumn()));- assertEquals("325", model.getLengthAsString());+ public void testEditorHexModeDefaultsFromOptions() throws Exception {+ // options default is hex+ provider = edit(complexStructure);+ model = provider.getModel();+ assertEquals(true, model.isShowingNumbersInHex());+ assertEquals("0x2f", model.getValueAt(15, model.getOffsetColumn()));+ assertEquals("0x2d", model.getValueAt(15, model.getLengthColumn()));+ assertEquals("0x145", model.getLengthAsString());- // Set the hex offset option value to Hex- options.setBoolean(hexNumbersName, true);+ closeProvider(provider);+ setOptions(HEX_OPTION_NAME, false);- // Get the hex option values- hexNumbers = options.getBoolean(hexNumbersName, false);- assertEquals(true, hexNumbers);- // Check the values (offset should still be decimal in editor)+ provider = edit(complexStructure);+ model = provider.getModel();assertEquals(false, model.isShowingNumbersInHex());assertEquals("47", model.getValueAt(15, model.getOffsetColumn()));assertEquals("45", model.getValueAt(15, model.getLengthColumn()));assertEquals("325", model.getLengthAsString());+ }- // Close the editor- runSwingLater(() -> provider.closeComponent());- waitForSwing();- waitForBusyTool(tool);- waitForSwing();- // Editor should be closed.- assertFalse(tool.isVisible(provider));- assertTrue(complexStructure.isEquivalent(oldDt));+ @Test+ public void testHexDisplayOptionsChangeDoesntAffectExisting() throws Exception {+ // options default is hex+ provider = edit(complexStructure);+ model = provider.getModel();+ assertEquals(true, model.isShowingNumbersInHex());+ assertEquals("0x2f", model.getValueAt(15, model.getOffsetColumn()));+ assertEquals("0x2d", model.getValueAt(15, model.getLengthColumn()));+ assertEquals("0x145", model.getLengthAsString());- // Re-open the editor- runSwing(() -> {- boolean showNumbersInHex = options.getBoolean(hexNumbersName, false);- installProvider(- new StructureEditorProvider(plugin, complexStructure, showNumbersInHex));- model = provider.getModel();- });+ setOptions(HEX_OPTION_NAME, false);- // Get the hex option values (offset should now be hexadecimal in editor)- hexNumbers = options.getBoolean(hexNumbersName, false);- assertEquals(true, hexNumbers);- // Check the valuesassertEquals(true, model.isShowingNumbersInHex());assertEquals("0x2f", model.getValueAt(15, model.getOffsetColumn()));assertEquals("0x2d", model.getValueAt(15, model.getLengthColumn()));assertEquals("0x145", model.getLengthAsString());+ }- // Set the hex offset option value to decimal- options.setBoolean(hexNumbersName, false);-- // Get the hex option values- hexNumbers = options.getBoolean(hexNumbersName, false);- assertEquals(false, hexNumbers);- // Check the values (offset should still be hexadecimal in editor)+ @Test+ public void testToggleHexModeAction() throws Exception {+ provider = edit(complexStructure);+ model = provider.getModel();assertEquals(true, model.isShowingNumbersInHex());assertEquals("0x2f", model.getValueAt(15, model.getOffsetColumn()));assertEquals("0x2d", model.getValueAt(15, model.getLengthColumn()));assertEquals("0x145", model.getLengthAsString());- // Close the editor- runSwingLater(() -> provider.closeComponent());- waitForSwing();- waitForBusyTool(tool);- waitForSwing();- // Editor should be closed.- assertFalse(tool.isVisible(provider));- assertTrue(complexStructure.isEquivalent(oldDt));- // Re-open the editor- init(complexStructure, pgmTestCat, false);+ DockingActionIf action = getAction(plugin, "Editor: Show Numbers In Hex");+ setToggleActionSelected((ToggleDockingActionIf) action, new ActionContext(), false);- // Get the hex option values (offset should now be decimal in editor)- hexNumbers = options.getBoolean(hexNumbersName, false);- assertEquals(false, hexNumbers);- // Check the values are in decimalassertEquals(false, model.isShowingNumbersInHex());assertEquals("47", model.getValueAt(15, model.getOffsetColumn()));assertEquals("45", model.getValueAt(15, model.getLengthColumn()));assertEquals("325", model.getLengthAsString());+}@Test@@ -795,4 +762,11 @@ public class StructureEditorProviderTest extends AbstractStructureEditorTest {assertFalse(tool.isVisible(provider));}++ protected StructureEditorProvider edit(DataType dt) {+ runSwing(() -> {+ plugin.edit(dt);+ });+ return waitForComponentProvider(StructureEditorProvider.class);+ }}diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorProviderTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorProviderTest.javaindex df0c79785f..18c7dc97ef 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorProviderTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/compositeeditor/UnionEditorProviderTest.java@@ -23,12 +23,16 @@ import org.junit.Assert;import org.junit.Test;import docking.ActionContext;+import docking.action.DockingActionIf;+import docking.action.ToggleDockingActionIf;import ghidra.framework.options.Options;import ghidra.program.model.data.*;import ghidra.util.Swing;import ghidra.util.exception.UsrException;public class UnionEditorProviderTest extends AbstractUnionEditorTest {+ private static final String HEX_OPTION_NAME =+ "Union Editor" + Options.DELIMITER + "Show Numbers In Hex";@Testpublic void testReplaceDataType() throws Exception {@@ -299,77 +303,55 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {}@Test- public void testChangeHexNumbersOption() throws Exception {- init(complexUnion, pgmTestCat, false);- DataType oldDt = model.viewComposite.clone(null);-- Options options = tool.getOptions("Editors");- String hexNumbersName = "Union Editor" + Options.DELIMITER + "Show Numbers In Hex";-- // Get the hex length option value- boolean hexLength = options.getBoolean(hexNumbersName, false);- assertEquals(false, hexLength);- // Check the length value is in decimal- assertEquals(false, model.isShowingNumbersInHex());- assertEquals("29", model.getValueAt(15, model.getLengthColumn()));- assertEquals("87", model.getLengthAsString());+ public void testEditorHexModeDefaultsFromOptions() throws Exception {+ // options default is hex+ provider = edit(complexUnion);+ model = provider.getModel();+ assertEquals(true, model.isShowingNumbersInHex());+ assertEquals("0x1d", model.getValueAt(15, model.getLengthColumn()));+ assertEquals("0x57", model.getLengthAsString());- // Set the hex length option value to Hex- options.setBoolean(hexNumbersName, true);+ closeProvider(provider);+ setOptions(HEX_OPTION_NAME, false);- // Get the hex length option value- hexLength = options.getBoolean(hexNumbersName, false);- assertEquals(true, hexLength);- // Check the value (length should still be decimal in editor)+ provider = edit(complexUnion);+ model = provider.getModel();assertEquals(false, model.isShowingNumbersInHex());assertEquals("29", model.getValueAt(15, model.getLengthColumn()));assertEquals("87", model.getLengthAsString());+ }- // Close the editor- Swing.runLater(() -> provider.closeComponent());- waitForSwing();- // Editor should be closed.- assertFalse(tool.isVisible(provider));- assertTrue(complexUnion.isEquivalent(oldDt));- // Re-open the editor- init(complexUnion, pgmTestCat, true);-- // Get the hex option value (length should now be hexadecimal in editor)- hexLength = options.getBoolean(hexNumbersName, false);- assertEquals(true, hexLength);- // Check the value is in hexadecimal+ @Test+ public void testHexDisplayOptionsChangeDoesntAffectExisting() throws Exception {+ // options default is hex+ provider = edit(complexUnion);+ model = provider.getModel();assertEquals(true, model.isShowingNumbersInHex());assertEquals("0x1d", model.getValueAt(15, model.getLengthColumn()));assertEquals("0x57", model.getLengthAsString());- // Set the hex length option value to decimal- options.setBoolean(hexNumbersName, false);+ setOptions(HEX_OPTION_NAME, false);- // Get the hex option value- hexLength = options.getBoolean(hexNumbersName, false);- assertEquals(false, hexLength);- // Check the value (length should still be hexadecimal in editor)assertEquals(true, model.isShowingNumbersInHex());assertEquals("0x1d", model.getValueAt(15, model.getLengthColumn()));assertEquals("0x57", model.getLengthAsString());+ }- // Close the editor- Swing.runLater(() -> provider.closeComponent());- waitForSwing();- // Editor should be closed.- assertFalse(tool.isVisible(provider));- assertTrue(complexUnion.isEquivalent(oldDt));+ @Test+ public void testToggleHexModeAction() throws Exception {+ provider = edit(complexUnion);+ model = provider.getModel();+ assertEquals(true, model.isShowingNumbersInHex());+ assertEquals("0x1d", model.getValueAt(15, model.getLengthColumn()));+ assertEquals("0x57", model.getLengthAsString());- // Re-open the editor- init(complexUnion, pgmTestCat, false);+ DockingActionIf action = getAction(plugin, "Editor: Show Numbers In Hex");+ setToggleActionSelected((ToggleDockingActionIf) action, new ActionContext(), false);- // Get the hex option value (length should now be decimal in editor)- hexLength = options.getBoolean(hexNumbersName, false);- assertEquals(false, hexLength);- // Check the value is in hexadecimalassertEquals(false, model.isShowingNumbersInHex());assertEquals("29", model.getValueAt(15, model.getLengthColumn()));assertEquals("87", model.getLengthAsString());+}private void delete(int... rows) {@@ -378,4 +360,11 @@ public class UnionEditorProviderTest extends AbstractUnionEditorTest {model.setSelection(rows);deleteAction.actionPerformed(new ActionContext());}++ protected UnionEditorProvider edit(DataType dt) {+ runSwing(() -> {+ plugin.edit(dt);+ });+ return waitForComponentProvider(UnionEditorProvider.class);+ }}