dbus-test.c revision 5c593d75fff379b06cb690ae755a661da47d49ee
1/* -*- mode: C; c-file-style: "gnu" -*- */ 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., 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 32static void 33die (const char *failure) 34{ 35 fprintf (stderr, "Unit test failed: %s\n", failure); 36 exit (1); 37} 38 39static void 40check_memleaks (void) 41{ 42 dbus_shutdown (); 43 44 printf ("%s: checking for memleaks\n", "dbus-test"); 45 if (_dbus_get_malloc_blocks_outstanding () != 0) 46 { 47 _dbus_warn ("%d dbus_malloc blocks were not freed\n", 48 _dbus_get_malloc_blocks_outstanding ()); 49 die ("memleaks"); 50 } 51} 52 53typedef dbus_bool_t (*TestFunc)(void); 54typedef dbus_bool_t (*TestDataFunc)(const char *data); 55 56static void 57run_test (const char *test_name, 58 const char *specific_test, 59 TestFunc test) 60{ 61 if (!specific_test || strcmp (specific_test, test_name) == 0) 62 { 63 printf ("%s: running %s tests\n", "dbus-test", test_name); 64 if (!test ()) 65 die (test_name); 66 } 67 68 check_memleaks (); 69} 70 71static void 72run_data_test (const char *test_name, 73 const char *specific_test, 74 TestDataFunc test, 75 const char *test_data_dir) 76{ 77 if (!specific_test || strcmp (specific_test, test_name) == 0) 78 { 79 printf ("%s: running %s tests\n", "dbus-test", test_name); 80 if (!test (test_data_dir)) 81 die (test_name); 82 } 83 84 check_memleaks (); 85} 86 87#endif /* DBUS_BUILD_TESTS */ 88 89/** 90 * An exported symbol to be run in order to execute 91 * unit tests. Should not be used by 92 * any app other than our test app, this symbol 93 * won't exist in some builds of the library. 94 * (with --enable-tests=no) 95 * 96 * @param test_data_dir the directory with test data (test/data normally) 97 */ 98void 99dbus_internal_do_not_use_run_tests (const char *test_data_dir, const char *specific_test) 100{ 101#ifdef DBUS_BUILD_TESTS 102 if (!_dbus_threads_init_debug ()) 103 die ("debug threads init"); 104 105 if (test_data_dir == NULL) 106 test_data_dir = _dbus_getenv ("DBUS_TEST_DATA"); 107 108 if (test_data_dir != NULL) 109 printf ("Test data in %s\n", test_data_dir); 110 else 111 printf ("No test data!\n"); 112 113 run_test ("string", specific_test, _dbus_string_test); 114 115 run_test ("sysdeps", specific_test, _dbus_sysdeps_test); 116 117 run_test ("data-slot", specific_test, _dbus_data_slot_test); 118 119 run_test ("misc", specific_test, _dbus_misc_test); 120 121 run_test ("address", specific_test, _dbus_address_test); 122 123 run_test ("server", specific_test, _dbus_server_test); 124 125 run_test ("object-tree", specific_test, _dbus_object_tree_test); 126 127 run_test ("signature", specific_test, _dbus_signature_test); 128 129 run_test ("marshalling", specific_test, _dbus_marshal_test); 130 131#if 0 132 printf ("%s: running recursive marshalling tests\n", "dbus-test"); 133 if (!_dbus_marshal_recursive_test ()) 134 die ("recursive marshal"); 135 136 check_memleaks (); 137#else 138 _dbus_warn ("recursive marshal tests disabled\n"); 139#endif 140 141 run_test ("byteswap", specific_test, _dbus_marshal_byteswap_test); 142 143 run_test ("memory", specific_test, _dbus_memory_test); 144 145#if 1 146 run_test ("mem-pool", specific_test, _dbus_mem_pool_test); 147#endif 148 149 run_test ("list", specific_test, _dbus_list_test); 150 151 run_test ("marshal-validate", specific_test, _dbus_marshal_validate_test); 152 153 run_test ("marshal-header", specific_test, _dbus_marshal_header_test); 154 155 run_data_test ("message", specific_test, _dbus_message_test, test_data_dir); 156 157 run_test ("hash", specific_test, _dbus_hash_test); 158 159#if !defined(DBUS_WINCE) 160 run_data_test ("spawn", specific_test, _dbus_spawn_test, test_data_dir); 161#endif 162 163 run_data_test ("userdb", specific_test, _dbus_userdb_test, test_data_dir); 164 165 run_test ("keyring", specific_test, _dbus_keyring_test); 166 167#if 0 168 printf ("%s: running md5 tests\n", "dbus-test"); 169 if (!_dbus_md5_test ()) 170 die ("md5"); 171 172 check_memleaks (); 173#endif 174 175 run_data_test ("sha", specific_test, _dbus_sha_test, test_data_dir); 176 177 run_data_test ("auth", specific_test, _dbus_auth_test, test_data_dir); 178 179 run_data_test ("pending-call", specific_test, _dbus_pending_call_test, test_data_dir); 180 181 printf ("%s: completed successfully\n", "dbus-test"); 182#else 183 printf ("Not compiled with unit tests, not running any\n"); 184#endif 185} 186 187