Class AbstractDockingTest
- Direct Known Subclasses:
AbstractGhidraHeadlessIntegrationTest
-
Nested Class Summary
Nested classes/interfaces inherited from class generic.test.AbstractGuiTest
AbstractGuiTest.ExceptionHandlingRunner
-
Field Summary
Fields inherited from class generic.test.AbstractGenericTest
concurrentTestExceptionRule, DEFAULT_TEST_TOOL_NAME, DEFAULT_TOOL_NAME, repeatedRule, 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
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
assertEnabled
(JComponent component, boolean enabled) Checks the enablement state of a JComponent in a thread safe way.void
assertIconsEqual
(Icon expected, Icon actual) Asserts that the two icons are or refer to the same icon (handles GIcon)static void
assertToggleButtonSelected
(JToggleButton button, boolean selected) Checks the selected state of a JToggleButton in a thread safe way.void
Creates and writes to file an image of the given component.static Component
clickComponentProvider
(ComponentProvider provider) Performs a single left mouse click in the center of the given provider.static 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
static void
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
Deprecated.void
Closes the given provider.static void
Will try to close dialogs prompting for changes to be saved, whether from program changes or from tool config changes.protected ApplicationConfiguration
protected ApplicationLayout
createContext
(ComponentProvider provider, Object contextObject) Creates a generic action context with the given provider, with the given context objectcreateContext
(Object contextObject) Creates a generic action context with no provider, with the given context objectstatic Image
static Image
Creates a png of the given component by capturing a screenshot of the image.static void
Turns off the gui displays for errors.void
void
static void
expandPath
(GTree tree, String... path) static void
expandTree
(GTree tree, String... path) static JButton
findButtonByActionName
(Container container, String name) static JButton
findButtonByIcon
(DialogComponentProvider provider, Icon icon) static AbstractButton
findButtonByName
(DialogComponentProvider provider, String name) Searches the component and subcomponents of the indicated provider and returns the component with the specified name.static JButton
findButtonByText
(DialogComponentProvider provider, String text) static <T extends Component>
TfindComponent
(DialogComponentProvider provider, Class<T> desiredClass) Returns the firstComponent
of the given type inside of the given dialogstatic Component
findComponentByName
(DialogComponentProvider provider, String name) Searches the component and subcomponents of the indicated provider and returns the component with the specified name.static DockingActionIf
getAction
(DialogComponentProvider provider, String actionName) Returns the given dialog's action that has the given namestatic DockingActionIf
Finds the singular tool action by the given name.static DockingActionIf
Finds the action by the given owner name and action name.static Set
<DockingActionIf> getActionsByName
(Tool tool, String name) A helper method to find all actions with the given namestatic Set
<DockingActionIf> getActionsByOwner
(Tool tool, String name) A helper method to find all actions with the given owner's name (this will not include reserved system actions)static Set
<DockingActionIf> getActionsByOwnerAndName
(Tool tool, String owner, String name) A helper method to find all actions by name, with the given owner's name (this will not include reserved system actions)Gets any current text on the clipboardstatic <T extends ComponentProvider>
TgetComponentProvider
(Class<T> clazz) Searches for the first occurrence of aComponentProvider
that is an instance of the givenproviderClass
.static <T extends DialogComponentProvider>
TgetDialogComponent
(Class<T> ghidraClass) Gets a dialog component provider of the given typeprotected static <T extends DialogComponentProvider>
TgetDialogComponentProvider
(Window window, 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
(JComponent component) Get the dockable component that contains this component if there is one.static DockingActionIf
getLocalAction
(ComponentProvider provider, String actionName) Returns the action by the given name that belongs to the given providerstatic String
Check for and display message component text associated with OptionDialog windowsstatic GTreeNode
static String
Returns a pretty-print string of all found windows that are showing, nesting by parent-child relationship.static String
getStatusText
(DialogComponentProvider provider) Get the dialog provider's status textstatic String
getTitleForWindow
(Window window) Gets the URL for the given iconprotected static Window
protected static Window
getWindowByTitle
(Window parentWindow, String title) static Window
getWindowByTitleContaining
(Window parentWindow, String text) getWindows
(Window parentWindow) static boolean
isEnabled
(DockingActionIf action) static boolean
isEnabled
(DockingActionIf action, ActionContextProvider contextProvider) static boolean
isEnabled
(AbstractButton button) static boolean
isSelected
(AbstractButton button) static boolean
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, 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, 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
Prints all found windows that are showing, nesting by parent-child relationship.static void
selectPath
(GTree tree, 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
(Container container, 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
(AbstractButton button, boolean selected) Ensures that the selected state of the button matchesselected
.showProvider
(Tool tool, String name) Shows the provider by the given name.static void
triggerActionKey
(Component c, int modifiers, int keyCode) Simulates a user typing a single key.static void
triggerActionKey
(Component destination, DockingActionIf action) Simulates a user initiated keystroke using the keybinding of the given actionstatic void
static void
Simulates the user pressing the 'Enter' key on the given text fieldstatic void
static void
triggerKey
(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
(Component c, int modifiers, int keyCode, char keyChar, BiConsumer<Component, KeyEvent> consumer) static void
triggerKey
(Component c, KeyStroke ks) Fires aKeyListener.keyPressed(KeyEvent)
,KeyListener.keyTyped(KeyEvent)
andKeyListener.keyReleased(KeyEvent)
for the given key strokestatic void
triggerText
(Component destination, String string) Types the indicated string using thetriggerKey(Component, int, int, char)
method.static void
triggerText
(Component destination, String string, BiConsumer<Component, KeyEvent> consumer) Types the indicated string using thetriggerKey(Component, int, int, char)
method.static <T extends ComponentProvider>
TwaitForComponentProvider
(Window parentWindow, 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
(Class<T> clazz) Searches for the first occurrence of aComponentProvider
that is an instance of the givenproviderClass
.static <T extends ComponentProvider>
TwaitForComponentProvider
(Class<T> clazz, String title) Allows you to find a component provider with the given title.static <T extends DialogComponentProvider>
TwaitForDialogComponent
(Window parentWindow, 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
(Class<T> ghidraClass) Waits for the first window of the given class.static DialogComponentProvider
waitForDialogComponent
(String title) Returns theDialogComponentProvider
with the given title.static AbstractErrDialog
Waits for the system error dialog to appearstatic OkDialog
Waits for the system info dialog to appearstatic JDialog
waitForJDialog
(Window window, String title, int timeoutMS) Deprecated.usewaitForJDialog(String)
insteadstatic JDialog
waitForJDialog
(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 Window
waitForWindow
(Class<?> windowClass) static Window
waitForWindow
(String title) Waits for a window with the given namestatic Window
waitForWindow
(String title, int timeoutMS) Deprecated.Instead call one of the methods that does not take a timeout (we are standardizing timeouts).static Window
waitForWindowByName
(String name) Waits for a window with the given name.static Window
static void
writeImage
(Image image, File imageFile) Writes the given image to the given fileprotected void
writeImage
(Image image, String name) Methods inherited from class generic.test.AbstractGuiTest
assertColorsEqual, clickListRange, clickMouse, clickMouse, clickTableCell, clickTableRange, doubleClick, dragMouse, editCell, executeOnSwingWithoutBlocking, findAbstractButtonByName, findAbstractButtonByText, findButtonByIcon, findButtonByName, findButtonByText, findComponent, findComponent, findComponentByName, findComponentByName, findComponents, findComponents, findOwnedWindows, findPathToText, findTreePathToText, fixupGUI, getAllWindows, getRenderedTableCellValue, getSwing, getText, leftClick, middleClick, moveMouse, postEvent, pressButton, pressButton, pressButtonByName, pressButtonByName, pressButtonByText, pressButtonByText, printMemory, privatewaitForSwing_SwingSafe, rightClick, runSwing, runSwing, runSwing, runSwingLater, runSwingWithException, setComboBoxSelection, setText, waitForPostedSwingRunnables, waitForSwing, waitForTasks, waitForTasks, yieldToSwing
Methods inherited from class generic.test.AbstractGenericTest
createStackTraceForAllThreads, createTempDirectory, createTempFile, createTempFile, createTempFileForTest, createTempFileForTest, createTempFilePath, createTempFilePath, deleteMatchingTempFiles, deleteSimilarTempFiles, findTestDataFile, getDebugFileDirectory, getFontMetrics, getInstanceField, getInstanceFieldByClassType, getTestDataDir, getTestDataDirectory, getTestDataFile, hasTestFailed, initializeLayout, initializeSystemProperties, invokeConstructor, invokeInstanceMethod, invokeInstanceMethod, loadTextResource, loadTextResource, resetLogging, setErrorsExpected, setInstanceField, setLogLevel, setLogLevel, testFailed, toString, windowForComponent
Methods inherited from class generic.test.AbstractGTest
assertArraysEqualOrdered, assertArraysEqualUnordered, assertArraysEqualUnordered, assertContainsExactly, assertContainsExactly, assertContainsString, assertContainsStringIgnoringCase, 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
-
Constructor Details
-
AbstractDockingTest
public AbstractDockingTest()
-
-
Method Details
-
dockingSetUp
public void dockingSetUp() -
dockingTearDown
public void dockingTearDown() -
createApplicationLayout
- Overrides:
createApplicationLayout
in classAbstractGenericTest
- Throws:
IOException
-
createApplicationConfiguration
- Overrides:
createApplicationConfiguration
in classAbstractGuiTest
-
waitForUpdateOnChooser
- Throws:
Exception
-
getWindowByTitleContaining
-
getWindow
-
getWindowByTitle
-
waitForErrorDialog
Waits for the system error dialog to appear- Returns:
- the dialog
-
waitForInfoDialog
Waits for the system info dialog to appear- Returns:
- the dialog
-
waitForWindow
-
waitForWindowByTitleContaining
-
waitForWindow
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
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
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
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
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
-
close
-
closeAllWindows
public static void closeAllWindows(boolean showError) -
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
-
waitForJDialog
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.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 Component> T findComponent(DialogComponentProvider provider, 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
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
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
ghidraClass
- See Also:
-
waitForDialogComponent
@Deprecated public static <T extends DialogComponentProvider> T waitForDialogComponent(Window parentWindow, 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
ghidraClass
-
getDialogComponent
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(Window window, 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
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
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(Class<T> clazz, 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(Window parentWindow, 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
-
pressButtonByText
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, 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(Container container, 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
as well asJToggleButton
, such as: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
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:- Parameters:
button
- the button to selectselected
- true to toggle the button to selected; false for de-selected
-
assertToggleButtonSelected
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
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
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
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
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
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
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
Returns the action by the given name that belongs to the given provider- Parameters:
provider
- the provideractionName
- the action name- Returns:
- the action
-
getAction
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
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
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
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
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
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 searchname
- the name of the desired component- Returns:
- the component, or null if not found
-
findButtonByText
-
findButtonByName
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 searchname
- the name of the desired component- Returns:
- the component, or null if not found
-
findButtonByIcon
-
findButtonByActionName
-
triggerActionKey
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
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
-
triggerBackspaceKey
-
triggerEnter
Simulates the user pressing the 'Enter' key on the given text field- Parameters:
c
- the component
-
triggerText
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(Component destination, String string, BiConsumer<Component, 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
Fires aKeyListener.keyPressed(KeyEvent)
,KeyListener.keyTyped(KeyEvent)
andKeyListener.keyReleased(KeyEvent)
for the given key stroke- Parameters:
c
- the destination componentks
- the key stroke
-
triggerKey
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(Component c, int modifiers, int keyCode, char keyChar, BiConsumer<Component, KeyEvent> consumer) -
getClipboardText
Gets any current text on the clipboard- Returns:
- the text on the clipboard; null if no text is on the clipboard
- Throws:
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
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
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
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:
-
selectTabIfAvailable
If this dockable component is in a tabbed pane then select the associated tab.- Parameters:
dockableComponent
- the dockable component of interest
-
getDockableComponent
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 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
Returns a pretty-print string of all found windows that are showing, nesting by parent-child relationship.- Returns:
- the result string
-
waitForTableModel
-
getNode
-
expandPath
-
expandTree
-
selectPath
-
waitForTree
-
isEnabled
-
isEnabled
-
isEnabled
-
isSelected
-
createContext
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
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
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:
Exception
- if there is any issue capturing the component
-
writeImage
- Throws:
IOException
-
createScreenImage
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:
AWTException
- if there is a problem creating the image
-
createRenderedImage
-
writeImage
Writes the given image to the given file- Parameters:
image
- the imageimageFile
- the file- Throws:
IOException
- if there is any issue writing the image
-
assertIconsEqual
Asserts that the two icons are or refer to the same icon (handles GIcon)- Parameters:
expected
- the expected iconactual
- the actual icon
-
getURL
Gets the URL for the given icon- Parameters:
icon
- the icon to get a URL for- Returns:
- the URL for the given icon
-
closeAllWindows()