mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-03 09:46:17 +01:00
gio/tests/sandbox: Use test portal utils to create fake snap.yaml
This commit is contained in:
parent
b1a2b64e94
commit
94ebd9f041
@ -108,7 +108,7 @@ gio_tests = {
|
|||||||
'proxy-test' : {},
|
'proxy-test' : {},
|
||||||
'readwrite' : {},
|
'readwrite' : {},
|
||||||
'sandbox' : {
|
'sandbox' : {
|
||||||
'source': ['sandbox.c', '../gsandbox.c'],
|
'extra_sources': ['../gsandbox.c', 'portal-support-utils.c'],
|
||||||
},
|
},
|
||||||
'simple-async-result' : {},
|
'simple-async-result' : {},
|
||||||
'simple-proxy' : {},
|
'simple-proxy' : {},
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
* Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "portal-support-utils.h"
|
||||||
|
|
||||||
#include "../gsandbox.h"
|
#include "../gsandbox.h"
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
@ -31,61 +33,38 @@ static void
|
|||||||
test_sandbox_snap (void)
|
test_sandbox_snap (void)
|
||||||
{
|
{
|
||||||
const char *temp_dir;
|
const char *temp_dir;
|
||||||
gchar *snap_path, *meta_path, *yaml_path;
|
gchar *snap_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";
|
|
||||||
|
|
||||||
temp_dir = g_getenv ("G_TEST_TMPDIR");
|
temp_dir = g_getenv ("G_TEST_TMPDIR");
|
||||||
g_assert_nonnull (temp_dir);
|
g_assert_nonnull (temp_dir);
|
||||||
|
|
||||||
snap_path = g_build_filename (temp_dir, "snap", "current", NULL);
|
snap_path = g_build_filename (temp_dir, "snap", "current", NULL);
|
||||||
meta_path = g_build_filename (snap_path, "meta", NULL);
|
create_fake_snap_yaml (snap_path, FALSE);
|
||||||
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);
|
|
||||||
g_setenv ("SNAP", snap_path, TRUE);
|
g_setenv ("SNAP", snap_path, TRUE);
|
||||||
|
|
||||||
g_assert_cmpint (glib_get_sandbox_type (), ==, G_SANDBOX_TYPE_SNAP);
|
g_assert_cmpint (glib_get_sandbox_type (), ==, G_SANDBOX_TYPE_SNAP);
|
||||||
|
|
||||||
g_unsetenv ("SNAP");
|
g_unsetenv ("SNAP");
|
||||||
g_free (snap_path);
|
g_free (snap_path);
|
||||||
g_free (meta_path);
|
|
||||||
g_free (yaml_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_sandbox_snap_classic (void)
|
test_sandbox_snap_classic (void)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
|
||||||
const char *temp_dir;
|
const char *temp_dir;
|
||||||
char *snap_path, *meta_path, *yaml_path;
|
char *snap_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";
|
|
||||||
|
|
||||||
temp_dir = g_getenv ("G_TEST_TMPDIR");
|
temp_dir = g_getenv ("G_TEST_TMPDIR");
|
||||||
g_assert_nonnull (temp_dir);
|
g_assert_nonnull (temp_dir);
|
||||||
|
|
||||||
snap_path = g_build_filename (temp_dir, "snap", "current", NULL);
|
snap_path = g_build_filename (temp_dir, "snap", "current", NULL);
|
||||||
meta_path = g_build_filename (snap_path, "meta", NULL);
|
create_fake_snap_yaml (snap_path, TRUE);
|
||||||
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);
|
|
||||||
g_setenv ("SNAP", snap_path, TRUE);
|
g_setenv ("SNAP", snap_path, TRUE);
|
||||||
|
|
||||||
g_assert_cmpint (glib_get_sandbox_type (), ==, G_SANDBOX_TYPE_UNKNOWN);
|
g_assert_cmpint (glib_get_sandbox_type (), ==, G_SANDBOX_TYPE_UNKNOWN);
|
||||||
|
|
||||||
g_unsetenv ("SNAP");
|
g_unsetenv ("SNAP");
|
||||||
g_free (snap_path);
|
g_free (snap_path);
|
||||||
g_free (meta_path);
|
|
||||||
g_free (yaml_path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user