]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
test: Move sysdeps tests here
authorSimon McVittie <smcv@collabora.com>
Fri, 28 Sep 2018 15:46:41 +0000 (16:46 +0100)
committerSimon McVittie <smcv@collabora.com>
Mon, 21 Jan 2019 15:22:05 +0000 (15:22 +0000)
Signed-off-by: Simon McVittie <smcv@collabora.com>
cmake/test/CMakeLists.txt
dbus/dbus-sysdeps-util.c
dbus/dbus-test.h
test/Makefile.am
test/internals/dbus-sysdeps-util.c [new file with mode: 0644]
test/internals/misc-internals.h

index 782a8eca0d96aaa251bb757aaeab88df545d27bc..3a7218a4f69f8d7d61c48f7b9d4e5402b4bfae5f 100644 (file)
@@ -121,6 +121,7 @@ if(DBUS_ENABLE_EMBEDDED_TESTS)
                 ${TEST_DIR}/internals/dbus-marshal-recursive-util.h
                 ${TEST_DIR}/internals/dbus-marshal-validate-util.c
                 ${TEST_DIR}/internals/dbus-string-util.c
+                ${TEST_DIR}/internals/dbus-sysdeps-util.c
                 ${TEST_DIR}/internals/misc-internals.c
                 ${TEST_DIR}/internals/misc-internals.h)
     add_test_executable(test-misc-internals "${SOURCES}" dbus-testutils)
index 4a7d08cc26c49f7593f8d18f19a11716288eae61..66af910e6ae9b7bd656c1e3a28fe9ac26f44a40f 100644 (file)
@@ -1,8 +1,11 @@
 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
 /* dbus-sysdeps-util.c Tests for dbus-sysdeps.h API
  *
- * Copyright (C) 2002, 2003, 2004, 2005  Red Hat, Inc.
- * Copyright (C) 2003 CodeFactory AB
+ * Copyright 2002-2008 Red Hat, Inc.
+ * Copyright 2003 CodeFactory AB
+ * Copyright 2006 Ralf Habacker
+ * Copyright 2006 Sjoerd Simons
+ * Copyright 2016-2018 Collabora Ltd.
  *
  * Licensed under the Academic Free License version 2.1
  *
@@ -26,8 +29,6 @@
 #include "dbus-sysdeps.h"
 #include "dbus-internals.h"
 #include "dbus-string.h"
-#include "dbus-test.h"
-#include <dbus/dbus-test-tap.h>
 
 #include <stdlib.h>
 
@@ -82,121 +83,3 @@ _dbus_get_environment (void)
 
   return environment;
 }
-
-#ifdef DBUS_ENABLE_EMBEDDED_TESTS
-static void
-check_dirname (const char *filename,
-               const char *dirname)
-{
-  DBusString f, d;
-  
-  _dbus_string_init_const (&f, filename);
-
-  if (!_dbus_string_init (&d))
-    _dbus_test_fatal ("no memory");
-
-  if (!_dbus_string_get_dirname (&f, &d))
-    _dbus_test_fatal ("no memory");
-
-  if (!_dbus_string_equal_c_str (&d, dirname))
-    {
-      _dbus_warn ("For filename \"%s\" got dirname \"%s\" and expected \"%s\"",
-                  filename,
-                  _dbus_string_get_const_data (&d),
-                  dirname);
-      exit (1);
-    }
-
-  _dbus_string_free (&d);
-}
-
-static void
-check_path_absolute (const char *path,
-                     dbus_bool_t expected)
-{
-  DBusString p;
-
-  _dbus_string_init_const (&p, path);
-
-  if (_dbus_path_is_absolute (&p) != expected)
-    {
-      _dbus_warn ("For path \"%s\" expected absolute = %d got %d",
-                  path, expected, _dbus_path_is_absolute (&p));
-      exit (1);
-    }
-}
-
-/**
- * Unit test for dbus-sysdeps.c.
- * 
- * @returns #TRUE on success.
- */
-dbus_bool_t
-_dbus_sysdeps_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
-{
-#ifdef DBUS_WIN
-  check_dirname ("foo\\bar", "foo");
-  check_dirname ("foo\\\\bar", "foo");
-  check_dirname ("foo/\\/bar", "foo");
-  check_dirname ("foo\\bar/", "foo");
-  check_dirname ("foo//bar\\", "foo");
-  check_dirname ("foo\\bar/", "foo");
-  check_dirname ("foo/bar\\\\", "foo");
-  check_dirname ("\\foo", "\\");
-  check_dirname ("\\\\foo", "\\");
-  check_dirname ("\\", "\\");
-  check_dirname ("\\\\", "\\");
-  check_dirname ("\\/", "\\");
-  check_dirname ("/\\/", "/");
-  check_dirname ("c:\\foo\\bar", "c:\\foo");
-  check_dirname ("c:\\foo", "c:\\");
-  check_dirname ("c:/foo", "c:/");
-  check_dirname ("c:\\", "c:\\");
-  check_dirname ("c:/", "c:/");
-  check_dirname ("", ".");  
-#else  
-  check_dirname ("foo", ".");
-  check_dirname ("foo/bar", "foo");
-  check_dirname ("foo//bar", "foo");
-  check_dirname ("foo///bar", "foo");
-  check_dirname ("foo/bar/", "foo");
-  check_dirname ("foo//bar/", "foo");
-  check_dirname ("foo///bar/", "foo");
-  check_dirname ("foo/bar//", "foo");
-  check_dirname ("foo//bar////", "foo");
-  check_dirname ("foo///bar///////", "foo");
-  check_dirname ("/foo", "/");
-  check_dirname ("////foo", "/");
-  check_dirname ("/foo/bar", "/foo");
-  check_dirname ("/foo//bar", "/foo");
-  check_dirname ("/foo///bar", "/foo");
-  check_dirname ("/", "/");
-  check_dirname ("///", "/");
-  check_dirname ("", ".");  
-#endif
-
-#ifdef DBUS_WIN
-  check_path_absolute ("c:/", TRUE);
-  check_path_absolute ("c:/foo", TRUE);
-  check_path_absolute ("", FALSE);
-  check_path_absolute ("foo", FALSE);
-  check_path_absolute ("foo/bar", FALSE);
-  check_path_absolute ("", FALSE);
-  check_path_absolute ("foo\\bar", FALSE);
-  check_path_absolute ("c:\\", TRUE);
-  check_path_absolute ("c:\\foo", TRUE);
-  check_path_absolute ("c:", TRUE);
-  check_path_absolute ("c:\\foo\\bar", TRUE);
-  check_path_absolute ("\\", TRUE);
-  check_path_absolute ("/", TRUE);
-#else  
-  check_path_absolute ("/", TRUE);
-  check_path_absolute ("/foo", TRUE);
-  check_path_absolute ("", FALSE);
-  check_path_absolute ("foo", FALSE);
-  check_path_absolute ("foo/bar", FALSE);
-#endif
-  
-  return TRUE;
-}
-#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
index 5dd07e9ede0c42291f2d40f2d0ddb0b0c2438dad..3ca2ef97d7fe89ae2b4741b13ab0db21a879c72a 100644 (file)
@@ -67,8 +67,6 @@ dbus_bool_t _dbus_keyring_test           (const char *test_data_dir);
 DBUS_PRIVATE_EXPORT
 dbus_bool_t _dbus_data_slot_test         (const char *test_data_dir);
 
-dbus_bool_t _dbus_sysdeps_test           (const char *test_data_dir);
-
 DBUS_PRIVATE_EXPORT
 dbus_bool_t _dbus_userdb_test            (const char *test_data_dir);
 
index ca96a3eea90ee0612e9e64e2275d63b625e00af1..6e81d1b6600c998f95cb7681c30ad1c0dd5a33c9 100644 (file)
@@ -231,6 +231,7 @@ test_misc_internals_SOURCES = \
        internals/dbus-marshal-recursive-util.h \
        internals/dbus-marshal-validate-util.c \
        internals/dbus-string-util.c \
+       internals/dbus-sysdeps-util.c \
        internals/misc-internals.c \
        internals/misc-internals.h \
        $(NULL)
diff --git a/test/internals/dbus-sysdeps-util.c b/test/internals/dbus-sysdeps-util.c
new file mode 100644 (file)
index 0000000..7e2dc06
--- /dev/null
@@ -0,0 +1,156 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-sysdeps-util.c Tests for dbus-sysdeps.h API
+ *
+ * Copyright 2002-2008 Red Hat, Inc.
+ * Copyright 2003 CodeFactory AB
+ * Copyright 2006 Ralf Habacker
+ * Copyright 2006 Sjoerd Simons
+ * Copyright 2016-2018 Collabora Ltd.
+ *
+ * Licensed under the Academic Free License version 2.1
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <config.h>
+
+#include "misc-internals.h"
+
+#include "dbus/dbus-sysdeps.h"
+#include "dbus/dbus-internals.h"
+#include "dbus/dbus-string.h"
+#include "dbus/dbus-test.h"
+#include <dbus/dbus-test-tap.h>
+
+#include <stdlib.h>
+
+#ifdef DBUS_ENABLE_EMBEDDED_TESTS
+static void
+check_dirname (const char *filename,
+               const char *dirname)
+{
+  DBusString f, d;
+
+  _dbus_string_init_const (&f, filename);
+
+  if (!_dbus_string_init (&d))
+    _dbus_test_fatal ("no memory");
+
+  if (!_dbus_string_get_dirname (&f, &d))
+    _dbus_test_fatal ("no memory");
+
+  if (!_dbus_string_equal_c_str (&d, dirname))
+    {
+      _dbus_warn ("For filename \"%s\" got dirname \"%s\" and expected \"%s\"",
+                  filename,
+                  _dbus_string_get_const_data (&d),
+                  dirname);
+      exit (1);
+    }
+
+  _dbus_string_free (&d);
+}
+
+static void
+check_path_absolute (const char *path,
+                     dbus_bool_t expected)
+{
+  DBusString p;
+
+  _dbus_string_init_const (&p, path);
+
+  if (_dbus_path_is_absolute (&p) != expected)
+    {
+      _dbus_warn ("For path \"%s\" expected absolute = %d got %d",
+                  path, expected, _dbus_path_is_absolute (&p));
+      exit (1);
+    }
+}
+
+/**
+ * Unit test for dbus-sysdeps.c.
+ *
+ * @returns #TRUE on success.
+ */
+dbus_bool_t
+_dbus_sysdeps_test (const char *test_data_dir _DBUS_GNUC_UNUSED)
+{
+#ifdef DBUS_WIN
+  check_dirname ("foo\\bar", "foo");
+  check_dirname ("foo\\\\bar", "foo");
+  check_dirname ("foo/\\/bar", "foo");
+  check_dirname ("foo\\bar/", "foo");
+  check_dirname ("foo//bar\\", "foo");
+  check_dirname ("foo\\bar/", "foo");
+  check_dirname ("foo/bar\\\\", "foo");
+  check_dirname ("\\foo", "\\");
+  check_dirname ("\\\\foo", "\\");
+  check_dirname ("\\", "\\");
+  check_dirname ("\\\\", "\\");
+  check_dirname ("\\/", "\\");
+  check_dirname ("/\\/", "/");
+  check_dirname ("c:\\foo\\bar", "c:\\foo");
+  check_dirname ("c:\\foo", "c:\\");
+  check_dirname ("c:/foo", "c:/");
+  check_dirname ("c:\\", "c:\\");
+  check_dirname ("c:/", "c:/");
+  check_dirname ("", ".");
+#else
+  check_dirname ("foo", ".");
+  check_dirname ("foo/bar", "foo");
+  check_dirname ("foo//bar", "foo");
+  check_dirname ("foo///bar", "foo");
+  check_dirname ("foo/bar/", "foo");
+  check_dirname ("foo//bar/", "foo");
+  check_dirname ("foo///bar/", "foo");
+  check_dirname ("foo/bar//", "foo");
+  check_dirname ("foo//bar////", "foo");
+  check_dirname ("foo///bar///////", "foo");
+  check_dirname ("/foo", "/");
+  check_dirname ("////foo", "/");
+  check_dirname ("/foo/bar", "/foo");
+  check_dirname ("/foo//bar", "/foo");
+  check_dirname ("/foo///bar", "/foo");
+  check_dirname ("/", "/");
+  check_dirname ("///", "/");
+  check_dirname ("", ".");
+#endif
+
+#ifdef DBUS_WIN
+  check_path_absolute ("c:/", TRUE);
+  check_path_absolute ("c:/foo", TRUE);
+  check_path_absolute ("", FALSE);
+  check_path_absolute ("foo", FALSE);
+  check_path_absolute ("foo/bar", FALSE);
+  check_path_absolute ("", FALSE);
+  check_path_absolute ("foo\\bar", FALSE);
+  check_path_absolute ("c:\\", TRUE);
+  check_path_absolute ("c:\\foo", TRUE);
+  check_path_absolute ("c:", TRUE);
+  check_path_absolute ("c:\\foo\\bar", TRUE);
+  check_path_absolute ("\\", TRUE);
+  check_path_absolute ("/", TRUE);
+#else
+  check_path_absolute ("/", TRUE);
+  check_path_absolute ("/foo", TRUE);
+  check_path_absolute ("", FALSE);
+  check_path_absolute ("foo", FALSE);
+  check_path_absolute ("foo/bar", FALSE);
+#endif
+
+  return TRUE;
+}
+#endif /* DBUS_ENABLE_EMBEDDED_TESTS */
index 7b969c382f910016cf5119573536e3fb4d6a7a90..700af46e77e36cd73d56a00ef3510718b8cef082 100644 (file)
@@ -31,5 +31,6 @@ dbus_bool_t _dbus_credentials_test       (const char *test_data_dir);
 dbus_bool_t _dbus_marshal_byteswap_test  (const char *test_data_dir);
 dbus_bool_t _dbus_marshal_validate_test  (const char *test_data_dir);
 dbus_bool_t _dbus_string_test            (const char *test_data_dir);
+dbus_bool_t _dbus_sysdeps_test           (const char *test_data_dir);
 
 #endif