-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathttt_functional_test.c
90 lines (62 loc) · 1.81 KB
/
ttt_functional_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "tictactoe.h"
#include "ttt_functional_test_util.h"
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
GtkWindow *window;
Tictactoe *ttt;
extern struct timespec ttt_functional_test_util_default_timeout;
void*
ttt_functional_test_gtk_main(void *ptr)
{
gtk_main();
pthread_exit(NULL);
}
void
ttt_functional_test_dumb_player_b()
{
GtkButton *buttons[3][3];
guint i;
/* to avoid race-conditions copy the buttons */
gdk_threads_enter();
memcpy(buttons, ttt->buttons, 9 * sizeof(GtkButton *));
gdk_threads_leave();
/* TEST 1 - the dumb player B */
for(i = 0; i < 3; i++){
/* assert player A clicks the button successfully */
if(!ttt_functional_test_util_button_click(buttons[0][i])){
exit(-1);
}
ttt_functional_test_util_idle_condition_and_timeout(ttt_functional_test_util_idle_test_toggle_active,
&ttt_functional_test_util_default_timeout,
&buttons[0][i]);
/* assert player B clicks the button successfully */
if(!ttt_functional_test_util_button_click(buttons[1][i])){
exit(-1);
}
ttt_functional_test_util_idle_condition_and_timeout(ttt_functional_test_util_idle_test_toggle_active,
&ttt_functional_test_util_default_timeout,
&buttons[1][i]);
}
}
int
main(int argc, char **argv)
{
pthread_t thread;
gtk_init(&argc, &argv);
/* start the tictactoe application */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
ttt = tictactoe_new();
gtk_container_add(window, ttt);
gtk_widget_show_all(window);
/* start the Gtk+ dispatcher */
pthread_create(&thread, NULL,
ttt_functional_test_gtk_main, NULL);
/* launch test routines */
ttt_functional_test_dumb_player_b();
/* terminate the application */
gdk_threads_enter();
gtk_main_quit();
gdk_threads_leave();
return(0);
}