[glib] tests: Add temporary working directory for monitor test
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] tests: Add temporary working directory for monitor test
- Date: Wed, 23 Aug 2017 10:28:08 +0000 (UTC)
commit a60359aee24e866ae9dfae33859a6cd73bc1e65c
Author: Philip Withnall <withnall endlessm com>
Date: Fri Aug 18 10:01:18 2017 +0100
tests: Add temporary working directory for monitor test
Similarly to the previous commit, move the temporary directory for the
monitor test from $(cwd) to the system temporary directory.
Signed-off-by: Philip Withnall <withnall endlessm com>
https://bugzilla.gnome.org/show_bug.cgi?id=785260
gio/tests/monitor.c | 36 ++++++++++++++++++++++++++++++------
1 files changed, 30 insertions(+), 6 deletions(-)
---
diff --git a/gio/tests/monitor.c b/gio/tests/monitor.c
index 67be3a4..69eae34 100644
--- a/gio/tests/monitor.c
+++ b/gio/tests/monitor.c
@@ -1,4 +1,30 @@
#include <gio/gio.h>
+#include <gstdio.h>
+
+typedef struct
+{
+ gchar *tmp_dir;
+} Fixture;
+
+static void
+setup (Fixture *fixture,
+ gconstpointer user_data)
+{
+ GError *error = NULL;
+
+ fixture->tmp_dir = g_dir_make_tmp ("gio-test-file-monitor_XXXXXX", &error);
+ g_assert_no_error (error);
+
+ g_test_message ("Using temporary directory: %s", fixture->tmp_dir);
+}
+
+static void
+teardown (Fixture *fixture,
+ gconstpointer user_data)
+{
+ g_assert_cmpint (g_rmdir (fixture->tmp_dir), ==, 0);
+ g_clear_pointer (&fixture->tmp_dir, g_free);
+}
typedef struct {
GFile *file;
@@ -127,9 +153,9 @@ file_changed_cb (GFileMonitor *monitor,
}
static void
-test_directory_monitor (void)
+test_directory_monitor (Fixture *fixture,
+ gconstpointer user_data)
{
- gchar *path;
GFile *file;
GFile *child;
GFileMonitor *dir_monitor;
@@ -139,8 +165,7 @@ test_directory_monitor (void)
gint state;
GMainLoop *loop;
- path = g_mkdtemp (g_strdup ("file_monitor_XXXXXX"));
- file = g_file_new_for_path (path);
+ file = g_file_new_for_path (fixture->tmp_dir);
dir_monitor = g_file_monitor_directory (file, 0, NULL, &error);
g_assert_no_error (error);
@@ -170,7 +195,6 @@ test_directory_monitor (void)
g_object_unref (file_monitor);
g_object_unref (child);
g_object_unref (file);
- g_free (path);
}
int
@@ -178,7 +202,7 @@ main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
- g_test_add_func ("/monitor/directory", test_directory_monitor);
+ g_test_add ("/monitor/directory", Fixture, NULL, setup, test_directory_monitor, teardown);
return g_test_run ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]