1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 /* dbus-auth-util.c Would be in dbus-auth.c, but only used for tests/bus
4 * Copyright (C) 2002, 2003, 2004 Red Hat Inc.
6 * Licensed under the Academic Free License version 2.1
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "dbus-internals.h"
26 #include "dbus-test.h"
27 #include "dbus-auth.h"
30 * @addtogroup DBusAuth
36 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
37 #include "dbus-test.h"
38 #include "dbus-auth-script.h"
42 process_test_subdir (const DBusString *test_base_dir,
45 DBusString test_directory;
49 DBusError error = DBUS_ERROR_INIT;
54 if (!_dbus_string_init (&test_directory))
55 _dbus_assert_not_reached ("didn't allocate test_directory\n");
57 _dbus_string_init_const (&filename, subdir);
59 if (!_dbus_string_copy (test_base_dir, 0,
61 _dbus_assert_not_reached ("couldn't copy test_base_dir to test_directory");
63 if (!_dbus_concat_dir_and_file (&test_directory, &filename))
64 _dbus_assert_not_reached ("couldn't allocate full path");
66 _dbus_string_free (&filename);
67 if (!_dbus_string_init (&filename))
68 _dbus_assert_not_reached ("didn't allocate filename string\n");
70 dir = _dbus_directory_open (&test_directory, &error);
73 _dbus_warn ("Could not open %s: %s\n",
74 _dbus_string_get_const_data (&test_directory),
76 dbus_error_free (&error);
80 printf ("Testing %s:\n", subdir);
83 while (_dbus_directory_get_next_file (dir, &filename, &error))
87 if (!_dbus_string_init (&full_path))
88 _dbus_assert_not_reached ("couldn't init string");
90 if (!_dbus_string_copy (&test_directory, 0, &full_path, 0))
91 _dbus_assert_not_reached ("couldn't copy dir to full_path");
93 if (!_dbus_concat_dir_and_file (&full_path, &filename))
94 _dbus_assert_not_reached ("couldn't concat file to dir");
96 if (!_dbus_string_ends_with_c_str (&filename, ".auth-script"))
98 _dbus_verbose ("Skipping non-.auth-script file %s\n",
99 _dbus_string_get_const_data (&filename));
100 _dbus_string_free (&full_path);
104 printf (" %s\n", _dbus_string_get_const_data (&filename));
106 if (!_dbus_auth_script_run (&full_path))
108 _dbus_string_free (&full_path);
112 _dbus_string_free (&full_path);
115 if (dbus_error_is_set (&error))
117 _dbus_warn ("Could not get next file in %s: %s\n",
118 _dbus_string_get_const_data (&test_directory), error.message);
119 dbus_error_free (&error);
128 _dbus_directory_close (dir);
129 _dbus_string_free (&test_directory);
130 _dbus_string_free (&filename);
136 process_test_dirs (const char *test_data_dir)
138 DBusString test_directory;
143 _dbus_string_init_const (&test_directory, test_data_dir);
145 if (!process_test_subdir (&test_directory, "auth"))
152 _dbus_string_free (&test_directory);
158 _dbus_auth_test (const char *test_data_dir)
161 if (test_data_dir == NULL)
164 if (!process_test_dirs (test_data_dir))
170 #endif /* DBUS_ENABLE_EMBEDDED_TESTS */