diff options
author | Thomas James Alexander Thurman <tthurman@src.gnome.org> | 2009-01-21 19:24:34 +0000 |
---|---|---|
committer | Thomas James Alexander Thurman <tthurman@src.gnome.org> | 2009-01-21 19:24:34 +0000 |
commit | e6f0cd27c6fb1cb3cd2c6f110b419717f9ed5496 (patch) | |
tree | 39a7e38bb9662289b93d2274fa902c0d34c27ad0 | |
parent | 7c34a2124988db1665d343666716b6f08d89b7b7 (diff) | |
download | metacity-e6f0cd27c6fb1cb3cd2c6f110b419717f9ed5496.tar.gz |
added bones of Veracity test suite
* test/veracity/Makefile.am:
* test/veracity/TODO:
* test/veracity/unit/reparent.js:
* test/veracity/unit/reparent.scm:
* test/veracity/veracity.c:
* test/veracity (added):
* test/veracity/unit (added):
* test/veracity/unit/reparent.scm (added):
* test/veracity/unit/reparent.js (added):
* test/veracity/build (added):
* test/veracity/stress (added):
* test/veracity/TODO (added):
* test/veracity/veracity.c (added):
* test/veracity/Makefile.am (added):
svn path=/branches/veracity/; revision=4079
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | test/veracity/Makefile.am | 19 | ||||
-rw-r--r-- | test/veracity/TODO | 6 | ||||
-rw-r--r-- | test/veracity/unit/reparent.js | 30 | ||||
-rw-r--r-- | test/veracity/unit/reparent.scm | 36 | ||||
-rw-r--r-- | test/veracity/veracity.c | 284 |
6 files changed, 394 insertions, 0 deletions
@@ -1,3 +1,22 @@ +2009-01-21 Thomas Thurman <tthurman@gnome.org> + + added bones of Veracity test suite + + * test/veracity/Makefile.am: + * test/veracity/TODO: + * test/veracity/unit/reparent.js: + * test/veracity/unit/reparent.scm: + * test/veracity/veracity.c: + * test/veracity (added): + * test/veracity/unit (added): + * test/veracity/unit/reparent.scm (added): + * test/veracity/unit/reparent.js (added): + * test/veracity/build (added): + * test/veracity/stress (added): + * test/veracity/TODO (added): + * test/veracity/veracity.c (added): + * test/veracity/Makefile.am (added): + 2009-01-10 Thomas Thurman <tthurman@gnome.org> * src/ui/theme.[ch]: add meta_theme_draw_frame_by_name, which diff --git a/test/veracity/Makefile.am b/test/veracity/Makefile.am new file mode 100644 index 00000000..6ba4f0fc --- /dev/null +++ b/test/veracity/Makefile.am @@ -0,0 +1,19 @@ +if BUILD_TESTS + +@INTLTOOL_DESKTOP_RULE@ +dfdfdf + +#INCLUDES=@METACITY_WINDOW_DEMO_CFLAGS@ @METACITY_MESSAGE_CFLAGS@ \ +# -DMETACITY_ICON_DIR=\"$(pkgdatadir)/icons\" \ +# -DMETACITY_LOCALEDIR=\"$(prefix)/@DATADIRNAME@/locale\" + +veracity_SOURCES= \ + veracity.c + +## don't install the test suite +#noinst_PROGRAMS=veracity + +veracity_LDADD= @METACITY_LIBS@ + +endif + diff --git a/test/veracity/TODO b/test/veracity/TODO new file mode 100644 index 00000000..19db7069 --- /dev/null +++ b/test/veracity/TODO @@ -0,0 +1,6 @@ +Replace gconf_test with actual gconf setting code. Check types. +Command-line switches. +Iterate over all in directory unless one was specified. +Pick display number sensibly. +Implement (listen) to call its argument with every X event until it returns false. +Wrap call to Xephyr with Xvfb (except if they specify -V). diff --git a/test/veracity/unit/reparent.js b/test/veracity/unit/reparent.js new file mode 100644 index 00000000..a57d8969 --- /dev/null +++ b/test/veracity/unit/reparent.js @@ -0,0 +1,30 @@ +// Test for Metacity +// Do windows get reparented when the WM starts? +// +// Copyright (C) 2008 Thomas Thurman +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License as +// published by the Free Software Foundation; either version 2 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. + +function test() +{ + a = make_window (); + b = make_window (); + if (parent (a) || parent (b)) + throw "Window has a parent at the beginning"; + start_wm (); + if (!parent (a) || !parent (b)) + throw "Window was not reparented"; +} diff --git a/test/veracity/unit/reparent.scm b/test/veracity/unit/reparent.scm new file mode 100644 index 00000000..d6616634 --- /dev/null +++ b/test/veracity/unit/reparent.scm @@ -0,0 +1,36 @@ +;;; Test for Metacity +;;; Do windows get reparented when the WM starts? +;;; +;;; Copyright (C) 2008 Thomas Thurman +;;; +;;; This program is free software; you can redistribute it and/or +;;; modify it under the terms of the GNU General Public License as +;;; published by the Free Software Foundation; either version 2 of the +;;; License, or (at your option) any later version. +;;; +;;; This program is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;;; General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with this program; if not, write to the Free Software +;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +;;; 02111-1307, USA. + +(define test + (lambda () + (define a (make-window)) + (define b (make-window)) + (if (or (parent a) (parent b)) + "Window has a parent at the beginning" + ;;; otherwise let's start the wm + (begin + (start-wm) + ;;; now, do we have a parent? + (if (or (not (parent a)) (not (parent b))) + "Window was not reparented" + ;;; otherwise pass + #t) + ) + ))) diff --git a/test/veracity/veracity.c b/test/veracity/veracity.c new file mode 100644 index 00000000..7705a579 --- /dev/null +++ b/test/veracity/veracity.c @@ -0,0 +1,284 @@ +/* + * veracity - test metacity + * + * Copyright (C) 2008 Thomas Thurman + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#include <stdio.h> +#include <libguile.h> +#include <guile/gh.h> +#include <sys/types.h> +#include <signal.h> + +#include <X11/Xlib.h> +#include <X11/Xutil.h> +#include <X11/Shell.h> +#include <X11/Intrinsic.h> +#include <X11/StringDefs.h> + +#include <gconf/gconf.h> + +int x_server = 0; /* PID of the tame X server */ +int window_manager = 0; /* PID of the window manager */ +int dbus_daemon = 0; +int gconf_daemon = 0; + +Display *current_display = NULL; + +gboolean verbose = FALSE; + +SCM +make_window() +{ + Window newbie; + + newbie = XCreateWindow(current_display, + DefaultRootWindow(current_display), + 0, 0, 300, 300, 0, + CopyFromParent, + InputOutput, + CopyFromParent, + 0, 0); + + XMapWindow (current_display, newbie); + + XSync (current_display, True); + + if (verbose) + printf ("Created window %x\n", (int) newbie); + + return scm_int2num(newbie); +} + +SCM +parent(SCM raw_window) +{ + Window window = gh_scm2int (raw_window); + Display *display; + Window w; + Window root_return; + Window parent_return; + Window *children_return; + unsigned int nchildren_return; + + XQueryTree(current_display, window, + &root_return, &parent_return, + &children_return, &nchildren_return); + + XFree (children_return); + + if (verbose) + printf ("Parent of %x is %x (root is %x)\n", (int) window, (int) parent_return, (int) root_return); + + if (root_return == parent_return) + return SCM_BOOL(0); + else + return scm_int2num (parent_return); +} + +static SCM +start_wm () +{ + /* FIXME: Which WM ought to be configurable */ + + if (!(window_manager = fork())) + { + execlp ("metacity", "metacity", NULL); + } + + /* have to wait a moment here while metacity starts up */ + sleep(2); + +} + +static SCM +key_event () +{ + /* + * Based around some public domain code by Adam Pierce + * http://www.doctort.org/adam/nerd-notes/x11-fake-keypress-event.html + */ +} + +static void +gconf_test (char *test) +{ + GConfValue *val = gconf_value_new_from_string (GCONF_VALUE_STRING, + test, NULL); + + if (verbose) + printf ("Setting the theme to %s\n", test); + gconf_client_set (gconf_client_get_default (), + "/apps/metacity/general/theme", + val, + NULL); + + gconf_value_free (val); +} + +static void +start_dbus_daemon () +{ + FILE *dbus_input; + int pipes[2]; + char text[10240]; + char *cursor = text; + ssize_t size; + + pipe (pipes); + + if (!(dbus_daemon = fork())) + { + close(1); + dup2(pipes[1], 1); + execlp ("dbus-launch", "dbus-launch", NULL); + } + sleep(1); + + size = read (pipes[0], &text, sizeof (text)-1); + text[size] = 0; + + /* okay, now we have FOO=bar\nBAZ=wombat\n... in text */ + + while (*cursor) { + char *newline = index (cursor, '\n'); + + *newline = 0; + putenv (cursor); + + cursor = newline+1; + } + +} + +static void +start_gconf_daemon () +{ + if (!(gconf_daemon = fork())) + { + execlp ("gconftool-2", "gconftool-2", "--spawn", NULL); + } + sleep(1); + + gconf_test ("Atlanta"); +} + +void +start_x_server () +{ + /* FIXME: Pick a sane number automagically */ + char *displaynumber = ":23"; + + if (!(x_server = fork())) + { + fclose(stderr); /* hide all the useless spew */ + + /* + execlp ("Xnest", "Xnest", displaynumber, "-ac", NULL); + */ + /* + execlp ("Xvfb", "Xvfb", displaynumber, "-ac", "+extension", "RANDR", NULL); + */ + execlp ("Xephyr", "Xephyr", displaynumber, "-nolisten", "tcp", "-host-cursor", + "-screen", "800x480x16", "-dpi", "96", "-ac", + "+extension", "Composite", + "+extension", "XFIXES", + "+extension", "DAMAGE", + "+extension", "RENDER", + "+extension", "GLX", + NULL); + } + sleep (1); + + current_display = XOpenDisplay (displaynumber); + setenv ("DISPLAY", displaynumber, 1); +} + +static void +start_guile () +{ + scm_init_guile (); + + scm_c_define_gsubr("make-window", 0, 0, 0, make_window); + scm_c_define_gsubr("parent", 1, 0, 0, parent); + scm_c_define_gsubr("start-wm", 0, 0, 0, start_wm); + scm_c_define_gsubr("key-event", 2, 0, 0, key_event); + scm_c_define_gsubr("gconf-set!", 2, 0, 0, gconf_set); +} + +static void +start () +{ + /* Normalise error messages */ + putenv ("LANG=C"); + + start_dbus_daemon (); + start_gconf_daemon (); + start_x_server (); + start_guile (); +} + +static gboolean +run_test (char *name) +{ + printf("%20s: ", name); + fflush(stdout); + + // Load the scheme function definitions + scm_c_primitive_load (name); + + SCM result = scm_c_eval_string("(test)"); + + if (scm_is_string (result)) + { + int length; + char *raw_text = gh_scm2newstr (result, &length); + printf ("FAIL (%s)\n", raw_text); + free (raw_text); + return FALSE; + } + else + { + printf ("pass\n"); + return TRUE; + } +} + +static void +finish () +{ + if (x_server) kill(x_server, SIGKILL); + if (window_manager) kill(window_manager, SIGKILL); + if (dbus_daemon) kill(dbus_daemon, SIGKILL); + if (gconf_daemon) kill(gconf_daemon, SIGKILL); + + XCloseDisplay (current_display); +} + +int +main (int argc, char *argv[]) +{ + start (); + + run_test ("001-reparent.scm"); + + finish (); + + /* I'm making a note here: HUGE SUCCESS. */ + exit(EXIT_SUCCESS); +} + |