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 #endif
00054
00055 typedef dbus_bool_t (*TestFunc)(void);
00056 typedef dbus_bool_t (*TestDataFunc)(const char *data);
00057
00058 static void
00059 run_test (const char *test_name,
00060 const char *specific_test,
00061 TestFunc test)
00062 {
00063 if (!specific_test || strcmp (specific_test, test_name) == 0)
00064 {
00065 printf ("%s: running %s tests\n", "dbus-test", test_name);
00066 if (!test ())
00067 die (test_name);
00068 }
00069
00070 check_memleaks ();
00071 }
00072
00073 static void
00074 run_data_test (const char *test_name,
00075 const char *specific_test,
00076 TestDataFunc test,
00077 const char *test_data_dir)
00078 {
00079 if (!specific_test || strcmp (specific_test, test_name) == 0)
00080 {
00081 printf ("%s: running %s tests\n", "dbus-test", test_name);
00082 if (!test (test_data_dir))
00083 die (test_name);
00084 }
00085
00086 check_memleaks ();
00087 }
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 ("address", specific_test, _dbus_address_test);
00120
00121 run_test ("server", specific_test, _dbus_server_test);
00122
00123 run_test ("object-tree", specific_test, _dbus_object_tree_test);
00124
00125 run_test ("signature", specific_test, _dbus_signature_test);
00126
00127 run_test ("marshalling", specific_test, _dbus_marshal_test);
00128
00129 #if 0
00130 printf ("%s: running recursive marshalling tests\n", "dbus-test");
00131 if (!_dbus_marshal_recursive_test ())
00132 die ("recursive marshal");
00133
00134 check_memleaks ();
00135 #else
00136 _dbus_warn ("recursive marshal tests disabled\n");
00137 #endif
00138
00139 run_test ("byteswap", specific_test, _dbus_marshal_byteswap_test);
00140
00141 run_test ("memory", specific_test, _dbus_memory_test);
00142
00143 #if 1
00144 run_test ("mem-pool", specific_test, _dbus_mem_pool_test);
00145 #endif
00146
00147 run_test ("list", specific_test, _dbus_list_test);
00148
00149 run_test ("marshal-validate", specific_test, _dbus_marshal_validate_test);
00150
00151 run_test ("marshal-header", specific_test, _dbus_marshal_header_test);
00152
00153 run_data_test ("message", specific_test, _dbus_message_test, test_data_dir);
00154
00155 run_test ("hash", specific_test, _dbus_hash_test);
00156
00157 run_data_test ("spawn", specific_test, _dbus_spawn_test, test_data_dir);
00158
00159 run_data_test ("userdb", specific_test, _dbus_userdb_test, test_data_dir);
00160
00161 run_test ("keyring", specific_test, _dbus_keyring_test);
00162
00163 #if 0
00164 printf ("%s: running md5 tests\n", "dbus-test");
00165 if (!_dbus_md5_test ())
00166 die ("md5");
00167
00168 check_memleaks ();
00169 #endif
00170
00171 run_data_test ("sha", specific_test, _dbus_sha_test, test_data_dir);
00172
00173 run_data_test ("auth", specific_test, _dbus_auth_test, test_data_dir);
00174
00175 run_data_test ("pending-call", specific_test, _dbus_pending_call_test, test_data_dir);
00176
00177 printf ("%s: completed successfully\n", "dbus-test");
00178 #else
00179 printf ("Not compiled with unit tests, not running any\n");
00180 #endif
00181 }