diff --git a/tests/json-report/full-good-report.json b/tests/json-report/full-good-report.json index 9edf332b24bbea8291d145520a645acb4ecfac97..c56e4e85ab08023e8e13e55448af1e0b75b632b6 100644 --- a/tests/json-report/full-good-report.json +++ b/tests/json-report/full-good-report.json @@ -247,6 +247,29 @@ "steam_uri_handler" : true } ], + "xdg-portals" : { + "details" : { + "interfaces" : { + "org.freedesktop.portal.OpenURI" : { + "available" : true, + "version" : 3 + }, + "org.freedesktop.portal.Email" : { + "available" : true, + "version" : 2 + } + }, + "backends" : { + "org.freedesktop.impl.portal.desktop.gtk" : { + "available" : true + }, + "org.freedesktop.impl.portal.desktop.kde" : { + "available" : false + } + } + }, + "issues" : [] + }, "cpu-features" : { "x86-64" : true, "sse3" : false, diff --git a/tests/json-report/partial-report.json b/tests/json-report/partial-report.json index a7fec110712b1f7fd6f2dfc9f6329f85b7afa6df..92d2d5e1b3980fb99d31eab6f87263c48dc2ae0c 100644 --- a/tests/json-report/partial-report.json +++ b/tests/json-report/partial-report.json @@ -41,5 +41,11 @@ "error" : "Something went wrong" } ] + }, + "xdg-portals" : { + "issues" : [ + "timeout" + ], + "messages" : "timeout: failed to run command ‘x86_64-linux-gnu-check-xdg-portal’: No such file or directory\n" } } diff --git a/tests/meson.build b/tests/meson.build index bc04ff99677b9b92aecec8ffc2be4b3ac5bf2e09..42355686599692629b71c6df0261eb7c738ff1b7 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -35,6 +35,7 @@ tests = [ {'name': 'locale'}, {'name': 'system-info'}, {'name': 'utils', 'static': true}, + {'name': 'xdg-portal'}, ] if get_option('bin') @@ -261,10 +262,14 @@ foreach helper : [ 'mock-bad-check-va-api', 'mock-bad-check-vdpau', 'mock-bad-check-vulkan', + 'mock-bad-check-xdg-portal', 'mock-bad-vulkaninfo', 'mock-good-check-va-api', 'mock-good-check-vdpau', + 'mock-good-check-xdg-portal', + 'mock-good-flatpak-check-xdg-portal', 'mock-good-vulkaninfo', + 'mock-hanging-check-xdg-portal', 'mock-hanging-wflinfo', 'mock-sigusr-wflinfo', ] diff --git a/tests/mock-bad-check-xdg-portal.c b/tests/mock-bad-check-xdg-portal.c new file mode 100644 index 0000000000000000000000000000000000000000..f0d5f1577b7c56a4a245fddd05fcc9ea6ac4fc9d --- /dev/null +++ b/tests/mock-bad-check-xdg-portal.c @@ -0,0 +1,57 @@ +/* + * Copyright © 2020 Collabora Ltd. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <stdio.h> + +int +main (int argc, + char **argv) +{ + // Give bad output + fprintf (stderr, "The 'version' property is not available for 'org.freedesktop.portal.OpenURI', either there isn't a working xdg-desktop-portal or it is a very old version\n"); + + printf ("{\n" + "\t\"interfaces\" : {\n" + "\t\t\"org.freedesktop.portal.OpenURI\" : {\n" + "\t\t\t\"available\" : false\n" + "\t\t},\n" + "\t\t\"org.freedesktop.portal.Email\" : {\n" + "\t\t\t\"available\" : true,\n" + "\t\t\t\"version\" : 3\n" + "\t\t}\n" + "\t},\n" + "\t\"backends\" : {\n" + "\t\t\"org.freedesktop.impl.portal.desktop.gtk\" : {\n" + "\t\t\t\"available\" : true\n" + "\t\t},\n" + "\t\t\"org.freedesktop.impl.portal.desktop.kde\" : {\n" + "\t\t\t\"available\" : false\n" + "\t\t}\n" + "\t}\n" + "}\n"); + + return 1; +} + diff --git a/tests/mock-good-check-xdg-portal.c b/tests/mock-good-check-xdg-portal.c new file mode 100644 index 0000000000000000000000000000000000000000..ce658f33f632da7ff34a87921a35d3fd83a2c2e0 --- /dev/null +++ b/tests/mock-good-check-xdg-portal.c @@ -0,0 +1,56 @@ +/* + * Copyright © 2020 Collabora Ltd. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <stdio.h> + +int +main (int argc, + char **argv) +{ + // Give good output + printf ("{\n" + "\t\"interfaces\" : {\n" + "\t\t\"org.freedesktop.portal.OpenURI\" : {\n" + "\t\t\t\"available\" : true,\n" + "\t\t\t\"version\" : 2\n" + "\t\t},\n" + "\t\t\"org.freedesktop.portal.Email\" : {\n" + "\t\t\t\"available\" : true,\n" + "\t\t\t\"version\" : 3\n" + "\t\t}\n" + "\t},\n" + "\t\"backends\" : {\n" + "\t\t\"org.freedesktop.impl.portal.desktop.gtk\" : {\n" + "\t\t\t\"available\" : true\n" + "\t\t},\n" + "\t\t\"org.freedesktop.impl.portal.desktop.kde\" : {\n" + "\t\t\t\"available\" : false\n" + "\t\t}\n" + "\t}\n" + "}\n"); + + return 0; +} + diff --git a/tests/mock-good-flatpak-check-xdg-portal.c b/tests/mock-good-flatpak-check-xdg-portal.c new file mode 100644 index 0000000000000000000000000000000000000000..0780c7e1efcc44263a38c5b53143a8d0519420f4 --- /dev/null +++ b/tests/mock-good-flatpak-check-xdg-portal.c @@ -0,0 +1,48 @@ +/* + * Copyright © 2020 Collabora Ltd. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <stdio.h> + +int +main (int argc, + char **argv) +{ + // Give good output as if we were in a Flatpak environment + printf ("{\n" + "\t\"interfaces\" : {\n" + "\t\t\"org.freedesktop.portal.OpenURI\" : {\n" + "\t\t\t\"available\" : true,\n" + "\t\t\t\"version\" : 3\n" + "\t\t},\n" + "\t\t\"org.freedesktop.portal.Email\" : {\n" + "\t\t\t\"available\" : true,\n" + "\t\t\t\"version\" : 3\n" + "\t\t}\n" + "\t}\n" + "}\n"); + + return 0; +} + diff --git a/tests/mock-hanging-check-xdg-portal.c b/tests/mock-hanging-check-xdg-portal.c new file mode 100644 index 0000000000000000000000000000000000000000..b02ae303cd56852bbad2b668e81e49588e48ec16 --- /dev/null +++ b/tests/mock-hanging-check-xdg-portal.c @@ -0,0 +1,59 @@ +/* + * Copyright © 2020 Collabora Ltd. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <stdio.h> +#include <unistd.h> + +int +main (int argc, + char **argv) +{ + sleep (300); // Sleep for 5 minutes + + // Give good output + printf ("{\n" + "\t\"interfaces\" : {\n" + "\t\t\"org.freedesktop.portal.OpenURI\" : {\n" + "\t\t\t\"available\" : true,\n" + "\t\t\t\"version\" : 2\n" + "\t\t},\n" + "\t\t\"org.freedesktop.portal.Email\" : {\n" + "\t\t\t\"available\" : true,\n" + "\t\t\t\"version\" : 3\n" + "\t\t}\n" + "\t},\n" + "\t\"backends\" : {\n" + "\t\t\"org.freedesktop.impl.portal.desktop.gtk\" : {\n" + "\t\t\t\"available\" : true\n" + "\t\t},\n" + "\t\t\"org.freedesktop.impl.portal.desktop.kde\" : {\n" + "\t\t\t\"available\" : false\n" + "\t\t}\n" + "\t}\n" + "}\n"); + + return 0; +} + diff --git a/tests/system-info.c b/tests/system-info.c index 7b4e4fffedc82e9aa5a9eee28bc08e137b3b2fc7..30dc5e4f8d953f6529259b208c8acbed59e577fd 100644 --- a/tests/system-info.c +++ b/tests/system-info.c @@ -2449,6 +2449,21 @@ typedef struct gboolean steam_handler; } DesktopEntryTest; +typedef struct +{ + const gchar *name; + gboolean available; + guint32 version; +} XdgPortalInfoTest; + +typedef struct +{ + XdgPortalInfoTest interfaces[3]; + XdgPortalInfoTest backends[3]; + SrtXdgPortalIssues issues; + const gchar *messages; +} XdgPortalTest; + typedef struct { const gchar *description; @@ -2465,6 +2480,7 @@ typedef struct IcdTest egl_icd[3]; IcdTest vulkan_icd[3]; DesktopEntryTest desktop_entry[3]; + XdgPortalTest xdg_portal; SrtX86FeatureFlags x86_features; SrtX86FeatureFlags x86_known; } JsonTest; @@ -2758,6 +2774,34 @@ static const JsonTest json_test[] = }, }, + .xdg_portal = + { + .interfaces = + { + { + .name = "org.freedesktop.portal.OpenURI", + .available = TRUE, + .version = 3, + }, + { + .name = "org.freedesktop.portal.Email", + .available = TRUE, + .version = 2, + }, + }, + .backends = + { + { + .name = "org.freedesktop.impl.portal.desktop.gtk", + .available = TRUE, + }, + { + .name = "org.freedesktop.impl.portal.desktop.kde", + .available = FALSE, + }, + }, + }, + .x86_features = SRT_X86_FEATURE_X86_64 | SRT_X86_FEATURE_CMPXCHG16B, .x86_known = SRT_X86_FEATURE_X86_64 | SRT_X86_FEATURE_SSE3 | SRT_X86_FEATURE_CMPXCHG16B, @@ -2829,6 +2873,11 @@ static const JsonTest json_test[] = .error_message = "Something went wrong", }, }, + .xdg_portal = + { + .issues = SRT_XDG_PORTAL_ISSUES_TIMEOUT, + .messages = "timeout: failed to run command ‘x86_64-linux-gnu-check-xdg-portal’: No such file or directory\n", + }, .x86_features = SRT_X86_FEATURE_NONE, .x86_known = SRT_X86_FEATURE_NONE, }, /* End Partial JSON report */ @@ -2875,6 +2924,10 @@ static const JsonTest json_test[] = .error_message = "(missing error message)", }, }, + .xdg_portal = + { + .issues = SRT_XDG_PORTAL_ISSUES_UNKNOWN, + }, .x86_features = SRT_X86_FEATURE_NONE, .x86_known = SRT_X86_FEATURE_NONE, }, /* End Partial-2 JSON report */ @@ -2904,6 +2957,10 @@ static const JsonTest json_test[] = }, }, .locale_issues = SRT_LOCALE_ISSUES_UNKNOWN, + .xdg_portal = + { + .issues = SRT_XDG_PORTAL_ISSUES_UNKNOWN, + }, .x86_features = SRT_X86_FEATURE_NONE, .x86_known = SRT_X86_FEATURE_NONE, }, /* End Empty JSON report */ @@ -2946,6 +3003,10 @@ static const JsonTest json_test[] = } }, .locale_issues = SRT_LOCALE_ISSUES_C_UTF8_MISSING | SRT_LOCALE_ISSUES_UNKNOWN, + .xdg_portal = + { + .issues = SRT_XDG_PORTAL_ISSUES_UNKNOWN, + }, .x86_features = SRT_X86_FEATURE_X86_64 | SRT_X86_FEATURE_SSE3 | SRT_X86_FEATURE_UNKNOWN, .x86_known = SRT_X86_FEATURE_X86_64 | SRT_X86_FEATURE_SSE3 | SRT_X86_FEATURE_CMPXCHG16B | SRT_X86_FEATURE_UNKNOWN, }, /* End Newer JSON report */ @@ -2975,8 +3036,12 @@ json_parsing (Fixture *f, gchar *name; gchar *pretty_name; gchar *host_directory; + g_autoptr(SrtObjectList) portal_interfaces = NULL; + g_autoptr(SrtObjectList) portal_backends = NULL; + g_autofree gchar *portal_messages = NULL; g_autofree gchar *steamscript_path = NULL; g_autofree gchar *steamscript_version = NULL; + SrtXdgPortalIssues issues; gchar **pinned_32 = NULL; gchar **messages_32 = NULL; gchar **pinned_64 = NULL; @@ -3211,6 +3276,33 @@ json_parsing (Fixture *f, srt_desktop_entry_is_steam_handler (iter->data)); } + portal_interfaces = srt_system_info_list_xdg_portal_interfaces (info); + for (j = 0, iter = portal_interfaces; iter != NULL; iter = iter->next, j++) + { + g_assert_cmpstr (t->xdg_portal.interfaces[j].name, ==, + srt_xdg_portal_interface_get_name (iter->data)); + g_assert_cmpint (t->xdg_portal.interfaces[j].available, ==, + srt_xdg_portal_interface_is_available (iter->data)); + g_assert_cmpint (t->xdg_portal.interfaces[j].version, ==, + srt_xdg_portal_interface_get_version (iter->data)); + } + g_assert_cmpstr (t->xdg_portal.interfaces[j].name, ==, NULL); + + portal_backends = srt_system_info_list_xdg_portal_backends (info); + for (j = 0, iter = portal_backends; iter != NULL; iter = iter->next, j++) + { + g_assert_cmpstr (t->xdg_portal.backends[j].name, ==, + srt_xdg_portal_backend_get_name (iter->data)); + g_assert_cmpint (t->xdg_portal.backends[j].available, ==, + srt_xdg_portal_backend_is_available (iter->data)); + } + g_assert_cmpstr (t->xdg_portal.backends[j].name, ==, NULL); + + issues = srt_system_info_get_xdg_portal_issues (info, &portal_messages); + + g_assert_cmpint (issues, ==, t->xdg_portal.issues); + g_assert_cmpstr (portal_messages, ==, t->xdg_portal.messages); + g_assert_cmpint (t->x86_features, ==, srt_system_info_get_x86_features (info)); g_assert_cmpint (t->x86_known, ==, srt_system_info_get_known_x86_features (info)); diff --git a/tests/xdg-portal.c b/tests/xdg-portal.c new file mode 100644 index 0000000000000000000000000000000000000000..305105435ed35cdc5177964cab01b702091ab9e1 --- /dev/null +++ b/tests/xdg-portal.c @@ -0,0 +1,257 @@ +/* + * Copyright © 2020 Collabora Ltd. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* Include this before steam-runtime-tools.h so that its backport of + * G_DEFINE_AUTOPTR_CLEANUP_FUNC will be visible to it */ +#include "steam-runtime-tools/glib-backports-internal.h" + +#include <steam-runtime-tools/steam-runtime-tools.h> + +#include <glib.h> +#include <glib/gstdio.h> +#include <glib-object.h> + +#include "steam-runtime-tools/xdg-portal-internal.h" +#include "test-utils.h" + +static const char *argv0; + +typedef struct +{ + gchar *builddir; +} Fixture; + +typedef struct +{ + int unused; +} Config; + +static void +setup (Fixture *f, + gconstpointer context) +{ + G_GNUC_UNUSED const Config *config = context; + + f->builddir = g_strdup (g_getenv ("G_TEST_BUILDDIR")); + + if (f->builddir == NULL) + f->builddir = g_path_get_dirname (argv0); +} + +static void +teardown (Fixture *f, + gconstpointer context) +{ + G_GNUC_UNUSED const Config *config = context; + + g_free (f->builddir); +} + +typedef struct +{ + const gchar *name; + gboolean is_available; +} XdgPortalBackendTest; + +typedef struct +{ + const gchar *name; + gboolean is_available; + guint32 version; +} XdgPortalInterfaceTest; + +typedef struct +{ + const gchar *description; + const gchar *multiarch_tuple; + const gchar *messages; + const gchar *sysroot; + SrtTestFlags test_flags; + SrtXdgPortalIssues issues; + XdgPortalInterfaceTest xdg_portal_interfaces_info[3]; + XdgPortalBackendTest xdg_portal_backends_info[3]; +} XdgPortalTest; + +static const XdgPortalTest xdg_portal_test[] = +{ + { + .description = "Missing OpenURI portal", + .multiarch_tuple = "mock-bad", + .messages = "The 'version' property is not available for 'org.freedesktop.portal.OpenURI', " + "either there isn't a working xdg-desktop-portal or it is a very old version\n", + .issues = SRT_XDG_PORTAL_ISSUES_MISSING_INTERFACE, + .xdg_portal_interfaces_info = + { + { + .name = "org.freedesktop.portal.OpenURI", + .is_available = FALSE, + .version = 0, + }, + { + .name = "org.freedesktop.portal.Email", + .is_available = TRUE, + .version = 3, + }, + }, + .xdg_portal_backends_info = + { + { + .name = "org.freedesktop.impl.portal.desktop.gtk", + .is_available = TRUE, + }, + { + .name = "org.freedesktop.impl.portal.desktop.kde", + .is_available = FALSE, + }, + }, + }, + + { + .description = "Good system check", + .multiarch_tuple = "mock-good", + .issues = SRT_XDG_PORTAL_ISSUES_NONE, + .xdg_portal_interfaces_info = + { + { + .name = "org.freedesktop.portal.OpenURI", + .is_available = TRUE, + .version = 2, + }, + { + .name = "org.freedesktop.portal.Email", + .is_available = TRUE, + .version = 3, + }, + }, + .xdg_portal_backends_info = + { + { + .name = "org.freedesktop.impl.portal.desktop.gtk", + .is_available = TRUE, + }, + { + .name = "org.freedesktop.impl.portal.desktop.kde", + .is_available = FALSE, + }, + }, + }, + + { + .description = "Good Flatpak environment", + .multiarch_tuple = "mock-good-flatpak", + .sysroot = "flatpak-example", + .issues = SRT_XDG_PORTAL_ISSUES_NONE, + .xdg_portal_interfaces_info = + { + { + .name = "org.freedesktop.portal.OpenURI", + .is_available = TRUE, + .version = 3, + }, + { + .name = "org.freedesktop.portal.Email", + .is_available = TRUE, + .version = 3, + }, + }, + }, + + { + .description = "XDG portal check timeout", + .multiarch_tuple = "mock-hanging", + .test_flags = SRT_TEST_FLAGS_TIME_OUT_SOONER, + .issues = SRT_XDG_PORTAL_ISSUES_TIMEOUT, + }, +}; + +static void +test_check_xdg_portal (Fixture *f, + gconstpointer context) +{ + for (gsize i = 0; i < G_N_ELEMENTS (xdg_portal_test); i++) + { + const XdgPortalTest *t = &xdg_portal_test[i]; + g_autoptr(SrtSystemInfo) info = NULL; + g_autoptr(SrtObjectList) portal_interfaces = NULL; + GList *portal_backends = NULL; + SrtXdgPortalIssues issues; + g_autofree gchar *messages = NULL; + g_autofree gchar *sysroot = NULL; + GList *iter; + gsize j; + + g_test_message ("%s", t->description); + + info = srt_system_info_new (NULL); + srt_system_info_set_helpers_path (info, f->builddir); + srt_system_info_set_primary_multiarch_tuple (info, t->multiarch_tuple); + srt_system_info_set_test_flags (info, t->test_flags); + if (t->sysroot != NULL) + { + sysroot = g_build_filename (f->builddir, "sysroots", t->sysroot, NULL); + srt_system_info_set_sysroot (info, sysroot); + } + + portal_interfaces = srt_system_info_list_xdg_portal_interfaces (info); + for (j = 0, iter = portal_interfaces; iter != NULL; iter = iter->next, j++) + { + g_assert_cmpstr (t->xdg_portal_interfaces_info[j].name, ==, + srt_xdg_portal_interface_get_name (iter->data)); + g_assert_cmpint (t->xdg_portal_interfaces_info[j].is_available, ==, + srt_xdg_portal_interface_is_available (iter->data)); + g_assert_cmpint (t->xdg_portal_interfaces_info[j].version, ==, + srt_xdg_portal_interface_get_version (iter->data)); + } + g_assert_cmpstr (t->xdg_portal_interfaces_info[j].name, ==, NULL); + + portal_backends = srt_system_info_list_xdg_portal_backends (info); + for (j = 0, iter = portal_backends; iter != NULL; iter = iter->next, j++) + { + g_assert_cmpstr (t->xdg_portal_backends_info[j].name, ==, + srt_xdg_portal_backend_get_name (iter->data)); + g_assert_cmpint (t->xdg_portal_backends_info[j].is_available, ==, + srt_xdg_portal_backend_is_available (iter->data)); + } + g_assert_cmpstr (t->xdg_portal_backends_info[j].name, ==, NULL); + + issues = srt_system_info_get_xdg_portal_issues (info, &messages); + + g_assert_cmpint (issues, ==, t->issues); + g_assert_cmpstr (messages, ==, t->messages); + } +} + +int +main (int argc, + char **argv) +{ + argv0 = argv[0]; + + g_test_init (&argc, &argv, NULL); + g_test_add ("/xdg-portal/test_check_xdg_portal", Fixture, NULL, setup, + test_check_xdg_portal, teardown); + + return g_test_run (); +}