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.
This commit is contained in:
John Ralls 2019-08-06 15:31:44 -07:00
parent f3eee511e8
commit ade7fc8b6e
3 changed files with 106 additions and 5 deletions

View File

@ -0,0 +1,18 @@
/*
* Temporary swig interface file while developing C++ options.
*/
%module sw_gnc_optiondb
%{
#include <libguile.h>
#include "gnc-optiondb.hpp"
extern "C" SCM scm_init_sw_gnc_optiondb_module(void);
%}
%include <std_string.i>
%ignore OptionClassifier;
%ignore GncOption;
%ignore GncOptionWrapper;
%include "gnc-optiondb.hpp"

View File

@ -82,12 +82,49 @@ gnc_add_scheme_test_targets(scm-test-c-interface
gnc_add_scheme_tests("${test_app_utils_scheme_SOURCES}") gnc_add_scheme_tests("${test_app_utils_scheme_SOURCES}")
if (HAVE_SRFI64) if (HAVE_SRFI64)
gnc_add_scheme_test_targets(scm-test-app-utils-srfi64 gnc_add_scheme_test_targets(scm-test-app-utils-srfi64
SOURCES "${test_app_utils_scheme_SRFI64_SOURCES}" "${test_app_utils_scheme_SRFI64_SOURCES}"
OUTPUT_DIR "tests" "tests"
DEPENDS "${GUILE_DEPENDS};scm-srfi64-extras") "${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() endif()
# Doesn't work yet: # Doesn't work yet:

View File

@ -0,0 +1,46 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; test-gnc-option.scm -- unit tests for GncOption class. ;
; Copyright (C) 2019 John Ralls <jralls@ceridwen.us> ;
; ;
; 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"))