正文
if
(
start_time
.
tv_sec
+
timeout
->
tv_sec
<
current_time
.
tv_sec
){
break
;
}
}
ttt_functional_test_util_reaction_time
();
}
与图形化用户界面交互
为了模拟用户交互的操作,
Gdk 库
[1]
为我们提供了一些需要的函数。要完成我们的工作,我们只需要如下 3 个函数:
◈
gdk_display_warp_pointer()
◈
gdk_test_simulate_button()
◈
gdk_test_simulate_key()
举个例子,为了测试按钮点击,我们可以这么做:
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