Skip to content

Commit

Permalink
Provide scheme function new-gnc-optiondb.
Browse files Browse the repository at this point in the history
Wraps creating a GncOptionDBPtr, freeing up gnc_option_db_new() to
return a GncOptionDB* for use in C code. Convert gnc_option_db_new()
calls in gtest-gnc-optiondb to call std::make_unique() as well.
  • Loading branch information
jralls committed Aug 1, 2021
1 parent f9e136d commit 6feb92d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
7 changes: 7 additions & 0 deletions libgnucash/app-utils/gnc-optiondb.i
Expand Up @@ -415,6 +415,13 @@ wrap_unique_ptr(GncOptionDBPtr, GncOptionDB);
}
GncOption_set_value_from_scm(db_opt, new_value);
}

GncOptionDBPtr
new_gnc_optiondb()
{
auto db_ptr{std::make_unique<GncOptionDB>()};
return db_ptr;
}
%}

#endif //SWIGGUILE
6 changes: 4 additions & 2 deletions libgnucash/app-utils/test/gtest-gnc-optiondb.cpp
Expand Up @@ -36,7 +36,7 @@ extern "C"
class GncOptionDBTest : public ::testing::Test
{
protected:
GncOptionDBTest() : m_db{gnc_option_db_new()} {}
GncOptionDBTest() : m_db{std::make_unique<GncOptionDB>()} {}

GncOptionDBPtr m_db;
};
Expand Down Expand Up @@ -271,7 +271,9 @@ TEST_F(GncOptionDBTest, test_register_start_date_option)
class GncOptionDBIOTest : public ::testing::Test
{
protected:
GncOptionDBIOTest() : m_book{gnc_get_current_book()}, m_root{gnc_account_create_root(m_book)}, m_db{gnc_option_db_new()}
GncOptionDBIOTest() :
m_book{gnc_get_current_book()}, m_root{gnc_account_create_root(m_book)},
m_db{std::make_unique<GncOptionDB>()}
{
auto create_account = [this](Account* parent, GNCAccountType type,
const char* name)->Account* {
Expand Down
18 changes: 9 additions & 9 deletions libgnucash/app-utils/test/test-gnc-optiondb.scm
Expand Up @@ -45,7 +45,7 @@

(define (test-gnc-make-text-option)
(test-begin "test-gnc-test-string-option")
(let* ((option-db (gnc-option-db-new))
(let* ((option-db (new-gnc-optiondb))
(string-opt (gnc-register-string-option option-db "foo" "bar" "baz"
"Phony Option" "waldo")))
(test-equal "waldo" (gnc-option-value option-db "foo" "bar"))
Expand Down Expand Up @@ -89,7 +89,7 @@

(define (test-make-account-list-option book)
(test-group "test-make-account-list-option"
(let ((optiondb (gnc-option-db-new))
(let ((optiondb (new-gnc-optiondb))
(acctlist (gnc-account-list-from-types book
(list ACCT-TYPE-STOCK))))
(gnc-register-account-list-option optiondb "foo" "bar" "baz"
Expand All @@ -100,7 +100,7 @@

(define (test-make-account-list-limited-option book)
(test-group "test-make-account-list-option"
(let ((optiondb (gnc-option-db-new))
(let ((optiondb (new-gnc-optiondb))
(acctlist (gnc-account-list-from-types book
(list ACCT-TYPE-STOCK))))
(gnc-register-account-list-limited-option optiondb "foo" "bar" "baz"
Expand All @@ -115,7 +115,7 @@

(define (test-make-account-sel-limited-option book)
(test-group "test-make-account-list-option"
(let ((optiondb (gnc-option-db-new))
(let ((optiondb (new-gnc-optiondb))
(acctlist (gnc-account-list-from-types book
(list ACCT-TYPE-STOCK))))
(gnc-register-account-sel-limited-option optiondb "salt" "pork" "baz"
Expand Down Expand Up @@ -148,7 +148,7 @@
(assq-ref (assq-ref keylist key) info))

(test-begin "test-gnc-test-multichoice-option")
(let* ((option-db (gnc-option-db-new))
(let* ((option-db (new-gnc-optiondb))
(multilist (list
(list "plugh" (cons 'text "xyzzy") (cons 'tip "thud"))
(list "waldo" (cons 'text "pepper") (cons 'tip "salt"))
Expand All @@ -166,7 +166,7 @@

(define (test-gnc-make-list-option)
(test-begin "test-gnc-test-list-option")
(let* ((option-db (gnc-option-db-new))
(let* ((option-db (new-gnc-optiondb))
(value-list (list (vector "AvgBalPlot" "Average" "Average Balance")
(vector "GainPlot" "Profit" "Profit (Gain minus Loss)")
(vector "GLPlot" "Gain/Loss" "Gain and Loss")))
Expand All @@ -181,7 +181,7 @@

(define (test-gnc-make-date-option)
(test-begin "test-gnc-test-date-option")
(let* ((option-db (gnc-option-db-new))
(let* ((option-db (new-gnc-optiondb))
(date-opt (gnc-register-date-option option-db "foo" "bar"
"baz" "Phony Option"
(RelativeDatePeriod-today)))
Expand All @@ -193,7 +193,7 @@

(define (test-gnc-make-date-set-option)
(test-begin "test-gnc-test-date-set-option")
(let* ((option-db (gnc-option-db-new))
(let* ((option-db (new-gnc-optiondb))
(date-opt (gnc-register-date-option-set
option-db "foo" "bar" "baz" "Phony Option"
(list (RelativeDatePeriod-today)
Expand All @@ -210,7 +210,7 @@

(define (test-gnc-make-number-range-option)
(test-begin "test-gnc-number-range-option")
(let* ((option-db (gnc-option-db-new))
(let* ((option-db (new-gnc-optiondb))
(number-opt (gnc-register-number-range-option option-db "foo" "bar"
"baz" "Phony Option"
15 5 30 1)))
Expand Down

0 comments on commit 6feb92d

Please sign in to comment.