[libdazzle] tests: add directory reaper test
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libdazzle] tests: add directory reaper test
- Date: Tue, 8 Aug 2017 22:46:21 +0000 (UTC)
commit 9d9c119dbd40c5c1c2fbed43a3bd0fdaced70cfe
Author: Christian Hergert <chergert redhat com>
Date: Tue Aug 8 15:45:25 2017 -0700
tests: add directory reaper test
tests/meson.build | 7 +++
tests/test-directory-reaper.c | 89 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 96 insertions(+), 0 deletions(-)
---
diff --git a/tests/meson.build b/tests/meson.build
index aadb66a..f71c4bf 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -312,4 +312,11 @@ test_box = executable('test-box', 'test-box.c',
dependencies: libdazzle_deps + [libdazzle_dep],
)
+test_directory_reaper = executable('test-directory-reaper', 'test-directory-reaper.c',
+ c_args: test_cflags,
+ link_args: test_link_args,
+ dependencies: libdazzle_deps + [libdazzle_dep],
+)
+test('test-directory-reaper', test_directory_reaper, env: test_env)
+
endif
diff --git a/tests/test-directory-reaper.c b/tests/test-directory-reaper.c
new file mode 100644
index 0000000..dfdba97
--- /dev/null
+++ b/tests/test-directory-reaper.c
@@ -0,0 +1,89 @@
+/* test-directory-reaper.c
+ *
+ * Copyright (C) 2017 Christian Hergert <chergert redhat com>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <dazzle.h>
+#include <glib/gstdio.h>
+#include <errno.h>
+
+typedef struct
+{
+ /* the test data path */
+ const gchar *path;
+
+ /* null for a directory, otherwise file contents */
+ const gchar *data;
+} FileInfo;
+
+static void
+test_reaper_basic (void)
+{
+ g_autoptr(DzlDirectoryReaper) reaper = dzl_directory_reaper_new ();
+ g_autoptr(GFile) file = g_file_new_for_path ("reaper");
+ g_autoptr(GError) error = NULL;
+ gboolean r;
+ static const FileInfo files[] = {
+ /* directories first */
+ { "a/b/c" },
+ { "a/c/b" },
+ { "a/d/e" },
+
+ /* then files */
+ { "a/b/c/f", "" },
+ { "a/c/b/g", "" },
+ { "a/d/e/h", "" },
+ };
+
+ /*
+ * Start out by creating some directories and files so that we can
+ * test that they've been reaped correctly.
+ */
+ for (guint i = 0; i < G_N_ELEMENTS (files); i++)
+ {
+ const FileInfo *info = &files[i];
+ g_autofree gchar *path = g_build_filename ("reaper", info->path, NULL);
+
+ if (info->data == NULL)
+ {
+ r = g_mkdir_with_parents (path, 0750);
+ g_assert_cmpint (r, ==, 0);
+ continue;
+ }
+
+ r = g_file_set_contents (path, info->data, -1, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (r, ==, TRUE);
+ }
+
+ dzl_directory_reaper_add_directory (reaper, file, 0);
+
+ r = dzl_directory_reaper_execute (reaper, NULL, &error);
+ g_assert_no_error (error);
+ g_assert_cmpint (r, ==, TRUE);
+
+ if (g_rmdir ("reaper") != 0)
+ g_error ("Failed to remove 'reaper': %s", g_strerror (errno));
+}
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/Dazzle/DirectoryReaper/basic", test_reaper_basic);
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]