mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-10 11:26:16 +01:00
Merge branch 'bookmarkfile-test-tmp' into 'main'
tests: Use a temporary file in the bookmarkfile tests See merge request GNOME/glib!2105
This commit is contained in:
commit
e7ebee5959
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user