From ade7fc8b6e29a43d7b47db246066c57e6c6af309 Mon Sep 17 00:00:00 2001 From: John Ralls Date: Tue, 6 Aug 2019 15:31:44 -0700 Subject: [PATCH] Initial SWIG of GncOptionDB and Scheme tests. This class will be heavily used by reports so we need to ensure SWIG and Scheme compatibility from the start. --- libgnucash/app-utils/gnc-optiondb.i | 18 +++++++ libgnucash/app-utils/test/CMakeLists.txt | 47 +++++++++++++++++-- .../app-utils/test/test-gnc-optiondb.scm | 46 ++++++++++++++++++ 3 files changed, 106 insertions(+), 5 deletions(-) create mode 100644 libgnucash/app-utils/gnc-optiondb.i create mode 100644 libgnucash/app-utils/test/test-gnc-optiondb.scm diff --git a/libgnucash/app-utils/gnc-optiondb.i b/libgnucash/app-utils/gnc-optiondb.i new file mode 100644 index 0000000000..d15c8598db --- /dev/null +++ b/libgnucash/app-utils/gnc-optiondb.i @@ -0,0 +1,18 @@ +/* + * Temporary swig interface file while developing C++ options. + */ + +%module sw_gnc_optiondb +%{ +#include +#include "gnc-optiondb.hpp" +extern "C" SCM scm_init_sw_gnc_optiondb_module(void); +%} + +%include + +%ignore OptionClassifier; +%ignore GncOption; +%ignore GncOptionWrapper; + +%include "gnc-optiondb.hpp" diff --git a/libgnucash/app-utils/test/CMakeLists.txt b/libgnucash/app-utils/test/CMakeLists.txt index 192c6d9d25..17de9412db 100644 --- a/libgnucash/app-utils/test/CMakeLists.txt +++ b/libgnucash/app-utils/test/CMakeLists.txt @@ -82,12 +82,49 @@ gnc_add_scheme_test_targets(scm-test-c-interface gnc_add_scheme_tests("${test_app_utils_scheme_SOURCES}") if (HAVE_SRFI64) - gnc_add_scheme_test_targets(scm-test-app-utils-srfi64 - SOURCES "${test_app_utils_scheme_SRFI64_SOURCES}" - OUTPUT_DIR "tests" - DEPENDS "${GUILE_DEPENDS};scm-srfi64-extras") + gnc_add_scheme_test_targets(scm-test-app-utils-srfi64 + "${test_app_utils_scheme_SRFI64_SOURCES}" + "tests" + "${GUILE_DEPENDS};scm-srfi64-extras" + FALSE + ) - gnc_add_scheme_tests("${test_app_utils_scheme_SRFI64_SOURCES}") + set(SWIG_ARGS "-c++" "-procdoc" "sw-gnc-option-doc" "-procdocformat" "plain") + gnc_add_swig_guile_command(swig-gnc-optiondb-guile + SWIG_GNC_OPTIONDB_GUILE_CPP swig-gnc-optiondb-guile.cpp + ${MODULEPATH}/gnc-optiondb.i + ) + add_library(swig-gnc-optiondb MODULE + ${MODULEPATH}/gnc-option.cpp + ${MODULEPATH}/gnc-optiondb.cpp + ${SWIG_GNC_OPTIONDB_GUILE_CPP} + ) + set(swig_gnc_optiondb_INCLUDES + ${MODULEPATH} + ${CMAKE_SOURCE_DIR}/libgnucash/engine + ${CMAKE_BINARY_DIR}/common # for config.h + ${GLIB2_INCLUDE_DIRS} + ${GUILE_INCLUDE_DIRS} + ) + + set(swig_gnc_optiondb_LIBS + gncmod-engine + ${GLIB2_LDFLAGS} + ${GUILE_LDFLAGS} + ) + + target_link_libraries(swig-gnc-optiondb ${swig_gnc_optiondb_LIBS}) + target_include_directories(swig-gnc-optiondb + PRIVATE ${swig_gnc_optiondb_INCLUDES}) + + gnc_add_scheme_test_targets(scm-test-gnc-optiondb + "test-gnc-optiondb.scm" + "tests" + "swig-gnc-optiondb;scm-srfi64-extras" + FALSE + ) + gnc_add_scheme_tests("test-gnc-optiondb.scm") + gnc_add_scheme_tests("${test_app_utils_scheme_SRFI64_SOURCES}") endif() # Doesn't work yet: diff --git a/libgnucash/app-utils/test/test-gnc-optiondb.scm b/libgnucash/app-utils/test/test-gnc-optiondb.scm new file mode 100644 index 0000000000..4d26a803f7 --- /dev/null +++ b/libgnucash/app-utils/test/test-gnc-optiondb.scm @@ -0,0 +1,46 @@ + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ; test-gnc-option.scm -- unit tests for GncOption class. ; + ; Copyright (C) 2019 John Ralls ; + ; ; + ; 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 ; + ; ; + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(use-modules (srfi srfi-64)) +(use-modules (tests srfi64-extras)) + +(eval-when + (compile load eval expand) + (load-extension "libswig-gnc-optiondb" "scm_init_sw_gnc_optiondb_module")) +(use-modules (sw_gnc_optiondb)) + +(define (run-test) + (test-runner-factory gnc:test-runner) + (test-begin "test-gnc-optiondb-scheme") + (test-gnc-make-text-option) + (test-end "test-gnc-optiondb-scheme")) + +(define (test-gnc-make-text-option) + (test-begin "test-gnc-test-string-option") + (let* ((option-db (new-GncOptionDB)) + (string-opt (gnc-register-string-option option-db "foo" "bar" "baz" + "Phony Option" "waldo"))) + (test-equal (GncOptionDB-lookup-option option-db "foo" "bar") "waldo") + (delete-GncOptionDB option-db)) + + (test-end "test-gnc-make-string-option"))