00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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_BUILD_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", "dbus-test");
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", "dbus-test", test_name);
00064 if (!test ())
00065 die (test_name);
00066 }
00067
00068 check_memleaks ();
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", "dbus-test", test_name);
00080 if (!test (test_data_dir))
00081 die (test_name);
00082 }
00083
00084 check_memleaks ();
00085 }
00086
00087 #endif
00088
00098 void
00099 dbus_internal_do_not_use_run_tests (const char *test_data_dir, const char *specific_test)
00100 {
00101 #ifdef DBUS_BUILD_TESTS
00102 if (!_dbus_threads_init_debug ())
00103 die ("debug threads init");
00104
00105 if (test_data_dir == NULL)
00106 test_data_dir = _dbus_getenv ("DBUS_TEST_DATA");
00107
00108 if (test_data_dir != NULL)
00109 printf ("Test data in %s\n", test_data_dir);
00110 else
00111 printf ("No test data!\n");
00112
00113 run_test ("string", specific_test, _dbus_string_test);
00114
00115 run_test ("sysdeps", specific_test, _dbus_sysdeps_test);
00116
00117 run_test ("data-slot", specific_test, _dbus_data_slot_test);
00118
00119 run_test ("misc", specific_test, _dbus_misc_test);
00120
00121 run_test ("address", specific_test, _dbus_address_test);
00122
00123 run_test ("server", specific_test, _dbus_server_test);
00124
00125 run_test ("object-tree", specific_test, _dbus_object_tree_test);
00126
00127 run_test ("signature", specific_test, _dbus_signature_test);
00128
00129 run_test ("marshalling", specific_test, _dbus_marshal_test);
00130
00131 #if 0
00132 printf ("%s: running recursive marshalling tests\n", "dbus-test");
00133 if (!_dbus_marshal_recursive_test ())
00134 die ("recursive marshal");
00135
00136 check_memleaks ();
00137 #else
00138 _dbus_warn ("recursive marshal tests disabled\n");
00139 #endif
00140
00141 run_test ("byteswap", specific_test, _dbus_marshal_byteswap_test);
00142
00143 run_test ("memory", specific_test, _dbus_memory_test);
00144
00145 #if 1
00146 run_test ("mem-pool", specific_test, _dbus_mem_pool_test);
00147 #endif
00148
00149 run_test ("list", specific_test, _dbus_list_test);
00150
00151 run_test ("marshal-validate", specific_test, _dbus_marshal_validate_test);
00152
00153 run_test ("marshal-header", specific_test, _dbus_marshal_header_test);
00154
00155 run_data_test ("message", specific_test, _dbus_message_test, test_data_dir);
00156
00157 run_test ("hash", specific_test, _dbus_hash_test);
00158
00159 #if !defined(DBUS_WINCE)
00160 run_data_test ("spawn", specific_test, _dbus_spawn_test, test_data_dir);
00161 #endif
00162
00163 run_data_test ("credentials", specific_test, _dbus_credentials_test, test_data_dir);
00164
00165 #ifdef DBUS_UNIX
00166 run_data_test ("userdb", specific_test, _dbus_userdb_test, test_data_dir);
00167 #endif
00168
00169 run_test ("keyring", specific_test, _dbus_keyring_test);
00170
00171 #if 0
00172 printf ("%s: running md5 tests\n", "dbus-test");
00173 if (!_dbus_md5_test ())
00174 die ("md5");
00175
00176 check_memleaks ();
00177 #endif
00178
00179 run_data_test ("sha", specific_test, _dbus_sha_test, test_data_dir);
00180
00181 run_data_test ("auth", specific_test, _dbus_auth_test, test_data_dir);
00182
00183 run_data_test ("pending-call", specific_test, _dbus_pending_call_test, test_data_dir);
00184
00185 printf ("%s: completed successfully\n", "dbus-test");
00186 #else
00187 printf ("Not compiled with unit tests, not running any\n");
00188 #endif
00189 }
00190