From 2a780a1d68df4d7841a322a9e1b20e53aa0d0eea Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Mon, 21 Jan 2019 19:47:54 +0000 Subject: =?UTF-8?q?tests:=20Add=20test=20for=20OARS=20=E2=86=92=20CSM=20ma?= =?UTF-8?q?ppings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Philip Withnall https://github.com/hughsie/appstream-glib/issues/280 --- libappstream-glib/as-self-test.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c index f151d97..f9facaa 100644 --- a/libappstream-glib/as-self-test.c +++ b/libappstream-glib/as-self-test.c @@ -1760,6 +1760,41 @@ as_test_content_rating_func (void) as_node_unref (root); } +/* Test that the OARS → CSM mapping table in as_content_rating_attribute_to_csm_age() + * is complete (contains mappings for all known IDs), and that the ages it + * returns are non-decreasing for increasing values of #AsContentRatingValue in + * each ID. + * + * Also test that unknown values of #AsContentRatingValue return an unknown age, + * and unknown IDs do similarly. */ +static void +as_test_content_rating_mappings (void) +{ + const AsContentRatingValue values[] = { + AS_CONTENT_RATING_VALUE_NONE, + AS_CONTENT_RATING_VALUE_MILD, + AS_CONTENT_RATING_VALUE_MODERATE, + AS_CONTENT_RATING_VALUE_INTENSE, + }; + g_autofree const gchar **ids = as_content_rating_get_all_rating_ids (); + + for (gsize i = 0; ids[i] != NULL; i++) { + guint max_age = 0; + + for (gsize j = 0; j < G_N_ELEMENTS (values); j++) { + guint age = as_content_rating_attribute_to_csm_age (ids[i], values[j]); + g_assert_cmpuint (age, >=, max_age); + max_age = age; + } + + g_assert_cmpuint (max_age, >, 0); + g_assert_cmpuint (as_content_rating_attribute_to_csm_age (ids[i], AS_CONTENT_RATING_VALUE_UNKNOWN), ==, 0); + g_assert_cmpuint (as_content_rating_attribute_to_csm_age (ids[i], AS_CONTENT_RATING_VALUE_LAST), ==, 0); + } + + g_assert_cmpuint (as_content_rating_attribute_to_csm_age ("not-valid-id", AS_CONTENT_RATING_VALUE_INTENSE), ==, 0); +} + static void as_test_app_func (void) { @@ -5583,6 +5618,7 @@ main (int argc, char **argv) g_test_add_func ("/AppStream/require", as_test_require_func); g_test_add_func ("/AppStream/checksum", as_test_checksum_func); g_test_add_func ("/AppStream/content_rating", as_test_content_rating_func); + g_test_add_func ("/AppStream/content_rating/mappings", as_test_content_rating_mappings); g_test_add_func ("/AppStream/release", as_test_release_func); g_test_add_func ("/AppStream/release{date}", as_test_release_date_func); g_test_add_func ("/AppStream/release{appdata}", as_test_release_appdata_func); -- cgit v1.2.1