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 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
|
/*
* Copyright (C) 2014 Igalia S.L.
*
* Author: Juan A. Suarez Romero <jasuarez@igalia.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 <locale.h>
#include <grilo.h>
#define THEGAMESDB "grl-thegamesdb"
static GrlMedia *
build_game_media (const gchar *title)
{
GrlMedia *media;
media = grl_media_new ();
grl_media_set_title (media, title);
return media;
}
static void
test_setup (void)
{
GError *error = NULL;
GrlRegistry *registry;
registry = grl_registry_get_default ();
grl_registry_load_all_plugins (registry, TRUE, &error);
g_assert_no_error (error);
}
#define DESCRIPTION "Set in the future, the game centers around a secret organization of ninja-like operatives known as \"Striders\", who specializes in various kinds of wetworks such as smuggling, kidnapping, demolitions, and disruption. The player takes control Strider Hiryu, the youngest elite-class Strider in the organization. Hiryu is summoned by the organization's second-in-command, Vice Director Matic, to assassinate his friend Kain, who has been captured by hostile forces and has become a liability to the Striders. Instead of killing him, Hiryu decides to rescue Kain from his captors. With the help of his fellow Strider Sheena, Hiryu uncovers a conspiracy between a certain faction of the Strider organization led by Matic himself and an unknown organization known simply as the \"Enterprise\" (headed by a man named Faceas Clay) which involves the development of a mind-control weapon codenamed \"Zain\". In the course of finding and destroying these Zain units, Hiryu learns that the faction of conspirators is headed by Vice Director Matic himself. Hiryu eventually tracks Matic to an orbiting space station where the two Striders face off; after a brief battle Hiryu bests Matic and kills him. Afterwards Hiryu locates and destroys the last of the Zain units.\n\nIn the epilogue, it is revealed that though Hiryu was asked to return to the Strider organization he instead opted to retire. The final credits show him sheathing his weapon and walking away."
static void
test_resolve_good_found (void)
{
GError *error = NULL;
GList *keys;
GrlMedia *media;
GrlOperationOptions *options;
GrlRegistry *registry;
GrlSource *source;
GDateTime *date_time;
guint expected_n_thumbnails, expected_n_external_urls;
registry = grl_registry_get_default ();
source = grl_registry_lookup_source (registry, THEGAMESDB);
g_assert (source);
media = build_game_media ("Strider");
grl_media_set_mime (media, "application/x-genesis-rom");
keys = grl_metadata_key_list_new (GRL_METADATA_KEY_THUMBNAIL,
GRL_METADATA_KEY_DESCRIPTION,
GRL_METADATA_KEY_EXTERNAL_URL,
GRL_METADATA_KEY_RATING,
GRL_METADATA_KEY_PUBLICATION_DATE,
GRL_METADATA_KEY_ORIGINAL_TITLE,
NULL);
options = grl_operation_options_new (NULL);
grl_operation_options_set_resolution_flags (options, GRL_RESOLVE_FULL);
grl_source_resolve_sync (source, media, keys, options, &error);
g_assert_no_error (error);
/* We should get a thumbnail */
expected_n_thumbnails = grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_THUMBNAIL);
g_assert_cmpuint (expected_n_thumbnails, ==, 1);
g_assert_cmpstr (grl_media_get_thumbnail_nth (media, 0),
==,
"http://thegamesdb.net/banners/boxart/original/front/702-1.jpg");
g_assert_cmpstr (grl_media_get_description (media),
==,
DESCRIPTION);
expected_n_external_urls = grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_EXTERNAL_URL);
g_assert_cmpuint (expected_n_external_urls, ==, 1);
g_assert_cmpstr (grl_media_get_external_url (media),
==,
"http://thegamesdb.net/game/702/");
/* Comparing floats fails with: (3.71000004 == 3.71) */
g_assert_cmpint (grl_media_get_rating (media) * 100, ==, 300);
date_time = grl_media_get_publication_date (media);
g_assert_cmpint (g_date_time_get_year (date_time), ==, 1989);
g_list_free (keys);
g_object_unref (options);
g_object_unref (media);
}
static void
test_resolve_thumbnail_found (GrlSource *source,
GList *keys,
GrlOperationOptions *options,
const gchar *title,
const gchar *mime,
const gchar *url,
guint expected_thumbnail_index,
const gchar *expected_thumbnail_url)
{
GError *error = NULL;
GrlMedia *media;
guint expected_n_thumbnails;
media = build_game_media (title);
grl_media_set_mime (media, mime);
grl_media_set_url (media, url);
grl_operation_options_set_resolution_flags (options, GRL_RESOLVE_FULL);
grl_source_resolve_sync (source, media, keys, options, &error);
g_assert_no_error (error);
/* We should get a thumbnail */
expected_n_thumbnails = grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_THUMBNAIL);
g_assert_cmpuint (expected_n_thumbnails, >, 0);
g_assert_cmpstr (grl_media_get_thumbnail_nth (media, expected_thumbnail_index),
==,
expected_thumbnail_url);
g_object_unref (media);
}
static void
test_resolve_thumbnails_found (void)
{
GList *keys;
GrlOperationOptions *options;
GrlRegistry *registry;
GrlSource *source;
registry = grl_registry_get_default ();
source = grl_registry_lookup_source (registry, THEGAMESDB);
g_assert (source);
keys = grl_metadata_key_list_new (GRL_METADATA_KEY_THUMBNAIL,
NULL);
options = grl_operation_options_new (NULL);
grl_operation_options_set_resolution_flags (options, GRL_RESOLVE_FULL);
test_resolve_thumbnail_found (source, keys, options,
"Kirby & the Amazing Mirror",
"application/x-gba-rom",
NULL,
0,
"http://thegamesdb.net/banners/boxart/original/front/2336-1.png");
test_resolve_thumbnail_found (source, keys, options,
"Kirby's Dream Land",
"application/x-gameboy-rom",
NULL,
0,
"http://thegamesdb.net/banners/boxart/original/front/8706-1.jpg");
test_resolve_thumbnail_found (source, keys, options,
"Sonic the Hedgehog",
"application/x-sms-rom",
NULL,
0,
"http://thegamesdb.net/banners/boxart/original/front/3016-1.jpg");
test_resolve_thumbnail_found (source, keys, options,
"Sonic the Hedgehog",
"application/x-sms-rom",
"sonic.gg",
0,
"http://thegamesdb.net/banners/boxart/original/front/5754-1.jpg");
test_resolve_thumbnail_found (source, keys, options,
"Astérix",
"application/x-gamegear-rom",
NULL,
0,
"http://thegamesdb.net/banners/boxart/original/front/11837-1.jpg");
test_resolve_thumbnail_found (source, keys, options,
"Shatterhand",
"application/x-nes-rom",
NULL,
0,
"http://thegamesdb.net/banners/boxart/original/front/22619-1.jpg");
g_list_free (keys);
g_object_unref (options);
}
static void
test_resolve_genre_found (GrlSource *source,
GList *keys,
GrlOperationOptions *options,
const gchar *title,
const gchar *mime,
guint no_of_genres)
{
GError *error = NULL;
GrlMedia *media;
guint expected_n_genres;
media = build_game_media (title);
grl_media_set_mime (media, mime);
grl_operation_options_set_resolution_flags (options, GRL_RESOLVE_FULL);
grl_source_resolve_sync (source, media, keys, options, &error);
g_assert_no_error (error);
/* We should get a genre */
expected_n_genres = grl_data_length (GRL_DATA (media), GRL_METADATA_KEY_GENRE);
g_assert_cmpuint (expected_n_genres, ==, no_of_genres);
g_object_unref (media);
}
static void
test_resolve_genres_found (void)
{
GList *keys;
GrlOperationOptions *options;
GrlRegistry *registry;
GrlSource *source;
registry = grl_registry_get_default ();
source = grl_registry_lookup_source (registry, THEGAMESDB);
g_assert (source);
keys = grl_metadata_key_list_new (GRL_METADATA_KEY_GENRE,
NULL);
options = grl_operation_options_new (NULL);
grl_operation_options_set_resolution_flags (options, GRL_RESOLVE_FULL);
test_resolve_genre_found (source, keys, options,
"Astérix",
"application/x-gamegear-rom",
1);
test_resolve_genre_found (source, keys, options,
"Shatterhand",
"application/x-nes-rom",
2);
g_list_free (keys);
g_object_unref (options);
}
static void
test_resolve_key_found (GrlRegistry *registry,
GrlSource *source,
GList *keys,
GrlOperationOptions *options,
const gchar *key_name,
const gchar *title,
const gchar *mime,
guint no_of_values)
{
GError *error = NULL;
GrlMedia *media;
GrlKeyID key;
guint expected_n_values;
media = build_game_media (title);
grl_media_set_mime (media, mime);
grl_operation_options_set_resolution_flags (options, GRL_RESOLVE_FULL);
key = grl_registry_lookup_metadata_key (registry, key_name);
g_assert_cmpuint (key, ==, GRL_METADATA_KEY_INVALID);
grl_source_resolve_sync (source, media, keys, options, &error);
g_assert_no_error (error);
key = grl_registry_lookup_metadata_key (registry, key_name);
g_assert_cmpuint (key, !=, GRL_METADATA_KEY_INVALID);
/* We should get a value */
expected_n_values = grl_data_length (GRL_DATA (media), key);
g_assert_cmpuint (expected_n_values, ==, no_of_values);
g_object_unref (media);
}
static void
test_resolve_keys_found (void)
{
GList *keys;
GrlOperationOptions *options;
GrlRegistry *registry;
GrlSource *source;
registry = grl_registry_get_default ();
source = grl_registry_lookup_source (registry, THEGAMESDB);
g_assert (source);
keys = grl_metadata_key_list_new (GRL_METADATA_KEY_GENRE,
NULL);
options = grl_operation_options_new (NULL);
grl_operation_options_set_resolution_flags (options, GRL_RESOLVE_FULL);
test_resolve_key_found (registry, source, keys, options,
"developer",
"Kirby & the Amazing Mirror",
"application/x-gba-rom",
1);
g_list_free (keys);
g_object_unref (options);
}
int
main(int argc, char **argv)
{
gint result;
setlocale (LC_ALL, "");
g_setenv ("GRL_PLUGIN_PATH", LUA_FACTORY_PLUGIN_PATH, TRUE);
g_setenv ("GRL_LUA_SOURCES_PATH", LUA_SOURCES_PATH, TRUE);
g_setenv ("GRL_PLUGIN_LIST", "grl-lua-factory", TRUE);
g_setenv ("GRL_NET_MOCKED", GAMES_DATA_PATH "network-data.ini", TRUE);
grl_init (&argc, &argv);
g_test_init (&argc, &argv, NULL);
test_setup ();
/* FIXME: Move tests to g_test_add() to init/deinit the registry for each test */
g_test_add_func ("/thegamesdb/resolve/keys-found", test_resolve_keys_found);
g_test_add_func ("/thegamesdb/resolve/good-found", test_resolve_good_found);
g_test_add_func ("/thegamesdb/resolve/thumbnails-found", test_resolve_thumbnails_found);
g_test_add_func ("/thegamesdb/resolve/genre-found", test_resolve_genres_found);
result = g_test_run ();
grl_deinit ();
return result;
}
|