Class AbstractDockingTest
- java.lang.Object
-
- generic.test.AbstractGTest
-
- generic.test.AbstractGenericTest
-
- docking.test.AbstractDockingTest
-
- Direct Known Subclasses:
AbstractGhidraHeadlessIntegrationTest
public abstract class AbstractDockingTest extends AbstractGenericTest
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class generic.test.AbstractGenericTest
AbstractGenericTest.ExceptionHandlingRunner
-
-
Field Summary
-
Fields inherited from class generic.test.AbstractGenericTest
concurrentTestExceptionRule, DEFAULT_TEST_TOOL_NAME, DEFAULT_TOOL_NAME, ruleChain, TESTDATA_DIRECTORY_NAME, watchman
-
Fields inherited from class generic.test.AbstractGTest
BATCH_MODE, DEFAULT_WAIT_DELAY, DEFAULT_WAIT_TIMEOUT, DEFAULT_WINDOW_TIMEOUT, PARALLEL_MODE, PRIVATE_LONG_WAIT_TIMEOUT, testName
-
-
Constructor Summary
Constructors Constructor Description AbstractDockingTest()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static void
assertEnabled(javax.swing.JComponent component, boolean enabled)
Checks the enablement state of a JComponent in a thread safe way.static void
assertToggleButtonSelected(javax.swing.JToggleButton button, boolean selected)
Checks the selected state of a JToggleButton in a thread safe way.void
capture(java.awt.Component c, java.lang.String name)
Creates and writes to file an image of the given component.static java.awt.Component
clickComponentProvider(ComponentProvider provider)
Performs a single left mouse click in the center of the given provider.static java.awt.Component
clickComponentProvider(ComponentProvider provider, int button, int x, int y, int clickCount, int modifiers, boolean popupTrigger)
Clicks the JComponent at the given point from within the given provider.void
close(DialogComponentProvider dialog)
void
close(java.awt.Window w)
static void
closeAllWindows()
A convenience method to close all of the windows and frames that the current Java windowing environment knows aboutstatic void
closeAllWindows(boolean showError)
static void
closeAllWindowsAndFrames()
Deprecated.instead call the newcloseAllWindows()
void
closeProvider(ComponentProvider p)
Closes the given provider.static void
closeSaveChangesDialog()
Will try to close dialogs prompting for changes to be saved, whether from program changes or from tool config changes.protected ApplicationConfiguration
createApplicationConfiguration()
protected ApplicationLayout
createApplicationLayout()
ActionContext
createContext(ComponentProvider provider, java.lang.Object contextObject)
Creates a generic action context with the given provider, with the given context objectActionContext
createContext(java.lang.Object contextObject)
Creates a generic action context with no provider, with the given context objectstatic java.awt.Image
createRenderedImage(java.awt.Component c)
static java.awt.Image
createScreenImage(java.awt.Component c)
Creates a png of the given component by capturing a screenshot of the image.static void
disposeErrorGUI()
Turns off the gui displays for errors.void
dockingSetUp()
void
dockingTearDown()
static void
expandPath(GTree tree, java.lang.String... path)
static void
expandTree(GTree tree, java.lang.String... path)
static javax.swing.JButton
findButtonByActionName(java.awt.Container container, java.lang.String name)
static javax.swing.JButton
findButtonByIcon(DialogComponentProvider provider, javax.swing.Icon icon)
static javax.swing.JButton
findButtonByText(DialogComponentProvider provider, java.lang.String text)
static <T extends java.awt.Component>
TfindComponent(DialogComponentProvider provider, java.lang.Class<T> desiredClass)
Returns the firstComponent
of the given type inside of the given dialogstatic java.awt.Component
findComponentByName(DialogComponentProvider provider, java.lang.String componentName)
Searches the component and subcomponents of the indicated provider and returns the component with the specified name.static DockingActionIf
getAction(DialogComponentProvider provider, java.lang.String actionName)
Returns the given dialog's action that has the given namestatic DockingActionIf
getAction(Tool tool, java.lang.String name)
Finds the singular tool action by the given name.static DockingActionIf
getAction(Tool tool, java.lang.String owner, java.lang.String name)
Finds the action by the given owner name and action name.static java.util.Set<DockingActionIf>
getActionsByName(Tool tool, java.lang.String name)
A helper method to find all actions with the given namestatic java.util.Set<DockingActionIf>
getActionsByOwner(Tool tool, java.lang.String name)
A helper method to find all actions with the given owner's name (this will not include reserved system actions)static java.util.Set<DockingActionIf>
getActionsByOwnerAndName(Tool tool, java.lang.String owner, java.lang.String name)
A helper method to find all actions by name, with the given owner's name (this will not include reserved system actions)java.lang.String
getClipboardText()
Gets any current text on the clipboardstatic <T extends ComponentProvider>
TgetComponentProvider(java.lang.Class<T> clazz)
Searches for the first occurrence of aComponentProvider
that is an instance of the givenproviderClass
.static <T extends DialogComponentProvider>
TgetDialogComponent(java.lang.Class<T> ghidraClass)
Gets a dialog component provider of the given typeprotected static <T extends DialogComponentProvider>
TgetDialogComponentProvider(java.awt.Window window, java.lang.Class<T> ghidraClass)
Gets the dialog component provider that is inside the given window or null if a provider of the given class type is not in the window.protected static DockableComponent
getDockableComponent(javax.swing.JComponent component)
Get the dockable component that contains this component if there is one.static DockingActionIf
getLocalAction(ComponentProvider provider, java.lang.String actionName)
Returns the action by the given name that belongs to the given providerstatic java.lang.String
getMessageText(java.awt.Window w)
Check for and display message component text associated with OptionDialog windowsstatic GTreeNode
getNode(GTree tree, java.lang.String... path)
static java.lang.String
getOpenWindowsAsString()
Returns a pretty-print string of all found windows that are showing, nesting by parent-child relationship.static java.lang.String
getStatusText(DialogComponentProvider provider)
Get the dialog provider's status textstatic java.lang.String
getTitleForWindow(java.awt.Window window)
protected static java.awt.Window
getWindow(java.lang.String title)
protected static java.awt.Window
getWindowByTitle(java.awt.Window parentWindow, java.lang.String title)
static java.awt.Window
getWindowByTitleContaining(java.awt.Window parentWindow, java.lang.String text)
protected static java.util.Set<java.awt.Window>
getWindows(java.awt.Window parentWindow)
static boolean
isEnabled(DockingActionIf action)
static boolean
isEnabled(javax.swing.AbstractButton button)
static boolean
isSelected(javax.swing.AbstractButton button)
static boolean
isUseErrorGUI()
static void
performAction(DockingActionIf action)
Performs the specified action within the Swing Thread.static void
performAction(DockingActionIf action, boolean waitForCompletion)
Performs the specified action within the Swing Thread.static void
performAction(DockingActionIf action, ActionContext context, boolean wait)
Performs the specified action with context within the Swing Thread.static void
performAction(DockingActionIf action, ComponentProvider provider, boolean wait)
Performs the specified action with context within the Swing Thread.static void
performDialogAction(DockingActionIf action, DialogComponentProvider provider, boolean wait)
Performs the specified action with context within the Swing Thread.static void
pressButtonByText(DialogComponentProvider provider, java.lang.String buttonText)
Finds the button with the indicated TEXT that is a sub-component of the indicated container, and then programmatically presses the button.static void
pressButtonByText(DialogComponentProvider provider, java.lang.String buttonText, boolean waitForCompletion)
Finds the button with the indicated TEXT that is a sub-component of the indicated container, and then programmatically presses the button.static void
printOpenWindows()
Prints all found windows that are showing, nesting by parent-child relationship.static void
selectPath(GTree tree, java.lang.String... path)
protected static void
selectTabIfAvailable(DockableComponent dockableComponent)
If this dockable component is in a tabbed pane then select the associated tab.static void
setErrorGUIEnabled(boolean enable)
By default Ghidra will use a modal error dialog to display errors when running tests.static void
setToggleActionSelected(ToggleDockingActionIf toggleAction, ActionContext context, boolean selected)
Ensures the given toggle action is in the given selected state.static void
setToggleActionSelected(ToggleDockingActionIf toggleAction, ActionContext context, boolean selected, boolean wait)
Ensures the given toggle action is in the given selected state.static void
setToggleButtonSelected(java.awt.Container container, java.lang.String buttonName, boolean selected)
Finds the toggle button with the given name inside of the given container and then ensures that the selected state of the button matchesselected
.static void
setToggleButtonSelected(javax.swing.AbstractButton button, boolean selected)
Ensures that the selected state of the button matchesselected
.ComponentProvider
showProvider(Tool tool, java.lang.String name)
Shows the provider by the given name.static void
triggerActionKey(java.awt.Component c, int modifiers, int keyCode)
Simulates a user typing a single key.static void
triggerActionKey(java.awt.Component destination, DockingActionIf action)
Simulates a user initiated keystroke using the keybinding of the given actionstatic void
triggerBackspaceKey(java.awt.Component c)
static void
triggerEnter(java.awt.Component c)
Simulates the user pressing the 'Enter' key on the given text fieldstatic void
triggerEscapeKey(java.awt.Component c)
static void
triggerKey(java.awt.Component c, int modifiers, int keyCode, char keyChar)
Fires aKeyListener.keyPressed(KeyEvent)
,KeyListener.keyTyped(KeyEvent)
andKeyListener.keyReleased(KeyEvent)
for the given key code and char.static void
triggerKey(java.awt.Component c, int modifiers, int keyCode, char keyChar, java.util.function.BiConsumer<java.awt.Component,java.awt.event.KeyEvent> consumer)
static void
triggerKey(java.awt.Component c, javax.swing.KeyStroke ks)
Fires aKeyListener.keyPressed(KeyEvent)
,KeyListener.keyTyped(KeyEvent)
andKeyListener.keyReleased(KeyEvent)
for the given key strokestatic void
triggerText(java.awt.Component destination, java.lang.String string)
Types the indicated string using thetriggerKey(Component, int, int, char)
method.static void
triggerText(java.awt.Component destination, java.lang.String string, java.util.function.BiConsumer<java.awt.Component,java.awt.event.KeyEvent> consumer)
Types the indicated string using thetriggerKey(Component, int, int, char)
method.static <T extends ComponentProvider>
TwaitForComponentProvider(java.awt.Window parentWindow, java.lang.Class<T> providerClass, int maxTimeMS)
Deprecated.Instead call one of the methods that does not take a timeout (we are standardizing timeouts).static <T extends ComponentProvider>
TwaitForComponentProvider(java.lang.Class<T> clazz)
Searches for the first occurrence of aComponentProvider
that is an instance of the givenproviderClass
.static <T extends ComponentProvider>
TwaitForComponentProvider(java.lang.Class<T> clazz, java.lang.String title)
Allows you to find a component provider with the given title.static <T extends DialogComponentProvider>
TwaitForDialogComponent(java.awt.Window parentWindow, java.lang.Class<T> clazz, int timeoutMS)
Deprecated.Instead call one of the methods that does not take a timeout (we are standardizing timeouts).static <T extends DialogComponentProvider>
TwaitForDialogComponent(java.lang.Class<T> ghidraClass)
Waits for the first window of the given class.static DialogComponentProvider
waitForDialogComponent(java.lang.String title)
Returns theDialogComponentProvider
with the given title.static AbstractErrDialog
waitForErrorDialog()
Waits for the system error dialog to appearstatic OkDialog
waitForInfoDialog()
Waits for the system info dialog to appearstatic javax.swing.JDialog
waitForJDialog(java.awt.Window window, java.lang.String title, int timeoutMS)
Deprecated.usewaitForJDialog(String)
insteadstatic javax.swing.JDialog
waitForJDialog(java.lang.String title)
Waits for the JDialog with the given titlestatic <T> void
waitForTableModel(ThreadedTableModel<T,?> model)
static void
waitForTree(GTree gTree)
static void
waitForUpdateOnChooser(GhidraFileChooser chooser)
static java.awt.Window
waitForWindow(java.lang.Class<?> windowClass)
static java.awt.Window
waitForWindow(java.lang.String title)
Waits for a window with the given namestatic java.awt.Window
waitForWindow(java.lang.String title, int timeoutMS)
Deprecated.Instead call one of the methods that does not take a timeout (we are standardizing timeouts).static java.awt.Window
waitForWindowByName(java.lang.String name)
Waits for a window with the given name.static java.awt.Window
waitForWindowByTitleContaining(java.lang.String text)
static void
writeImage(java.awt.Image image, java.io.File imageFile)
Writes the given image to the given fileprotected void
writeImage(java.awt.Image image, java.lang.String name)
-
Methods inherited from class generic.test.AbstractGenericTest
clickListRange, clickMouse, clickMouse, clickTableCell, clickTableRange, createStackTraceForAllThreads, createTempDirectory, createTempFile, createTempFile, createTempFileForTest, createTempFileForTest, createTempFilePath, createTempFilePath, deleteMatchingTempFiles, deleteSimilarTempFiles, doubleClick, dragMouse, editCell, executeOnSwingWithoutBlocking, findAbstractButtonByName, findAbstractButtonByText, findButtonByIcon, findButtonByText, findComponent, findComponent, findComponentByName, findComponentByName, findComponentsByName, findOwnedWindows, findPathToText, findTestDataFile, findTreePathToText, fixupGUI, getAllWindows, getDebugFileDirectory, getFontMetrics, getInstanceField, getInstanceFieldByClassType, getLocalResourceFile, getRenderedTableCellValue, getTestDataDir, getTestDataDirectory, getTestDataFile, getText, hasTestFailed, initializeLayout, initializeSystemProperties, invokeConstructor, invokeInstanceMethod, invokeInstanceMethod, leftClick, loadTextResource, loadTextResource, middleClick, moveMouse, postEvent, pressButton, pressButton, pressButtonByName, pressButtonByName, pressButtonByText, pressButtonByText, printMemory, privateWaitForPostedSwingRunnables_SwingSafe, rightClick, runSwing, runSwing, runSwing, runSwingLater, runSwingWithException, setComboBoxSelection, setErrorsExpected, setInstanceField, setText, testFailed, toString, waitForPostedSwingRunnables, waitForSwing, waitForTasks, windowForComponent, yieldToSwing
-
Methods inherited from class generic.test.AbstractGTest
assertArraysEqualOrdered, assertArraysEqualUnordered, assertArraysEqualUnordered, assertContainsExactly, assertContainsExactly, assertListEqualOrdered, assertListEqualOrdered, assertListEqualsArrayOrdered, assertListEqualsArrayUnordered, assertListEqualUnordered, bytes, failWithException, getName, getRandomInt, getRandomInt, getRandomString, getRandomString, getTestDirectoryPath, sleep, waitFor, waitFor, waitFor, waitFor, waitFor, waitForCondition, waitForCondition, waitForCondition, waitForConditionWithoutFailing, waitForValue, waitForValueWithoutFailing
-
-
-
-
Method Detail
-
dockingSetUp
public void dockingSetUp()
-
dockingTearDown
public void dockingTearDown()
-
createApplicationLayout
protected ApplicationLayout createApplicationLayout()
- Overrides:
createApplicationLayout
in classAbstractGenericTest
-
createApplicationConfiguration
protected ApplicationConfiguration createApplicationConfiguration()
- Overrides:
createApplicationConfiguration
in classAbstractGenericTest
-
waitForUpdateOnChooser
public static void waitForUpdateOnChooser(GhidraFileChooser chooser) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getWindowByTitleContaining
public static java.awt.Window getWindowByTitleContaining(java.awt.Window parentWindow, java.lang.String text)
-
getWindow
protected static java.awt.Window getWindow(java.lang.String title)
-
getWindowByTitle
protected static java.awt.Window getWindowByTitle(java.awt.Window parentWindow, java.lang.String title)
-
waitForErrorDialog
public static AbstractErrDialog waitForErrorDialog()
Waits for the system error dialog to appear- Returns:
- the dialog
-
waitForInfoDialog
public static OkDialog waitForInfoDialog()
Waits for the system info dialog to appear- Returns:
- the dialog
-
waitForWindow
public static java.awt.Window waitForWindow(java.lang.Class<?> windowClass)
-
waitForWindowByTitleContaining
public static java.awt.Window waitForWindowByTitleContaining(java.lang.String text)
-
waitForWindow
@Deprecated public static java.awt.Window waitForWindow(java.lang.String title, int timeoutMS)
Deprecated.Instead call one of the methods that does not take a timeout (we are standardizing timeouts). The timeouts passed to this method will be ignored in favor of the standard value.Waits for a window with the given name.- Parameters:
title
- The title of the window for which to searchtimeoutMS
- The timeout after which this method will wait no more- Returns:
- The window, if found, null otherwise.
-
waitForWindow
public static java.awt.Window waitForWindow(java.lang.String title)
Waits for a window with the given name- Parameters:
title
- The title of the window for which to search- Returns:
- The window, if found, null otherwise.
-
waitForWindowByName
public static java.awt.Window waitForWindowByName(java.lang.String name)
Waits for a window with the given name.- Parameters:
name
- The name of the window for which to search- Returns:
- The window, if found, null otherwise
-
getMessageText
public static java.lang.String getMessageText(java.awt.Window w)
Check for and display message component text associated with OptionDialog windows- Parameters:
w
- any window- Returns:
- the message string if one can be found;
null
otherwise
-
getStatusText
public static java.lang.String getStatusText(DialogComponentProvider provider)
Get the dialog provider's status text- Parameters:
provider
- dialog component provider- Returns:
- status text
-
closeSaveChangesDialog
public static void closeSaveChangesDialog()
Will try to close dialogs prompting for changes to be saved, whether from program changes or from tool config changes.
-
close
public void close(DialogComponentProvider dialog)
-
close
public void close(java.awt.Window w)
-
closeAllWindows
public static void closeAllWindows(boolean showError)
-
closeAllWindowsAndFrames
@Deprecated public static void closeAllWindowsAndFrames()
Deprecated.instead call the newcloseAllWindows()
A convenience method to close all of the windows and frames that the current Java windowing environment knows about
-
closeAllWindows
public static void closeAllWindows()
A convenience method to close all of the windows and frames that the current Java windowing environment knows about
-
getTitleForWindow
public static java.lang.String getTitleForWindow(java.awt.Window window)
-
waitForJDialog
public static javax.swing.JDialog waitForJDialog(java.lang.String title)
Waits for the JDialog with the given titleNote: Sometimes the task dialog might have the same title as the dialog you pop up and you want to get yours instead of the one for the task monitor.
- Parameters:
title
- the title of the dialog- Returns:
- the dialog
-
waitForJDialog
@Deprecated public static javax.swing.JDialog waitForJDialog(java.awt.Window window, java.lang.String title, int timeoutMS)
Deprecated.usewaitForJDialog(String)
insteadWaits for the JDialog with the indicated title and that is parented to the indicated windowNote: Sometimes the task dialog might have the same title as the dialog you pop up and you want to get yours instead of the one for the task monitor.
- Parameters:
window
- the parent windowtitle
- the title of the dialogtimeoutMS
- Maximum time to wait for the dialog- Returns:
- the dialog
-
findComponent
public static <T extends java.awt.Component> T findComponent(DialogComponentProvider provider, java.lang.Class<T> desiredClass)
Returns the firstComponent
of the given type inside of the given dialog- Parameters:
provider
- the dialogdesiredClass
- the class of the component- Returns:
- the component; null if none was found
-
waitForDialogComponent
public static DialogComponentProvider waitForDialogComponent(java.lang.String title)
Returns theDialogComponentProvider
with the given title. This method is not preferred, but instead you should use awaitForDialogComponent(Class)
that takes a class so that you can get the correct return type. This method is meant for clients that need a dialog, but that type is private of package restricted and thus cannot be referenced by a test. Also, code that relies on a title is more subject to breaking when code is refactored; code that relies on class types will get refactored along side the referenced code.This method will fail if no dialog can be found
- Parameters:
title
- the title of the desired dialog- Returns:
- the dialog
-
waitForDialogComponent
public static <T extends DialogComponentProvider> T waitForDialogComponent(java.lang.Class<T> ghidraClass)
Waits for the first window of the given class.- Parameters:
ghidraClass
- The class of the dialog the user desires- Returns:
- The first occurrence of a dialog that extends the given
ghirdraClass
- See Also:
waitForDialogComponent(Window, Class, int)
-
waitForDialogComponent
@Deprecated public static <T extends DialogComponentProvider> T waitForDialogComponent(java.awt.Window parentWindow, java.lang.Class<T> clazz, int timeoutMS)
Deprecated.Instead call one of the methods that does not take a timeout (we are standardizing timeouts). The timeouts passed to this method will be ignored in favor of the standard value.Waits for the first window of the given class. This method assumes that the desired dialog is parented byparentWindow
.- Parameters:
parentWindow
- The parent of the desired dialog; may be nullclazz
- The class of the dialog the user desirestimeoutMS
- The max amount of time in milliseconds to wait for the requested dialog to appear.- Returns:
- The first occurrence of a dialog that extends the given
ghirdraClass
-
getDialogComponent
public static <T extends DialogComponentProvider> T getDialogComponent(java.lang.Class<T> ghidraClass)
Gets a dialog component provider of the given type- Parameters:
ghidraClass
- the class of the desiredDialogComponentProvider
.- Returns:
- the dialog or null if it cannot be found
-
getDialogComponentProvider
protected static <T extends DialogComponentProvider> T getDialogComponentProvider(java.awt.Window window, java.lang.Class<T> ghidraClass)
Gets the dialog component provider that is inside the given window or null if a provider of the given class type is not in the window.- Parameters:
window
- the window that contains the desired provider.ghidraClass
- the class of the desired provider- Returns:
- the desired provider or null if the window does not contain a provider of the given type.
-
getComponentProvider
public static <T extends ComponentProvider> T getComponentProvider(java.lang.Class<T> clazz)
Searches for the first occurrence of aComponentProvider
that is an instance of the givenproviderClass
.- Parameters:
clazz
- The class of the ComponentProvider to locate- Returns:
- The component provider, or null if one cannot be found
-
waitForComponentProvider
public static <T extends ComponentProvider> T waitForComponentProvider(java.lang.Class<T> clazz)
Searches for the first occurrence of aComponentProvider
that is an instance of the givenproviderClass
. This method will repeat the search everyAbstractGTest.DEFAULT_WAIT_DELAY
milliseconds until the provider is found, or the maximum number of searches has been reached, wheremaximum number of searches = MaxTimeMS /
AbstractGTest.DEFAULT_WAIT_DELAY
- Parameters:
clazz
- The class of the ComponentProvider to locate- Returns:
- The component provider, or null if one cannot be found
-
waitForComponentProvider
public static <T extends ComponentProvider> T waitForComponentProvider(java.lang.Class<T> clazz, java.lang.String title)
Allows you to find a component provider with the given title. Most plugins will only ever have a single provider. In those cases, usewaitForComponentProvider(Class)
. This version of that method is to allow you to differentiate between multiple instances of a given provider that have different titles.- Parameters:
clazz
- The class of the ComponentProvider to locatetitle
- the title of the component provider- Returns:
- The component provider, or null if one cannot be found
-
waitForComponentProvider
@Deprecated public static <T extends ComponentProvider> T waitForComponentProvider(java.awt.Window parentWindow, java.lang.Class<T> providerClass, int maxTimeMS)
Deprecated.Instead call one of the methods that does not take a timeout (we are standardizing timeouts). The timeouts passed to this method will be ignored in favor of the standard value.Searches for the first occurrence of aComponentProvider
that is an instance of the givenproviderClass
. This method will repeat the search everyAbstractGTest.DEFAULT_WAIT_DELAY
milliseconds until the provider is found, or the maximum number of searches has been reached, wheremaximum number of searches = MaxTimeMS /
AbstractGTest.DEFAULT_WAIT_DELAY
- Parameters:
parentWindow
- The window that will become the parent window of the provider (this is typically the tool's frame).providerClass
- The class of the ComponentProvider to locate.maxTimeMS
- The maximum amount of time to wait. This is an approximation (see above).- Returns:
- The component provider, or null if one cannot be found
-
getWindows
protected static java.util.Set<java.awt.Window> getWindows(java.awt.Window parentWindow)
-
pressButtonByText
public static void pressButtonByText(DialogComponentProvider provider, java.lang.String buttonText)
Finds the button with the indicated TEXT that is a sub-component of the indicated container, and then programmatically presses the button.
The following is a sample JUnit test use:env.showTool(); OptionDialog dialog = (OptionDialog)env.waitForDialog(OptionDialog.class, 1000); assertNotNull(dialog); pressButtonByText(dialog, "OK");
- Parameters:
provider
- the DialogComponentProvider containing the button.buttonText
- the text on the desired JButton.
-
pressButtonByText
public static void pressButtonByText(DialogComponentProvider provider, java.lang.String buttonText, boolean waitForCompletion)
Finds the button with the indicated TEXT that is a sub-component of the indicated container, and then programmatically presses the button.- Parameters:
provider
- the DialogComponentProvider containing the button.buttonText
- the text on the desired JButton.waitForCompletion
- if true wait for action to complete before returning, otherwise schedule action to be performed and return immediately.
-
setToggleButtonSelected
public static void setToggleButtonSelected(java.awt.Container container, java.lang.String buttonName, boolean selected)
Finds the toggle button with the given name inside of the given container and then ensures that the selected state of the button matchesselected
.Note: this works for any instanceof
JToggleButton
, such as:JCheckBox
JRadioButton
EmptyBorderToggleButton
s.- Parameters:
container
- a container that has the desired button as a descendantbuttonName
- the name of the button (you must set this on the button when it is constructed; if there is no button with the given name found, then this method will search for a button with the given textselected
- true to toggle the button to selected; false for de-selected
-
setToggleButtonSelected
public static void setToggleButtonSelected(javax.swing.AbstractButton button, boolean selected)
Ensures that the selected state of the button matchesselected
.Note: this works for most toggle button implementations which are derived from AbstractButton and relay on
AbstractButton.isSelected()
andAbstractButton.doClick()
for toggling, such as:JCheckBox
JRadioButton
EmptyBorderToggleButton
- Parameters:
button
- the button to selectselected
- true to toggle the button to selected; false for de-selected
-
assertToggleButtonSelected
public static void assertToggleButtonSelected(javax.swing.JToggleButton button, boolean selected)
Checks the selected state of a JToggleButton in a thread safe way.- Parameters:
button
- the toggle button for which to check the selected state.selected
- the expected state of the toggle button.
-
assertEnabled
public static void assertEnabled(javax.swing.JComponent component, boolean enabled)
Checks the enablement state of a JComponent in a thread safe way.- Parameters:
component
- the component for which to check the enablement state.enabled
- the expected enablement state for the component.
-
getActionsByName
public static java.util.Set<DockingActionIf> getActionsByName(Tool tool, java.lang.String name)
A helper method to find all actions with the given name- Parameters:
tool
- the tool containing all system actionsname
- the name to match- Returns:
- the matching actions; empty list if no matches
-
getActionsByOwner
public static java.util.Set<DockingActionIf> getActionsByOwner(Tool tool, java.lang.String name)
A helper method to find all actions with the given owner's name (this will not include reserved system actions)- Parameters:
tool
- the tool containing all system actionsname
- the owner's name to match- Returns:
- the matching actions; empty list if no matches
-
getActionsByOwnerAndName
public static java.util.Set<DockingActionIf> getActionsByOwnerAndName(Tool tool, java.lang.String owner, java.lang.String name)
A helper method to find all actions by name, with the given owner's name (this will not include reserved system actions)- Parameters:
tool
- the tool containing all system actionsowner
- the owner's namename
- the owner's name to match- Returns:
- the matching actions; empty list if no matches
-
getAction
public static DockingActionIf getAction(Tool tool, java.lang.String name)
Finds the singular tool action by the given name. If more than one action exists with that name, then an exception is thrown. If you want more than one matching action, the callgetActionsByName(Tool, String)
instead.Note: more specific test case subclasses provide other methods for finding actions when you have an owner name (which is usually the plugin name).
- Parameters:
tool
- the tool containing all system actionsname
- the name to match- Returns:
- the matching action; null if no matching action can be found
-
getAction
public static DockingActionIf getAction(Tool tool, java.lang.String owner, java.lang.String name)
Finds the action by the given owner name and action name. If you do not know the owner name, then use the callgetActionsByName(Tool, String)
instead (this will not include reserved system actions).Note: more specific test case subclasses provide other methods for finding actions when you have an owner name (which is usually the plugin name).
- Parameters:
tool
- the tool containing all system actionsowner
- the owner of the actionname
- the name to match- Returns:
- the matching action; null if no matching action can be found
-
getLocalAction
public static DockingActionIf getLocalAction(ComponentProvider provider, java.lang.String actionName)
Returns the action by the given name that belongs to the given provider- Parameters:
provider
- the provideractionName
- the action name- Returns:
- the action
-
getAction
public static DockingActionIf getAction(DialogComponentProvider provider, java.lang.String actionName)
Returns the given dialog's action that has the given name- Parameters:
provider
- the dialog provideractionName
- the name of the action- Returns:
- the action
-
performAction
public static void performAction(DockingActionIf action)
Performs the specified action within the Swing Thread. This method will block until the action completes. Do not use this method if the given actions triggers a modal dialog. Instead, callperformAction(DockingActionIf, boolean)
with a false value.If the action results in a modal dialog, then call
performAction(DockingActionIf, boolean)
with a value of false.- Parameters:
action
- action to be performed (event will be null)
-
performAction
public static void performAction(DockingActionIf action, boolean waitForCompletion)
Performs the specified action within the Swing Thread. If the action results in a modal dialog, waitForCompletion must be false.- Parameters:
action
- action to be performedwaitForCompletion
- if true wait for action to complete before returning, otherwise schedule action to be performed and return immediately.
-
performAction
public static void performAction(DockingActionIf action, ComponentProvider provider, boolean wait)
Performs the specified action with context within the Swing Thread. If the action results in a modal dialog, waitForCompletion must be false.- Parameters:
action
- action to be performedprovider
- the component provider from which to get action context; if null, then an empty context will usedwait
- if true wait for action to complete before returning, otherwise schedule action to be performed and return immediately.
-
performDialogAction
public static void performDialogAction(DockingActionIf action, DialogComponentProvider provider, boolean wait)
Performs the specified action with context within the Swing Thread. If the action results in a modal dialog, waitForCompletion must be false.- Parameters:
action
- action to be performedprovider
- the component provider from which to get action contextwait
- if true wait for action to complete before returning, otherwise schedule action to be performed and return immediately.
-
performAction
public static void performAction(DockingActionIf action, ActionContext context, boolean wait)
Performs the specified action with context within the Swing Thread. If the action results in a modal dialog, waitForCompletion must be false.- Parameters:
action
- action to be performedcontext
- the context to use with the actionwait
- if true wait for action to complete before returning, otherwise schedule action to be performed and return immediately.
-
setToggleActionSelected
public static void setToggleActionSelected(ToggleDockingActionIf toggleAction, ActionContext context, boolean selected)
Ensures the given toggle action is in the given selected state. If it is not, then the action will be performed. This call will wait for the action to finish.- Parameters:
toggleAction
- the actioncontext
- the context for the actionselected
- true if the action is be be selected; false for not selected
-
setToggleActionSelected
public static void setToggleActionSelected(ToggleDockingActionIf toggleAction, ActionContext context, boolean selected, boolean wait)
Ensures the given toggle action is in the given selected state. If it is not, then the action will be performed. This call will wait for the action to finish.- Parameters:
toggleAction
- the actioncontext
- the context for the actionselected
- true if the action is be be selected; false for not selectedwait
- true to wait for the action to finish; false to invoke later
-
findComponentByName
public static java.awt.Component findComponentByName(DialogComponentProvider provider, java.lang.String componentName)
Searches the component and subcomponents of the indicated provider and returns the component with the specified name.- Parameters:
provider
- the provider of the component to searchcomponentName
- the name of the desired component- Returns:
- the component, or null if not found
-
findButtonByText
public static javax.swing.JButton findButtonByText(DialogComponentProvider provider, java.lang.String text)
-
findButtonByIcon
public static javax.swing.JButton findButtonByIcon(DialogComponentProvider provider, javax.swing.Icon icon)
-
findButtonByActionName
public static javax.swing.JButton findButtonByActionName(java.awt.Container container, java.lang.String name)
-
triggerActionKey
public static void triggerActionKey(java.awt.Component c, int modifiers, int keyCode)
Simulates a user typing a single key. This method should used for the special keyboard keys (ARROW, F1, END, etc) and alpha keys when associated with actions.- Parameters:
c
- the component that should be the receiver of the key event; the event sourcemodifiers
- the modifier keys down during event (shift, ctrl, alt, meta) Either extended _DOWN_MASK or old _MASK modifiers should be used, but both models should not be mixed in one event. Use of the extended modifiers is preferred.keyCode
- the integer code for an actual key.
-
triggerActionKey
public static void triggerActionKey(java.awt.Component destination, DockingActionIf action)
Simulates a user initiated keystroke using the keybinding of the given action- Parameters:
destination
- the component for the action being executedaction
- The action to simulate pressing
-
triggerEscapeKey
public static void triggerEscapeKey(java.awt.Component c)
-
triggerBackspaceKey
public static void triggerBackspaceKey(java.awt.Component c)
-
triggerEnter
public static void triggerEnter(java.awt.Component c)
Simulates the user pressing the 'Enter' key on the given text field- Parameters:
c
- the component
-
triggerText
public static void triggerText(java.awt.Component destination, java.lang.String string)
Types the indicated string using thetriggerKey(Component, int, int, char)
method. This method should be used when typing into text components. For example, JTextFields and JTextAreas. All three events are fired, KEY_PRESSED, KEY_TYPED, and KEY_RELEASED.
Note: Handles the following characters:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
`1234567890-=[]\;',./
~!@#$%^&*()_+{}|:"<>?
It also handles '\n', '\t', and '\b'.- Parameters:
destination
- the component to receive the eventsstring
- the string to be typed.
-
triggerText
public static void triggerText(java.awt.Component destination, java.lang.String string, java.util.function.BiConsumer<java.awt.Component,java.awt.event.KeyEvent> consumer)
Types the indicated string using thetriggerKey(Component, int, int, char)
method. This method should be used when typing into text components. For example, JTextFields and JTextAreas. All three events are fired, KEY_PRESSED, KEY_TYPED, and KEY_RELEASED.
Note: Handles the following characters:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
abcdefghijklmnopqrstuvwxyz
`1234567890-=[]\;',./
~!@#$%^&*()_+{}|:"<>?
It also handles '\n', '\t', and '\b'.- Parameters:
destination
- the component to receive the eventsstring
- the string to be typed.consumer
- the consumer of the text to be generated
-
triggerKey
public static void triggerKey(java.awt.Component c, javax.swing.KeyStroke ks)
Fires aKeyListener.keyPressed(KeyEvent)
,KeyListener.keyTyped(KeyEvent)
andKeyListener.keyReleased(KeyEvent)
for the given key stroke- Parameters:
c
- the destination componentks
- the key stroke
-
triggerKey
public static void triggerKey(java.awt.Component c, int modifiers, int keyCode, char keyChar)
Fires aKeyListener.keyPressed(KeyEvent)
,KeyListener.keyTyped(KeyEvent)
andKeyListener.keyReleased(KeyEvent)
for the given key code and char.If the key you need is not a character, but is an action, pass
KeyEvent.CHAR_UNDEFINED
for thekeyChar
parameter.- Parameters:
c
- the destination componentmodifiers
- any modifiers, like ControlkeyCode
- the key code (seeKeyEvent
's VK_xyz values)keyChar
- the key char orKeyEvent.CHAR_UNDEFINED
-
triggerKey
public static void triggerKey(java.awt.Component c, int modifiers, int keyCode, char keyChar, java.util.function.BiConsumer<java.awt.Component,java.awt.event.KeyEvent> consumer)
-
getClipboardText
public java.lang.String getClipboardText() throws java.lang.Exception
Gets any current text on the clipboard- Returns:
- the text on the clipboard; null if no text is on the clipboard
- Throws:
java.lang.Exception
- if there are any issues copying from the clipboard
-
isUseErrorGUI
public static boolean isUseErrorGUI()
-
setErrorGUIEnabled
public static void setErrorGUIEnabled(boolean enable)
By default Ghidra will use a modal error dialog to display errors when running tests. This method should be used to disable this feature, as opposed to calling:Err.setErrorDisplay( new ConsoleErrorDisplay() );
- Parameters:
enable
- true to use the GUI; false to use the error console
-
disposeErrorGUI
public static void disposeErrorGUI()
Turns off the gui displays for errors. This does not change the "isUseErrorGUI()" value for other tests in the TestCase.
-
showProvider
public ComponentProvider showProvider(Tool tool, java.lang.String name)
Shows the provider by the given name.- Parameters:
tool
- the tool in which the provider livesname
- the name of the provider to show- Returns:
- the newly shown provider
-
closeProvider
public void closeProvider(ComponentProvider p)
Closes the given provider. You could just callTool.removeComponentProvider(ComponentProvider)
, but some providers have extra logic that happens whenComponentProvider.closeComponent()
is called. This will likely change in the future.- Parameters:
p
- the provider to close
-
clickComponentProvider
public static java.awt.Component clickComponentProvider(ComponentProvider provider)
Performs a single left mouse click in the center of the given provider. This is useful when trying to make a provider the active provider, while making sure that one of the provider's components has focus.- Parameters:
provider
- The provider to click- Returns:
- the actual Java JComponent that was clicked.
- See Also:
clickComponentProvider(ComponentProvider, int, int, int, int, int, boolean)
-
selectTabIfAvailable
protected static void selectTabIfAvailable(DockableComponent dockableComponent)
If this dockable component is in a tabbed pane then select the associated tab.- Parameters:
dockableComponent
- the dockable component of interest
-
getDockableComponent
protected static DockableComponent getDockableComponent(javax.swing.JComponent component)
Get the dockable component that contains this component if there is one.- Parameters:
component
- the component that may be within a dockable component.- Returns:
- the dockable component or null
-
clickComponentProvider
public static java.awt.Component clickComponentProvider(ComponentProvider provider, int button, int x, int y, int clickCount, int modifiers, boolean popupTrigger)
Clicks the JComponent at the given point from within the given provider.- Parameters:
provider
- The provider to be clicked.button
- The mouse button to use (left, center, right)x
- the x location of the clicky
- the y location of the clickclickCount
- the number of times to clickmodifiers
- the modifiers to apply (Ctrl, Alt, etc; 0 is none)popupTrigger
- true if this click should show a popup menu- Returns:
- the actual Java JComponent that was clicked
-
printOpenWindows
public static void printOpenWindows()
Prints all found windows that are showing, nesting by parent-child relationship.
-
getOpenWindowsAsString
public static java.lang.String getOpenWindowsAsString()
Returns a pretty-print string of all found windows that are showing, nesting by parent-child relationship.- Returns:
- the result string
-
waitForTableModel
public static <T> void waitForTableModel(ThreadedTableModel<T,?> model)
-
expandPath
public static void expandPath(GTree tree, java.lang.String... path)
-
expandTree
public static void expandTree(GTree tree, java.lang.String... path)
-
selectPath
public static void selectPath(GTree tree, java.lang.String... path)
-
waitForTree
public static void waitForTree(GTree gTree)
-
isEnabled
public static boolean isEnabled(DockingActionIf action)
-
isEnabled
public static boolean isEnabled(javax.swing.AbstractButton button)
-
isSelected
public static boolean isSelected(javax.swing.AbstractButton button)
-
createContext
public ActionContext createContext(java.lang.Object contextObject)
Creates a generic action context with no provider, with the given context object- Parameters:
contextObject
- the generic object to put in the context- Returns:
- the new context
-
createContext
public ActionContext createContext(ComponentProvider provider, java.lang.Object contextObject)
Creates a generic action context with the given provider, with the given context object- Parameters:
provider
- the providercontextObject
- the generic object to put in the context- Returns:
- the new context
-
capture
public void capture(java.awt.Component c, java.lang.String name) throws java.lang.Exception
Creates and writes to file an image of the given component. The file will be written to the reports directory (this differs depending upon how the test was run), nested inside a directory structure of the form {test class name}/{test name}. A console statement will be written indicating the location of the written file.- Parameters:
c
- the component to capturename
- the file name suffix- Throws:
java.lang.Exception
- if there is any issue capturing the component
-
writeImage
protected void writeImage(java.awt.Image image, java.lang.String name) throws java.io.IOException
- Throws:
java.io.IOException
-
createScreenImage
public static java.awt.Image createScreenImage(java.awt.Component c) throws java.awt.AWTException
Creates a png of the given component by capturing a screenshot of the image. This differs from creating the image by rendering it via aGraphics
object.- Parameters:
c
- the component- Returns:
- the new image
- Throws:
java.awt.AWTException
- if there is a problem creating the image
-
createRenderedImage
public static java.awt.Image createRenderedImage(java.awt.Component c)
-
writeImage
public static void writeImage(java.awt.Image image, java.io.File imageFile) throws java.io.IOException
Writes the given image to the given file- Parameters:
image
- the imageimageFile
- the file- Throws:
java.io.IOException
- if there is any issue writing the image
-
-