48cd13f05283cadb7f2aa4d8a1104708fb63c74a
[platform/upstream/dbus.git] / glib / dbus-gtest.c
1 /* -*- mode: C; c-file-style: "gnu" -*- */
2 /* dbus-test.c  Program to run all tests
3  *
4  * Copyright (C) 2002, 2003  Red Hat Inc.
5  *
6  * Licensed under the Academic Free License version 1.2
7  * 
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  * 
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #include <config.h>
25 #include "dbus-gtest.h"
26 #include <stdio.h>
27 #include <stdlib.h>
28
29 #ifdef DBUS_BUILD_TESTS
30 static void
31 die (const char *failure)
32 {
33   fprintf (stderr, "Unit test failed: %s\n", failure);
34   exit (1);
35 }
36 #endif /* DBUS_BUILD_TESTS */
37
38 /**
39  * An exported symbol to be run in order to execute
40  * unit tests. Should not be used by
41  * any app other than our test app, this symbol
42  * won't exist in some builds of the library.
43  * (with --enable-tests=no)
44  *
45  * @param test_data_dir the directory with test data (test/data normally)
46  */
47 void
48 dbus_glib_internal_do_not_use_run_tests (const char *test_data_dir)
49 {
50 #ifdef DBUS_BUILD_TESTS  
51   if (test_data_dir == NULL)
52     test_data_dir = g_getenv ("DBUS_TEST_DATA");
53
54   if (test_data_dir != NULL)
55     printf ("Test data in %s\n", test_data_dir);
56   else
57     printf ("No test data!\n");
58
59   printf ("%s: running utils tests\n", "dbus-glib-test");
60   if (!_dbus_gutils_test (test_data_dir))
61     die ("gutils");
62   
63   printf ("%s: running mainloop integration tests\n", "dbus-glib-test");
64   if (!_dbus_gmain_test (test_data_dir))
65     die ("gmain");
66
67   printf ("%s: running GObject tests\n", "dbus-glib-test");
68   if (!_dbus_gobject_test (test_data_dir))
69     die ("gobject");
70   
71   printf ("%s: completed successfully\n", "dbus-glib-test");
72 #else
73   printf ("Not compiled with unit tests, not running any\n");
74 #endif
75 }
76
77