From 94ebd9f041c9c07da2e42f5682f16d08feb9b3c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Thu, 24 Nov 2022 05:33:30 +0100 Subject: [PATCH] gio/tests/sandbox: Use test portal utils to create fake snap.yaml --- gio/tests/meson.build | 2 +- gio/tests/sandbox.c | 33 ++++++--------------------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/gio/tests/meson.build b/gio/tests/meson.build index baf114c96..43c5820cc 100644 --- a/gio/tests/meson.build +++ b/gio/tests/meson.build @@ -108,7 +108,7 @@ gio_tests = { 'proxy-test' : {}, 'readwrite' : {}, 'sandbox' : { - 'source': ['sandbox.c', '../gsandbox.c'], + 'extra_sources': ['../gsandbox.c', 'portal-support-utils.c'], }, 'simple-async-result' : {}, 'simple-proxy' : {}, diff --git a/gio/tests/sandbox.c b/gio/tests/sandbox.c index 1f5c8bd15..a432556dd 100644 --- a/gio/tests/sandbox.c +++ b/gio/tests/sandbox.c @@ -17,6 +17,8 @@ * Public License along with this library; if not, see . */ +#include "portal-support-utils.h" + #include "../gsandbox.h" #include #include @@ -31,61 +33,38 @@ static void test_sandbox_snap (void) { const char *temp_dir; - gchar *snap_path, *meta_path, *yaml_path; - GError *error = NULL; - const char *contents = "name: glib-test-portal-support\n" - "title: GLib Portal Support Test\n" - "version: 2.76\n" - "summary: Test it works\n"; + gchar *snap_path; temp_dir = g_getenv ("G_TEST_TMPDIR"); g_assert_nonnull (temp_dir); snap_path = g_build_filename (temp_dir, "snap", "current", NULL); - meta_path = g_build_filename (snap_path, "meta", NULL); - yaml_path = g_build_filename (meta_path, "snap.yaml", NULL); - g_mkdir_with_parents (meta_path, 0700); - g_file_set_contents (yaml_path, contents, -1, &error); - g_assert_no_error (error); + create_fake_snap_yaml (snap_path, FALSE); g_setenv ("SNAP", snap_path, TRUE); g_assert_cmpint (glib_get_sandbox_type (), ==, G_SANDBOX_TYPE_SNAP); g_unsetenv ("SNAP"); g_free (snap_path); - g_free (meta_path); - g_free (yaml_path); } static void test_sandbox_snap_classic (void) { - GError *error = NULL; const char *temp_dir; - char *snap_path, *meta_path, *yaml_path; - const char *contents = "name: glib-test-portal-support\n" - "title: GLib Portal Support Test\n" - "version: 2.76\n" - "summary: Test it works\n" - "confinement: classic\n"; + char *snap_path; temp_dir = g_getenv ("G_TEST_TMPDIR"); g_assert_nonnull (temp_dir); snap_path = g_build_filename (temp_dir, "snap", "current", NULL); - meta_path = g_build_filename (snap_path, "meta", NULL); - yaml_path = g_build_filename (meta_path, "snap.yaml", NULL); - g_mkdir_with_parents (meta_path, 0700); - g_file_set_contents (yaml_path, contents, -1, &error); - g_assert_no_error (error); + create_fake_snap_yaml (snap_path, TRUE); g_setenv ("SNAP", snap_path, TRUE); g_assert_cmpint (glib_get_sandbox_type (), ==, G_SANDBOX_TYPE_UNKNOWN); g_unsetenv ("SNAP"); g_free (snap_path); - g_free (meta_path); - g_free (yaml_path); } int