1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-test.c Program to run all tests
4 * Copyright (C) 2002, 2003, 2004, 2005 Red Hat Inc.
6 * Licensed under the Academic Free License version 2.1
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.
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.
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
25 #include "dbus-test.h"
26 #include "dbus-sysdeps.h"
27 #include "dbus-internals.h"
31 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
32 static void die (const char *failure) _DBUS_GNUC_NORETURN;
35 die (const char *failure)
37 fprintf (stderr, "Unit test failed: %s\n", failure);
46 printf ("%s: checking for memleaks\n", "test-dbus");
47 if (_dbus_get_malloc_blocks_outstanding () != 0)
49 _dbus_warn ("%d dbus_malloc blocks were not freed",
50 _dbus_get_malloc_blocks_outstanding ());
55 typedef dbus_bool_t (*TestFunc)(void);
56 typedef dbus_bool_t (*TestDataFunc)(const char *data);
59 run_test (const char *test_name,
60 const char *specific_test,
63 if (!specific_test || strcmp (specific_test, test_name) == 0)
65 printf ("%s: running %s tests\n", "test-dbus", test_name);
74 run_data_test (const char *test_name,
75 const char *specific_test,
77 const char *test_data_dir)
79 if (!specific_test || strcmp (specific_test, test_name) == 0)
81 printf ("%s: running %s tests\n", "test-dbus", test_name);
82 if (!test (test_data_dir))
89 #endif /* DBUS_ENABLE_EMBEDDED_TESTS */
92 * An exported symbol to be run in order to execute
93 * unit tests. Should not be used by
94 * any app other than our test app, this symbol
95 * won't exist in some builds of the library.
96 * (with --enable-tests=no)
98 * @param test_data_dir the directory with test data (test/data normally)
99 * @param specific_test run specific test or #NULL to run all tests
102 dbus_internal_do_not_use_run_tests (const char *test_data_dir, const char *specific_test)
104 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
105 if (!_dbus_threads_init_debug ())
106 die ("debug threads init");
108 if (test_data_dir == NULL)
109 test_data_dir = _dbus_getenv ("DBUS_TEST_DATA");
111 if (test_data_dir != NULL)
112 printf ("Test data in %s\n", test_data_dir);
114 printf ("No test data!\n");
116 run_test ("string", specific_test, _dbus_string_test);
118 run_test ("sysdeps", specific_test, _dbus_sysdeps_test);
120 run_test ("data-slot", specific_test, _dbus_data_slot_test);
122 run_test ("misc", specific_test, _dbus_misc_test);
124 run_test ("address", specific_test, _dbus_address_test);
126 run_test ("server", specific_test, _dbus_server_test);
128 run_test ("object-tree", specific_test, _dbus_object_tree_test);
130 run_test ("signature", specific_test, _dbus_signature_test);
132 run_test ("marshalling", specific_test, _dbus_marshal_test);
134 run_test ("marshal-recursive", specific_test, _dbus_marshal_recursive_test);
136 run_test ("byteswap", specific_test, _dbus_marshal_byteswap_test);
138 run_test ("memory", specific_test, _dbus_memory_test);
141 run_test ("mem-pool", specific_test, _dbus_mem_pool_test);
144 run_test ("list", specific_test, _dbus_list_test);
146 run_test ("marshal-validate", specific_test, _dbus_marshal_validate_test);
148 run_data_test ("message", specific_test, _dbus_message_test, test_data_dir);
150 run_test ("hash", specific_test, _dbus_hash_test);
152 #if !defined(DBUS_WINCE)
153 run_data_test ("spawn", specific_test, _dbus_spawn_test, test_data_dir);
156 run_data_test ("credentials", specific_test, _dbus_credentials_test, test_data_dir);
159 run_data_test ("userdb", specific_test, _dbus_userdb_test, test_data_dir);
161 run_test ("transport-unix", specific_test, _dbus_transport_unix_test);
164 run_test ("keyring", specific_test, _dbus_keyring_test);
166 run_data_test ("sha", specific_test, _dbus_sha_test, test_data_dir);
168 run_data_test ("auth", specific_test, _dbus_auth_test, test_data_dir);
170 printf ("%s: completed successfully\n", "test-dbus");
172 printf ("Not compiled with unit tests, not running any\n");