summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Toso <me@victortoso.com>2018-10-02 15:20:26 +0200
committerVictor Toso <me@victortoso.com>2018-10-02 16:24:47 +0200
commit009372748b1d795c2e8347b745f54cd8c708d955 (patch)
tree62b67bd39c4c42336aa05f2baa82380f980fd127
parentaf568e8ca8e0bc65cffa0a1c6859e0ec9c9f4b13 (diff)
downloadgrilo-009372748b1d795c2e8347b745f54cd8c708d955.tar.gz
tests: Supported metadata-key transformations
Grilo got support to transform similar GValues while using grl_data_add_for_id() and grl_data_set_for() API. This commmit include tests to verify supported and unsupported GValues. Signed-off-by: Victor Toso <victortoso@gnome.org>
-rw-r--r--tests/media.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/tests/media.c b/tests/media.c
index 6d228c5..ec00ad8 100644
--- a/tests/media.c
+++ b/tests/media.c
@@ -166,6 +166,62 @@ test_set_for_id_existing_key (Fixture *fixture, gconstpointer data)
#undef TEST_EXISTING
}
+static void
+test_set_for_id_different_key_type (Fixture *fixture, gconstpointer data)
+{
+ gboolean is_set_op = GPOINTER_TO_INT (data);
+
+#define TEST_OTHER_GTYPE(key_name, value_type, getter, value, success) { \
+ GrlKeyID key_id = grl_registry_lookup_metadata_key (fixture->registry, key_name); \
+ g_assert_true (key_id != GRL_METADATA_KEY_INVALID); \
+ GType key_type = grl_registry_lookup_metadata_key_type (fixture->registry, \
+ key_id); \
+ g_assert_true (key_type != value_type); \
+ \
+ GValue key_value = G_VALUE_INIT; \
+ g_value_init (&key_value, value_type); \
+ g_value_set_##getter (&key_value, value); \
+ \
+ GrlMedia *media = grl_media_new (); \
+ if (!success) \
+ g_test_expect_message ("Grilo", G_LOG_LEVEL_WARNING, \
+ "*Value type*can't be set to*of type*"); \
+ if (is_set_op) { \
+ g_assert_##success (grl_data_set_for_id (GRL_DATA (media), key_name, &key_value)); \
+ } else { \
+ g_assert_##success (grl_data_set_for_id (GRL_DATA (media), key_name, &key_value)); \
+ } \
+ if (!success) \
+ g_test_assert_expected_messages (); \
+ g_object_unref (media); \
+ }
+
+ /* Works */
+
+ /* duration is int */
+ TEST_OTHER_GTYPE("duration", G_TYPE_INT64, int64, 302, true);
+ TEST_OTHER_GTYPE("duration", G_TYPE_FLOAT, float, 303.1, true);
+ TEST_OTHER_GTYPE("duration", G_TYPE_BOOLEAN, boolean, TRUE, true);
+ /* title is string */
+ TEST_OTHER_GTYPE("title", G_TYPE_INT64, int64, 666, true);
+ TEST_OTHER_GTYPE("title", G_TYPE_FLOAT, float, 303.1, true);
+ TEST_OTHER_GTYPE("title", G_TYPE_BOOLEAN, boolean, TRUE, true);
+ /* rating is float */
+ TEST_OTHER_GTYPE("rating", G_TYPE_INT64, int64, 302, true);
+ TEST_OTHER_GTYPE("rating", G_TYPE_UINT64, uint64, G_MAXUINT64, true);
+
+ /* Fails */
+
+ TEST_OTHER_GTYPE("duration", G_TYPE_STRING, string, "301", false);
+ TEST_OTHER_GTYPE("favourite", G_TYPE_STRING, string, "true", false);
+ TEST_OTHER_GTYPE("favourite", G_TYPE_STRING, string, "FALSE", false);
+ TEST_OTHER_GTYPE("favourite", G_TYPE_STRING, string, NULL, false);
+ TEST_OTHER_GTYPE("rating", G_TYPE_BOOLEAN, boolean, TRUE, false);
+ TEST_OTHER_GTYPE("rating", G_TYPE_STRING, string, "304.2", false);
+
+#undef TEST_OTHER_GTYPE
+}
+
int
main (int argc, char **argv)
{
@@ -199,5 +255,17 @@ main (int argc, char **argv)
test_set_for_id_existing_key,
fixture_teardown);
+ g_test_add ("/data/different-key-type/set-for-id",
+ Fixture, GINT_TO_POINTER (TRUE),
+ fixture_setup,
+ test_set_for_id_different_key_type,
+ fixture_teardown);
+
+ g_test_add ("/data/different-key-type/add-for-id",
+ Fixture, GINT_TO_POINTER (FALSE),
+ fixture_setup,
+ test_set_for_id_different_key_type,
+ fixture_teardown);
+
return g_test_run ();
}