| Version: 3.3.1

Classes | Macros
testing.h File Reference

## Classes
class | wxExpectModalBase< T, E >
| Base class for the expectation of a dialog of the given type T. More...
class | wxExpectAny
| Expectation of any kind of modal dialog. More...
class | wxTestingModalHook
| Implementation of wxModalDialogHook for use in testing. More...

## Macros
#define | wxTEST_DIALOG_HOOK_CLASS wxTestingModalHook
| Macro determining the class of modal dialog hook to use. More...
#define | wxTEST_DIALOG(codeToRun, ...)
| Runs given code with all modal dialogs redirected to wxExpectModal<T> hooks, instead of being shown to the user. More...

## Macro Definition Documentation

## ◆ wxTEST_DIALOG

#define wxTEST_DIALOG | ( |  | codeToRun,
|  |  | ...
| ) |  |

Runs given code with all modal dialogs redirected to wxExpectModal<T> hooks, instead of being shown to the user.

This macro is useful for non-interactive tests that need to call a function showing a modal dialog, as it allows to check that the expected dialog is indeed shown and then continues the execution with the provided result instead of blocking.

The first argument is any valid expression, typically a function call. The remaining arguments are wxExpectModal<T> instances defining the dialogs that are expected to be shown, in order of appearance.

Some typical examples:

wxTEST_DIALOG
(
rc = dlg.ShowModal(),
wxExpectModal<wxFileDialog>(wxGetCwd() + "/test.txt")
);
wxExpectModal
This template is specialized for some of the standard dialog classes and can also be specialized outs...
Definition: testing.h:19
wxGetCwd
wxString wxGetCwd()
Returns a string containing the current (or working) directory.
wxTEST_DIALOG
#define wxTEST_DIALOG(codeToRun,...)
Runs given code with all modal dialogs redirected to wxExpectModal<T> hooks, instead of being shown t...
Definition: testing.h:233

Sometimes, the code may show more than one dialog:

wxTEST_DIALOG
(
RunSomeFunction(),
wxExpectModal<wxMessageDialog>(wxNO),
wxExpectModal<MyConfirmationDialog>(wxYES),
wxExpectModal<wxFileDialog>(wxGetCwd() + "/test.txt")
);
wxNO
#define wxNO
Definition: defs.h:446
wxYES
#define wxYES
Definition: defs.h:444

Notice that wxExpectModal<T> has some convenience methods for further tweaking the expectations. For example, it's possible to mark an expected dialog as optional for situations when a dialog may be shown, but isn't required to, by calling the Optional() method:

wxTEST_DIALOG
(
RunSomeFunction(),
wxExpectModal<wxMessageDialog>(wxNO),
wxExpectModal<wxFileDialog>(wxGetCwd() + "/test.txt").Optional()
);

Note
  By default, errors are reported with wxFAIL_MSG(). You may customize this by implementing a class derived from wxTestingModalHook, overriding its ReportFailure() method and redefining the wxTEST_DIALOG_HOOK_CLASS macro to be the name of this class.
  Custom dialogs are supported too. All you have to do is to specialize wxExpectModal<> for your dialog type and implement its OnInvoked() method.

Since
  2.9.5

## ◆ wxTEST_DIALOG_HOOK_CLASS

#define wxTEST_DIALOG_HOOK_CLASS wxTestingModalHook

Macro determining the class of modal dialog hook to use.

By default defined as wxTestingModalHook but can be predefined before including this file to the name of a custom class inheriting from it to customize its behaviour, e.g. provide better error reporting.