summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-08-02 12:15:10 +0100
committerRichard Hughes <richard@hughsie.com>2016-08-02 12:15:10 +0100
commite4b8d2522b88d4e601b183a8da6276b634401fc6 (patch)
tree50e0a75821a0f201863e5c9a9534e85097e30ff7
parent0e4f23ded03b21060c5ec7886cfd056031a20720 (diff)
downloadappstream-glib-e4b8d2522b88d4e601b183a8da6276b634401fc6.tar.gz
trivial: Add some initial self tests for AS_STORE_ADD_FLAG_USE_UNIQUE_ID
-rw-r--r--libappstream-glib/as-app.c18
-rw-r--r--libappstream-glib/as-self-test.c61
2 files changed, 71 insertions, 8 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c
index 951b4f6..69e220c 100644
--- a/libappstream-glib/as-app.c
+++ b/libappstream-glib/as-app.c
@@ -2976,6 +2976,16 @@ as_app_add_bundle (AsApp *app, AsBundle *bundle)
return;
}
}
+
+ /* set the architecture and branch */
+ if (as_bundle_get_kind (bundle) == AS_BUNDLE_KIND_FLATPAK) {
+ g_auto(GStrv) split = g_strsplit (as_bundle_get_id (bundle), "/", -1);
+ if (priv->architectures->len == 0)
+ as_app_add_arch (app, split[2]);
+ if (priv->branch == NULL)
+ as_app_set_branch (app, split[3]);
+ }
+
g_ptr_array_add (priv->bundles, g_object_ref (bundle));
}
@@ -3982,14 +3992,6 @@ as_app_node_parse_child (AsApp *app, GNode *n, AsAppParseFlags flags,
if (!as_bundle_node_parse (bu, n, ctx, error))
return FALSE;
as_app_add_bundle (app, bu);
-
- /* set the architecture and branch */
- if (as_bundle_get_kind (bu) == AS_BUNDLE_KIND_FLATPAK) {
- g_auto(GStrv) split = g_strsplit (as_bundle_get_id (bu), "/", -1);
- as_app_add_arch (app, split[2]);
- if (priv->branch == NULL)
- priv->branch = g_strdup (split[3]);
- }
break;
}
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 6d86f88..8bd9889 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -3364,6 +3364,66 @@ as_test_store_func (void)
}
static void
+as_test_store_unique_func (void)
+{
+ AsApp *app;
+ GPtrArray *apps;
+ g_autoptr(AsApp) app1 = NULL;
+ g_autoptr(AsApp) app2 = NULL;
+ g_autoptr(AsApp) app3 = NULL;
+ g_autoptr(AsBundle) bundle2 = NULL;
+ g_autoptr(AsBundle) bundle3 = NULL;
+ g_autoptr(AsStore) store = NULL;
+
+ /* create a store and add a single app */
+ store = as_store_new ();
+ as_store_set_add_flags (store, AS_STORE_ADD_FLAG_USE_UNIQUE_ID);
+ app1 = as_app_new ();
+ as_app_set_id (app1, "org.gnome.Software.desktop");
+ as_app_set_kind (app1, AS_APP_KIND_DESKTOP);
+ as_app_add_pkgname (app1, "gnome-software");
+ as_store_add_app (store, app1);
+
+ /* add a stable bundle */
+ app2 = as_app_new ();
+ bundle2 = as_bundle_new ();
+ as_bundle_set_kind (bundle2, AS_BUNDLE_KIND_FLATPAK);
+ as_bundle_set_id (bundle2, "app/org.gnome.Software/i386/3-18");
+ as_app_set_id (app2, "org.gnome.Software.desktop");
+ as_app_set_kind (app2, AS_APP_KIND_DESKTOP);
+ as_app_add_bundle (app2, bundle2);
+ as_store_add_app (store, app2);
+
+ /* add a master bundle */
+ app3 = as_app_new ();
+ bundle3 = as_bundle_new ();
+ as_bundle_set_kind (bundle3, AS_BUNDLE_KIND_FLATPAK);
+ as_bundle_set_id (bundle3, "app/org.gnome.Software/i386/master");
+ as_app_set_id (app3, "org.gnome.Software.desktop");
+ as_app_set_kind (app3, AS_APP_KIND_DESKTOP);
+ as_app_add_bundle (app3, bundle3);
+ as_store_add_app (store, app3);
+
+ g_assert_cmpint (as_store_get_size (store), ==, 3);
+ apps = as_store_get_apps_by_id (store, "org.gnome.Software.desktop");
+ g_assert_cmpint (apps->len, ==, 3);
+ app = g_ptr_array_index (apps, 0);
+ g_assert_cmpstr (as_app_get_unique_id (app), ==,
+ "*/package/*/desktop/org.gnome.Software.desktop/*/*/*");
+ app = g_ptr_array_index (apps, 1);
+ g_assert_cmpstr (as_app_get_unique_id (app), ==,
+ "*/flatpak/*/desktop/org.gnome.Software.desktop/i386/3-18/*");
+ app = g_ptr_array_index (apps, 2);
+ g_assert_cmpstr (as_app_get_unique_id (app), ==,
+ "*/flatpak/*/desktop/org.gnome.Software.desktop/i386/master/*");
+ app = as_store_get_app_by_unique_id (store,
+ "*/flatpak/*/desktop/"
+ "org.gnome.Software.desktop/i386/master/*",
+ AS_STORE_SEARCH_FLAG_NONE);
+ g_assert (app != NULL);
+}
+
+static void
as_test_store_provides_func (void)
{
AsApp *app;
@@ -4997,6 +5057,7 @@ main (int argc, char **argv)
}
g_test_add_func ("/AppStream/yaml", as_test_yaml_func);
g_test_add_func ("/AppStream/store", as_test_store_func);
+ g_test_add_func ("/AppStream/store{unique}", as_test_store_unique_func);
g_test_add_func ("/AppStream/store{empty}", as_test_store_empty_func);
if (g_test_slow ()) {
g_test_add_func ("/AppStream/store{auto-reload-dir}", as_test_store_auto_reload_dir_func);