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 "test.h"
00025 #include <stdio.h>
00026 #include <stdlib.h>
00027 #include <dbus/dbus-string.h>
00028 #include <dbus/dbus-sysdeps.h>
00029 #include <dbus/dbus-internals.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 (const char *name)
00041 {
00042 dbus_shutdown ();
00043
00044 printf ("%s: checking for memleaks\n", name);
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 #endif
00053
00054 int
00055 main (int argc, char **argv)
00056 {
00057 #ifdef DBUS_BUILD_TESTS
00058 const char *dir;
00059 DBusString test_data_dir;
00060
00061 if (argc > 1)
00062 dir = argv[1];
00063 else
00064 dir = _dbus_getenv ("DBUS_TEST_DATA");
00065
00066 if (dir == NULL)
00067 {
00068 fprintf (stderr, "Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable\n");
00069 return 1;
00070 }
00071
00072 _dbus_string_init_const (&test_data_dir, dir);
00073
00074 #if 0
00075
00076 if (!_dbus_threads_init_debug ())
00077 die ("initializing debug threads");
00078 #endif
00079
00080 printf ("%s: Running config file parser test\n", argv[0]);
00081 if (!bus_config_parser_test (&test_data_dir))
00082 die ("parser");
00083
00084 check_memleaks (argv[0]);
00085
00086 printf ("%s: Running policy test\n", argv[0]);
00087 if (!bus_policy_test (&test_data_dir))
00088 die ("policy");
00089
00090 check_memleaks (argv[0]);
00091
00092 printf ("%s: Running SHA1 connection test\n", argv[0]);
00093 if (!bus_dispatch_sha1_test (&test_data_dir))
00094 die ("sha1");
00095
00096 check_memleaks (argv[0]);
00097
00098 printf ("%s: Running message dispatch test\n", argv[0]);
00099 if (!bus_dispatch_test (&test_data_dir))
00100 die ("dispatch");
00101
00102 check_memleaks (argv[0]);
00103
00104 printf ("%s: Success\n", argv[0]);
00105
00106 return 0;
00107 #else
00108
00109 printf ("Not compiled with test support\n");
00110
00111 return 0;
00112 #endif
00113 }