[grilo-plugins/tmdb-test] tests: tmdb: Test the age certificate API too.



commit b85a525fdc231b728bc0fa92cd2344c2b28eb9c5
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Nov 14 10:48:39 2012 +0100

    tests: tmdb: Test the age certificate API too.

 test/test_tmdb_full_resolution.c |   49 +++++++++++++++++++++++++++++++------
 1 files changed, 41 insertions(+), 8 deletions(-)
---
diff --git a/test/test_tmdb_full_resolution.c b/test/test_tmdb_full_resolution.c
index be9c404..7b031ee 100644
--- a/test/test_tmdb_full_resolution.c
+++ b/test/test_tmdb_full_resolution.c
@@ -31,11 +31,39 @@
  * A simple == will fail on values that are effectively the same,
  * due to rounding issues.
  */
-static gboolean compare_floats(gfloat a, gfloat b)
+static gboolean
+compare_floats(gfloat a, gfloat b)
 {
    return fabs(a - b) < DBL_EPSILON;
 }
 
+static const gchar*
+get_region_certificate (GrlMedia *media, const gchar *region)
+{
+  guint count = grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_REGION);
+  for (guint i = 0; i < count; ++i) {
+    const GDateTime* publication_date = NULL;
+    const gchar *certificate = NULL;
+    const gchar *this_region =
+    grl_media_get_region_data_nth (media, i,
+      &publication_date, &certificate);
+
+    /* printf("idnex=%d, region=%s, cert=%s\n", i, this_region, certificate); */
+
+    if(g_strcmp0 (region, this_region) == 0)
+      return certificate;
+  }
+
+  return NULL;
+}
+
+static void
+test_region_certificate (GrlMedia *media, const gchar *region, const gchar *expected_certificate)
+{
+  const gchar *certificate = get_region_certificate (media, region);
+  g_assert_cmpstr(certificate, ==, expected_certificate);
+}
+
 #define DESCRIPTION \
 "In a dynamic new portrayal of Arthur Conan Doyleâs most famous characters, âSherlock Holmesâ sends Holmes and his stalwart partner Watson on their latest challenge. Revealing fighting skills as lethal as his legendary intellect, Holmes will battle as never before to bring down a new nemesis and unravel a deadly plot that could destroy England."
 
@@ -103,9 +131,8 @@ test (void)
 
   g_assert_cmpstr (grl_media_get_description (media), ==, DESCRIPTION);
 
-  /* TODO: See https://bugzilla.gnome.org/show_bug.cgi?id=679686#c13
-  g_assert_cmpstr (grl_media_get_certificate (media), ==, "PG-13");
-  */
+   /* TODO: Uncomment this. It is returning NULL. See below. */
+  /* g_assert_cmpstr (grl_media_get_certificate (media), ==, "PG-13"); */
 
   g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), imdb_id), ==, "tt0988045");
   g_assert_cmpint (grl_data_length (GRL_DATA (media), keywords), ==, 15);
@@ -117,10 +144,16 @@ test (void)
   g_assert_cmpint (grl_data_length (GRL_DATA (media), director), ==, 1);
   g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), director), ==, "Guy Ritchie");
 
-  /* TODO: See https://bugzilla.gnome.org/show_bug.cgi?id=679686#c13
-  g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), age_certs), ==,
-                   "GB:12A;NL:12;BG:C;HU:16;DE:12;DK:15;US:PG-13");
-  */
+  guint count = grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_REGION);
+  g_assert_cmpint (count, ==, 9);  /* TODO: This should be 8. The first one (index=0) is NULL, NULL. */
+  test_region_certificate (media, "GB", "12A");
+  test_region_certificate (media, "FR", ""); /* TODO: Should this be here? */
+  test_region_certificate (media, "NL", "12");
+  test_region_certificate (media, "BG", "C");
+  test_region_certificate (media, "HU", "16");
+  test_region_certificate (media, "DE", "12");
+  test_region_certificate (media, "DK", "15");
+  test_region_certificate (media, "US", "PG-13");
 
   g_object_unref (media);
   media = NULL;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]