[tepl] testsuite: create tepl-test-utils



commit 6a92a65b1174fd5700e6c23aae6c5a8b46da5c42
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Fri May 22 13:57:35 2020 +0200

    testsuite: create tepl-test-utils

 testsuite/meson.build       |  2 +-
 testsuite/tepl-test-utils.c | 25 +++++++++++++++++++++++++
 testsuite/tepl-test-utils.h | 17 +++++++++++++++++
 testsuite/test-file.c       | 21 ++-------------------
 4 files changed, 45 insertions(+), 20 deletions(-)
---
diff --git a/testsuite/meson.build b/testsuite/meson.build
index 422adc4..e4577c4 100644
--- a/testsuite/meson.build
+++ b/testsuite/meson.build
@@ -13,7 +13,7 @@ unit_tests = [
 foreach test_name : unit_tests
   test_exe = executable(
     test_name,
-    test_name + '.c',
+    [test_name + '.c', 'tepl-test-utils.c'],
     dependencies: TEPL_STATIC_DEP,
     c_args: '-DUNIT_TESTS_SOURCE_DIR="@0@"'.format(meson.current_source_dir())
   )
diff --git a/testsuite/tepl-test-utils.c b/testsuite/tepl-test-utils.c
new file mode 100644
index 0000000..dc5c1e0
--- /dev/null
+++ b/testsuite/tepl-test-utils.c
@@ -0,0 +1,25 @@
+/* SPDX-FileCopyrightText: 2020 - Sébastien Wilmet <swilmet gnome org>
+ * SPDX-License-Identifier: LGPL-3.0-or-later
+ */
+
+#include "tepl-test-utils.h"
+
+/* Common utility functions for the unit tests. */
+
+void
+_tepl_test_utils_set_file_content (GFile       *file,
+                                  const gchar *content)
+{
+       GError *error = NULL;
+
+       g_file_replace_contents (file,
+                                content,
+                                strlen (content),
+                                NULL,
+                                FALSE,
+                                G_FILE_CREATE_REPLACE_DESTINATION,
+                                NULL,
+                                NULL,
+                                &error);
+       g_assert_no_error (error);
+}
diff --git a/testsuite/tepl-test-utils.h b/testsuite/tepl-test-utils.h
new file mode 100644
index 0000000..188d5fa
--- /dev/null
+++ b/testsuite/tepl-test-utils.h
@@ -0,0 +1,17 @@
+/* SPDX-FileCopyrightText: 2020 - Sébastien Wilmet <swilmet gnome org>
+ * SPDX-License-Identifier: LGPL-3.0-or-later
+ */
+
+#ifndef TEPL_TEST_UTILS_H
+#define TEPL_TEST_UTILS_H
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+void   _tepl_test_utils_set_file_content       (GFile       *file,
+                                                const gchar *content);
+
+G_END_DECLS
+
+#endif /* TEPL_TEST_UTILS_H */
diff --git a/testsuite/test-file.c b/testsuite/test-file.c
index 4788287..f47be4f 100644
--- a/testsuite/test-file.c
+++ b/testsuite/test-file.c
@@ -5,6 +5,7 @@
 #include "config.h"
 #include <tepl/tepl.h>
 #include <glib/gi18n-lib.h>
+#include "tepl-test-utils.h"
 
 typedef struct _WaitSignalData WaitSignalData;
 struct _WaitSignalData
@@ -54,24 +55,6 @@ wait_signal (WaitSignalData *data)
        g_free (data);
 }
 
-static void
-set_file_content (GFile       *file,
-                 const gchar *content)
-{
-       GError *error = NULL;
-
-       g_file_replace_contents (file,
-                                content,
-                                strlen (content),
-                                NULL,
-                                FALSE,
-                                G_FILE_CREATE_REPLACE_DESTINATION,
-                                NULL,
-                                NULL,
-                                &error);
-       g_assert_no_error (error);
-}
-
 static void
 check_short_name (TeplFile    *file,
                  const gchar *expected_short_name)
@@ -161,7 +144,7 @@ test_short_name (void)
        g_object_unref (file);
 
        /* Get the display-name for a local file (so the file must exist). */
-       set_file_content (location, "file content");
+       _tepl_test_utils_set_file_content (location, "file content");
 
        file = tepl_file_new ();
        data = wait_signal_setup (G_OBJECT (file), "notify::short-name");


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