-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathttt_functional_test_util.c
130 lines (94 loc) · 2.83 KB
/
ttt_functional_test_util.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include "ttt_functional_test_util.h"
#include <glib.h>
#include <glib-object.h>
#include <gtk/gtk.h>
struct timespec ttt_functional_test_util_default_timeout = {
20,
0,
};
void
ttt_functional_test_util_reaction_time()
{
usleep(TTT_FUNCTIONAL_TEST_UTIL_REACTION_TIME);
}
void
ttt_functional_test_util_reaction_time_long()
{
usleep(TTT_FUNCTIONAL_TEST_UTIL_REACTION_TIME_LONG);
}
void
ttt_functional_test_util_idle_condition_and_timeout(TttFunctionalTestUtilIdleCondition idle_condition,
struct timespec *timeout,
gpointer data)
{
struct timespec start_time, current_time;
clock_gettime(CLOCK_MONOTONIC,
&start_time);
while(TTT_FUNCTIONAL_TEST_UTIL_IDLE_CONDITION(idle_condition)(data)){
ttt_functional_test_util_reaction_time();
clock_gettime(CLOCK_MONOTONIC,
¤t_time);
if(start_time.tv_sec + timeout->tv_sec < current_time.tv_sec){
break;
}
}
ttt_functional_test_util_reaction_time();
}
gboolean
ttt_functional_test_util_button_click(GtkButton *button)
{
GtkWidget *widget;
GdkWindow *window;
gint x, y;
gint origin_x, origin_y;
if(button == NULL ||
!GTK_IS_BUTTON(button)){
return(FALSE);
}
widget = button;
if(!GTK_WIDGET_REALIZED(widget)){
ttt_functional_test_util_reaction_time_long();
}
/* retrieve window and pointer position */
gdk_threads_enter();
window = gtk_widget_get_window(widget);
x = widget->allocation.x + widget->allocation.width / 2.0;
y = widget->allocation.y + widget->allocation.height / 2.0;
gdk_window_get_origin(window, &origin_x, &origin_y);
gdk_display_warp_pointer(gtk_widget_get_display(widget),
gtk_widget_get_screen(widget),
origin_x + x, origin_y + y);
gdk_threads_leave();
/* click the button */
ttt_functional_test_util_reaction_time();
gdk_test_simulate_button(window,
x,
y,
1,
GDK_BUTTON1_MASK,
GDK_BUTTON_PRESS);
ttt_functional_test_util_reaction_time();
gdk_test_simulate_button(window,
x,
y,
1,
GDK_BUTTON1_MASK,
GDK_BUTTON_RELEASE);
ttt_functional_test_util_reaction_time();
ttt_functional_test_util_reaction_time_long();
return(TRUE);
}
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);
}