summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Withnall <withnall@endlessm.com>2019-01-21 19:47:54 +0000
committerRichard Hughes <richard@hughsie.com>2019-01-23 15:56:25 +0000
commit2a780a1d68df4d7841a322a9e1b20e53aa0d0eea (patch)
treebed1e0a9b319e7efe6a006bf4d0b89b59029a54c
parent6479ed4914013bc196f8df38214e164da9f34149 (diff)
downloadappstream-glib-2a780a1d68df4d7841a322a9e1b20e53aa0d0eea.tar.gz
tests: Add test for OARS → CSM mappings
Signed-off-by: Philip Withnall <withnall@endlessm.com> https://github.com/hughsie/appstream-glib/issues/280
-rw-r--r--libappstream-glib/as-self-test.c36
1 files changed, 36 insertions, 0 deletions
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);