summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan McInerney <ian.s.mcinerney@ieee.org>2020-06-14 17:15:09 +0100
committerRichard Hughes <richard@hughsie.com>2020-06-15 10:27:40 +0100
commit0306be0e508364eb7672bf9ba0d2d8541a4517e4 (patch)
treebdd503810c8862d94de1b893ab9e0437193c4ac9
parent31f5093a06288ee5aa907ada6e53ae4c0cbaa88d (diff)
downloadappstream-glib-0306be0e508364eb7672bf9ba0d2d8541a4517e4.tar.gz
Test launchable tags in validation
-rw-r--r--data/tests/broken.appdata.xml3
-rw-r--r--libappstream-glib/as-app-validate.c32
-rw-r--r--libappstream-glib/as-self-test.c8
3 files changed, 41 insertions, 2 deletions
diff --git a/data/tests/broken.appdata.xml b/data/tests/broken.appdata.xml
index cf80f5b..1603848 100644
--- a/data/tests/broken.appdata.xml
+++ b/data/tests/broken.appdata.xml
@@ -22,6 +22,9 @@
<url type="bugtracker">www.dave.org</url>
<updatecontact></updatecontact>
<categories><category>Game</category></categories>
+ <launchable type="desktop-id">test.desktop</launchable>
+ <launchable type="desktop">test.desktop</launchable>
+ <launchable type="desktop-id"></launchable>
<xxx>This is not a valid tag</xxx>
<releases>
diff --git a/libappstream-glib/as-app-validate.c b/libappstream-glib/as-app-validate.c
index 246ef14..60b46e5 100644
--- a/libappstream-glib/as-app-validate.c
+++ b/libappstream-glib/as-app-validate.c
@@ -1179,6 +1179,35 @@ as_app_validate_check_id (AsAppValidateHelper *helper, const gchar *id)
}
}
+static void
+as_app_validate_launchables (AsApp *app, AsAppValidateHelper *helper)
+{
+ GPtrArray *launchables = as_app_get_launchables (app);
+
+ /* launchable isn't required */
+ if (launchables == NULL)
+ return;
+
+ /* check each launchable in the file */
+ for (guint j = 0; j < launchables->len; j++) {
+ AsLaunchable *tmp = g_ptr_array_index (launchables, j);
+
+ if (as_launchable_get_kind (tmp) == AS_LAUNCHABLE_KIND_UNKNOWN) {
+ ai_app_validate_add (helper,
+ AS_PROBLEM_KIND_ATTRIBUTE_INVALID,
+ "<launchable> has invalid type attribute");
+ continue;
+ }
+
+ if (as_launchable_get_value (tmp) == NULL) {
+ ai_app_validate_add (helper,
+ AS_PROBLEM_KIND_VALUE_MISSING,
+ "<launchable> missing value");
+ continue;
+ }
+ }
+}
+
/**
* as_app_validate:
* @app: a #AsApp instance.
@@ -1590,6 +1619,9 @@ as_app_validate (AsApp *app, guint32 flags, GError **error)
/* icons */
as_app_validate_icons (app, helper);
+ /* launchables */
+ as_app_validate_launchables (app, helper);
+
/* releases */
if (!as_app_validate_releases (app, helper, error))
return NULL;
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index d7c726e..78af947 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -2433,7 +2433,11 @@ as_test_app_validate_file_bad_func (void)
"<release> timestamp is in the future");
as_test_app_validate_check (probs, AS_PROBLEM_KIND_MARKUP_INVALID,
"<id> has invalid character");
- g_assert_cmpint (probs->len, ==, 21);
+ as_test_app_validate_check (probs, AS_PROBLEM_KIND_ATTRIBUTE_INVALID,
+ "<launchable> has invalid type attribute");
+ as_test_app_validate_check (probs, AS_PROBLEM_KIND_VALUE_MISSING,
+ "<launchable> missing value");
+ g_assert_cmpint (probs->len, ==, 23);
/* again, harder */
probs2 = as_app_validate (app, AS_APP_VALIDATE_FLAG_STRICT, &error);
@@ -2441,7 +2445,7 @@ as_test_app_validate_file_bad_func (void)
g_assert (probs2 != NULL);
as_test_app_validate_check (probs2, AS_PROBLEM_KIND_TAG_INVALID,
"XML data contains unknown tag");
- g_assert_cmpint (probs2->len, ==, 35);
+ g_assert_cmpint (probs2->len, ==, 37);
}
static void