341601166de32be3aa2e040f0d6b88e2f0c4b0f4
[platform/upstream/dbus.git] / dbus / dbus-test.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-test.h"
26 #include "dbus-sysdeps.h"
27 #include "dbus-internals.h"
28 #include <stdio.h>
29 #include <stdlib.h>
30
31 #ifdef DBUS_BUILD_TESTS
32 static void
33 die (const char *failure)
34 {
35   fprintf (stderr, "Unit test failed: %s\n", failure);
36   exit (1);
37 }
38 #endif /* DBUS_BUILD_TESTS */
39
40 /**
41  * An exported symbol to be run in order to execute
42  * unit tests. Should not be used by
43  * any app other than our test app, this symbol
44  * won't exist in some builds of the library.
45  * (with --enable-tests=no)
46  *
47  * @param test_data_dir the directory with test data (test/data normally)
48  */
49 void
50 dbus_internal_do_not_use_run_tests (const char *test_data_dir)
51 {
52 #ifdef DBUS_BUILD_TESTS
53   if (test_data_dir == NULL)
54     test_data_dir = _dbus_getenv ("DBUS_TEST_DATA");
55
56   if (test_data_dir != NULL)
57     printf ("Test data in %s\n", test_data_dir);
58   else
59     printf ("No test data!\n");
60
61   printf ("%s: running string tests\n", "dbus-test");
62   if (!_dbus_string_test ())
63     die ("strings");
64   
65   printf ("%s: running data slot tests\n", "dbus-test");
66   if (!_dbus_data_slot_test ())
67     die ("dataslot");
68   
69   printf ("%s: running keyring tests\n", "dbus-test");
70   if (!_dbus_keyring_test ())
71     die ("keyring");
72   
73 #if 0
74   printf ("%s: running md5 tests\n", "dbus-test");
75   if (!_dbus_md5_test ())
76     die ("md5");
77 #endif
78   
79   printf ("%s: running SHA-1 tests\n", "dbus-test");
80   if (!_dbus_sha_test (test_data_dir))
81     die ("SHA-1");
82   
83   printf ("%s: running auth tests\n", "dbus-test");
84   if (!_dbus_auth_test (test_data_dir))
85     die ("auth");
86   
87   printf ("%s: running address parse tests\n", "dbus-test");
88   if (!_dbus_address_test ())
89     die ("address parsing");
90   
91   printf ("%s: running marshalling tests\n", "dbus-test");
92   if (!_dbus_marshal_test ())
93     die ("marshalling");
94
95   printf ("%s: running message tests\n", "dbus-test");
96   if (!_dbus_message_test (test_data_dir))
97     die ("messages");
98
99   printf ("%s: running memory pool tests\n", "dbus-test");
100   if (!_dbus_mem_pool_test ())
101     die ("memory pools");
102   
103   printf ("%s: running linked list tests\n", "dbus-test");
104   if (!_dbus_list_test ())
105     die ("lists");
106
107   printf ("%s: running hash table tests\n", "dbus-test");
108   if (!_dbus_hash_test ())
109     die ("hash tables");
110   
111   printf ("%s: running dict tests\n", "dbus-test");
112   if (!_dbus_dict_test ())
113     die ("dicts");
114
115   dbus_shutdown ();
116
117   printf ("%s: checking for memleaks\n", "dbus-test");
118   if (_dbus_get_malloc_blocks_outstanding () != 0)
119     {
120       _dbus_warn ("%d dbus_malloc blocks were not freed\n",
121                   _dbus_get_malloc_blocks_outstanding ());
122       die ("memleaks");
123     }
124   
125   printf ("%s: completed successfully\n", "dbus-test");
126 #else
127   printf ("Not compiled with unit tests, not running any\n");
128 #endif
129 }
130
131