gtk_test_find_widget bug?



This seems to be either a bug in my understanding of how to use this
functionality or a bug in the gtk_test_find_widget function itself.

Here's the smallest working code I could come up with to demonstrate
the problem:

--------------------------------
#include <gtk/gtk.h>
#include <stdio.h>
#include <stdlib.h>

static void
do_import (GtkWidget *widget, gconstpointer data)
{
  printf ("Import!\n");
}

static void
do_quit (GtkWidget *widget, gconstpointer data)
{
  printf ("Quit!\n");
}

GtkWidget*
build_menu (void)
{
  GtkWidget *menu;
  GtkWidget *import;
  GtkWidget *quit;

  menu = gtk_menu_new ();

  import = gtk_image_menu_item_new_with_label ("Import");
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), import);
  g_signal_connect (G_OBJECT (import), "activate", G_CALLBACK
(do_import), NULL);

  quit = gtk_image_menu_item_new_with_label ("Quit");
  gtk_menu_shell_append (GTK_MENU_SHELL (menu), quit);
  g_signal_connect (G_OBJECT (quit), "activate", G_CALLBACK (do_quit), NULL);

  return menu;
}

int
main (int argc, char* argv[])
{
  GtkWidget *menu;
  GtkWidget *found_import;
  GtkWidget *found_quit;

  gtk_test_init (&argc, &argv, NULL);

  menu = build_menu ();

  found_quit = gtk_test_find_widget (menu, "Quit", GTK_TYPE_MENU_ITEM);
  g_assert (NULL != found_quit);
  gtk_menu_item_activate (GTK_MENU_ITEM (found_quit));

  found_import = gtk_test_find_widget (menu, "Import", GTK_TYPE_MENU_ITEM);
  g_assert (NULL != found_import);
  gtk_menu_item_activate (GTK_MENU_ITEM (found_import));

  return 0;
}
--------------------------------

When I run this I expect it to print:

 Quit!
 Import!

Instead I get:

 Quit!
 Quit!

If I change "Import" in the last call to gtk_test_find_widget with
"Anything", I get the expected failure from the next g_assert.

-- 
Michael C. Libby
www.mikelibby.com


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]