Main Page   Modules   Data Structures   File List   Data Fields   Related Pages  

test-main.c

00001 /* -*- mode: C; c-file-style: "gnu" -*- */
00002 /* test-main.c  main() for make check
00003  *
00004  * Copyright (C) 2003 Red Hat, Inc.
00005  *
00006  * Licensed under the Academic Free License version 1.2
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 "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 /* DBUS_BUILD_TESTS */
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   /* FIXME this is disabled because of thread bugs that need fixing... */
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 signals test\n", argv[0]);
00093   if (!bus_signals_test (&test_data_dir))
00094     die ("signals");
00095 
00096   check_memleaks (argv[0]);
00097   
00098   printf ("%s: Running SHA1 connection test\n", argv[0]);
00099   if (!bus_dispatch_sha1_test (&test_data_dir))
00100     die ("sha1");
00101 
00102   check_memleaks (argv[0]);
00103   
00104   printf ("%s: Running message dispatch test\n", argv[0]);
00105   if (!bus_dispatch_test (&test_data_dir))
00106     die ("dispatch");
00107 
00108   check_memleaks (argv[0]);
00109   
00110   printf ("%s: Success\n", argv[0]);
00111   
00112   return 0;
00113 #else /* DBUS_BUILD_TESTS */
00114 
00115   printf ("Not compiled with test support\n");
00116   
00117   return 0;
00118 #endif
00119 }

Generated on Mon Sep 29 21:31:02 2003 for D-BUS by doxygen1.2.15