### Learn how to test your application's function with this simple tutorial.
![Functional testing Gtk+ applications in C ](https://opensource.com/sites/default/files/styles/image-full-size/public/images/business/cube_innovation_block_collaboration.png?itok=CbG3Mpqi "Functional testing Gtk+ applications in C ")
Image by :
opensource.com
Automated tests are required to ensure your program's quality and that it works as expected. Unit tests examine only certain parts of your algorithm, but don't look at how each component fits together. That's where functional testing, sometimes referred as integration testing, comes in.
A functional test basically interacts with your user interface, whether through a website or a desktop application. To show you how that works, let's look at how to test a Gtk+ application. For simplicity, in this tutorial let's use the[Tictactoe][6]example from the Gtk+ 2.0 tutorial.
### Basic setup
For every functional test, you usually define some global variables, such as "user interaction delay" or "timeout until a failure is indicated" (i.e., when an event doesn't occur until the specified time and the application is doomed).
The timeout function delays execution until a state of a control is applied. It is useful for actions that are applied asynchronously, and that is why it delays for a longer period of time.
We want to ensure the button has an active state, so we provide an idle-condition function:
```
gboolean
ttt_functional_test_util_idle_test_toggle_active(
GtkToggleButton **toggle_button)
{
gboolean do_idle;
do_idle = TRUE;
gdk_threads_enter();
if(*toggle_button != NULL &&
GTK_IS_TOGGLE_BUTTON(*toggle_button) &&
gtk_toggle_button_get_active(*toggle_button)){
do_idle = FALSE;
}
gdk_threads_leave();
return(do_idle);
}
```
### The test scenario
Since the Tictactoe program is very simple, we just need to ensure that a[**GtkToggleButton**][8]was clicked. The functional test can proceed once it asserts the button entered the active state. To click the buttons, we use the handy**util**function provided above.
For illustration, let's assume player A wins immediately by filling the very first row, because player B is not paying attention and just filled the second row:
Joël Krähemann - Free software enthusiast with a strong knowledge about the C programming language. I don't fear any code complexity as long it is written in a simple manner. As developer of Advanced Gtk+ Sequencer I know how challenging multi-threaded applications can be and with it we have a great basis for future demands.my personal website