diff options
author | Richard Hughes <richard@hughsie.com> | 2014-04-08 10:59:16 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2014-04-08 10:59:31 +0100 |
commit | d62a1fb592fd4bdadd3178215ee5067c40586cf4 (patch) | |
tree | c9c5e2ac0e8625939ea37bf163331ba39d6305eb | |
parent | 40e48343af0399ec7c04804ebb4e2e2c9dac8191 (diff) | |
download | appstream-glib-d62a1fb592fd4bdadd3178215ee5067c40586cf4.tar.gz |
Add mimetype data to the AsApp object
A typo was adding each mimetype as NULL, so we couldn't match on the mimetype
tokens. Fix this, and add critical warnings and self tests to catch this kind
of bug in the future.
-rw-r--r-- | libappstream-glib/as-app.c | 10 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 6 |
2 files changed, 13 insertions, 3 deletions
diff --git a/libappstream-glib/as-app.c b/libappstream-glib/as-app.c index 67abccb..07c6bf8 100644 --- a/libappstream-glib/as-app.c +++ b/libappstream-glib/as-app.c @@ -1476,7 +1476,7 @@ as_app_node_parse_child (AsApp *app, GNode *n, GError **error) for (c = n->children; c != NULL; c = c->next) { if (as_node_get_tag (c) != AS_TAG_MIMETYPE) continue; - g_ptr_array_add (priv->mimetypes, as_node_take_data (n)); + g_ptr_array_add (priv->mimetypes, as_node_take_data (c)); } break; @@ -1648,8 +1648,11 @@ as_app_add_tokens (AsApp *app, AsAppTokenItem *token_item; /* sanity check */ - if (value == NULL) + if (value == NULL) { + g_critical ("trying to add NULL search token to %s", + as_app_get_id_full (app)); return; + } token_item = g_slice_new0 (AsAppTokenItem); #if GLIB_CHECK_VERSION(2,39,1) @@ -1675,7 +1678,8 @@ as_app_create_token_cache (AsApp *app) guint i; /* add all the data we have */ - as_app_add_tokens (app, priv->id, "C", 100); + if (priv->id != NULL) + as_app_add_tokens (app, priv->id, "C", 100); locales = g_get_language_names (); for (i = 0; locales[i] != NULL; i++) { tmp = as_app_get_name (app, locales[i]); diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index e6510d8..d260d54 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -276,6 +276,9 @@ ch_test_app_func (void) "<architectures>" "<arch>i386</arch>" "</architectures>" + "<mimetypes>" + "<mimetype>application/vnd.oasis.opendocument.spreadsheet</mimetype>" + "</mimetypes>" "<project_license>GPLv2+</project_license>" "<url type=\"homepage\">https://wiki.gnome.org/Design/Apps/Software</url>" "<project_group>GNOME</project_group>" @@ -683,16 +686,19 @@ ch_test_app_search_func (void) AsApp *app; const gchar *all[] = { "gnome", "install", "software", NULL }; const gchar *none[] = { "gnome", "xxx", "software", NULL }; + const gchar *mime[] = { "application", "vnd", "oasis", "opendocument","text", NULL }; app = as_app_new (); as_app_set_name (app, NULL, "GNOME Software", -1); as_app_set_comment (app, NULL, "Install and remove software", -1); + as_app_add_mimetype (app, "application/vnd.oasis.opendocument.text", -1); g_assert_cmpint (as_app_search_matches (app, "software"), ==, 80); g_assert_cmpint (as_app_search_matches (app, "soft"), ==, 80); g_assert_cmpint (as_app_search_matches (app, "install"), ==, 60); g_assert_cmpint (as_app_search_matches_all (app, (gchar**) all), ==, 220); g_assert_cmpint (as_app_search_matches_all (app, (gchar**) none), ==, 0); + g_assert_cmpint (as_app_search_matches_all (app, (gchar**) mime), ==, 5); g_object_unref (app); } |