diff options
-rw-r--r-- | data/tests/broken.appdata.xml | 1 | ||||
-rw-r--r-- | libappstream-glib/as-app-validate.c | 13 | ||||
-rw-r--r-- | libappstream-glib/as-self-test.c | 6 |
3 files changed, 18 insertions, 2 deletions
diff --git a/data/tests/broken.appdata.xml b/data/tests/broken.appdata.xml index 68071d8..bc8f1b5 100644 --- a/data/tests/broken.appdata.xml +++ b/data/tests/broken.appdata.xml @@ -21,6 +21,7 @@ </description> <url type="bugtracker">www.dave.org</url> <updatecontact></updatecontact> + <categories><category>Game</category></categories> <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 d145f2c..05959ca 100644 --- a/libappstream-glib/as-app-validate.c +++ b/libappstream-glib/as-app-validate.c @@ -1091,6 +1091,7 @@ as_app_validate (AsApp *app, AsAppValidateFlags flags, GError **error) gboolean require_content_license = TRUE; gboolean require_name = TRUE; gboolean require_translation = TRUE; + gboolean require_content_rating = TRUE; gboolean validate_license = TRUE; gboolean ret; guint length_name_max = 30; @@ -1125,6 +1126,7 @@ as_app_validate (AsApp *app, AsAppValidateFlags flags, GError **error) number_para_min = 1; require_sentence_case = FALSE; require_translation = FALSE; + require_content_rating = FALSE; switch (as_format_get_kind (format)) { case AS_FORMAT_KIND_METAINFO: case AS_FORMAT_KIND_APPDATA: @@ -1393,6 +1395,17 @@ as_app_validate (AsApp *app, AsAppValidateFlags flags, GError **error) "<id> is not present"); } + /* games require a content rating */ + if (require_content_rating && as_app_has_category (app, "Game")) { + GPtrArray *ratings = as_app_get_content_ratings (app); + if (ratings->len == 0) { + ai_app_validate_add (helper, + AS_PROBLEM_KIND_TAG_MISSING, + "<content_rating> required for game " + "[use https://odrs.gnome.org/oars]"); + } + } + /* url */ urls = as_app_get_urls (app); keys = g_hash_table_get_keys (urls); diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index a87390f..a3639bf 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -2033,13 +2033,15 @@ as_test_app_validate_file_bad_func (void) "<release> version was duplicated"); as_test_app_validate_check (probs, AS_PROBLEM_KIND_ATTRIBUTE_INVALID, "<release> timestamp is in the future"); - g_assert_cmpint (probs->len, ==, 35); + as_test_app_validate_check (probs, AS_PROBLEM_KIND_TAG_MISSING, + "<content_rating> required for game"); + g_assert_cmpint (probs->len, ==, 36); /* again, harder */ probs2 = as_app_validate (app, AS_APP_VALIDATE_FLAG_STRICT, &error); as_test_app_validate_check (probs2, AS_PROBLEM_KIND_TAG_INVALID, "XML data contains unknown tag"); - g_assert_cmpint (probs2->len, ==, 41); + g_assert_cmpint (probs2->len, ==, 42); } static void |