dbus-test.c

00001 /* -*- mode: C; c-file-style: "gnu" -*- */
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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_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 /* DBUS_BUILD_TESTS */
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   run_data_test ("spawn", specific_test, _dbus_spawn_test, test_data_dir);
00160   
00161   run_data_test ("userdb", specific_test, _dbus_userdb_test, test_data_dir);
00162   
00163   run_test ("keyring", specific_test, _dbus_keyring_test);
00164   
00165 #if 0
00166   printf ("%s: running md5 tests\n", "dbus-test");
00167   if (!_dbus_md5_test ())
00168     die ("md5");
00169 
00170   check_memleaks ();
00171 #endif
00172   
00173   run_data_test ("sha", specific_test, _dbus_sha_test, test_data_dir);
00174   
00175   run_data_test ("auth", specific_test, _dbus_auth_test, test_data_dir);
00176 
00177   run_data_test ("pending-call", specific_test, _dbus_pending_call_test, test_data_dir);
00178   
00179   printf ("%s: completed successfully\n", "dbus-test");
00180 #else
00181   printf ("Not compiled with unit tests, not running any\n");
00182 #endif
00183 }
00184 

Generated on Fri Sep 21 18:12:13 2007 for D-Bus by  doxygen 1.5.1