Commit 447f7272 authored by Philip Withnall's avatar Philip Withnall
Browse files

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's avatarPhilip Withnall <pwithnall@endlessos.org>
parent 3bca6ee2
Pipeline #282753 passed with stages
in 28 minutes and 51 seconds
#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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment