| 1 |
/* |
| 2 |
* Copyright (C) 2019 Grilo Project |
| 3 |
* |
| 4 |
* Author: Jean Felder <[email protected]> |
| 5 |
* |
| 6 |
* This library is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU Lesser General Public License |
| 8 |
* as published by the Free Software Foundation; version 2.1 of |
| 9 |
* the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This library is distributed in the hope that it will be useful, but |
| 12 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
* Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this library; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 19 |
* 02110-1301 USA |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
#include <locale.h> |
| 24 |
#include "test_lua_factory_utils.h" |
| 25 |
|
| 26 |
#define THEAUDIODB_ID "grl-theaudiodb-cover" |
| 27 |
|
| 28 |
#define TEST_PLUGINS_PATH LUA_FACTORY_PLUGIN_PATH |
| 29 |
#define TEST_PLUGINS_LOAD LUA_FACTORY_ID |
| 30 |
|
| 31 |
#define THEAUDIODB_OPS GRL_OP_RESOLVE |
| 32 |
|
| 33 |
static void |
| 34 |
test_resolve_album_cover (void) |
| 35 |
{ |
| 36 |
guint i, expected_nr_thumbnails; |
| 37 |
GList *keys; |
| 38 |
GrlMedia *media; |
| 39 |
GrlOperationOptions *options; |
| 40 |
GrlSource *source; |
| 41 |
GError *error = NULL; |
| 42 |
|
| 43 |
struct { |
| 44 |
gchar *artist; |
| 45 |
gchar *album; |
| 46 |
guint nr_thumbnails; |
| 47 |
gchar *first_thumbnail; |
| 48 |
gchar *second_thumbnail; |
| 49 |
} audios[] = { |
| 50 |
{ "pixies", "doolittle", |
| 51 |
2, |
| 52 |
"https://www.theaudiodb.com/images/media/album/thumb/doolittle-4e3a8a18cb017.jpg", |
| 53 |
"https://www.theaudiodb.com/images/media/album/cdart/doolittle-4e73926514e07.png" |
| 54 |
}, |
| 55 |
{ |
| 56 |
"nirvana", "nevermind", |
| 57 |
2, |
| 58 |
"https://www.theaudiodb.com/images/media/album/thumb/nevermind-4dcdd240da9e2.jpg", |
| 59 |
"https://www.theaudiodb.com/images/media/album/cdart/nevermind-5232416c46820.png" |
| 60 |
}, |
| 61 |
}; |
| 62 |
|
| 63 |
source = test_lua_factory_get_source (THEAUDIODB_ID, THEAUDIODB_OPS); |
| 64 |
|
| 65 |
keys = grl_metadata_key_list_new (GRL_METADATA_KEY_THUMBNAIL); |
| 66 |
options = grl_operation_options_new (NULL); |
| 67 |
grl_operation_options_set_resolution_flags (options, GRL_RESOLVE_NORMAL); |
| 68 |
|
| 69 |
for (i = 0; i < G_N_ELEMENTS (audios); i++) { |
| 70 |
media = grl_media_audio_new (); |
| 71 |
grl_media_set_album (media, audios[i].album); |
| 72 |
grl_media_set_artist (media, audios[i].artist); |
| 73 |
|
| 74 |
grl_source_resolve_sync (source, |
| 75 |
GRL_MEDIA (media), |
| 76 |
keys, |
| 77 |
options, |
| 78 |
&error); |
| 79 |
g_assert_no_error (error); |
| 80 |
|
| 81 |
expected_nr_thumbnails = grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_THUMBNAIL); |
| 82 |
g_assert_cmpuint (expected_nr_thumbnails, ==, audios[i].nr_thumbnails); |
| 83 |
|
| 84 |
g_assert_cmpstr (grl_media_get_thumbnail_nth (GRL_MEDIA (media), 0), ==, audios[i].first_thumbnail); |
| 85 |
g_assert_cmpstr (grl_media_get_thumbnail_nth (GRL_MEDIA (media), 1), ==, audios[i].second_thumbnail); |
| 86 |
|
| 87 |
g_object_unref (media); |
| 88 |
} |
| 89 |
|
| 90 |
g_list_free (keys); |
| 91 |
g_object_unref (options); |
| 92 |
} |
| 93 |
|
| 94 |
static void |
| 95 |
test_resolve_artist_art (void) |
| 96 |
{ |
| 97 |
guint i, j, expected_nr_thumbnails; |
| 98 |
GList *keys; |
| 99 |
GrlMedia *media; |
| 100 |
GrlOperationOptions *options; |
| 101 |
GrlSource *source; |
| 102 |
GError *error = NULL; |
| 103 |
|
| 104 |
struct { |
| 105 |
gchar *artist; |
| 106 |
int nr_thumbnails; |
| 107 |
gchar *thumbnails[5]; |
| 108 |
} audios[] = { |
| 109 |
{ "coldplay", |
| 110 |
5, |
| 111 |
{ "https://www.theaudiodb.com/images/media/artist/thumb/uxrqxy1347913147.jpg", |
| 112 |
"https://www.theaudiodb.com/images/media/artist/clearart/ruyuwv1510827568.png", |
| 113 |
"https://www.theaudiodb.com/images/media/artist/fanart/spvryu1347980801.jpg", |
| 114 |
"https://www.theaudiodb.com/images/media/artist/fanart/uupyxx1342640221.jpg", |
| 115 |
"https://www.theaudiodb.com/images/media/artist/fanart/qstpsp1342640238.jpg" |
| 116 |
} |
| 117 |
}, |
| 118 |
{ |
| 119 |
"system of a down", |
| 120 |
4, |
| 121 |
{ "https://www.theaudiodb.com/images/media/artist/thumb/tutqyy1340536730.jpg", |
| 122 |
"https://www.theaudiodb.com/images/media/artist/fanart/system-of-a-down-4def4cf79b8f7.jpg", |
| 123 |
"https://www.theaudiodb.com/images/media/artist/fanart/system-of-a-down-4ddaf61d98ce2.jpg", |
| 124 |
"https://www.theaudiodb.com/images/media/artist/fanart/system-of-a-down-4def4d1583fcc.jpg" |
| 125 |
} |
| 126 |
}, |
| 127 |
}; |
| 128 |
|
| 129 |
source = test_lua_factory_get_source (THEAUDIODB_ID, THEAUDIODB_OPS); |
| 130 |
|
| 131 |
keys = grl_metadata_key_list_new (GRL_METADATA_KEY_THUMBNAIL); |
| 132 |
options = grl_operation_options_new (NULL); |
| 133 |
grl_operation_options_set_resolution_flags (options, GRL_RESOLVE_NORMAL); |
| 134 |
|
| 135 |
for (i = 0; i < G_N_ELEMENTS (audios); i++) { |
| 136 |
media = grl_media_audio_new (); |
| 137 |
grl_media_set_artist (media, audios[i].artist); |
| 138 |
|
| 139 |
grl_source_resolve_sync (source, |
| 140 |
GRL_MEDIA (media), |
| 141 |
keys, |
| 142 |
options, |
| 143 |
&error); |
| 144 |
g_assert_no_error (error); |
| 145 |
|
| 146 |
expected_nr_thumbnails = grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_THUMBNAIL); |
| 147 |
g_assert_cmpuint (expected_nr_thumbnails, ==, audios[i].nr_thumbnails); |
| 148 |
|
| 149 |
for (j = 0; j < expected_nr_thumbnails; j++) { |
| 150 |
g_assert_cmpstr (grl_media_get_thumbnail_nth (GRL_MEDIA (media), j), ==, audios[i].thumbnails[j]); |
| 151 |
} |
| 152 |
|
| 153 |
g_object_unref (media); |
| 154 |
} |
| 155 |
|
| 156 |
g_list_free (keys); |
| 157 |
g_object_unref (options); |
| 158 |
} |
| 159 |
|
| 160 |
static void |
| 161 |
test_theaudiodb_setup (gint *p_argc, |
| 162 |
gchar ***p_argv) |
| 163 |
{ |
| 164 |
GrlConfig *config; |
| 165 |
|
| 166 |
g_setenv ("GRL_PLUGIN_PATH", TEST_PLUGINS_PATH, TRUE); |
| 167 |
g_setenv ("GRL_PLUGIN_LIST", TEST_PLUGINS_LOAD, TRUE); |
| 168 |
g_setenv ("GRL_LUA_SOURCES_PATH", LUA_FACTORY_SOURCES_PATH, TRUE); |
| 169 |
g_setenv ("GRL_NET_MOCKED", LUA_FACTORY_SOURCES_DATA_PATH "config.ini", TRUE); |
| 170 |
|
| 171 |
grl_init (p_argc, p_argv); |
| 172 |
g_test_init (p_argc, p_argv, NULL); |
| 173 |
|
| 174 |
config = grl_config_new (LUA_FACTORY_ID, THEAUDIODB_ID); |
| 175 |
grl_config_set_api_key (config, "THEAUDIODB_TEST_MOCK_API_KEY"); |
| 176 |
test_lua_factory_setup (config); |
| 177 |
} |
| 178 |
|
| 179 |
gint |
| 180 |
main (gint argc, gchar **argv) |
| 181 |
{ |
| 182 |
setlocale (LC_ALL, ""); |
| 183 |
|
| 184 |
test_theaudiodb_setup (&argc, &argv); |
| 185 |
|
| 186 |
g_test_add_func ("/lua_factory/sources/theaudiodb/resolve/albumcover", |
| 187 |
test_resolve_album_cover); |
| 188 |
|
| 189 |
g_test_add_func ("/lua_factory/sources/theaudiodb/resolve/artistart", |
| 190 |
test_resolve_artist_art); |
| 191 |
|
| 192 |
gint result = g_test_run (); |
| 193 |
|
| 194 |
test_lua_factory_shutdown (); |
| 195 |
test_lua_factory_deinit (); |
| 196 |
|
| 197 |
return result; |
| 198 |
} |