Files
gnucash/libgnucash/app-utils/test/test-option-util.cpp

137 lines
5.6 KiB
C++
Raw Normal View History

/********************************************************************
* test-option-util.cpp: GLib test suite for option-util.c. *
* Copyright 2013 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, you can retrieve it from *
* https://www.gnu.org/licenses/old-licenses/gpl-2.0.html *
* or 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 <kvp-frame.hpp>
#include <gmp.h>
extern "C"
{
#include <config.h>
#include <glib.h>
#include <unittest-support.h>
#include <qofbookslots.h>
Book-Currency Feature step 6 Modify File->Properties dialog to maintain a default gain/loss account in a book KVP. The changes made are: app-utils/app-utils.scm - define items related to book default gain/loss acct app-utils/business-prefs.scm - define items related to book default gain/loss acct;re-arrange sequence of options to make default (neither) first app-utils/gnc-ui-util.c - refine gnc_book_get_default_gains_policy to check for hidden and/or placeholder status app-utils/option-util.c & h - define items related to book default gain/loss acct app-utils/options.scm - add functionality related to book default gain/loss acct app-utils/test/test-gnc-ui-util.c - for gnc_book_get_default_gains_policy, add tests to check for hidden and/or placeholder status app-utils/test/test-option-util.cpp - add tests related to book default gain/loss acct engine/engine.i - define item related to book default gain/loss acct gnome-utils/dialog-options.c & h - add functionality related to book default gain/loss acct and rearrange dialog layout; make gain/loss acct widget refresh on account maintenance gnome-utils/gnc-main-window.c - only allow one book-option dialog if called from file->properties gnome-utils/gtkbuilder/dialog-options.glade - increase dialog height to accomodate book default gain/loss acct widget; add tooltip text for dialog buttons gnome/assistant-hierarchy.c - change sequence of pages: book options before currency selection; if book currency selected, currency also selected gnome/gtkbuilder/assistant-hierarchy.glade - increase dialog height to accomodate book default gain/loss acct widget
2017-07-09 12:19:36 -07:00
#include "test-engine-stuff.h"
#include "../option-util.h"
}
static const gchar *suitename = "/app-utils/option-util";
extern "C" void test_suite_option_util (void);
typedef struct
{
QofBook *book;
GSList *hdlrs;
} Fixture;
/* Expose a mostly-private QofInstance function to load options into
* the Book.
*/
extern "C" KvpFrame *qof_instance_get_slots (const QofInstance*);
static void
setup (Fixture *fixture, gconstpointer pData)
{
fixture->book = qof_book_new ();
fixture->hdlrs = NULL;
}
static void
setup_kvp (Fixture *fixture, gconstpointer pData)
{
QofBook *book;
KvpFrame *slots;
setup (fixture, pData);
book = fixture->book;
slots = qof_instance_get_slots (QOF_INSTANCE (book));
qof_begin_edit (QOF_INSTANCE (book));
qof_instance_set (QOF_INSTANCE (book),
Book-Currency Feature Step 3 Add an option to the File->Properties dialog to select a Currency Accounting Method, and to specify the book-currency and a default gains/loss policy if the 'book-currency' method is selected. Revert some changes made in prior commits. Other than storing and retrieving the book-currency and policy in book KVPs, the behavior of gnucash has not been affected by these changes. The changes made are: engine/policy.c & .h - define valid policies and their descriptions and hints; define functions gnc_get_valid_policy_list and gnc_valid_policy engine/engine.i - include policy.h; define 'CURRENCY-ACCOUNTING', 'BOOK-CURRENCY', and 'DEFAULT-GAINS-POLICY' as option names engine/test/utest-Split.cpp - revert prior commit that modified test function for trading accounts engine/test/utest-Transaction.c - revert prior commit that modified test function for trading accounts libqof/qof/qofbookslots.h - revert prior commit that defined Currency Accounting Method; modify definitions of Currency Accounting and Book Currency; add definition of default gains policy; keep the previous Trading Accounts definition libqof/qof/qofbook.cpp & .h - reverted function to determine currency accounting method; add function to get book-currency, revert previously committed changes to function to determine if book uses trading accounts; add function to get gains policy; modify gobject properties accordingly libqof/qof/test/test-qofbook.c - revert prior modification to test function for trading accounts; define tests for book-currency and default gains policies app-utils/options.scm - define make-currency-accounting-option and required support functions app-utils/options-util.c & .h - make support functions of make-currency-accounting-option available in c code app-utils/test/test-options-util.c - include tests for using book-currency app-utils/gnc-ui-util.c & .h - define gnc_book_use_book_currency, gnc_book_get_book_currency and gnc_book_get_default_gains_policy functions app-utils/test/test-gnc-ui-util.c - set up tests for new gnc-ui-util functions app-utils/test/test-app-utils.c - include test-gnc-ui-util.c app-utils/test/Makefile.am - include test-gnc-ui-util.c app-utils/app-utils.scm - define and export book options for Currency Accounting, Book-Currency and Default Gains Policy; export required currency-accounting-option support functions app-utils/business-prefs.scm - replace the Trading Accounts boolean option with a currency-accounting-option and rearrange the order of the options gnome-utils/dialog-options.c - define functions for set-ui-widget, set-ui-value, and get-ui-value for 'currency-accounting' option and various other support functions
2015-06-27 16:06:56 -07:00
"trading-accts", "t",
"split-action-num-field", "t",
"autoreadonly-days", (double)21,
NULL);
slots->set_path({"options", "Business", "Company Name"},
new KvpValue(g_strdup ("Bogus Company")));
qof_commit_edit (QOF_INSTANCE (book));
}
static void
teardown (Fixture *fixture, gconstpointer pData)
{
qof_book_destroy (fixture->book);
g_slist_free_full (fixture->hdlrs, test_free_log_handler);
test_clear_error_list();
}
static void
test_option_load (Fixture *fixture, gconstpointer pData)
{
Book-Currency Feature Step 3 Add an option to the File->Properties dialog to select a Currency Accounting Method, and to specify the book-currency and a default gains/loss policy if the 'book-currency' method is selected. Revert some changes made in prior commits. Other than storing and retrieving the book-currency and policy in book KVPs, the behavior of gnucash has not been affected by these changes. The changes made are: engine/policy.c & .h - define valid policies and their descriptions and hints; define functions gnc_get_valid_policy_list and gnc_valid_policy engine/engine.i - include policy.h; define 'CURRENCY-ACCOUNTING', 'BOOK-CURRENCY', and 'DEFAULT-GAINS-POLICY' as option names engine/test/utest-Split.cpp - revert prior commit that modified test function for trading accounts engine/test/utest-Transaction.c - revert prior commit that modified test function for trading accounts libqof/qof/qofbookslots.h - revert prior commit that defined Currency Accounting Method; modify definitions of Currency Accounting and Book Currency; add definition of default gains policy; keep the previous Trading Accounts definition libqof/qof/qofbook.cpp & .h - reverted function to determine currency accounting method; add function to get book-currency, revert previously committed changes to function to determine if book uses trading accounts; add function to get gains policy; modify gobject properties accordingly libqof/qof/test/test-qofbook.c - revert prior modification to test function for trading accounts; define tests for book-currency and default gains policies app-utils/options.scm - define make-currency-accounting-option and required support functions app-utils/options-util.c & .h - make support functions of make-currency-accounting-option available in c code app-utils/test/test-options-util.c - include tests for using book-currency app-utils/gnc-ui-util.c & .h - define gnc_book_use_book_currency, gnc_book_get_book_currency and gnc_book_get_default_gains_policy functions app-utils/test/test-gnc-ui-util.c - set up tests for new gnc-ui-util functions app-utils/test/test-app-utils.c - include test-gnc-ui-util.c app-utils/test/Makefile.am - include test-gnc-ui-util.c app-utils/app-utils.scm - define and export book options for Currency Accounting, Book-Currency and Default Gains Policy; export required currency-accounting-option support functions app-utils/business-prefs.scm - replace the Trading Accounts boolean option with a currency-accounting-option and rearrange the order of the options gnome-utils/dialog-options.c - define functions for set-ui-widget, set-ui-value, and get-ui-value for 'currency-accounting' option and various other support functions
2015-06-27 16:06:56 -07:00
gchar *str = NULL;
SCM symbol_value;
QofBook *book = fixture->book;
GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK);
qof_book_load_options (book, gnc_option_db_load, odb);
g_assert (gnc_option_db_lookup_boolean_option (odb, OPTION_SECTION_ACCOUNTS, OPTION_NAME_TRADING_ACCOUNTS, FALSE));
Book-Currency Feature Step 3 Add an option to the File->Properties dialog to select a Currency Accounting Method, and to specify the book-currency and a default gains/loss policy if the 'book-currency' method is selected. Revert some changes made in prior commits. Other than storing and retrieving the book-currency and policy in book KVPs, the behavior of gnucash has not been affected by these changes. The changes made are: engine/policy.c & .h - define valid policies and their descriptions and hints; define functions gnc_get_valid_policy_list and gnc_valid_policy engine/engine.i - include policy.h; define 'CURRENCY-ACCOUNTING', 'BOOK-CURRENCY', and 'DEFAULT-GAINS-POLICY' as option names engine/test/utest-Split.cpp - revert prior commit that modified test function for trading accounts engine/test/utest-Transaction.c - revert prior commit that modified test function for trading accounts libqof/qof/qofbookslots.h - revert prior commit that defined Currency Accounting Method; modify definitions of Currency Accounting and Book Currency; add definition of default gains policy; keep the previous Trading Accounts definition libqof/qof/qofbook.cpp & .h - reverted function to determine currency accounting method; add function to get book-currency, revert previously committed changes to function to determine if book uses trading accounts; add function to get gains policy; modify gobject properties accordingly libqof/qof/test/test-qofbook.c - revert prior modification to test function for trading accounts; define tests for book-currency and default gains policies app-utils/options.scm - define make-currency-accounting-option and required support functions app-utils/options-util.c & .h - make support functions of make-currency-accounting-option available in c code app-utils/test/test-options-util.c - include tests for using book-currency app-utils/gnc-ui-util.c & .h - define gnc_book_use_book_currency, gnc_book_get_book_currency and gnc_book_get_default_gains_policy functions app-utils/test/test-gnc-ui-util.c - set up tests for new gnc-ui-util functions app-utils/test/test-app-utils.c - include test-gnc-ui-util.c app-utils/test/Makefile.am - include test-gnc-ui-util.c app-utils/app-utils.scm - define and export book options for Currency Accounting, Book-Currency and Default Gains Policy; export required currency-accounting-option support functions app-utils/business-prefs.scm - replace the Trading Accounts boolean option with a currency-accounting-option and rearrange the order of the options gnome-utils/dialog-options.c - define functions for set-ui-widget, set-ui-value, and get-ui-value for 'currency-accounting' option and various other support functions
2015-06-27 16:06:56 -07:00
g_assert (gnc_option_db_lookup_boolean_option (odb,
OPTION_SECTION_ACCOUNTS,
OPTION_NAME_NUM_FIELD_SOURCE, FALSE));
g_assert_cmpstr (gnc_option_db_lookup_string_option (odb, "Business", "Company Name", FALSE), ==, "Bogus Company");
g_assert_cmpfloat (gnc_option_db_lookup_number_option (odb, OPTION_SECTION_ACCOUNTS, OPTION_NAME_AUTO_READONLY_DAYS, FALSE), ==, 21);
gnc_option_db_destroy (odb);
}
static void
test_option_save (Fixture *fixture, gconstpointer pData)
{
QofBook *book = fixture->book;
GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK);
KvpFrame *slots = qof_instance_get_slots (QOF_INSTANCE (book));
g_assert (gnc_option_db_set_boolean_option (odb, OPTION_SECTION_ACCOUNTS,
OPTION_NAME_TRADING_ACCOUNTS,
TRUE));
g_assert (gnc_option_db_set_boolean_option (odb, OPTION_SECTION_ACCOUNTS,
Book-Currency Feature Step 3 Add an option to the File->Properties dialog to select a Currency Accounting Method, and to specify the book-currency and a default gains/loss policy if the 'book-currency' method is selected. Revert some changes made in prior commits. Other than storing and retrieving the book-currency and policy in book KVPs, the behavior of gnucash has not been affected by these changes. The changes made are: engine/policy.c & .h - define valid policies and their descriptions and hints; define functions gnc_get_valid_policy_list and gnc_valid_policy engine/engine.i - include policy.h; define 'CURRENCY-ACCOUNTING', 'BOOK-CURRENCY', and 'DEFAULT-GAINS-POLICY' as option names engine/test/utest-Split.cpp - revert prior commit that modified test function for trading accounts engine/test/utest-Transaction.c - revert prior commit that modified test function for trading accounts libqof/qof/qofbookslots.h - revert prior commit that defined Currency Accounting Method; modify definitions of Currency Accounting and Book Currency; add definition of default gains policy; keep the previous Trading Accounts definition libqof/qof/qofbook.cpp & .h - reverted function to determine currency accounting method; add function to get book-currency, revert previously committed changes to function to determine if book uses trading accounts; add function to get gains policy; modify gobject properties accordingly libqof/qof/test/test-qofbook.c - revert prior modification to test function for trading accounts; define tests for book-currency and default gains policies app-utils/options.scm - define make-currency-accounting-option and required support functions app-utils/options-util.c & .h - make support functions of make-currency-accounting-option available in c code app-utils/test/test-options-util.c - include tests for using book-currency app-utils/gnc-ui-util.c & .h - define gnc_book_use_book_currency, gnc_book_get_book_currency and gnc_book_get_default_gains_policy functions app-utils/test/test-gnc-ui-util.c - set up tests for new gnc-ui-util functions app-utils/test/test-app-utils.c - include test-gnc-ui-util.c app-utils/test/Makefile.am - include test-gnc-ui-util.c app-utils/app-utils.scm - define and export book options for Currency Accounting, Book-Currency and Default Gains Policy; export required currency-accounting-option support functions app-utils/business-prefs.scm - replace the Trading Accounts boolean option with a currency-accounting-option and rearrange the order of the options gnome-utils/dialog-options.c - define functions for set-ui-widget, set-ui-value, and get-ui-value for 'currency-accounting' option and various other support functions
2015-06-27 16:06:56 -07:00
OPTION_NAME_NUM_FIELD_SOURCE,
TRUE));
g_assert (gnc_option_db_set_string_option (odb, "Business", "Company Name",
"Bogus Company"));
g_assert (gnc_option_db_set_number_option (odb, OPTION_SECTION_ACCOUNTS,
OPTION_NAME_AUTO_READONLY_DAYS,
17));
qof_book_save_options (book, gnc_option_db_save, odb, TRUE);
g_assert_cmpstr (slots->get_slot({"options", "Accounts", "Use Trading Accounts"})->get<const char*>(), == , "t");
g_assert_cmpstr (slots->get_slot({"options", "Accounts", "Use Split Action Field for Number"})->get<const char*>(), == , "t");
g_assert_cmpstr (slots->get_slot({"options", "Business", "Company Name"})->get<const char*>(), ==, "Bogus Company");
g_assert_cmpfloat (slots->get_slot({"options", "Accounts", "Day Threshold for Read-Only Transactions (red line)"})->get<double>(), ==, 17);
gnc_option_db_destroy (odb);
}
extern "C" void
test_suite_option_util (void)
{
GNC_TEST_ADD (suitename, "Option DB Load", Fixture, NULL, setup_kvp, test_option_load, teardown);
GNC_TEST_ADD (suitename, "Option DB Save", Fixture, NULL, setup, test_option_save, teardown);
}