2003-02-10 Havoc Pennington <hp@pobox.com>
[platform/upstream/dbus.git] / dbus / dbus-test.c
index ad01fe0..3145349 100644 (file)
  *
  */
 
-#include "dbus-types.h"
+#include <config.h>
 #include "dbus-test.h"
+#include "dbus-sysdeps.h"
 #include <stdio.h>
+#include <stdlib.h>
 
-int
-main (int    argc,
-      char **argv)
+static void
+die (const char *failure)
 {
-  printf ("%s: running linked list tests\n", argv[0]);
+  fprintf (stderr, "Unit test failed: %s\n", failure);
+  exit (1);
+}
+
+/**
+ * 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)
+{
+#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: 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 ())
-    return 1;
+    die ("lists");
 
-  printf ("%s: running hash table tests\n", argv[0]);
+  printf ("%s: running hash table tests\n", "dbus-test");
   if (!_dbus_hash_test ())
-    return 1;
+    die ("hash tables");
   
-  printf ("%s: completed successfully\n", argv[0]);
-  return 0;
+  printf ("%s: completed successfully\n", "dbus-test");
+#else
+  printf ("Not compiled with unit tests, not running any\n");
+#endif
 }
+
+