| 1 |
/* |
| 2 |
* Copyright (C) 2015. All rights reserved. |
| 3 |
* |
| 4 |
* Author: Victor Toso <[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 "test_lua_factory_utils.h" |
| 24 |
|
| 25 |
void |
| 26 |
test_lua_factory_init (gint *p_argc, |
| 27 |
gchar ***p_argv, |
| 28 |
gboolean net_mocked) |
| 29 |
{ |
| 30 |
g_setenv ("GRL_PLUGIN_PATH", LUA_FACTORY_PLUGIN_PATH, TRUE); |
| 31 |
g_setenv ("GRL_PLUGIN_LIST", LUA_FACTORY_ID, TRUE); |
| 32 |
g_setenv ("GRL_LUA_SOURCES_PATH", LUA_FACTORY_SOURCES_PATH, TRUE); |
| 33 |
|
| 34 |
/* For some sources it doesn't make sense to mock the network request, |
| 35 |
* mainly because is hard to track changes in the provider of data. |
| 36 |
* (e.g. if source rely on a website) */ |
| 37 |
if (net_mocked) { |
| 38 |
g_setenv ("GRL_NET_MOCKED", LUA_FACTORY_PLUGIN_TEST_DATA_PATH "config.ini", TRUE); |
| 39 |
} |
| 40 |
|
| 41 |
grl_init (p_argc, p_argv); |
| 42 |
g_test_init (p_argc, p_argv, NULL); |
| 43 |
} |
| 44 |
|
| 45 |
void |
| 46 |
test_lua_factory_setup (GrlConfig *config) |
| 47 |
{ |
| 48 |
GrlRegistry *registry; |
| 49 |
GError *error = NULL; |
| 50 |
|
| 51 |
registry = grl_registry_get_default (); |
| 52 |
|
| 53 |
if (config != NULL) { |
| 54 |
grl_registry_add_config (registry, config, &error); |
| 55 |
g_assert_no_error (error); |
| 56 |
} |
| 57 |
|
| 58 |
grl_registry_load_plugin (registry, LUA_FACTORY_PLUGIN_PATH "/libgrlluafactory.so", &error); |
| 59 |
g_assert_no_error (error); |
| 60 |
grl_registry_activate_plugin_by_id (registry, LUA_FACTORY_ID, &error); |
| 61 |
g_assert_no_error (error); |
| 62 |
} |
| 63 |
|
| 64 |
GrlSource* |
| 65 |
test_lua_factory_get_source (gchar *source_id, |
| 66 |
GrlSupportedOps source_ops) |
| 67 |
{ |
| 68 |
GrlRegistry *registry = grl_registry_get_default (); |
| 69 |
GrlSource *source = grl_registry_lookup_source (registry, source_id); |
| 70 |
g_assert_nonnull (source); |
| 71 |
g_assert (grl_source_supported_operations (source) & source_ops); |
| 72 |
return source; |
| 73 |
} |
| 74 |
|
| 75 |
void |
| 76 |
test_lua_factory_shutdown (void) |
| 77 |
{ |
| 78 |
GrlRegistry *registry; |
| 79 |
GError *error = NULL; |
| 80 |
|
| 81 |
registry = grl_registry_get_default (); |
| 82 |
grl_registry_unload_plugin (registry, LUA_FACTORY_ID, &error); |
| 83 |
g_assert_no_error (error); |
| 84 |
} |
| 85 |
|
| 86 |
void |
| 87 |
test_lua_factory_deinit (void) |
| 88 |
{ |
| 89 |
grl_deinit (); |
| 90 |
} |
| 91 |
|