mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-01 02:16:14 +01:00
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>
This commit is contained in:
parent
3bca6ee2e4
commit
447f727284
@ -1,6 +1,7 @@
|
|||||||
#undef G_DISABLE_ASSERT
|
#undef G_DISABLE_ASSERT
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <glib/gstdio.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -44,19 +45,25 @@ test_to_file (void)
|
|||||||
gboolean res;
|
gboolean res;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
char *in, *out;
|
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 ();
|
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_title (bookmark, "file:///tmp/schedule.ps", "schedule.ps");
|
||||||
g_bookmark_file_set_mime_type (bookmark, "file:///tmp/schedule.ps", "application/postscript");
|
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");
|
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_no_error (error);
|
||||||
g_assert_true (res);
|
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_no_error (error);
|
||||||
g_assert_true (res);
|
g_assert_true (res);
|
||||||
|
|
||||||
@ -70,7 +77,7 @@ test_to_file (void)
|
|||||||
g_assert_cmpstr (out, ==, "application/postscript");
|
g_assert_cmpstr (out, ==, "application/postscript");
|
||||||
g_free (out);
|
g_free (out);
|
||||||
|
|
||||||
remove ("out.xbel");
|
remove (tmp_filename);
|
||||||
|
|
||||||
g_test_message ("Roundtrip from a valid bookmark file");
|
g_test_message ("Roundtrip from a valid bookmark file");
|
||||||
filename = g_test_get_filename (G_TEST_DIST, "bookmarks", "valid-01.xbel", NULL);
|
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_no_error (error);
|
||||||
g_assert_true (res);
|
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_no_error (error);
|
||||||
g_assert_true (res);
|
g_assert_true (res);
|
||||||
|
|
||||||
@ -86,16 +93,17 @@ test_to_file (void)
|
|||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert_true (res);
|
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_no_error (error);
|
||||||
g_assert_true (res);
|
g_assert_true (res);
|
||||||
remove ("out.xbel");
|
remove (tmp_filename);
|
||||||
|
|
||||||
g_assert_cmpstr (in, ==, out);
|
g_assert_cmpstr (in, ==, out);
|
||||||
g_free (in);
|
g_free (in);
|
||||||
g_free (out);
|
g_free (out);
|
||||||
|
|
||||||
g_bookmark_file_free (bookmark);
|
g_bookmark_file_free (bookmark);
|
||||||
|
g_free (tmp_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user