From: Mark Doffman Date: Mon, 29 Sep 2008 18:50:15 +0000 (+0100) Subject: 2008-09-29 Mark Doffman X-Git-Tag: AT_SPI2_CORE_0_1_3~131 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e26d8561b46bcbb55b5836c02d3c1a432d75d17c;p=platform%2Fupstream%2Fat-spi2-core.git 2008-09-29 Mark Doffman * tests/cspi/classy-test-* tests/cspi/simple-test.c tests/cspi/accessible-test.c Add a test suite infrastructure similar to pasytest for the pyatspi bindings. Test suite is currently unused. --- diff --git a/tests/cspi/accessible-test.c b/tests/cspi/accessible-test.c new file mode 100644 index 0000000..ab490db --- /dev/null +++ b/tests/cspi/accessible-test.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2008 Codethink Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#include +#include +#include + +typedef struct { + gchar *none; +} AccessibleObjectFixture; + +static void +test_getChildAtIndex (AccessibleObjectFixture *fix, gconstpointer test_data) +{ + return; +} + +int +main (int argc, char *argv[]) +{ + return 0; +} diff --git a/tests/cspi/classy-test-suite.c b/tests/cspi/classy-test-suite.c new file mode 100644 index 0000000..dd22e7a --- /dev/null +++ b/tests/cspi/classy-test-suite.c @@ -0,0 +1,211 @@ +/* + * Copyright (C) 2008 Codethink Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include + +#include "classy-test.h" +#include "classy-test-suite.h" + +/*---------------------------------------------------------------------------*/ + +static gboolean +run_test_app(gchar *module_name, gchar *dbus_name) +{ + gboolean result; + GPid pid; + GError *err = NULL; + + const gchar *test_data_directory; + const gchar *test_modules_directory; + const gchar *test_atspi_library; + const gchar *test_application; + gchar *test_module; + gchar *command_line; + + test_data_directory = g_getenv("TEST_DATA_DIRECTORY"); + test_modules_directory = g_getenv("TEST_MODULES_DIRECTORY"); + test_atspi_library = g_getenv("TEST_ATSPI_LIBRARY"); + test_application = g_getenv("TEST_APPLICATION"); + + test_module = g_build_path("/", test_modules_directory, module_name, NULL); + + command_line = g_build_path(" ", test_application, + "--atspi-dbus-name", dbus_name, + "--test-atspi-library", test_atspi_library, + "--test-module", test_module, + "--test-data-directory", test_data_directory, + NULL); + + if (!(result = g_spawn_command_line_async(NULL, &err))) + { + fprintf(stderr, "\nCould not spawn test application - %s", err->message); + } + + g_free(test_module); + g_free(command_line); + + return result; +} + +/*---------------------------------------------------------------------------*/ + +static gboolean +suite_idle_handler(gpointer data); + +static void +suite_finished_handler(gpointer data) +{ + ClassyTestSuite *suite = CLASSY_TEST_SUITE(data); + ClassyTest *test = CLASSY_TEST(g_array_index(suite->cases, gpointer, suite->current)); + + if ((classy_test_state(test) == CLASSY_TEST_WIN) || suite->cont) { + g_idle_add(suite_idle_handler, suite); + } + /* TODO If test has failed remember to send signal saying so */ +} + +static gboolean +suite_idle_handler(gpointer data) +{ + ClassyTestSuite *suite = CLASSY_TEST_SUITE(data); + + suite->current++; + if (suite->current >= suite->cases->len) { + /* No more tests, check for success or fail */ + gboolean succeeded = TRUE; + gint i; + for (i=0; i < suite->cases->len; i++) { + ClassyTest *test; + test = CLASSY_TEST(g_array_index(suite->cases, gpointer, i)); + succeeded = succeeded && (classy_test_state(test) == CLASSY_TEST_WIN); + } + if (succeeded == TRUE) + classy_test_pass(CLASSY_TEST(suite)); + else + classy_test_fail(CLASSY_TEST(suite), "Sub-test has failed"); + } else { + /* More tests, run this one*/ + ClassyTest *test; + test = CLASSY_TEST(g_array_index(suite->cases, gpointer, suite->current)); + g_signal_connect(test, "finished", (GCallback) suite_finished_handler, data); + classy_test_run(test); + } + return FALSE; +} + +static void +suite_run(ClassyTest *test) +{ + g_idle_add(suite_idle_handler, test); +} + +/*---------------------------------------------------------------------------*/ + +static gchar * +suite_report(ClassyTest *test) +{ + ClassyTestSuite *suite = CLASSY_TEST_SUITE(test); + GString *report; + gint i; + + report = g_string_new(""); + + switch (classy_test_state(test)) { + case CLASSY_TEST_FAIL: + g_string_printf(report, "FAIL : %s\n : %s\n ", test->name); + case CLASSY_TEST_WIN: + g_string_printf(report, "PASS : %s\n", test->name); + default: + g_string_printf(report, "INCOMPLETE : %s\n", test->name); + } + + for (i=0; i < suite->cases->len; i++) { + ClassyTest *subtest = CLASSY_TEST(g_array_index(suite->cases, gpointer, i)); + g_string_append_printf(report, " "); + g_string_append_printf(report, "%s", classy_test_report(subtest)); + } + return g_string_free(report, FALSE); +} + +/*---------------------------------------------------------------------------*/ + +G_DEFINE_TYPE (ClassyTestSuite, classy_test_suite, TYPE_CLASSY_TEST) + +static void +classy_test_suite_finalize (GObject *obj) +{ + ClassyTestSuite *suite = CLASSY_TEST_SUITE(obj); + gint i; + + for (i=0; i < suite->cases->len; i++) { + ClassyTest *test; + test = CLASSY_TEST(g_array_index(suite->cases, gpointer, i)); + g_object_unref(test); + } + g_free(suite->data); + + G_OBJECT_CLASS (classy_test_suite_parent_class)->finalize (obj); +} + +static void +classy_test_suite_class_init (ClassyTestSuiteClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + ClassyTestClass *test_class = CLASSY_TEST_CLASS(klass); + + gobject_class->finalize = classy_test_suite_finalize; + + test_class->report = suite_report; + test_class->run = suite_run; +} + +static void +classy_test_suite_init (ClassyTestSuite *suite) +{ + suite->cases = g_array_new(FALSE, FALSE, sizeof(gpointer)); + suite->current = -1; +} + +/*---------------------------------------------------------------------------*/ + +ClassyTestSuite * +classy_test_suite_new(gchar *name, gint dsize, gboolean cont) +{ + ClassyTestSuite *suite; + ClassyTest *test; + + suite = g_object_new(TYPE_CLASSY_TEST_SUITE, NULL); + suite->cont = cont; + suite->data = g_malloc0(dsize); + + test = CLASSY_TEST(suite); + test->name = g_strdup(name); + + return suite; +} + +void +classy_test_suite_add(ClassyTestSuite *suite, ClassyTest *test) +{ + g_array_append(suite->cases, test); +} + +/*---------------------------------------------------------------------------*/ diff --git a/tests/cspi/classy-test-suite.h b/tests/cspi/classy-test-suite.h new file mode 100644 index 0000000..d27aad0 --- /dev/null +++ b/tests/cspi/classy-test-suite.h @@ -0,0 +1,76 @@ +/* + * Classy Test - Terrible framework for testing asyncronous interface + * + * Copyright (C) 2008 Codethink Ltd + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef CLASSY_TEST_SUITE_H +#define CLASSY_TEST_SUITE_H + +#include + +G_BEGIN_DECLS + +GType classy_test_suite_get_type(void); + +#define TYPE_CLASSY_TEST_SUITE (classy_test_suite_get_type()) + +#define CLASSY_TEST_SUITE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + TYPE_CLASSY_TEST_SUITE, \ + ClassyTestSuite)) + +#define CLASSY_TEST_SUITE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ + TYPE_CLASSY_TEST_SUITE, \ + ClassyTestSuiteClass)) + +#define IS_CLASSY_TEST_SUITE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + TYPE_CLASSY_TEST_SUITE)) + +#define IS_CLASSY_TEST_SUITE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ + TYPE_CLASSY_TEST_SUITE)) + +#define CLASSY_TEST_SUITE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ + TYPE_CLASSY_TEST_SUITE, \ + ClassyTestSuiteClass)) + +typedef struct _ClassyTestSuite ClassyTestSuite; +typedef struct _ClassyTestSuiteClass ClassyTestSuiteClass; + +struct _ClassyTestSuite { + ClassyTest parent; + + GArray *cases; + gint current; + gboolean cont; + + gpointer data; +}; + +struct _ClassyTestSuiteClass { + ClassyTestClass parent; +}; + +ClassyTestSuite * +classy_test_suite_new(gchar *name, gint dsize, gboolean cont); + +void +classy_test_suite_add(ClassyTestSuite *suite, ClassyTest *test); + +/*---------------------------------------------------------------------------*/ + +G_END_DECLS +#endif /* CLASSY_TEST_SUITE_H */ diff --git a/tests/cspi/classy-test.c b/tests/cspi/classy-test.c new file mode 100644 index 0000000..e5ef266 --- /dev/null +++ b/tests/cspi/classy-test.c @@ -0,0 +1,145 @@ +/* + * Classy Test - Terrible framework for testing asyncronous interface + * + * Copyright (C) 2008 Codethink Ltd + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +#include "classy-test.h" + +static gchar * +classy_test_report(ClassyTest *test) +{ + switch (classy_test_state(test)) { + case CLASSY_TEST_FAIL: + return g_strdup_printf("FAIL : %s - %s\n ", test->name, test->failm); + case CLASSY_TEST_WIN: + return g_strdup_printf("PASS : %s\n", test->name); + default: + return g_strdup_printf("INCOMPLETE : %s\n", test->name); + } +} + +/*---------------------------------------------------------------------------*/ + +static void +classy_test_run(ClassyTest *test) +{ + test->tstate = CLASSY_TEST_IN_PROGRESS; + (test->entry)(test, test->data); +} + +/*---------------------------------------------------------------------------*/ + +G_DEFINE_TYPE (ClassyTest, classy_test, G_TYPE_OBJECT) + +static void +classy_test_finalize (GObject *obj) +{ + ClassyTest *test = CLASSY_TEST(obj); + + g_free(test->name); + if (test->failm) { + g_free(test->failm); + test->failm = NULL; + } + G_OBJECT_CLASS (classy_test_parent_class)->finalize (obj); +} + +static void +classy_test_class_init (ClassyTestClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->finalize = classy_test_finalize; + + klass->report = classy_test_report; + klass->run = classy_test_run; + + /*Signals*/ + klass->finished = g_signal_newv("finished", + TYPE_CLASSY_TEST, + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS, + NULL, + NULL, + NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0, + NULL); +} + +static void +classy_test_init (ClassyTest *test) +{ + test->failm = NULL; + test->tstate = CLASSY_TEST_NOT_STARTED; +} + +/*---------------------------------------------------------------------------*/ + +ClassyTest * +classy_test_new(gchar *name, + void (*entry) (ClassyTest*, gpointer data), + gint istate, + gpointer data) +{ + ClassyTest *test; + + test = g_object_new(TYPE_CLASSY_TEST, NULL); + + test->name = g_strdup(name); + test->entry = entry; + test->data = data; + + return test; +} + +/*---------------------------------------------------------------------------*/ + +void +classy_test_pass(ClassyTest *test) +{ + test->tstate = CLASSY_TEST_WIN; + g_signal_emit (test, CLASSY_TEST_CLASS(test)->finished, 0, NULL); +} + +/*---------------------------------------------------------------------------*/ + +void +classy_test_fail(ClassyTest *test, gchar *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + test->failm = g_strdup_vprintf(fmt, args); + va_end(args); + test->tstate = CLASSY_TEST_FAIL; + g_signal_emit (test, CLASSY_TEST_CLASS(test)->finished, 0, NULL); +} + +/*---------------------------------------------------------------------------*/ + +gint +classy_test_state(ClassyTest *test) +{ + return test->tstate; +} + +/*---------------------------------------------------------------------------*/ diff --git a/tests/cspi/classy-test.h b/tests/cspi/classy-test.h new file mode 100644 index 0000000..68e59e1 --- /dev/null +++ b/tests/cspi/classy-test.h @@ -0,0 +1,99 @@ +/* + * Classy Test - Terrible framework for testing asyncronous interface + * + * Copyright (C) 2008 Codethink Ltd + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#ifndef CLASSY_TEST_H +#define CLASSY_TEST_H + +#include + +G_BEGIN_DECLS + +GType classy_test_get_type(void); + +#define TYPE_CLASSY_TEST (classy_test_get_type()) + +#define CLASSY_TEST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + TYPE_CLASSY_TEST, \ + ClassyTest)) + +#define CLASSY_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ + TYPE_CLASSY_TEST, \ + ClassyTestClass)) + +#define IS_CLASSY_TEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + TYPE_CLASSY_TEST)) + +#define IS_CLASSY_TEST_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ + TYPE_CLASSY_TEST)) + +#define CLASSY_TEST_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ + TYPE_CLASSY_TEST, \ + ClassyTestClass)) + +typedef struct _ClassyTest ClassyTest; +typedef struct _ClassyTestClass ClassyTestClass; + +enum { + CLASSY_TEST_NOT_STARTED, + CLASSY_TEST_IN_PROGRESS, + CLASSY_TEST_FAIL, + CLASSY_TEST_WIN +}; + +struct _ClassyTest { + GObject parent; + + gchar *name; + gchar *failm; + gint tstate; + + void (*entry) (ClassyTest *tc, gpointer data); + + gpointer data; +}; + +struct _ClassyTestClass { + GObjectClass parent; + + /*Virtuals*/ + gchar *(*report) (ClassyTest *test); + void (*run) (ClassyTest *test); + + /*Signals*/ + gint finished; +}; + +ClassyTest * +classy_test_new(gchar *name, + void (*entry) (ClassyTest*, gpointer data), + gint istate, + gpointer data); + +void +classy_test_pass(ClassyTest *test); + +void +classy_test_fail(ClassyTest *test, gchar *fmt, ...); + +gint +classy_test_state(ClassyTest *test); + +G_END_DECLS +#endif /* CLASSY_TEST_H */ diff --git a/tests/cspi/simple-test.c b/tests/cspi/simple-test.c new file mode 100644 index 0000000..21c74a6 --- /dev/null +++ b/tests/cspi/simple-test.c @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2008 Codethink Ltd. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include + +#include + +int +main (int argc, char **argv) +{ + gint i; + gint n_desktops; + gchar *s; + + SPI_init (); + + n_desktops = SPI_getDesktopCount (); + + for (i=0; i