gio/tests/sandbox: Use test portal utils to create fake snap.yaml

This commit is contained in:
Marco Trevisan (Treviño) 2022-11-24 05:33:30 +01:00
parent b1a2b64e94
commit 94ebd9f041
2 changed files with 7 additions and 28 deletions

View File

@ -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' : {},

View File

@ -17,6 +17,8 @@
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#include "portal-support-utils.h"
#include "../gsandbox.h"
#include <gio/gio.h>
#include <glib/gstdio.h>
@ -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