2003-03-13 06:18:06 +00:00
|
|
|
/* -*- mode: C; c-file-style: "gnu" -*- */
|
|
|
|
|
/* test-main.c main() for make check
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 Red Hat, Inc.
|
|
|
|
|
*
|
2004-08-10 03:07:01 +00:00
|
|
|
* Licensed under the Academic Free License version 2.1
|
2003-03-13 06:18:06 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "test.h"
|
2003-03-14 01:27:58 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <dbus/dbus-string.h>
|
|
|
|
|
#include <dbus/dbus-sysdeps.h>
|
2003-03-24 03:16:58 +00:00
|
|
|
#include <dbus/dbus-internals.h>
|
2004-07-30 05:59:34 +00:00
|
|
|
#include "selinux.h"
|
2003-03-14 01:27:58 +00:00
|
|
|
|
2003-04-11 04:52:29 +00:00
|
|
|
#ifdef DBUS_BUILD_TESTS
|
2003-03-14 01:27:58 +00:00
|
|
|
static void
|
|
|
|
|
die (const char *failure)
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Unit test failed: %s\n", failure);
|
|
|
|
|
exit (1);
|
|
|
|
|
}
|
2003-03-13 06:18:06 +00:00
|
|
|
|
2003-03-26 07:16:03 +00:00
|
|
|
static void
|
|
|
|
|
check_memleaks (const char *name)
|
|
|
|
|
{
|
|
|
|
|
dbus_shutdown ();
|
|
|
|
|
|
|
|
|
|
printf ("%s: checking for memleaks\n", name);
|
|
|
|
|
if (_dbus_get_malloc_blocks_outstanding () != 0)
|
|
|
|
|
{
|
|
|
|
|
_dbus_warn ("%d dbus_malloc blocks were not freed\n",
|
|
|
|
|
_dbus_get_malloc_blocks_outstanding ());
|
|
|
|
|
die ("memleaks");
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-04-11 04:52:29 +00:00
|
|
|
#endif /* DBUS_BUILD_TESTS */
|
2003-03-26 07:16:03 +00:00
|
|
|
|
2004-08-23 16:09:54 +00:00
|
|
|
static void
|
|
|
|
|
test_pre_hook (void)
|
|
|
|
|
{
|
|
|
|
|
|
2004-11-02 20:27:48 +00:00
|
|
|
if (_dbus_getenv ("DBUS_TEST_SELINUX")
|
2004-11-03 16:38:35 +00:00
|
|
|
&& (!bus_selinux_pre_init ()
|
|
|
|
|
|| !bus_selinux_full_init ()))
|
2004-08-23 16:09:54 +00:00
|
|
|
die ("could not init selinux support");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *progname = "";
|
|
|
|
|
static void
|
|
|
|
|
test_post_hook (void)
|
|
|
|
|
{
|
|
|
|
|
if (_dbus_getenv ("DBUS_TEST_SELINUX"))
|
|
|
|
|
bus_selinux_shutdown ();
|
|
|
|
|
check_memleaks (progname);
|
|
|
|
|
}
|
|
|
|
|
|
2003-03-13 06:18:06 +00:00
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
#ifdef DBUS_BUILD_TESTS
|
2003-03-14 01:27:58 +00:00
|
|
|
const char *dir;
|
|
|
|
|
DBusString test_data_dir;
|
|
|
|
|
|
2004-08-23 16:09:54 +00:00
|
|
|
progname = argv[0];
|
|
|
|
|
|
2003-03-14 01:27:58 +00:00
|
|
|
if (argc > 1)
|
|
|
|
|
dir = argv[1];
|
|
|
|
|
else
|
|
|
|
|
dir = _dbus_getenv ("DBUS_TEST_DATA");
|
|
|
|
|
|
|
|
|
|
if (dir == NULL)
|
2003-03-31 08:19:50 +00:00
|
|
|
{
|
|
|
|
|
fprintf (stderr, "Must specify test data directory as argv[1] or in DBUS_TEST_DATA env variable\n");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2003-03-13 06:18:06 +00:00
|
|
|
|
2003-03-14 01:27:58 +00:00
|
|
|
_dbus_string_init_const (&test_data_dir, dir);
|
2003-04-06 19:12:45 +00:00
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
/* FIXME this is disabled because of thread bugs that need fixing... */
|
|
|
|
|
if (!_dbus_threads_init_debug ())
|
|
|
|
|
die ("initializing debug threads");
|
|
|
|
|
#endif
|
2004-03-12 14:07:16 +00:00
|
|
|
|
2004-08-23 16:09:54 +00:00
|
|
|
test_pre_hook ();
|
2003-10-11 06:20:28 +00:00
|
|
|
printf ("%s: Running expire list test\n", argv[0]);
|
|
|
|
|
if (!bus_expire_list_test (&test_data_dir))
|
|
|
|
|
die ("expire list");
|
2004-08-23 16:09:54 +00:00
|
|
|
test_post_hook ();
|
|
|
|
|
|
|
|
|
|
test_pre_hook ();
|
2003-03-26 03:58:11 +00:00
|
|
|
printf ("%s: Running config file parser test\n", argv[0]);
|
|
|
|
|
if (!bus_config_parser_test (&test_data_dir))
|
|
|
|
|
die ("parser");
|
2004-08-23 16:09:54 +00:00
|
|
|
test_post_hook ();
|
|
|
|
|
|
|
|
|
|
test_pre_hook ();
|
2003-03-26 03:58:11 +00:00
|
|
|
printf ("%s: Running policy test\n", argv[0]);
|
|
|
|
|
if (!bus_policy_test (&test_data_dir))
|
|
|
|
|
die ("policy");
|
2004-08-23 16:09:54 +00:00
|
|
|
test_post_hook ();
|
2003-03-26 07:16:03 +00:00
|
|
|
|
2004-08-23 16:09:54 +00:00
|
|
|
test_pre_hook ();
|
2003-09-21 19:53:56 +00:00
|
|
|
printf ("%s: Running signals test\n", argv[0]);
|
|
|
|
|
if (!bus_signals_test (&test_data_dir))
|
|
|
|
|
die ("signals");
|
2004-08-23 16:09:54 +00:00
|
|
|
test_post_hook ();
|
2003-09-21 19:53:56 +00:00
|
|
|
|
2004-08-23 16:09:54 +00:00
|
|
|
test_pre_hook ();
|
2003-04-14 23:52:40 +00:00
|
|
|
printf ("%s: Running SHA1 connection test\n", argv[0]);
|
|
|
|
|
if (!bus_dispatch_sha1_test (&test_data_dir))
|
|
|
|
|
die ("sha1");
|
2004-08-23 16:09:54 +00:00
|
|
|
test_post_hook ();
|
2003-04-14 23:52:40 +00:00
|
|
|
|
2004-08-23 16:09:54 +00:00
|
|
|
test_pre_hook ();
|
2003-03-17 23:29:03 +00:00
|
|
|
printf ("%s: Running message dispatch test\n", argv[0]);
|
2004-03-12 14:07:16 +00:00
|
|
|
if (!bus_dispatch_test (&test_data_dir))
|
2003-03-14 01:27:58 +00:00
|
|
|
die ("dispatch");
|
2004-08-23 16:09:54 +00:00
|
|
|
test_post_hook ();
|
2003-03-26 07:16:03 +00:00
|
|
|
|
2004-08-23 16:09:54 +00:00
|
|
|
test_pre_hook ();
|
2004-03-12 14:07:16 +00:00
|
|
|
printf ("%s: Running service files reloading test\n", argv[0]);
|
|
|
|
|
if (!bus_activation_service_reload_test (&test_data_dir))
|
|
|
|
|
die ("service reload");
|
2004-08-23 16:09:54 +00:00
|
|
|
test_post_hook ();
|
2004-03-12 14:07:16 +00:00
|
|
|
|
2003-03-17 23:29:03 +00:00
|
|
|
printf ("%s: Success\n", argv[0]);
|
2004-07-30 05:59:34 +00:00
|
|
|
|
2003-03-13 06:18:06 +00:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
#else /* DBUS_BUILD_TESTS */
|
2003-03-15 02:19:02 +00:00
|
|
|
|
|
|
|
|
printf ("Not compiled with test support\n");
|
|
|
|
|
|
2003-03-13 06:18:06 +00:00
|
|
|
return 0;
|
|
|
|
|
#endif
|
|
|
|
|
}
|