From efefd9f0bab3c57494a55b0418b5d488f0dae64b Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Sat, 3 Mar 2001 18:23:21 +0000 Subject: [PATCH] Add plug-socket tests. (Won't work worth a darn until I commit the rest of Sat Mar 3 13:21:27 2001 Owen Taylor * tests/Makefile.am tests/testsocket.c tests/testsocket_child.c: Add plug-socket tests. (Won't work worth a darn until I commit the rest of the plug-socket changes, but no reason these can't go into CVS now.) --- ChangeLog | 7 ++ ChangeLog.pre-2-0 | 7 ++ ChangeLog.pre-2-10 | 7 ++ ChangeLog.pre-2-2 | 7 ++ ChangeLog.pre-2-4 | 7 ++ ChangeLog.pre-2-6 | 7 ++ ChangeLog.pre-2-8 | 7 ++ tests/.cvsignore | 2 + tests/Makefile.am | 6 ++ tests/testsocket.c | 158 +++++++++++++++++++++++++++++++++++++++ tests/testsocket_child.c | 95 +++++++++++++++++++++++ 11 files changed, 310 insertions(+) create mode 100644 tests/testsocket.c create mode 100644 tests/testsocket_child.c diff --git a/ChangeLog b/ChangeLog index a6251c3040..dae1f026b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sat Mar 3 13:21:27 2001 Owen Taylor + + * tests/Makefile.am tests/testsocket.c tests/testsocket_child.c: + Add plug-socket tests. (Won't work worth a darn until I commit + the rest of the plug-socket changes, but no reason these + can't go into CVS now.) + 2001-03-02 Havoc Pennington * gdk/x11/gdkgc-x11.c (_gdk_x11_gc_flush): use diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index a6251c3040..dae1f026b0 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,10 @@ +Sat Mar 3 13:21:27 2001 Owen Taylor + + * tests/Makefile.am tests/testsocket.c tests/testsocket_child.c: + Add plug-socket tests. (Won't work worth a darn until I commit + the rest of the plug-socket changes, but no reason these + can't go into CVS now.) + 2001-03-02 Havoc Pennington * gdk/x11/gdkgc-x11.c (_gdk_x11_gc_flush): use diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index a6251c3040..dae1f026b0 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +Sat Mar 3 13:21:27 2001 Owen Taylor + + * tests/Makefile.am tests/testsocket.c tests/testsocket_child.c: + Add plug-socket tests. (Won't work worth a darn until I commit + the rest of the plug-socket changes, but no reason these + can't go into CVS now.) + 2001-03-02 Havoc Pennington * gdk/x11/gdkgc-x11.c (_gdk_x11_gc_flush): use diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index a6251c3040..dae1f026b0 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,10 @@ +Sat Mar 3 13:21:27 2001 Owen Taylor + + * tests/Makefile.am tests/testsocket.c tests/testsocket_child.c: + Add plug-socket tests. (Won't work worth a darn until I commit + the rest of the plug-socket changes, but no reason these + can't go into CVS now.) + 2001-03-02 Havoc Pennington * gdk/x11/gdkgc-x11.c (_gdk_x11_gc_flush): use diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index a6251c3040..dae1f026b0 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,10 @@ +Sat Mar 3 13:21:27 2001 Owen Taylor + + * tests/Makefile.am tests/testsocket.c tests/testsocket_child.c: + Add plug-socket tests. (Won't work worth a darn until I commit + the rest of the plug-socket changes, but no reason these + can't go into CVS now.) + 2001-03-02 Havoc Pennington * gdk/x11/gdkgc-x11.c (_gdk_x11_gc_flush): use diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index a6251c3040..dae1f026b0 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +Sat Mar 3 13:21:27 2001 Owen Taylor + + * tests/Makefile.am tests/testsocket.c tests/testsocket_child.c: + Add plug-socket tests. (Won't work worth a darn until I commit + the rest of the plug-socket changes, but no reason these + can't go into CVS now.) + 2001-03-02 Havoc Pennington * gdk/x11/gdkgc-x11.c (_gdk_x11_gc_flush): use diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index a6251c3040..dae1f026b0 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +Sat Mar 3 13:21:27 2001 Owen Taylor + + * tests/Makefile.am tests/testsocket.c tests/testsocket_child.c: + Add plug-socket tests. (Won't work worth a darn until I commit + the rest of the plug-socket changes, but no reason these + can't go into CVS now.) + 2001-03-02 Havoc Pennington * gdk/x11/gdkgc-x11.c (_gdk_x11_gc_flush): use diff --git a/tests/.cvsignore b/tests/.cvsignore index 1c8eda3354..357cb951cb 100644 --- a/tests/.cvsignore +++ b/tests/.cvsignore @@ -6,3 +6,5 @@ makefile.msc .libs testtreeview testtreecolumns +testsocket +testsocket_child diff --git a/tests/Makefile.am b/tests/Makefile.am index 116d4f56aa..24f1b293d5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -31,11 +31,17 @@ LDADDS = @STRIP_BEGIN@ \ @STRIP_END@ noinst_PROGRAMS = \ + testsocket \ + testsocket_child \ testtreeview \ testtreecolumns +testsocket_DEPENDENCIES = $(DEPS) +testsocket_child_DEPENDENCIES = $(DEPS) testtreeview_DEPENDENCIES = $(DEPS) +testsocket_LDADD = $(LDADDS) +testsocket_child_LDADD = $(LDADDS) testtreeview_LDADD = $(LDADDS) testtreeview_SOURCES = testtreeview.c diff --git a/tests/testsocket.c b/tests/testsocket.c new file mode 100644 index 0000000000..3957463766 --- /dev/null +++ b/tests/testsocket.c @@ -0,0 +1,158 @@ +#include +#include "x11/gdkx.h" + +#include +#include +#include + +GtkWidget *window; +GtkWidget *vbox; +GtkWidget *lastsocket = NULL; + +static void +quit_cb (gpointer callback_data, + guint callback_action, + GtkWidget *widget) +{ + GtkWidget *message_dialog = gtk_message_dialog_new (GTK_WINDOW (window), 0, + GTK_MESSAGE_QUESTION, + GTK_BUTTONS_YES_NO, + "Really Quit?"); + gtk_dialog_set_default_response (GTK_DIALOG (message_dialog), GTK_RESPONSE_NO); + + if (gtk_dialog_run (GTK_DIALOG (message_dialog)) == GTK_RESPONSE_YES) + gtk_widget_destroy (window); + + gtk_widget_destroy (message_dialog); +} + +static GtkItemFactoryEntry menu_items[] = +{ + { "/_File", NULL, 0, 0, "" }, + { "/File/_Quit", "Q", quit_cb, 0 }, +}; + +void +steal (GtkWidget *window, GtkEntry *entry) +{ + guint32 xid; + gchar *text; + GtkWidget *socket; + + text = gtk_entry_get_text (entry); + + xid = strtol (text, NULL, 0); + if (xid == 0) + { + g_warning ("Invalid window id '%s'\n", text); + return; + } + + socket = gtk_socket_new (); + gtk_box_pack_start (GTK_BOX (vbox), socket, TRUE, TRUE, 0); + gtk_widget_show (socket); + + gtk_socket_steal (GTK_SOCKET (socket), xid); +} + +void +remove_child (GtkWidget *window) +{ + if(lastsocket) + gtk_widget_destroy (lastsocket); + lastsocket = NULL; +} + +void +add_child (GtkWidget *window) +{ + GtkWidget *socket; + char *argv[3] = { "./testsocket_child", NULL, NULL }; + char buffer[20]; + GError *error = NULL; + + socket = gtk_socket_new (); + gtk_box_pack_start (GTK_BOX (vbox), socket, TRUE, TRUE, 0); + gtk_widget_show (socket); + + lastsocket = socket; + + sprintf(buffer, "%#lx", GDK_WINDOW_XWINDOW (socket->window)); + argv[1] = buffer; + +#if 1 + if (!g_spawn_async (NULL, argv, NULL, 0, NULL, NULL, NULL, &error)) + { + fprintf (stderr, "Can't exec testsocket_child: %s\n", error->message); + exit (1); + } +#else + fprintf(stderr,"%s\n", buffer); +#endif +} + +int +main (int argc, char *argv[]) +{ + GtkWidget *button; + GtkWidget *hbox; + GtkWidget *entry; + GtkItemFactory *item_factory; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_signal_connect (GTK_OBJECT (window), "destroy", + (GtkSignalFunc) gtk_main_quit, NULL); + + gtk_window_set_title (GTK_WINDOW (window), "Socket Test"); + gtk_container_set_border_width (GTK_CONTAINER (window), 0); + + vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), vbox); + + item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "
", + gtk_window_get_default_accel_group (GTK_WINDOW (window))); + gtk_item_factory_create_items (item_factory, + G_N_ELEMENTS (menu_items), menu_items, + NULL); + + gtk_box_pack_start (GTK_BOX (vbox), + gtk_item_factory_get_widget (item_factory, "
"), + FALSE, FALSE, 0); + + button = gtk_button_new_with_label ("Add Child"); + gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0); + + gtk_signal_connect_object (GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(add_child), + GTK_OBJECT(vbox)); + + button = gtk_button_new_with_label ("Remove Last Child"); + gtk_box_pack_start (GTK_BOX(vbox), button, FALSE, FALSE, 0); + + gtk_signal_connect_object (GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(remove_child), + GTK_OBJECT(vbox)); + + hbox = gtk_hbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + + entry = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX(hbox), entry, FALSE, FALSE, 0); + + button = gtk_button_new_with_label ("Steal"); + gtk_box_pack_start (GTK_BOX(hbox), button, FALSE, FALSE, 0); + + gtk_signal_connect (GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(steal), + entry); + + gtk_widget_show_all (window); + + gtk_main (); + + return 0; +} + + diff --git a/tests/testsocket_child.c b/tests/testsocket_child.c new file mode 100644 index 0000000000..873067bbf0 --- /dev/null +++ b/tests/testsocket_child.c @@ -0,0 +1,95 @@ +#include +#include + +#include + +void +remove_buttons (GtkWidget *widget, GtkWidget *other_button) +{ + gtk_widget_destroy (other_button); + gtk_widget_destroy (widget); +} + +void +add_buttons (GtkWidget *widget, GtkWidget *box) +{ + GtkWidget *add_button; + GtkWidget *remove_button; + GtkWidget *toplevel = gtk_widget_get_toplevel (box); + GtkAccelGroup *accel_group = gtk_window_get_default_accel_group (GTK_WINDOW (toplevel)); + + add_button = gtk_button_new_accel ("_Add", accel_group); + gtk_box_pack_start (GTK_BOX (box), add_button, TRUE, TRUE, 0); + gtk_widget_show (add_button); + + gtk_signal_connect (GTK_OBJECT (add_button), "clicked", + GTK_SIGNAL_FUNC (add_buttons), + box); + + remove_button = gtk_button_new_accel ("_Remove", accel_group); + gtk_box_pack_start (GTK_BOX (box), remove_button, TRUE, TRUE, 0); + gtk_widget_show (remove_button); + + gtk_signal_connect (GTK_OBJECT (remove_button), "clicked", + GTK_SIGNAL_FUNC (remove_buttons), + add_button); +} + +int +main (int argc, char *argv[]) +{ + guint32 xid; + + GtkWidget *window; + GtkWidget *hbox; + GtkWidget *entry; + GtkWidget *button; + GtkAccelGroup *accel_group; + gtk_init (&argc, &argv); + + if (argc < 2) + { + fprintf (stderr, "Usage: testsocket_child WINDOW_ID\n"); + exit (1); + } + + xid = strtol (argv[1], NULL, 0); + if (xid == 0) + { + fprintf (stderr, "Invalid window id '%s'\n", argv[1]); + exit (1); + } + + window = gtk_plug_new (xid); + gtk_signal_connect (GTK_OBJECT (window), "destroy", + (GtkSignalFunc) gtk_exit, NULL); + gtk_container_set_border_width (GTK_CONTAINER (window), 0); + + hbox = gtk_hbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), hbox); + gtk_widget_show (hbox); + + entry = gtk_entry_new (); + gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); + gtk_widget_show (entry); + + accel_group = gtk_window_get_default_accel_group (GTK_WINDOW (window)); + + button = gtk_button_new_accel ("_Close", accel_group); + gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + gtk_widget_show (button); + + gtk_signal_connect_object (GTK_OBJECT (button), "clicked", + GTK_SIGNAL_FUNC (gtk_widget_destroy), + GTK_OBJECT (window)); + + add_buttons (NULL, hbox); + + gtk_widget_show (window); + + gtk_main (); + + return 0; +} + +