1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
* vi:set noexpandtab tabstop=8 shiftwidth=8:
*
* Copyright (C) 2017 Joaquim Rocha <jrocha@endlessm.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "config.h"
#include <glib/gstdio.h>
#include "gnome-software-private.h"
#include "gs-appstream.h"
#include "gs-test.h"
const gchar * const allowlist[] = {
"appstream",
"generic-updates",
"icons",
"os-release",
NULL
};
static void
gs_plugins_core_search_repo_name_func (GsPluginLoader *plugin_loader)
{
GsApp *app;
g_autoptr(GError) error = NULL;
g_autoptr(GsApp) app_tmp = NULL;
GsAppList *list;
g_autoptr(GsPluginJob) plugin_job = NULL;
g_autoptr(GsAppQuery) query = NULL;
const gchar *keywords[2] = { NULL, };
/* drop all caches */
gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
/* force this app to be installed */
app_tmp = gs_plugin_loader_app_create (plugin_loader, "*/*/yellow/arachne.desktop/*", NULL, &error);
g_assert_no_error (error);
g_assert_nonnull (app_tmp);
gs_app_set_state (app_tmp, GS_APP_STATE_INSTALLED);
/* get search result based on addon keyword */
keywords[0] = "yellow";
query = gs_app_query_new ("keywords", keywords,
"refine-require-flags", GS_PLUGIN_REFINE_REQUIRE_FLAGS_ICON,
"dedupe-flags", GS_APP_QUERY_DEDUPE_FLAGS_DEFAULT,
"sort-func", gs_utils_app_sort_match_value,
NULL);
plugin_job = gs_plugin_job_list_apps_new (query, GS_PLUGIN_LIST_APPS_FLAGS_NONE);
gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
list = gs_plugin_job_list_apps_get_result_list (GS_PLUGIN_JOB_LIST_APPS (plugin_job));
gs_test_flush_main_context ();
g_assert_no_error (error);
g_assert_nonnull (list);
/* make sure there is at least one entry, the parent app */
g_assert_cmpint (gs_app_list_length (list), >=, 1);
app = gs_app_list_index (list, 0);
g_assert_cmpstr (gs_app_get_id (app), ==, "arachne.desktop");
g_assert_cmpint (gs_app_get_kind (app), ==, AS_COMPONENT_KIND_DESKTOP_APP);
}
static void
gs_plugins_core_os_release_func (GsPluginLoader *plugin_loader)
{
gboolean ret;
g_autoptr(GsApp) app = NULL;
g_autoptr(GsApp) app3 = NULL;
g_autoptr(GsPluginJob) plugin_job = NULL;
g_autoptr(GError) error = NULL;
/* drop all caches */
gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
/* refine system application */
app = gs_plugin_loader_get_system_app (plugin_loader, NULL, &error);
g_assert_no_error (error);
g_assert_nonnull (app);
plugin_job = gs_plugin_job_refine_new_for_app (app,
GS_PLUGIN_REFINE_FLAGS_NONE,
GS_PLUGIN_REFINE_REQUIRE_FLAGS_URL |
GS_PLUGIN_REFINE_REQUIRE_FLAGS_VERSION);
ret = gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
gs_test_flush_main_context ();
g_assert_no_error (error);
g_assert_true (ret);
/* make sure there is valid content */
g_assert_cmpstr (gs_app_get_id (app), ==, "org.fedoraproject.fedora-25");
g_assert_cmpint (gs_app_get_kind (app), ==, AS_COMPONENT_KIND_OPERATING_SYSTEM);
g_assert_cmpint (gs_app_get_state (app), ==, GS_APP_STATE_INSTALLED);
g_assert_cmpstr (gs_app_get_name (app), ==, "Fedora");
g_assert_cmpstr (gs_app_get_version (app), ==, "25");
g_assert_cmpstr (gs_app_get_url (app, AS_URL_KIND_HOMEPAGE), ==,
"https://fedoraproject.org/");
g_assert_cmpstr (gs_app_get_metadata_item (app, "GnomeSoftware::CpeName"), ==,
"cpe:/o:fedoraproject:fedora:25");
/* this comes from appstream */
g_assert_cmpstr (gs_app_get_summary (app), ==, "Fedora Workstation");
/* check we can get this by the old name too */
app3 = gs_plugin_loader_get_system_app (plugin_loader, NULL, &error);
g_assert_no_error (error);
g_assert_nonnull (app3);
g_assert_true (app3 == app);
}
static void
gs_plugins_core_generic_updates_func (GsPluginLoader *plugin_loader)
{
gboolean ret;
GsApp *os_update;
GsAppList *related;
g_autoptr(GsPluginJob) plugin_job = NULL;
g_autoptr(GsPluginJob) plugin_job2 = NULL;
g_autoptr(GError) error = NULL;
g_autoptr(GsApp) app1 = NULL;
g_autoptr(GsApp) app2 = NULL;
g_autoptr(GsApp) app_wildcard = NULL;
g_autoptr(GsAppList) list = NULL;
g_autoptr(GsAppList) list_wildcard = NULL;
GsAppList *result_list;
GsAppList *result_list_wildcard;
/* drop all caches */
gs_utils_rmtree (g_getenv ("GS_SELF_TEST_CACHEDIR"), NULL);
gs_test_reinitialise_plugin_loader (plugin_loader, allowlist, NULL);
/* create a list with generic apps */
list = gs_app_list_new ();
app1 = gs_app_new ("package1");
app2 = gs_app_new ("package2");
gs_app_set_kind (app1, AS_COMPONENT_KIND_GENERIC);
gs_app_set_kind (app2, AS_COMPONENT_KIND_GENERIC);
gs_app_set_bundle_kind (app1, AS_BUNDLE_KIND_PACKAGE);
gs_app_set_bundle_kind (app2, AS_BUNDLE_KIND_PACKAGE);
gs_app_set_scope (app1, AS_COMPONENT_SCOPE_SYSTEM);
gs_app_set_scope (app2, AS_COMPONENT_SCOPE_SYSTEM);
gs_app_set_state (app1, GS_APP_STATE_UPDATABLE);
gs_app_set_state (app2, GS_APP_STATE_UPDATABLE);
gs_app_add_source (app1, "package1");
gs_app_add_source (app2, "package2");
gs_app_list_add (list, app1);
gs_app_list_add (list, app2);
/* refine to make the generic-updates plugin merge them into a single OsUpdate item */
plugin_job = gs_plugin_job_refine_new (list, GS_PLUGIN_REFINE_FLAGS_NONE, GS_PLUGIN_REFINE_REQUIRE_FLAGS_UPDATE_DETAILS);
ret = gs_plugin_loader_job_process (plugin_loader, plugin_job, NULL, &error);
gs_test_flush_main_context ();
g_assert_no_error (error);
g_assert_true (ret);
/* make sure there is one entry, the os update */
result_list = gs_plugin_job_refine_get_result_list (GS_PLUGIN_JOB_REFINE (plugin_job));
g_assert_cmpint (gs_app_list_length (result_list), ==, 1);
os_update = gs_app_list_index (result_list, 0);
/* make sure the os update is valid */
g_assert_cmpstr (gs_app_get_id (os_update), ==, "org.gnome.Software.OsUpdate");
g_assert_cmpint (gs_app_get_kind (os_update), ==, AS_COMPONENT_KIND_GENERIC);
g_assert_cmpint (gs_app_get_special_kind (os_update), ==, GS_APP_SPECIAL_KIND_OS_UPDATE);
g_assert_true (gs_app_has_quirk (os_update, GS_APP_QUIRK_IS_PROXY));
/* must have two related apps, the ones we added earlier */
related = gs_app_get_related (os_update);
g_assert_cmpint (gs_app_list_length (related), ==, 2);
/* another test to make sure that we don't get an OsUpdate item created for wildcard apps */
list_wildcard = gs_app_list_new ();
app_wildcard = gs_app_new ("nosuchapp.desktop");
gs_app_add_quirk (app_wildcard, GS_APP_QUIRK_IS_WILDCARD);
gs_app_set_kind (app_wildcard, AS_COMPONENT_KIND_GENERIC);
gs_app_list_add (list_wildcard, app_wildcard);
plugin_job2 = gs_plugin_job_refine_new (list_wildcard, GS_PLUGIN_REFINE_FLAGS_NONE, GS_PLUGIN_REFINE_REQUIRE_FLAGS_UPDATE_DETAILS);
ret = gs_plugin_loader_job_process (plugin_loader, plugin_job2, NULL, &error);
gs_test_flush_main_context ();
g_assert_no_error (error);
g_assert_true (ret);
result_list_wildcard = gs_plugin_job_refine_get_result_list (GS_PLUGIN_JOB_REFINE (plugin_job2));
/* no OsUpdate item created */
for (guint i = 0; i < gs_app_list_length (result_list_wildcard); i++) {
GsApp *app_tmp = gs_app_list_index (result_list_wildcard, i);
g_assert_cmpint (gs_app_get_kind (app_tmp), !=, AS_COMPONENT_KIND_GENERIC);
g_assert_cmpint (gs_app_get_special_kind (app_tmp), !=, GS_APP_SPECIAL_KIND_OS_UPDATE);
g_assert_false (gs_app_has_quirk (app_tmp, GS_APP_QUIRK_IS_PROXY));
}
}
int
main (int argc, char **argv)
{
g_autofree gchar *tmp_root = NULL;
gboolean ret;
int retval;
g_autofree gchar *os_release_filename = NULL;
g_autoptr(GError) error = NULL;
g_autoptr(GsPluginLoader) plugin_loader = NULL;
const gchar *xml;
/* While we use %G_TEST_OPTION_ISOLATE_DIRS to create temporary directories
* for each of the tests, we want to use the system MIME registry, assuming
* that it exists and correctly has shared-mime-info installed. */
g_content_type_set_mime_dirs (NULL);
/* Similarly, add the system-wide icon theme path before it’s
* overwritten by %G_TEST_OPTION_ISOLATE_DIRS. */
gs_test_expose_icon_theme_paths ();
gs_test_init (&argc, &argv);
/* Use a common cache directory for all tests, since the appstream
* plugin uses it and cannot be reinitialised for each test. */
tmp_root = g_dir_make_tmp ("gnome-software-core-test-XXXXXX", NULL);
g_assert_nonnull (tmp_root);
g_setenv ("GS_SELF_TEST_CACHEDIR", tmp_root, TRUE);
os_release_filename = gs_test_get_filename (TESTDATADIR, "os-release");
g_assert_nonnull (os_release_filename);
g_setenv ("GS_SELF_TEST_OS_RELEASE_FILENAME", os_release_filename, TRUE);
/* fake some data */
xml = "<?xml version=\"1.0\"?>\n"
"<components origin=\"yellow\" version=\"0.9\">\n"
" <component type=\"desktop\">\n"
" <id>arachne.desktop</id>\n"
" <name>test</name>\n"
" <summary>Test</summary>\n"
" <icon type=\"stock\">system-file-manager</icon>\n"
" <pkgname>arachne</pkgname>\n"
" </component>\n"
" <component type=\"os-upgrade\">\n"
" <id>org.fedoraproject.fedora-25</id>\n"
" <name>Fedora</name>\n"
" <summary>Fedora Workstation</summary>\n"
" <pkgname>fedora-release</pkgname>\n"
" </component>\n"
" <info>\n"
" <scope>user</scope>\n"
" </info>\n"
"</components>\n";
g_setenv ("GS_SELF_TEST_APPSTREAM_XML", xml, TRUE);
/* we can only load this once per process */
plugin_loader = gs_plugin_loader_new (NULL, NULL);
gs_plugin_loader_add_location (plugin_loader, LOCALPLUGINDIR);
ret = gs_plugin_loader_setup (plugin_loader,
allowlist,
NULL,
NULL,
&error);
g_assert_no_error (error);
g_assert_true (ret);
/* plugin tests go here */
g_test_add_data_func ("/gnome-software/plugins/core/search-repo-name",
plugin_loader,
(GTestDataFunc) gs_plugins_core_search_repo_name_func);
g_test_add_data_func ("/gnome-software/plugins/core/os-release",
plugin_loader,
(GTestDataFunc) gs_plugins_core_os_release_func);
g_test_add_data_func ("/gnome-software/plugins/core/generic-updates",
plugin_loader,
(GTestDataFunc) gs_plugins_core_generic_updates_func);
retval = g_test_run ();
/* Clean up. */
gs_utils_rmtree (tmp_root, NULL);
return retval;
}
|