[glib: 1/2] tests: Use a temporary file in the bookmarkfile tests
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib: 1/2] tests: Use a temporary file in the bookmarkfile tests
- Date: Mon, 14 Jun 2021 15:47:43 +0000 (UTC)
commit 447f7272843409742ac488e2ba69d438aa195347
Author: Philip Withnall <pwithnall endlessos org>
Date: Thu May 13 22:53:38 2021 +0100
tests: Use a temporary file in the bookmarkfile tests
Rather than always writing to `out.xbel` in the build directory, which
could cause issues when running tests in parallel, or expecting the
tests to not touch the build directory.
Signed-off-by: Philip Withnall <pwithnall endlessos org>
glib/tests/bookmarkfile.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/glib/tests/bookmarkfile.c b/glib/tests/bookmarkfile.c
index bc1a7a213..1700ad8b8 100644
--- a/glib/tests/bookmarkfile.c
+++ b/glib/tests/bookmarkfile.c
@@ -1,6 +1,7 @@
#undef G_DISABLE_ASSERT
#include <glib.h>
+#include <glib/gstdio.h>
#include <time.h>
#include <locale.h>
#include <string.h>
@@ -44,19 +45,25 @@ test_to_file (void)
gboolean res;
GError *error = NULL;
char *in, *out;
+ gchar *tmp_filename = NULL;
+ gint fd;
+
+ fd = g_file_open_tmp ("bookmarkfile-test-XXXXXX.xbel", &tmp_filename, NULL);
+ g_assert_cmpint (fd, >, -1);
+ g_close (fd, NULL);
bookmark = g_bookmark_file_new ();
- g_test_message ("Roundtrip from newly created bookmark file");
+ g_test_message ("Roundtrip from newly created bookmark file %s", tmp_filename);
g_bookmark_file_set_title (bookmark, "file:///tmp/schedule.ps", "schedule.ps");
g_bookmark_file_set_mime_type (bookmark, "file:///tmp/schedule.ps", "application/postscript");
g_bookmark_file_add_application (bookmark, "file:///tmp/schedule.ps", "ghostscript", "ghostscript %F");
- res = g_bookmark_file_to_file (bookmark, "out.xbel", &error);
+ res = g_bookmark_file_to_file (bookmark, tmp_filename, &error);
g_assert_no_error (error);
g_assert_true (res);
- res = g_bookmark_file_load_from_file (bookmark, "out.xbel", &error);
+ res = g_bookmark_file_load_from_file (bookmark, tmp_filename, &error);
g_assert_no_error (error);
g_assert_true (res);
@@ -70,7 +77,7 @@ test_to_file (void)
g_assert_cmpstr (out, ==, "application/postscript");
g_free (out);
- remove ("out.xbel");
+ remove (tmp_filename);
g_test_message ("Roundtrip from a valid bookmark file");
filename = g_test_get_filename (G_TEST_DIST, "bookmarks", "valid-01.xbel", NULL);
@@ -78,7 +85,7 @@ test_to_file (void)
g_assert_no_error (error);
g_assert_true (res);
- res = g_bookmark_file_to_file (bookmark, "out.xbel", &error);
+ res = g_bookmark_file_to_file (bookmark, tmp_filename, &error);
g_assert_no_error (error);
g_assert_true (res);
@@ -86,16 +93,17 @@ test_to_file (void)
g_assert_no_error (error);
g_assert_true (res);
- res = g_file_get_contents ("out.xbel", &out, NULL, &error);
+ res = g_file_get_contents (tmp_filename, &out, NULL, &error);
g_assert_no_error (error);
g_assert_true (res);
- remove ("out.xbel");
+ remove (tmp_filename);
g_assert_cmpstr (in, ==, out);
g_free (in);
g_free (out);
g_bookmark_file_free (bookmark);
+ g_free (tmp_filename);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]