gnc-module - expand c-interface load test and make it guile independent

This commit is contained in:
Geert Janssens
2019-11-20 18:19:13 +01:00
parent fbd73c83cf
commit 331039cdcc
12 changed files with 312 additions and 46 deletions

View File

@@ -1,5 +1,7 @@
add_subdirectory(misc-mods)
add_subdirectory(mod-ordinary)
add_subdirectory(mod-withdep)
set(GNC_MODULE_TEST_INCLUDE_DIRS
${CMAKE_BINARY_DIR}/common # for config.h
@@ -18,7 +20,8 @@ set(GNC_MODULE_TEST_LIBS
gncmod-agedver
gncmod-futuremodsys
gncmod-incompatdep
gncmod-ordinarymod
gncmod-ordinary
gncmod-withdep
)
gnc_add_test_with_guile(test-load-c test-load-c.c GNC_MODULE_TEST_INCLUDE_DIRS GNC_MODULE_TEST_LIBS "GNC_MODULE_PATH=${LIBDIR_BUILD}/gnucash/test")
@@ -58,4 +61,4 @@ set(test_gnc_module_EXTRA_DIST
set_local_dist(test_gnc_module_DIST_local CMakeLists.txt README ${test_gnc_module_SOURCE_DIST} ${test_gnc_module_EXTRA_DIST})
set(test_gnc_module_DIST ${test_gnc_module_DIST_local} ${misc_mods_DIST}
${mod_bar_DIST} ${mod_baz_DIST} ${mod_foo_DIST} PARENT_SCOPE)
${mod_ordinary_DIST} ${mod_withdep_DIST} PARENT_SCOPE)

View File

@@ -13,12 +13,9 @@ target_link_libraries(gncmod-futuremodsys ${GLIB2_LDFLAGS})
add_library(gncmod-incompatdep EXCLUDE_FROM_ALL incompatdep.c)
target_link_libraries(gncmod-incompatdep gnc-module ${GLIB2_LDFLAGS})
add_library(gncmod-ordinarymod EXCLUDE_FROM_ALL ordinarymod.c)
target_link_libraries(gncmod-ordinarymod gnc-module ${GLIB2_LDFLAGS})
set_target_properties(gncmod-agedver gncmod-futuremodsys gncmod-incompatdep gncmod-ordinarymod PROPERTIES
set_target_properties(gncmod-agedver gncmod-futuremodsys gncmod-incompatdep PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${LIBDIR_BUILD}/gnucash/test
ARCHIVE_OUTPUT_DIRECTORY ${LIBDIR_BUILD}/gnucash/test
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_dist_list(misc_mods_DIST CMakeLists.txt agedver.c futuremodsys.c incompatdep.c ordinarymod.c)
set_dist_list(misc_mods_DIST CMakeLists.txt agedver.c futuremodsys.c incompatdep.c)

View File

@@ -51,7 +51,7 @@ libgncmod_incompatdep_gnc_module_description(void)
int
libgncmod_incompatdep_gnc_module_init(int refcount)
{
if (gnc_module_load("gnucash/ordinarymod", 25))
if (gnc_module_load("gnucash/ordinary", 25))
{
return TRUE;
}

View File

@@ -0,0 +1,21 @@
add_library(ordinary EXCLUDE_FROM_ALL ordinary.c ordinary.h)
add_library(gncmod-ordinary EXCLUDE_FROM_ALL gnc-mod-ordinary.c)
target_link_libraries(gncmod-ordinary ordinary gnc-module)
target_include_directories(gncmod-ordinary PRIVATE
${CMAKE_BINARY_DIR}/common
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/common
${CMAKE_SOURCE_DIR}/libgnucash/gnc-module
${GLIB2_INCLUDE_DIRS}
${GUILE_INCLUDE_DIRS}
)
set_target_properties(ordinary gncmod-ordinary PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${LIBDIR_BUILD}/gnucash/test
ARCHIVE_OUTPUT_DIRECTORY ${LIBDIR_BUILD}/gnucash/test
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_dist_list(mod_ordinary_DIST CMakeLists.txt ordinary.c ordinary.h gnc-mod-ordinary.c)

View File

@@ -1,4 +1,5 @@
/* ordinarymod.c : ordinary module */
/* gnc-mod-ordinary.c : the Gnucash plugin that wraps the library
* 'libordinary.so'. it does this by being linked against libordinary.so */
/********************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@@ -20,40 +21,35 @@
\********************************************************************/
#include <config.h>
#include <stdio.h>
#include <gmodule.h>
#include <libguile.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
GNC_MODULE_API_DECL(libgncmod_ordinarymod)
GNC_MODULE_API_DECL(libgncmod_ordinary)
int libgncmod_ordinarymod_gnc_module_system_interface = 0;
int libgncmod_ordinary_gnc_module_system_interface = 0;
int libgncmod_ordinarymod_gnc_module_current = 0;
int libgncmod_ordinarymod_gnc_module_age = 0;
int libgncmod_ordinarymod_gnc_module_revision = 0;
int libgncmod_ordinary_gnc_module_current = 0;
int libgncmod_ordinary_gnc_module_age = 0;
int libgncmod_ordinary_gnc_module_revision = 0;
char *
libgncmod_ordinarymod_gnc_module_path(void)
libgncmod_ordinary_gnc_module_path(void)
{
return g_strdup("gnucash/ordinarymod");
return g_strdup("gnucash/ordinary");
}
char *
libgncmod_ordinarymod_gnc_module_description(void)
libgncmod_ordinary_gnc_module_description(void)
{
return g_strdup("this is a very ordinary module");
return g_strdup("this is an ordinary module");
}
int
libgncmod_ordinarymod_gnc_module_init(int refcount)
{
return TRUE;
}
int
libgncmod_ordinarymod_gnc_module_end(int refcount)
libgncmod_ordinary_gnc_module_init(int refcount)
{
return TRUE;
}

View File

@@ -0,0 +1,33 @@
/* libordinary. this is a dependency-free client library, equivalent to
* the engine or some other core component that's ignorant of guile
* and the module system */
/********************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include <stdio.h>
#include "ordinary.h"
int
ordinary_hello(void)
{
return 10;
}

View File

@@ -0,0 +1,28 @@
/* ordinary.h: header for a dependency-free, guile-free client lib */
/********************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#ifndef ORDINARY_H
#define ORDINARY_H
int ordinary_hello(void);
#endif

View File

@@ -0,0 +1,27 @@
add_library(withdep EXCLUDE_FROM_ALL withdep.c withdep.h)
target_include_directories(withdep PRIVATE
${CMAKE_SOURCE_DIR}/libgnucash/gnc-module/test/mod-ordinary
)
target_link_libraries(withdep ordinary)
add_library(gncmod-withdep EXCLUDE_FROM_ALL gnc-mod-withdep.c)
target_link_libraries(gncmod-withdep withdep gnc-module)
target_include_directories(gncmod-withdep PRIVATE
${CMAKE_BINARY_DIR}/common
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}/common
${CMAKE_SOURCE_DIR}/libgnucash/gnc-module
${GLIB2_INCLUDE_DIRS}
${GUILE_INCLUDE_DIRS}
)
set_target_properties(withdep gncmod-withdep PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${LIBDIR_BUILD}/gnucash/test
ARCHIVE_OUTPUT_DIRECTORY ${LIBDIR_BUILD}/gnucash/test
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set_dist_list(mod_withdep_DIST CMakeLists.txt withdep.c withdep.h gnc-mod-withdep.c)

View File

@@ -0,0 +1,60 @@
/* gnc-mod-withdep.c : the Gnucash plugin that wraps the library
* 'libwithdep.so'. it does this by being linked against libwithdep.so */
/********************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include <config.h>
#include <stdio.h>
#include <gmodule.h>
#include <libguile.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
GNC_MODULE_API_DECL(libgncmod_withdep)
int libgncmod_withdep_gnc_module_system_interface = 0;
int libgncmod_withdep_gnc_module_current = 0;
int libgncmod_withdep_gnc_module_age = 0;
int libgncmod_withdep_gnc_module_revision = 0;
char *
libgncmod_withdep_gnc_module_path(void)
{
return g_strdup("gnucash/withdep");
}
char *
libgncmod_withdep_gnc_module_description(void)
{
return g_strdup("this is the withdep module");
}
int
libgncmod_withdep_gnc_module_init(int refcount)
{
/* load libfoo */
if (gnc_module_load("gnucash/ordinary", 0))
return TRUE;
else
return FALSE;
}

View File

@@ -0,0 +1,34 @@
/* libwithdep. this library depends on ordinary */
/********************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#include <stdio.h>
#include "withdep.h"
#include "ordinary.h"
int
withdep_hello(void)
{
// ordinary_hello returns 10 so the final return value should be 11
return ordinary_hello() + 1;
}

View File

@@ -0,0 +1,28 @@
/* withdep.h: header for a dependency-free, guile-free client lib */
/********************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
* *
\********************************************************************/
#ifndef WITHDEP_H
#define WITHDEP_H
int withdep_hello(void);
#endif

View File

@@ -21,15 +21,17 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <libguile.h>
#include <unittest-support.h>
#include "test/mod-ordinary/ordinary.h"
#include "test/mod-withdep/withdep.h"
#include "gnc-module.h"
static void
guile_main(void *closure, int argc, char ** argv)
int
main(int argc, char ** argv)
{
GNCModule ordinarymod;
gint retval = 0;
GNCModule testmod;
gchar *msg = "Module '../../../libgnucash/gnc-module/test/misc-mods/.libs/libgncmod-futuremodsys.so' requires newer module system\n";
gchar *logdomain = "gnc.module";
guint loglevel = G_LOG_LEVEL_WARNING;
@@ -37,31 +39,68 @@ guile_main(void *closure, int argc, char ** argv)
g_log_set_handler (logdomain, loglevel,
(GLogFunc)test_checked_handler, &check);
g_test_message(" test-load-c.c: testing module load/unload from C ... ");
gnc_module_system_init();
ordinarymod = gnc_module_load("gnucash/ordinarymod", 0);
if (!ordinarymod)
g_test_message(" test-load-c.c: load module gnucash/ordinary from C ... ");
testmod = gnc_module_load("gnucash/ordinary", 0);
if (!testmod)
{
g_test_message(" Failed to load ordinarymod\n");
g_test_message(" failed\n");
exit(-1);
}
g_test_message(" ok\n");
if (!gnc_module_unload(ordinarymod))
g_test_message(" test-load-c.c: call function ordinary_hello in module gnucash/ordinary ... ");
retval = ordinary_hello();
if (retval != 10)
{
g_test_message(" Failed to unload ordinarymod\n");
g_test_message(" failed. Expected 10, got %i\n", retval);
exit(-1);
}
g_test_message(" successful.\n");
g_test_message(" ok\n");
g_test_message(" test-load-c.c: unload module gnucash/ordinary from C ... ");
if (!gnc_module_unload(testmod))
{
g_test_message(" failed\n");
exit(-1);
}
g_test_message(" ok.\n");
g_test_message(" test-load-c.c: load module gnucash/withdep from C ... ");
testmod = gnc_module_load("gnucash/withdep", 0);
if (!testmod)
{
g_test_message(" failed\n");
exit(-1);
}
g_test_message(" ok\n");
g_test_message(" test-load-c.c: call function withdep_hello in module gnucash/withdep ... ");
retval = withdep_hello();
if (retval != 11)
{
g_test_message(" failed. Expected 11, got %i\n", retval);
exit(-1);
}
g_test_message(" ok\n");
g_test_message(" test-load-c.c: call function ordinary_hello in depended on module gnucash/ordinary ... ");
retval = ordinary_hello();
if (retval != 10)
{
g_test_message(" failed. Expected 10, got %i\n", retval);
exit(-1);
}
g_test_message(" ok\n");
g_test_message(" test-load-c.c: unload module gnucash/withdep from C ... ");
if (!gnc_module_unload(testmod))
{
g_test_message(" failed\n");
exit(-1);
}
g_test_message(" ok.\n");
exit(0);
}
int
main(int argc, char ** argv)
{
scm_boot_guile(argc, argv, guile_main, NULL);
return 0;
}