1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
* Copyright (C) 2012 Openismus GmbH
*
* Author: Jens Georg <jensg@openismus.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*
*/
#include <grilo.h>
#include "test_tmdb_utils.h"
#include <math.h>
#include <float.h>
#define TMDB_PLUGIN_ID "grl-tmdb"
/** Compare the floats.
* A simple == will fail on values that are effectively the same,
* due to rounding issues.
*/
static gboolean compare_floats(gfloat a, gfloat b)
{
return fabs(a - b) < DBL_EPSILON;
}
static void
test_fast_resolution_by_id (void)
{
GrlKeyID backdrop, posters, tmdb_id;
GrlRegistry *registry;
GrlOperationOptions *options = NULL;
GrlMedia *media = NULL;
GError *error = NULL;
test_setup_tmdb ();
registry = grl_registry_get_default ();
backdrop = grl_registry_lookup_metadata_key (registry, "tmdb-backdrop");
g_assert_cmpint (backdrop, !=, GRL_METADATA_KEY_INVALID);
posters = grl_registry_lookup_metadata_key (registry, "tmdb-poster");
g_assert_cmpint (posters, !=, GRL_METADATA_KEY_INVALID);
tmdb_id = grl_registry_lookup_metadata_key (registry, "tmdb-id");
g_assert_cmpint (tmdb_id, !=, GRL_METADATA_KEY_INVALID);
options = grl_operation_options_new (NULL);
g_assert (options != NULL);
grl_operation_options_set_resolution_flags (options, GRL_RESOLVE_FAST_ONLY);
media = grl_media_video_new ();
g_assert (media != NULL);
grl_data_set_string (GRL_DATA (media), tmdb_id, "10528");
GrlSource *source = test_get_source();
g_assert (source);
grl_source_resolve_sync (source,
media,
grl_source_supported_keys (source),
options,
&error);
/* Fast resolution must not result in an error if the details are missing */
g_assert (error == NULL);
/* Check if we have everything we need */
g_assert (compare_floats (grl_media_get_rating (media), 3.8f));
g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), GRL_METADATA_KEY_ORIGINAL_TITLE), ==,
"Sherlock Holmes");
/* There's only one poster/backdrop in the search result */
g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), backdrop), ==,
"http://cf2.imgobject.com/t/p/original/uM414ugc1B910bTvGEIzsucfMMC.jpg");
g_assert_cmpstr (grl_data_get_string (GRL_DATA (media), posters), ==,
"http://cf2.imgobject.com/t/p/original/22ngurXbLqab7Sko6aTSdwOCe5W.jpg");
g_assert (grl_media_get_publication_date (media) == NULL);
g_clear_object (&media);
g_clear_object (&options);
test_shutdown_tmdb ();
}
int
main(int argc, char **argv)
{
g_setenv ("GRL_PLUGIN_PATH", GRILO_PLUGINS_TESTS_TMDB_PLUGIN_PATH, TRUE);
g_setenv ("GRL_PLUGIN_LIST", TMDB_PLUGIN_ID, TRUE);
/* We must set this before calling grl_init.
* See https://bugzilla.gnome.org/show_bug.cgi?id=685967#c17
*/
g_setenv ("GRL_NET_MOCKED", GRILO_PLUGINS_TESTS_TMDB_DATA_PATH "fast-by-id.ini", TRUE);
grl_init (&argc, &argv);
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/tmdb/fast-resolution-by-id", test_fast_resolution_by_id);
gint result = g_test_run ();
grl_deinit ();
return result;
}
|