D-Bus  1.13.7
dbus-test.c
1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-test.c Program to run all tests
3  *
4  * Copyright (C) 2002, 2003, 2004, 2005 Red Hat Inc.
5  *
6  * Licensed under the Academic Free License version 2.1
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 <dbus/dbus-test-tap.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 
32 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
33 typedef dbus_bool_t (*TestFunc)(void);
34 typedef dbus_bool_t (*TestDataFunc)(const char *data);
35 
36 static void
37 run_test (const char *test_name,
38  const char *specific_test,
39  TestFunc test)
40 {
41  if (specific_test != NULL && strcmp (specific_test, test_name) != 0)
42  {
43  _dbus_test_skip ("%s - Only intending to run %s", test_name, specific_test);
44  return;
45  }
46 
47  _dbus_test_diag ("%s: running %s tests", "test-dbus", test_name);
48 
49  if (test ())
50  _dbus_test_ok ("%s", test_name);
51  else
52  _dbus_test_not_ok ("%s", test_name);
53 
54  _dbus_test_check_memleaks (test_name);
55 }
56 
57 static void
58 run_data_test (const char *test_name,
59  const char *specific_test,
60  TestDataFunc test,
61  const char *test_data_dir)
62 {
63  if (specific_test != NULL && strcmp (specific_test, test_name) != 0)
64  {
65  _dbus_test_skip ("%s - Only intending to run %s", test_name, specific_test);
66  return;
67  }
68 
69  _dbus_test_diag ("%s: running %s tests", "test-dbus", test_name);
70 
71  if (test (test_data_dir))
72  _dbus_test_ok ("%s", test_name);
73  else
74  _dbus_test_not_ok ("%s", test_name);
75 
76  _dbus_test_check_memleaks (test_name);
77 }
78 
89 void
90 _dbus_run_tests (const char *test_data_dir,
91  const char *specific_test)
92 {
93  if (!_dbus_threads_init_debug ())
94  _dbus_test_fatal ("debug threads init failed");
95 
96  if (test_data_dir == NULL)
97  test_data_dir = _dbus_getenv ("DBUS_TEST_DATA");
98 
99  if (test_data_dir != NULL)
100  _dbus_test_diag ("Test data in %s", test_data_dir);
101  else
102  _dbus_test_diag ("No test data!");
103 
104  run_test ("string", specific_test, _dbus_string_test);
105 
106  run_test ("sysdeps", specific_test, _dbus_sysdeps_test);
107 
108  run_test ("data-slot", specific_test, _dbus_data_slot_test);
109 
110  run_test ("misc", specific_test, _dbus_misc_test);
111 
112  run_test ("address", specific_test, _dbus_address_test);
113 
114  run_test ("server", specific_test, _dbus_server_test);
115 
116  run_test ("object-tree", specific_test, _dbus_object_tree_test);
117 
118  run_test ("signature", specific_test, _dbus_signature_test);
119 
120  run_test ("marshalling", specific_test, _dbus_marshal_test);
121 
122  run_test ("marshal-recursive", specific_test, _dbus_marshal_recursive_test);
123 
124  run_test ("byteswap", specific_test, _dbus_marshal_byteswap_test);
125 
126  run_test ("memory", specific_test, _dbus_memory_test);
127 
128 #if 1
129  run_test ("mem-pool", specific_test, _dbus_mem_pool_test);
130 #endif
131 
132  run_test ("list", specific_test, _dbus_list_test);
133 
134  run_test ("marshal-validate", specific_test, _dbus_marshal_validate_test);
135 
136  run_data_test ("message", specific_test, _dbus_message_test, test_data_dir);
137 
138  run_test ("hash", specific_test, _dbus_hash_test);
139 
140 #if !defined(DBUS_WINCE)
141  run_data_test ("spawn", specific_test, _dbus_spawn_test, test_data_dir);
142 #endif
143 
144  run_data_test ("credentials", specific_test, _dbus_credentials_test, test_data_dir);
145 
146 #ifdef DBUS_UNIX
147  run_data_test ("userdb", specific_test, _dbus_userdb_test, test_data_dir);
148 
149  run_test ("transport-unix", specific_test, _dbus_transport_unix_test);
150 #endif
151 
152  run_test ("keyring", specific_test, _dbus_keyring_test);
153 
154  run_data_test ("sha", specific_test, _dbus_sha_test, test_data_dir);
155 
156  run_data_test ("auth", specific_test, _dbus_auth_test, test_data_dir);
157 }
158 
159 #endif /* DBUS_ENABLE_EMBEDDED_TESTS */
#define NULL
A null pointer, defined appropriately for C or C++.
dbus_uint32_t dbus_bool_t
A boolean, valid values are TRUE and FALSE.
Definition: dbus-types.h:35
const char * _dbus_getenv(const char *varname)
Wrapper for getenv().
Definition: dbus-sysdeps.c:195