D-Bus
1.10.12
|
00001 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ 00002 /* dbus-test.c Program to run all tests 00003 * 00004 * Copyright (C) 2002, 2003, 2004, 2005 Red Hat Inc. 00005 * 00006 * Licensed under the Academic Free License version 2.1 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 * 00022 */ 00023 00024 #include <config.h> 00025 #include "dbus-test.h" 00026 #include "dbus-sysdeps.h" 00027 #include "dbus-internals.h" 00028 #include <stdio.h> 00029 #include <stdlib.h> 00030 00031 #ifdef DBUS_ENABLE_EMBEDDED_TESTS 00032 static void 00033 die (const char *failure) 00034 { 00035 fprintf (stderr, "Unit test failed: %s\n", failure); 00036 exit (1); 00037 } 00038 00039 static void 00040 check_memleaks (void) 00041 { 00042 dbus_shutdown (); 00043 00044 printf ("%s: checking for memleaks\n", "test-dbus"); 00045 if (_dbus_get_malloc_blocks_outstanding () != 0) 00046 { 00047 _dbus_warn ("%d dbus_malloc blocks were not freed\n", 00048 _dbus_get_malloc_blocks_outstanding ()); 00049 die ("memleaks"); 00050 } 00051 } 00052 00053 typedef dbus_bool_t (*TestFunc)(void); 00054 typedef dbus_bool_t (*TestDataFunc)(const char *data); 00055 00056 static void 00057 run_test (const char *test_name, 00058 const char *specific_test, 00059 TestFunc test) 00060 { 00061 if (!specific_test || strcmp (specific_test, test_name) == 0) 00062 { 00063 printf ("%s: running %s tests\n", "test-dbus", test_name); 00064 if (!test ()) 00065 die (test_name); 00066 00067 check_memleaks (); 00068 } 00069 } 00070 00071 static void 00072 run_data_test (const char *test_name, 00073 const char *specific_test, 00074 TestDataFunc test, 00075 const char *test_data_dir) 00076 { 00077 if (!specific_test || strcmp (specific_test, test_name) == 0) 00078 { 00079 printf ("%s: running %s tests\n", "test-dbus", test_name); 00080 if (!test (test_data_dir)) 00081 die (test_name); 00082 00083 check_memleaks (); 00084 } 00085 } 00086 00087 #endif /* DBUS_ENABLE_EMBEDDED_TESTS */ 00088 00099 void 00100 dbus_internal_do_not_use_run_tests (const char *test_data_dir, const char *specific_test) 00101 { 00102 #ifdef DBUS_ENABLE_EMBEDDED_TESTS 00103 if (!_dbus_threads_init_debug ()) 00104 die ("debug threads init"); 00105 00106 if (test_data_dir == NULL) 00107 test_data_dir = _dbus_getenv ("DBUS_TEST_DATA"); 00108 00109 if (test_data_dir != NULL) 00110 printf ("Test data in %s\n", test_data_dir); 00111 else 00112 printf ("No test data!\n"); 00113 00114 run_test ("string", specific_test, _dbus_string_test); 00115 00116 run_test ("sysdeps", specific_test, _dbus_sysdeps_test); 00117 00118 run_test ("data-slot", specific_test, _dbus_data_slot_test); 00119 00120 run_test ("misc", specific_test, _dbus_misc_test); 00121 00122 run_test ("address", specific_test, _dbus_address_test); 00123 00124 run_test ("server", specific_test, _dbus_server_test); 00125 00126 run_test ("object-tree", specific_test, _dbus_object_tree_test); 00127 00128 run_test ("signature", specific_test, _dbus_signature_test); 00129 00130 run_test ("marshalling", specific_test, _dbus_marshal_test); 00131 00132 run_test ("marshal-recursive", specific_test, _dbus_marshal_recursive_test); 00133 00134 run_test ("byteswap", specific_test, _dbus_marshal_byteswap_test); 00135 00136 run_test ("memory", specific_test, _dbus_memory_test); 00137 00138 #if 1 00139 run_test ("mem-pool", specific_test, _dbus_mem_pool_test); 00140 #endif 00141 00142 run_test ("list", specific_test, _dbus_list_test); 00143 00144 run_test ("marshal-validate", specific_test, _dbus_marshal_validate_test); 00145 00146 run_data_test ("message", specific_test, _dbus_message_test, test_data_dir); 00147 00148 run_test ("hash", specific_test, _dbus_hash_test); 00149 00150 #if !defined(DBUS_WINCE) 00151 run_data_test ("spawn", specific_test, _dbus_spawn_test, test_data_dir); 00152 #endif 00153 00154 run_data_test ("credentials", specific_test, _dbus_credentials_test, test_data_dir); 00155 00156 #ifdef DBUS_UNIX 00157 run_data_test ("userdb", specific_test, _dbus_userdb_test, test_data_dir); 00158 00159 run_test ("transport-unix", specific_test, _dbus_transport_unix_test); 00160 #endif 00161 00162 run_test ("keyring", specific_test, _dbus_keyring_test); 00163 00164 run_data_test ("sha", specific_test, _dbus_sha_test, test_data_dir); 00165 00166 run_data_test ("auth", specific_test, _dbus_auth_test, test_data_dir); 00167 00168 printf ("%s: completed successfully\n", "test-dbus"); 00169 #else 00170 printf ("Not compiled with unit tests, not running any\n"); 00171 #endif 00172 } 00173