[glib: 1/2] Moving tests/dirname-test.c to glib/tests/fileutils.c




commit 9f760a7cc1ff787ba79ba0dd80bae12b70f12e9b
Author: Emmanuel Fleury <emmanuel fleury gmail com>
Date:   Thu Dec 16 01:16:41 2021 +0100

    Moving tests/dirname-test.c to glib/tests/fileutils.c
    
    Helps issue #1434

 glib/tests/fileutils.c |  62 ++++++++++++++++++++++++++
 tests/dirname-test.c   | 117 -------------------------------------------------
 tests/meson.build      |   1 -
 3 files changed, 62 insertions(+), 118 deletions(-)
---
diff --git a/glib/tests/fileutils.c b/glib/tests/fileutils.c
index a3c1c33d0..f11a855b9 100644
--- a/glib/tests/fileutils.c
+++ b/glib/tests/fileutils.c
@@ -834,6 +834,67 @@ test_basename (void)
   g_free (b);
 }
 
+static void
+test_dirname (void)
+{
+  gsize i;
+  struct {
+    const gchar *filename;
+    const gchar *dirname;
+  } dirname_checks[] = {
+    { "/", "/" },
+    { "////", "/" },
+    { ".////", "." },
+    { ".", "." },
+    { "..", "." },
+    { "../", ".." },
+    { "..////", ".." },
+    { "", "." },
+    { "a/b", "a" },
+    { "a/b/", "a/b" },
+    { "c///", "c" },
+    { "/a/b", "/a" },
+    { "/a/b/", "/a/b" },
+#ifdef G_OS_WIN32
+    { "\\", "\\" },
+    { ".\\\\\\\\", "." },
+    { ".\\/\\/", "." },
+    { ".", "." },
+    { "..", "." },
+    { "..\\", ".." },
+    { "..\\\\\\\\", ".." },
+    { "..\\//\\", ".." },
+    { "", "." },
+    { "a\\b", "a" },
+    { "a\\b\\", "a\\b" },
+    { "\\a\\b", "\\a" },
+    { "\\a\\b\\", "\\a\\b" },
+    { "c\\\\\\", "c" },
+    { "c/\\\\", "c" },
+    { "a:", "a:." },
+    { "a:foo", "a:." },
+    { "a:foo\\bar", "a:foo" },
+    { "a:/foo", "a:/" },
+    { "a:/foo/bar", "a:/foo" },
+    { "a:/", "a:/" },
+    { "a://", "a:/" },
+    { "a:\\foo", "a:\\" },
+    { "a:\\", "a:\\" },
+    { "a:\\\\", "a:\\" },
+    { "a:\\/", "a:\\" },
+#endif
+  };
+
+  for (i = 0; i < G_N_ELEMENTS (dirname_checks); i++)
+    {
+      gchar *dirname;
+
+      dirname = g_path_get_dirname (dirname_checks[i].filename);
+      g_assert_cmpstr (dirname, ==, dirname_checks[i].dirname);
+      g_free (dirname);
+    }
+}
+
 static void
 test_dir_make_tmp (void)
 {
@@ -1839,6 +1900,7 @@ main (int   argc,
   g_test_add_func ("/fileutils/format-size-for-display", test_format_size_for_display);
   g_test_add_func ("/fileutils/errors", test_file_errors);
   g_test_add_func ("/fileutils/basename", test_basename);
+  g_test_add_func ("/fileutils/dirname", test_dirname);
   g_test_add_func ("/fileutils/dir-make-tmp", test_dir_make_tmp);
   g_test_add_func ("/fileutils/file-open-tmp", test_file_open_tmp);
   g_test_add_func ("/fileutils/mkstemp", test_mkstemp);
diff --git a/tests/meson.build b/tests/meson.build
index 0f120edee..9bb97fd5e 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -18,7 +18,6 @@ subdir('refcount')
 tests = {
   'testglib' : {'tap' : true},
   'testgdate' : {},
-  'dirname-test' : {},
   'file-test' : {},
   'env-test' : {},
   'gio-test' : {},


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]