2021-03-23 13:20:24 +00:00
/*
2021-04-09 13:07:30 +00:00
* Copyright ( C ) 2021 Purism SPC
2021-03-23 13:20:24 +00:00
*
* SPDX - License - Identifier : GPL - 3.0 +
*
* Author : Evangelos Ribeiro Tzaras < evangelos . tzaras @ puri . sm >
*/
2022-10-26 13:09:11 +00:00
# include "config.h"
2021-03-23 13:20:24 +00:00
# include "calls-provider.h"
# include <gtk/gtk.h>
# include <libpeas/peas.h>
static void
2021-06-02 18:18:50 +00:00
test_calls_plugin_loading ( void )
2021-03-23 13:20:24 +00:00
{
g_autoptr ( CallsProvider ) dummy_provider = NULL ;
g_autoptr ( CallsProvider ) mm_provider = NULL ;
g_autoptr ( CallsProvider ) ofono_provider = NULL ;
2021-04-05 00:05:00 +00:00
g_autoptr ( CallsProvider ) sip_provider = NULL ;
2021-03-23 13:20:24 +00:00
g_autoptr ( CallsProvider ) not_a_provider = NULL ;
2021-04-02 17:50:09 +00:00
dummy_provider = calls_provider_load_plugin ( " dummy " ) ;
2021-03-23 13:20:24 +00:00
g_assert_nonnull ( dummy_provider ) ;
2021-04-02 17:50:09 +00:00
mm_provider = calls_provider_load_plugin ( " mm " ) ;
2021-03-23 13:20:24 +00:00
g_assert_nonnull ( mm_provider ) ;
2021-04-02 17:50:09 +00:00
ofono_provider = calls_provider_load_plugin ( " ofono " ) ;
2021-03-23 13:20:24 +00:00
g_assert_nonnull ( ofono_provider ) ;
2021-04-05 00:05:00 +00:00
sip_provider = calls_provider_load_plugin ( " sip " ) ;
g_assert_nonnull ( sip_provider ) ;
2021-04-02 17:50:09 +00:00
not_a_provider = calls_provider_load_plugin ( " not-a-valid-provider-plugin " ) ;
2021-03-23 13:20:24 +00:00
g_assert_null ( not_a_provider ) ;
2021-04-02 17:50:09 +00:00
calls_provider_unload_plugin ( " dummy " ) ;
calls_provider_unload_plugin ( " mm " ) ;
calls_provider_unload_plugin ( " ofono " ) ;
2021-04-05 00:05:00 +00:00
calls_provider_unload_plugin ( " sip " ) ;
2021-03-23 13:20:24 +00:00
}
gint
main ( gint argc ,
gchar * argv [ ] )
{
2022-10-26 13:09:11 +00:00
PeasEngine * peas ;
const gchar * dir ;
g_autofree char * default_plugin_dir_provider = NULL ;
2022-07-16 20:16:24 +00:00
2021-03-23 13:20:24 +00:00
gtk_test_init ( & argc , & argv , NULL ) ;
2022-10-26 13:09:11 +00:00
peas = peas_engine_get_default ( ) ;
2022-11-19 13:08:11 +00:00
dir = g_getenv ( " CALLS_PLUGIN_DIR " ) ;
if ( dir & & dir [ 0 ] ! = ' \0 ' ) {
g_autofree char * plugin_dir_provider = NULL ;
plugin_dir_provider = g_build_filename ( dir , " provider " , NULL ) ;
2022-09-22 15:54:44 +00:00
if ( g_file_test ( plugin_dir_provider , G_FILE_TEST_EXISTS ) ) {
g_debug ( " Adding %s to plugin search path " , plugin_dir_provider ) ;
peas_engine_prepend_search_path ( peas , plugin_dir_provider , NULL ) ;
} else {
g_warning ( " Not adding %s to plugin search path, because the directory doesn't exist. Check if env CALLS_PLUGIN_DIR is set correctly " , plugin_dir_provider ) ;
}
2022-11-19 13:08:11 +00:00
}
default_plugin_dir_provider = g_build_filename ( PLUGIN_LIBDIR , " provider " , NULL ) ;
g_debug ( " Adding %s to plugin search path " , default_plugin_dir_provider ) ;
peas_engine_add_search_path ( peas , default_plugin_dir_provider , NULL ) ;
peas_engine_rescan_plugins ( peas ) ;
2021-03-23 13:20:24 +00:00
2022-10-26 13:09:11 +00:00
dir = g_getenv ( " CALLS_PLUGIN_DIR " ) ;
if ( dir & & dir [ 0 ] ! = ' \0 ' ) {
g_autofree char * plugin_dir_provider = NULL ;
plugin_dir_provider = g_build_filename ( dir , " provider " , NULL ) ;
g_debug ( " Adding %s to plugin search path " , plugin_dir_provider ) ;
peas_engine_prepend_search_path ( peas , plugin_dir_provider , NULL ) ;
}
default_plugin_dir_provider = g_build_filename ( PLUGIN_LIBDIR , " provider " , NULL ) ;
g_debug ( " Adding %s to plugin search path " , default_plugin_dir_provider ) ;
peas_engine_add_search_path ( peas , default_plugin_dir_provider , NULL ) ;
peas_engine_rescan_plugins ( peas ) ;
2021-03-23 13:20:24 +00:00
g_test_add_func ( " /Calls/Plugins/load_plugins " , test_calls_plugin_loading ) ;
return g_test_run ( ) ;
}