[tepl] utils: more unit tests for replace_home_dir_with_tilde()



commit c2ceec4e007ea57e43c448e38fe02ae465006a53
Author: Sébastien Wilmet <sw swilmet be>
Date:   Wed Jan 13 13:51:27 2021 +0100

    utils: more unit tests for replace_home_dir_with_tilde()

 testsuite/test-utils.c | 46 +++++++++++++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 17 deletions(-)
---
diff --git a/testsuite/test-utils.c b/testsuite/test-utils.c
index 9f22855..bb4cd59 100644
--- a/testsuite/test-utils.c
+++ b/testsuite/test-utils.c
@@ -143,26 +143,38 @@ test_get_file_shortname (void)
        g_free (shortname);
 }
 
+static void
+check_replace_home_dir_with_tilde (const gchar *home_dir,
+                                  const gchar *filename_before,
+                                  const gchar *expected_filename_after)
+{
+       gchar *received_filename_after;
+
+       received_filename_after = _tepl_utils_replace_home_dir_with_tilde_with_param (filename_before, 
home_dir);
+       g_assert_cmpstr (received_filename_after, ==, expected_filename_after);
+       g_free (received_filename_after);
+}
+
 static void
 test_replace_home_dir_with_tilde (void)
 {
-       const gchar *homedir = g_get_home_dir ();
-       gchar *before;
-       gchar *after;
-
-       before = g_build_filename (homedir, "blah", NULL);
-       after = tepl_utils_replace_home_dir_with_tilde (before);
-       g_assert_cmpstr (after, ==, "~/blah");
-       g_free (before);
-       g_free (after);
-
-       after = tepl_utils_replace_home_dir_with_tilde (homedir);
-       g_assert_cmpstr (after, ==, "~");
-       g_free (after);
-
-       after = tepl_utils_replace_home_dir_with_tilde ("/blah");
-       g_assert_cmpstr (after, ==, "/blah");
-       g_free (after);
+       check_replace_home_dir_with_tilde ("/home/foo", "/home/foo", "~");
+       check_replace_home_dir_with_tilde ("/home/foo", "/home/foo/", "~");
+       check_replace_home_dir_with_tilde ("/home/foo/", "/home/foo", "~");
+       check_replace_home_dir_with_tilde ("/home/foo/", "/home/foo/", "~");
+
+       check_replace_home_dir_with_tilde ("/home/foo", "/home/foo/bar", "~/bar");
+       check_replace_home_dir_with_tilde ("/home/foo/", "/home/foo/bar", "~/bar");
+       check_replace_home_dir_with_tilde ("/home/foo", "/home/foo/bar/", "~/bar/");
+       check_replace_home_dir_with_tilde ("/home/foo/", "/home/foo/bar/", "~/bar/");
+
+       check_replace_home_dir_with_tilde ("/home/foo", "/blah", "/blah");
+       check_replace_home_dir_with_tilde ("/home/foo/", "/blah", "/blah");
+
+       check_replace_home_dir_with_tilde (NULL, "/home/foo", "/home/foo");
+       check_replace_home_dir_with_tilde (NULL, "/home/foo/", "/home/foo/");
+       check_replace_home_dir_with_tilde ("", "/home/foo", "/home/foo");
+       check_replace_home_dir_with_tilde ("", "/home/foo/", "/home/foo/");
 }
 
 static void


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