From 94e91bc4174dc076f1d4d6b4cf207eaf1793f689 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Fri, 6 Aug 2021 11:42:03 -0400 Subject: [PATCH] Test fixes; deprecation --- .../core/progmgr/ProgramManagerPlugin.java | 21 ++--- .../ghidra/app/services/ProgramManager.java | 90 ++++++++++--------- .../searchtext/SearchTextPlugin1Test.java | 6 +- .../searchtext/SearchTextPlugin2Test.java | 28 +++--- .../searchtext/SearchTextPlugin3Test.java | 74 +++++++-------- 5 files changed, 111 insertions(+), 108 deletions(-) diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramManagerPlugin.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramManagerPlugin.java index a16d1eb1fd..83f4a9b2cc 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramManagerPlugin.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/progmgr/ProgramManagerPlugin.java @@ -288,21 +288,17 @@ public class ProgramManagerPlugin extends Plugin implements ProgramManager { @Override public Program openProgram(DomainFile df, Component parent) { - return openProgram(df, -1, OPEN_CURRENT, parent); + return openProgram(df, -1, OPEN_CURRENT); } @Override - public Program openProgram(final DomainFile df, final int version) { + public Program openProgram(DomainFile df, int version) { return openProgram(df, version, OPEN_CURRENT); } @Override - public Program openProgram(final DomainFile df, final int version, final int state) { - return openProgram(df, version, state, tool.getToolFrame()); - } + public Program openProgram(DomainFile domainFile, int version, int state) { - private Program openProgram(final DomainFile domainFile, final int version, final int state, - final Component parent) { if (domainFile == null) { throw new IllegalArgumentException("Domain file cannot be null"); } @@ -312,15 +308,12 @@ public class ProgramManagerPlugin extends Plugin implements ProgramManager { return null; } - AtomicReference ref = new AtomicReference<>(); - Runnable r = () -> { - ref.set(doOpenProgram(domainFile, version, state)); + Program program = Swing.runNow(() -> { + Program p = doOpenProgram(domainFile, version, state); updateActions(); - }; + return p; + }); - SystemUtilities.runSwingNow(r); - - Program program = ref.get(); if (program != null) { Msg.info(this, "Opened program in " + tool.getName() + " tool: " + domainFile); } diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/services/ProgramManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/services/ProgramManager.java index b46e835786..c7dea6e54e 100644 --- a/Ghidra/Features/Base/src/main/java/ghidra/app/services/ProgramManager.java +++ b/Ghidra/Features/Base/src/main/java/ghidra/app/services/ProgramManager.java @@ -26,9 +26,8 @@ import ghidra.program.model.address.Address; import ghidra.program.model.listing.Program; /** - * Service for managing programs. Multiple programs may be open in a tool, - * but only one is active at any given time. - * + * Service for managing programs. Multiple programs may be open in a tool, but only one is active + * at any given time. */ @ServiceInfo(defaultProvider = ProgramManagerPlugin.class, description = "Get the currently open program") public interface ProgramManager { @@ -59,11 +58,9 @@ public interface ProgramManager { public Program getCurrentProgram(); /** - * Returns true if the specified program is open and considiered visible to - * the user. - * @param program - * @return true if the specified program is open and considiered visible to - * the user + * Returns true if the specified program is open and considered visible to the user. + * @param program the program + * @return true if the specified program is open and considered visible to the user */ public boolean isVisible(Program program); @@ -75,8 +72,7 @@ public interface ProgramManager { public boolean closeProgram(); /** - * Open the program corresponding to the given url. Once open it will - * become + * Open the program corresponding to the given url. * @param ghidraURL valid server-based program URL * @param state initial open state (OPEN_HIDDEN, OPEN_CURRENT, OPEN_VISIBLE). * The visibility states will be ignored if the program is already open. @@ -94,6 +90,17 @@ public interface ProgramManager { */ public Program openProgram(DomainFile domainFile); + /** + * Open the program for the given domainFile. Once open it will become the active program. + * + *

Note: this method functions exactly as {@link #openProgram(DomainFile)} + * + * @param domainFile domain file that has the program + * @param dialogParent unused + * @return the program + * @deprecated deprecated for 10.1; removal for 10.3 or later; use {@link #openProgram(DomainFile)} + */ + @Deprecated public Program openProgram(DomainFile domainFile, Component dialogParent); /** @@ -123,7 +130,7 @@ public interface ProgramManager { * may not have it registered as open. The program is made the active program. * @param program the program to register as open with the tool. */ - void openProgram(Program program); + public void openProgram(Program program); /** * Opens the program to the tool. In this case the program is already open, but this tool @@ -134,22 +141,21 @@ public interface ProgramManager { * @deprecated use openProgram(Program program, int state) instead. */ @Deprecated - void openProgram(Program program, boolean current); + public void openProgram(Program program, boolean current); /** - * Open the specified program in te tool. - * @param program + * Open the specified program in the tool. + * @param program the program * @param state initial open state (OPEN_HIDDEN, OPEN_CURRENT, OPEN_VISIBLE). * The visibility states will be ignored if the program is already open. */ public void openProgram(Program program, int state); /** - * Establish a persistent owner on an open program. - * This will cause the program manager to simply make a program - * hidden if it is closed. - * @param program - * @param owner + * Establish a persistent owner on an open program. This will cause the program manager to + * imply make a program hidden if it is closed. + * @param program the program + * @param owner the owner * @return true if program is open and another object is not already the owner, * or the specified owner is already the owner. * @see #releaseProgram(Program, Object) @@ -158,14 +164,14 @@ public interface ProgramManager { /** * Release the persistent ownership of a program. - * The program will automatically be closed if it is hidden or was - * marked as temporary. If any of these closures corresponds to a - * program with changes the user will be given an opportunity to - * save or keep the program open. - * If persistentOwner is not the correct owner, the method will - * have no affect. - * @param program - * @param persistentOwner + *

+ * The program will automatically be closed if it is hidden or was marked as temporary. If + * any of these closures corresponds to a program with changes the user will be given an + * opportunity to save or keep the program open. + *

+ * If persistentOwner is not the correct owner, the method will have no affect. + * @param program the program + * @param persistentOwner the owner defined by {@link #setPersistentOwner(Program, Object)} */ public void releaseProgram(Program program, Object persistentOwner); @@ -192,7 +198,7 @@ public interface ProgramManager { * @return true if all other programs were closed. Returns false if the user canceled the close * while being prompted to save. */ - boolean closeOtherPrograms(boolean ignoreChanges); + public boolean closeOtherPrograms(boolean ignoreChanges); /** * Closes all open programs in this tool. If this tool is the only tool with a program @@ -202,13 +208,13 @@ public interface ProgramManager { * @return true if all programs were closed. Returns false if the user canceled the close * while being prompted to save. */ - boolean closeAllPrograms(boolean ignoreChanges); + public boolean closeAllPrograms(boolean ignoreChanges); /** * Sets the given program to be the current active program in the tool. * @param p the program to make active. */ - void setCurrentProgram(Program p); + public void setCurrentProgram(Program p); /** * Returns the first program in the list of open programs that contains the given address. @@ -218,24 +224,28 @@ public interface ProgramManager { * @param addr the address for which to search. * @return the first program that can be found to contain the given address. */ - Program getProgram(Address addr); + public Program getProgram(Address addr); /** - * Returns a list of all open program.s + * Returns a list of all open program. + * @return the programs */ - Program[] getAllOpenPrograms(); + public Program[] getAllOpenPrograms(); /** - * Allows program manager state to be locked/unlocked. - * While locked, the program manager will not support opening - * additional programs. + * Allows program manager state to be locked/unlocked. While locked, the program manager will + * not support opening additional programs. * @param state locked if true, unlocked if false + * @deprecated deprecated for 10.1; removal for 10.3 or later */ - void lockDown(boolean state); + @Deprecated + public void lockDown(boolean state); /** - * Returns true if program manager - * @return + * Returns true if program manager is in the locked state + * @return true if program manager is in the locked state + * @deprecated deprecated for 10.1; removal for 10.3 or later */ - boolean isLocked(); + @Deprecated + public boolean isLocked(); } diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin1Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin1Test.java index 1cbd6d2e9c..29f3917b68 100644 --- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin1Test.java +++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin1Test.java @@ -681,9 +681,9 @@ public class SearchTextPlugin1Test extends AbstractGhidraHeadedIntegrationTest { AddressBasedTableModel model) { GThreadedTablePanel threadedTablePanel = (GThreadedTablePanel) providers[0].getThreadedTablePanel(); - final GTable table = threadedTablePanel.getTable(); + GTable table = threadedTablePanel.getTable(); Random random = new Random(); - final int randomRow = random.nextInt(model.getRowCount()); + int randomRow = random.nextInt(model.getRowCount()); DockingActionIf deleteRowAction = getAction(tool, "TableServicePlugin", "Remove Items"); ProgramLocation toBeDeleted = model.getRowObject(randomRow); @@ -972,7 +972,7 @@ public class SearchTextPlugin1Test extends AbstractGhidraHeadedIntegrationTest { } private void searchOnce(JTextField tf) throws Exception { - final ActionListener listener = tf.getActionListeners()[0]; + ActionListener listener = tf.getActionListeners()[0]; runSwing(() -> listener.actionPerformed(null)); } diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin2Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin2Test.java index 046b8b77de..158854832f 100644 --- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin2Test.java +++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin2Test.java @@ -155,7 +155,7 @@ public class SearchTextPlugin2Test extends AbstractGhidraHeadedIntegrationTest { JRadioButton exactRB = (JRadioButton) findAbstractButtonByText(container, SearchTextPlugin1Test.EXACT_MATCH_SEARCH); assertNotNull(exactRB); - assertTrue(!exactRB.isSelected()); + assertFalse(exactRB.isSelected()); JRadioButton searchFieldsRB = (JRadioButton) findAbstractButtonByText(container, "Selected Fields"); @@ -188,24 +188,24 @@ public class SearchTextPlugin2Test extends AbstractGhidraHeadedIntegrationTest { JRadioButton searchAllRB = (JRadioButton) findAbstractButtonByText(container, "All Fields"); assertNotNull(searchAllRB); - assertTrue(!searchAllRB.isSelected()); + assertFalse(searchAllRB.isSelected()); setSelected(searchAllRB); assertTrue(exactRB.isSelected()); - assertTrue(!functionCB.isEnabled()); - assertTrue(!commentsCB.isEnabled()); - assertTrue(!labelCB.isEnabled()); - assertTrue(!instMnemonicCB.isEnabled()); - assertTrue(!instOpCB.isEnabled()); - assertTrue(!dataMnemonicCB.isEnabled()); - assertTrue(!dataOpCB.isEnabled()); + assertFalse(functionCB.isEnabled()); + assertFalse(commentsCB.isEnabled()); + assertFalse(labelCB.isEnabled()); + assertFalse(instMnemonicCB.isEnabled()); + assertFalse(instOpCB.isEnabled()); + assertFalse(dataMnemonicCB.isEnabled()); + assertFalse(dataOpCB.isEnabled()); // Select Quick Search --> Search Fields is selected setSelected(quickRB); assertTrue(searchFieldsRB.isSelected()); - assertTrue(!searchAllRB.isSelected()); + assertFalse(searchAllRB.isSelected()); assertTrue(functionCB.isEnabled()); assertTrue(commentsCB.isEnabled()); @@ -434,7 +434,7 @@ public class SearchTextPlugin2Test extends AbstractGhidraHeadedIntegrationTest { waitForSwing(); cbPlugin.updateNow(); loc = cbPlugin.getCurrentLocation(); - assertTrue(!(addr.equals(loc.getAddress()))); + assertFalse((addr.equals(loc.getAddress()))); } @Test @@ -491,7 +491,7 @@ public class SearchTextPlugin2Test extends AbstractGhidraHeadedIntegrationTest { runSwing(() -> dismissButton.getActionListeners()[0].actionPerformed(null)); waitForSearchTasks(tempDialog); - assertTrue(!tempDialog.isVisible()); + assertFalse(tempDialog.isVisible()); } private AbstractButton findButton(Container guiContainer, String text) { @@ -555,7 +555,7 @@ public class SearchTextPlugin2Test extends AbstractGhidraHeadedIntegrationTest { setTextAndPressEnter(tf, "hello"); runSwing(() -> tool.removePlugins(new Plugin[] { plugin })); - assertTrue(!tempDialog.isVisible()); + assertFalse(tempDialog.isVisible()); } private void closeToolDuringSearch(String buttonText) throws Exception { @@ -588,7 +588,7 @@ public class SearchTextPlugin2Test extends AbstractGhidraHeadedIntegrationTest { env.restartTool(); waitForSearchTasks(tempDialog); - assertTrue(!tempDialog.isVisible()); + assertFalse(tempDialog.isVisible()); } private void closeToolDuringSearch2(String buttonText) throws Exception { diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin3Test.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin3Test.java index d3204e18c2..82ba8fa353 100644 --- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin3Test.java +++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/searchtext/SearchTextPlugin3Test.java @@ -194,29 +194,29 @@ public class SearchTextPlugin3Test extends AbstractGhidraHeadedIntegrationTest { SearchTextDialog dialog = getDialog(); JComponent container = dialog.getComponent(); - final JTextField tf = findTextField(container); + JTextField tf = findTextField(container); JCheckBox cb = (JCheckBox) findAbstractButtonByText(container, "Functions"); cb.setSelected(true); cb = (JCheckBox) findAbstractButtonByText(container, "Labels"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); cb = (JCheckBox) findAbstractButtonByText(container, "Instruction Mnemonics"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); cb = (JCheckBox) findAbstractButtonByText(container, "Instruction Operands"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); cb = (JCheckBox) findAbstractButtonByText(container, "Defined Data Mnemonics"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); cb = (JCheckBox) findAbstractButtonByText(container, "Defined Data Values"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); goToService.goTo(new ProgramLocation(program, getAddr(0x01002c92))); - final ActionListener listener = tf.getActionListeners()[0]; + ActionListener listener = tf.getActionListeners()[0]; runSwing(() -> { tf.setText("eax"); listener.actionPerformed(null); @@ -281,10 +281,10 @@ public class SearchTextPlugin3Test extends AbstractGhidraHeadedIntegrationTest { SearchTextDialog dialog = getDialog(); JComponent container = dialog.getComponent(); - final JTextField tf = findTextField(container); - final JButton searchButton = (JButton) findAbstractButtonByText(container, "Next"); + JTextField tf = findTextField(container); + JButton searchButton = (JButton) findAbstractButtonByText(container, "Next"); JCheckBox cb = (JCheckBox) findAbstractButtonByText(container, "Functions"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); runSwing(() -> { tf.setText("sscanf"); @@ -296,8 +296,8 @@ public class SearchTextPlugin3Test extends AbstractGhidraHeadedIntegrationTest { ProgramLocation loc = cbPlugin.getCurrentLocation(); assertTrue(loc instanceof CommentFieldLocation); assertEquals(CodeUnit.PLATE_COMMENT, ((CommentFieldLocation) loc).getCommentType()); - final ActionListener listener = searchButton.getActionListeners()[0]; + ActionListener listener = searchButton.getActionListeners()[0]; runSwing(() -> listener.actionPerformed(null)); waitForSearchTasks(dialog); @@ -364,16 +364,16 @@ public class SearchTextPlugin3Test extends AbstractGhidraHeadedIntegrationTest { SearchTextDialog dialog = getDialog(); JComponent container = dialog.getComponent(); - final JTextField tf = findTextField(container); + JTextField tf = findTextField(container); selectRadioButton(container, SearchTextPlugin1Test.EXACT_MATCH_SEARCH); JCheckBox cb = (JCheckBox) findAbstractButtonByText(container, "Instruction Mnemonics"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); cb = (JCheckBox) findAbstractButtonByText(container, "Instruction Operands"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); cb = (JCheckBox) findAbstractButtonByText(container, "Comments"); - cb.setSelected(false); + setToggleButtonSelected(cb, false); goToService.goTo(new ProgramLocation(program, getAddr(0x01004160))); runSwing(() -> tf.setText("sscanf")); @@ -455,15 +455,15 @@ public class SearchTextPlugin3Test extends AbstractGhidraHeadedIntegrationTest { final JTextField tf = findTextField(container); selectRadioButton(container, SearchTextPlugin1Test.EXACT_MATCH_SEARCH); JCheckBox cb = (JCheckBox) findAbstractButtonByText(container, "Instruction Mnemonics"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); cb = (JCheckBox) findAbstractButtonByText(container, "Instruction Operands"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); cb = (JCheckBox) findAbstractButtonByText(container, "Comments"); - cb.setSelected(false); - // Backwards + setToggleButtonSelected(cb, true); + // Backwards goToService.goTo(new ProgramLocation(program, getAddr(0x01004160))); runSwing(() -> tf.setText("call sscanf")); JButton searchButton = (JButton) findAbstractButtonByText(container, "Previous"); @@ -492,19 +492,19 @@ public class SearchTextPlugin3Test extends AbstractGhidraHeadedIntegrationTest { @Test public void testHighlights() throws Exception { - final SearchTextDialog dialog = getDialog(); + SearchTextDialog dialog = getDialog(); JComponent container = dialog.getComponent(); - final JTextField tf = findTextField(container); + JTextField tf = findTextField(container); JCheckBox cb = (JCheckBox) findAbstractButtonByText(container, "Instruction Mnemonics"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); cb = (JCheckBox) findAbstractButtonByText(container, "Instruction Operands"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); cb = (JCheckBox) findAbstractButtonByText(container, "Functions"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); - final String searchText = "param_"; + String searchText = "param_"; runSwing(() -> { tf.setText(searchText); ActionListener[] listeners = tf.getActionListeners(); @@ -543,19 +543,19 @@ public class SearchTextPlugin3Test extends AbstractGhidraHeadedIntegrationTest { @Test public void testHighlightsWithMultipleProviders() throws Exception { - final SearchTextDialog dialog = getDialog(); + SearchTextDialog dialog = getDialog(); JComponent container = dialog.getComponent(); - final JTextField tf = findTextField(container); + JTextField tf = findTextField(container); JCheckBox cb = (JCheckBox) findAbstractButtonByText(container, "Instruction Mnemonics"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); cb = (JCheckBox) findAbstractButtonByText(container, "Instruction Operands"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); cb = (JCheckBox) findAbstractButtonByText(container, "Functions"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); - final JButton searchAllButton = (JButton) getInstanceField("allButton", dialog); + JButton searchAllButton = (JButton) getInstanceField("allButton", dialog); runSwing(() -> { tf.setText("param_"); searchAllButton.doClick(); @@ -582,10 +582,10 @@ public class SearchTextPlugin3Test extends AbstractGhidraHeadedIntegrationTest { assertTrue("Did not find highlights at expected field.", (numberOfHighlights > 0)); // re-show the dialog to perform a new search - final SearchTextDialog dialogTwo = getDialog(); + SearchTextDialog dialogTwo = getDialog(); container = dialogTwo.getComponent(); - final JTextField tfTwo = findTextField(container); - final JButton searchAllButtonTwo = (JButton) getInstanceField("allButton", dialog); + JTextField tfTwo = findTextField(container); + JButton searchAllButtonTwo = (JButton) getInstanceField("allButton", dialog); runSwing(() -> { tfTwo.setText("text"); searchAllButtonTwo.doClick(); @@ -612,13 +612,13 @@ public class SearchTextPlugin3Test extends AbstractGhidraHeadedIntegrationTest { private void cancelSearch(String buttonText) throws Exception { - final SearchTextDialog dialog = getDialog(); + SearchTextDialog dialog = getDialog(); JComponent container = dialog.getComponent(); - final JTextField tf = findTextField(container); + JTextField tf = findTextField(container); selectRadioButton(container, buttonText); JCheckBox cb = (JCheckBox) findAbstractButtonByText(container, "Functions"); - cb.setSelected(true); + setToggleButtonSelected(cb, true); cb = (JCheckBox) findAbstractButtonByText(container, "Labels"); setToggleButtonSelected(cb, true);