Example #1
0
int
main
(
	int argc,
	char **argv
)
{
	GtkWindow* window;
	GtkDrawingArea* area;
	GtkIMContext* im;

	gtk_init(&argc, &argv);

	window = (GtkWindow*) gtk_window_new(GTK_WINDOW_TOPLEVEL);
	area = (GtkDrawingArea*) gtk_drawing_area_new();
        GTK_WIDGET_SET_FLAGS(area, GTK_CAN_FOCUS);

	gtk_container_add((GtkContainer*) window, (GtkWidget*) area);

	im = gtk_im_context_simple_new();

	g_signal_connect(area, "key-press-event", G_CALLBACK(keystroke_cb), im);
	g_signal_connect(area, "key-release-event", G_CALLBACK(keystroke_cb), im);
	g_signal_connect(im, "commit", G_CALLBACK(commit_cb), NULL);

	gtk_widget_show_all((GtkWidget*) window);

	/*
	 * Get the Window on screen and let GTK settle.
	 */

	while (gtk_events_pending()) {
		gtk_main_iteration();
	}

	/*
	 * Generate the compose sequence.
	 */

	gtk_test_widget_send_key((GtkWidget*) area, GDK_Multi_key, 0);
	gtk_test_widget_send_key((GtkWidget*) area, GDK_e, 0);
	gtk_test_widget_send_key((GtkWidget*) area, GDK_equal, 0);

	/*
	 * Will return if and only if commit is hit.
	 */

	gtk_main();

	return 0;
}
static void load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
{
    KeyEventFixture* fixture = (KeyEventFixture*)data;
    WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
    if (status == WEBKIT_LOAD_FINISHED) {
        gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
                                 gdk_unicode_to_keyval('a'), 0);
    }

}
static void test_blocking_load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
{
    KeyEventFixture* fixture = (KeyEventFixture*)data;
    WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
    if (status != WEBKIT_LOAD_FINISHED)
        return;

    // The first keypress event should not modify the field.
    fixture->info->text = g_strdup("bc");
    if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
                                 gdk_unicode_to_keyval('a'), 0))
        g_assert_not_reached();
    if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
                                  gdk_unicode_to_keyval('b'), 0))
        g_assert_not_reached();
    if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
                                  gdk_unicode_to_keyval('c'), 0))
        g_assert_not_reached();

    g_idle_add(verify_contents, fixture);
}
static void test_keypress_events_load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
{
    KeyEventFixture* fixture = (KeyEventFixture*)data;
    WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
    if (status == WEBKIT_LOAD_FINISHED) {
        g_signal_connect(fixture->webView, "key-press-event",
                         G_CALLBACK(key_press_event_cb), fixture);
        g_signal_connect(fixture->webView, "key-release-event",
                         G_CALLBACK(key_release_event_cb), fixture);
        if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
                                      gdk_unicode_to_keyval('a'), 0))
            g_assert_not_reached();
    }

}
Example #5
0
static void test_gebr_help_about(void)
{
	GtkWidget *about = gebr_gui_about_setup_ui("gebr", NULL).dialog;
	gtk_widget_show(about);
	gtk_loop();
	GtkWidget *ok = gtk_test_find_widget (about, "Close", GTK_TYPE_BUTTON);
	gboolean hit = gtk_test_widget_send_key (ok, GDK_Return, 0);
	g_assert (hit == TRUE);
	gtk_loop();
	gtk_widget_show(about);
	gtk_loop();
	gboolean click = gtk_test_widget_click(ok, 1, 0);
	g_assert (click == TRUE);
	gtk_loop();
}
Example #6
0
static void
test_button_keys (void)
{
  int a = 0, b = 0, c = 0;
  GtkWidget *window = gtk_test_display_button_window ("Test Window",
                                                      "Test: gtk_test_widget_send_key",
                                                      "IgnoreMe1", &a,
                                                      "ClickMe", &b,
                                                      "IgnoreMe2", &c,
                                                      NULL);
  GtkWidget *button = gtk_test_find_widget (window, "*Click*", GTK_TYPE_BUTTON);
  gboolean simsuccess;
  g_assert (button != NULL);
  gtk_widget_grab_focus (button);
  g_assert (gtk_widget_has_focus (button));
  simsuccess = gtk_test_widget_send_key (button, GDK_Return, 0);
  g_assert (simsuccess == TRUE);
  while (gtk_events_pending ())
    gtk_main_iteration ();
  g_assert (a == 0);
  g_assert (b > 0);
  g_assert (c == 0);
}
static void test_xim_load_status_cb(WebKitWebView* webView, GParamSpec* spec, gpointer data)
{
    KeyEventFixture* fixture = (KeyEventFixture*)data;
    WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
    if (status != WEBKIT_LOAD_FINISHED)
        return;

    GtkIMContext* imContext = 0;
    g_object_get(webView, "im-context", &imContext, NULL);
    g_assert(imContext);

    gchar* originalId = g_strdup(gtk_im_multicontext_get_context_id(GTK_IM_MULTICONTEXT(imContext)));
    gtk_im_multicontext_set_context_id(GTK_IM_MULTICONTEXT(imContext), "xim");

    // Test that commits that happen outside of key events
    // change the text field immediately. This closely replicates
    // the behavior of SCIM.
    fixture->info->text = g_strdup("debian");
    if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
                                 gdk_unicode_to_keyval('d'), 0))
        g_assert_not_reached();
    if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
                             gdk_unicode_to_keyval('e'), 0))
        g_assert_not_reached();
    if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
                             gdk_unicode_to_keyval('b'), 0))
        g_assert_not_reached();
    if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
                             gdk_unicode_to_keyval('i'), 0))
        g_assert_not_reached();
    if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
                             gdk_unicode_to_keyval('a'), 0))
        g_assert_not_reached();
    if (!gtk_test_widget_send_key(GTK_WIDGET(fixture->webView),
                             gdk_unicode_to_keyval('n'), 0))
        g_assert_not_reached();

    gtk_im_multicontext_set_context_id(GTK_IM_MULTICONTEXT(imContext), originalId);
    g_free(originalId);
    g_object_unref(imContext);

    g_idle_add(verify_contents, fixture);
}