Skip to content

Commit

Permalink
Test launchable tags in validation
Browse files Browse the repository at this point in the history
  • Loading branch information
imciner2 authored and hughsie committed Jun 15, 2020
1 parent 31f5093 commit 0306be0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
3 changes: 3 additions & 0 deletions data/tests/broken.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
32 changes: 32 additions & 0 deletions libappstream-glib/as-app-validate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 6 additions & 2 deletions libappstream-glib/as-self-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2433,15 +2433,19 @@ 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);
g_assert_no_error (error);
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
Expand Down

0 comments on commit 0306be0

Please sign in to comment.