*
*/
-#include "dbus-types.h"
+#include <config.h>
+#include "dbus-test.h"
+#include "dbus-sysdeps.h"
#include <stdio.h>
+#include <stdlib.h>
-/* To add a test, write a function like this one,
- * declare it here, define it in the file to be tested,
- * then call it from main() below. Test functions
- * should return FALSE on failure.
- */
-dbus_bool_t _dbus_hash_test (void);
+static void
+die (const char *failure)
+{
+ fprintf (stderr, "Unit test failed: %s\n", failure);
+ exit (1);
+}
-int
-main (int argc,
- char **argv)
+/**
+ * An exported symbol to be run in order to execute
+ * unit tests. Should not be used by
+ * any app other than our test app, this symbol
+ * won't exist in some builds of the library.
+ * (with --enable-tests=no)
+ *
+ * @param test_data_dir the directory with test data (test/data normally)
+ */
+void
+dbus_internal_do_not_use_run_tests (const char *test_data_dir)
{
- printf ("%s: running hash table tests\n", argv[0]);
- if (!_dbus_hash_test ())
- return 1;
+#ifdef DBUS_BUILD_TESTS
+ if (test_data_dir == NULL)
+ test_data_dir = _dbus_getenv ("DBUS_TEST_DATA");
+
+ if (test_data_dir != NULL)
+ printf ("Test data in %s\n", test_data_dir);
+ else
+ printf ("No test data!\n");
+
+ printf ("%s: running string tests\n", "dbus-test");
+ if (!_dbus_string_test ())
+ die ("strings");
+ printf ("%s: running auth tests\n", "dbus-test");
+ if (!_dbus_auth_test (test_data_dir))
+ die ("auth");
+
+ printf ("%s: running address parse tests\n", "dbus-test");
+ if (!_dbus_address_test ())
+ die ("address parsing");
- printf ("%s: completed successfully\n", argv[0]);
- return 0;
+ printf ("%s: running marshalling tests\n", "dbus-test");
+ if (!_dbus_marshal_test ())
+ die ("marshalling");
+
+ printf ("%s: running message tests\n", "dbus-test");
+ if (!_dbus_message_test (test_data_dir))
+ die ("messages");
+
+ printf ("%s: running memory pool tests\n", "dbus-test");
+ if (!_dbus_mem_pool_test ())
+ die ("memory pools");
+
+ printf ("%s: running linked list tests\n", "dbus-test");
+ if (!_dbus_list_test ())
+ die ("lists");
+
+ printf ("%s: running hash table tests\n", "dbus-test");
+ if (!_dbus_hash_test ())
+ die ("hash tables");
+
+ printf ("%s: completed successfully\n", "dbus-test");
+#else
+ printf ("Not compiled with unit tests, not running any\n");
+#endif
}
+
+