2 * Copyright (C) 2008 Codethink Ltd.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #include <glib-object.h>
24 #include "classy-test.h"
25 #include "classy-test-suite.h"
27 /*---------------------------------------------------------------------------*/
30 run_test_app(gchar *module_name, gchar *dbus_name)
36 const gchar *test_data_directory;
37 const gchar *test_modules_directory;
38 const gchar *test_atspi_library;
39 const gchar *test_application;
43 test_data_directory = g_getenv("TEST_DATA_DIRECTORY");
44 test_modules_directory = g_getenv("TEST_MODULES_DIRECTORY");
45 test_atspi_library = g_getenv("TEST_ATSPI_LIBRARY");
46 test_application = g_getenv("TEST_APPLICATION");
48 test_module = g_build_path("/", test_modules_directory, module_name, NULL);
50 command_line = g_build_path(" ", test_application,
51 "--atspi-dbus-name", dbus_name,
52 "--test-atspi-library", test_atspi_library,
53 "--test-module", test_module,
54 "--test-data-directory", test_data_directory,
57 if (!(result = g_spawn_command_line_async(NULL, &err)))
59 fprintf(stderr, "\nCould not spawn test application - %s", err->message);
68 /*---------------------------------------------------------------------------*/
71 suite_idle_handler(gpointer data);
74 suite_finished_handler(gpointer data)
76 ClassyTestSuite *suite = CLASSY_TEST_SUITE(data);
77 ClassyTest *test = CLASSY_TEST(g_array_index(suite->cases, gpointer, suite->current));
79 if ((classy_test_state(test) == CLASSY_TEST_WIN) || suite->cont) {
80 g_idle_add(suite_idle_handler, suite);
82 /* TODO If test has failed remember to send signal saying so */
86 suite_idle_handler(gpointer data)
88 ClassyTestSuite *suite = CLASSY_TEST_SUITE(data);
91 if (suite->current >= suite->cases->len) {
92 /* No more tests, check for success or fail */
93 gboolean succeeded = TRUE;
95 for (i=0; i < suite->cases->len; i++) {
97 test = CLASSY_TEST(g_array_index(suite->cases, gpointer, i));
98 succeeded = succeeded && (classy_test_state(test) == CLASSY_TEST_WIN);
100 if (succeeded == TRUE)
101 classy_test_pass(CLASSY_TEST(suite));
103 classy_test_fail(CLASSY_TEST(suite), "Sub-test has failed");
105 /* More tests, run this one*/
107 test = CLASSY_TEST(g_array_index(suite->cases, gpointer, suite->current));
108 g_signal_connect(test, "finished", (GCallback) suite_finished_handler, data);
109 classy_test_run(test);
115 suite_run(ClassyTest *test)
117 g_idle_add(suite_idle_handler, test);
120 /*---------------------------------------------------------------------------*/
123 suite_report(ClassyTest *test)
125 ClassyTestSuite *suite = CLASSY_TEST_SUITE(test);
129 report = g_string_new("");
131 switch (classy_test_state(test)) {
132 case CLASSY_TEST_FAIL:
133 g_string_printf(report, "FAIL : %s\n : %s\n ", test->name);
134 case CLASSY_TEST_WIN:
135 g_string_printf(report, "PASS : %s\n", test->name);
137 g_string_printf(report, "INCOMPLETE : %s\n", test->name);
140 for (i=0; i < suite->cases->len; i++) {
141 ClassyTest *subtest = CLASSY_TEST(g_array_index(suite->cases, gpointer, i));
142 g_string_append_printf(report, " ");
143 g_string_append_printf(report, "%s", classy_test_report(subtest));
145 return g_string_free(report, FALSE);
148 /*---------------------------------------------------------------------------*/
150 G_DEFINE_TYPE (ClassyTestSuite, classy_test_suite, TYPE_CLASSY_TEST)
153 classy_test_suite_finalize (GObject *obj)
155 ClassyTestSuite *suite = CLASSY_TEST_SUITE(obj);
158 for (i=0; i < suite->cases->len; i++) {
160 test = CLASSY_TEST(g_array_index(suite->cases, gpointer, i));
161 g_object_unref(test);
165 G_OBJECT_CLASS (classy_test_suite_parent_class)->finalize (obj);
169 classy_test_suite_class_init (ClassyTestSuiteClass *klass)
171 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
172 ClassyTestClass *test_class = CLASSY_TEST_CLASS(klass);
174 gobject_class->finalize = classy_test_suite_finalize;
176 test_class->report = suite_report;
177 test_class->run = suite_run;
181 classy_test_suite_init (ClassyTestSuite *suite)
183 suite->cases = g_array_new(FALSE, FALSE, sizeof(gpointer));
187 /*---------------------------------------------------------------------------*/
190 classy_test_suite_new(gchar *name, gint dsize, gboolean cont)
192 ClassyTestSuite *suite;
195 suite = g_object_new(TYPE_CLASSY_TEST_SUITE, NULL);
197 suite->data = g_malloc0(dsize);
199 test = CLASSY_TEST(suite);
200 test->name = g_strdup(name);
206 classy_test_suite_add(ClassyTestSuite *suite, ClassyTest *test)
208 g_array_append(suite->cases, test);
211 /*---------------------------------------------------------------------------*/