2 * Classy Test - Terrible framework for testing asyncronous interface
4 * Copyright (C) 2008 Codethink Ltd
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include <glib-object.h>
24 #include "classy-test.h"
27 classy_test_report(ClassyTest *test)
29 switch (classy_test_state(test)) {
30 case CLASSY_TEST_FAIL:
31 return g_strdup_printf("FAIL : %s - %s\n ", test->name, test->failm);
33 return g_strdup_printf("PASS : %s\n", test->name);
35 return g_strdup_printf("INCOMPLETE : %s\n", test->name);
39 /*---------------------------------------------------------------------------*/
42 classy_test_run(ClassyTest *test)
44 test->tstate = CLASSY_TEST_IN_PROGRESS;
45 (test->entry)(test, test->data);
48 /*---------------------------------------------------------------------------*/
50 G_DEFINE_TYPE (ClassyTest, classy_test, G_TYPE_OBJECT)
53 classy_test_finalize (GObject *obj)
55 ClassyTest *test = CLASSY_TEST(obj);
62 G_OBJECT_CLASS (classy_test_parent_class)->finalize (obj);
66 classy_test_class_init (ClassyTestClass *klass)
68 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
70 gobject_class->finalize = classy_test_finalize;
72 klass->report = classy_test_report;
73 klass->run = classy_test_run;
76 klass->finished = g_signal_newv("finished",
78 G_SIGNAL_RUN_LAST | G_SIGNAL_NO_HOOKS,
82 g_cclosure_marshal_VOID__VOID,
89 classy_test_init (ClassyTest *test)
92 test->tstate = CLASSY_TEST_NOT_STARTED;
95 /*---------------------------------------------------------------------------*/
98 classy_test_new(gchar *name,
99 void (*entry) (ClassyTest*, gpointer data),
105 test = g_object_new(TYPE_CLASSY_TEST, NULL);
107 test->name = g_strdup(name);
114 /*---------------------------------------------------------------------------*/
117 classy_test_pass(ClassyTest *test)
119 test->tstate = CLASSY_TEST_WIN;
120 g_signal_emit (test, CLASSY_TEST_CLASS(test)->finished, 0, NULL);
123 /*---------------------------------------------------------------------------*/
126 classy_test_fail(ClassyTest *test, gchar *fmt, ...)
131 test->failm = g_strdup_vprintf(fmt, args);
133 test->tstate = CLASSY_TEST_FAIL;
134 g_signal_emit (test, CLASSY_TEST_CLASS(test)->finished, 0, NULL);
137 /*---------------------------------------------------------------------------*/
140 classy_test_state(ClassyTest *test)
145 /*---------------------------------------------------------------------------*/