27 #include <unittest-support.h>
28 #include <qofbookslots.h>
30 #include "../option-util.h"
32 static const gchar *suitename =
"/app-utils/option-util";
33 void test_suite_option_util (
void);
47 setup (
Fixture *fixture, gconstpointer pData)
50 fixture->hdlrs = NULL;
54 setup_kvp (
Fixture *fixture, gconstpointer pData)
58 setup (fixture, pData);
60 slots = qof_instance_get_slots (QOF_INSTANCE (book));
64 "split-action-num-field",
"t",
65 "autoreadonly-days", (
double)21,
74 teardown (
Fixture *fixture, gconstpointer pData)
77 g_slist_free_full (fixture->hdlrs, test_free_log_handler);
78 test_clear_error_list();
82 test_option_load_from_kvp (
Fixture *fixture, gconstpointer pData)
85 GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK);
87 qof_book_load_options (book, gnc_option_db_load_from_kvp, odb);
88 g_assert (gnc_option_db_lookup_boolean_option (odb, OPTION_SECTION_ACCOUNTS,
89 OPTION_NAME_TRADING_ACCOUNTS, FALSE));
90 g_assert_cmpstr (gnc_option_db_lookup_string_option (odb,
"Business",
"Company Name", FALSE), ==,
"Bogus Company");
91 g_assert_cmpfloat (gnc_option_db_lookup_number_option (odb, OPTION_SECTION_ACCOUNTS, OPTION_NAME_AUTO_READONLY_DAYS, FALSE), ==, 21);
93 gnc_option_db_destroy (odb);
97 test_option_save_to_kvp (
Fixture *fixture, gconstpointer pData)
100 GNCOptionDB *odb = gnc_option_db_new_for_type (QOF_ID_BOOK);
101 KvpFrame *slots = qof_instance_get_slots (QOF_INSTANCE (book));
103 g_assert (gnc_option_db_set_boolean_option (odb, OPTION_SECTION_ACCOUNTS,
104 OPTION_NAME_TRADING_ACCOUNTS,
106 g_assert (gnc_option_db_set_string_option (odb,
"Business",
"Company Name",
108 g_assert (gnc_option_db_set_number_option (odb, OPTION_SECTION_ACCOUNTS,
109 OPTION_NAME_AUTO_READONLY_DAYS,
111 qof_book_save_options (book, gnc_option_db_save_to_kvp, odb, TRUE);
112 g_assert_cmpstr (kvp_frame_get_string (slots,
"options/Accounts/Use Trading Accounts"), == ,
"t");
113 g_assert_cmpstr (kvp_frame_get_string (slots,
"options/Business/Company Name"), ==,
"Bogus Company");
114 g_assert_cmpfloat (kvp_frame_get_double (slots,
"options/Accounts/Day Threshold for Read-Only Transactions (red line)"), ==, 17);
116 gnc_option_db_destroy (odb);
121 test_suite_option_util (
void)
123 GNC_TEST_ADD (suitename,
"Option DB Load from KVP",
Fixture, NULL, setup_kvp, test_option_load_from_kvp, teardown);
124 GNC_TEST_ADD (suitename,
"Option DB Save to KVP",
Fixture, NULL, setup, test_option_save_to_kvp, teardown);
void qof_instance_set(QofInstance *inst, const gchar *first_param,...)
Wrapper for g_object_set Group setting multiple parameters in a single begin/commit/rollback.
QofBook * qof_book_new(void)
gboolean qof_commit_edit(QofInstance *inst)
gboolean qof_begin_edit(QofInstance *inst)
struct KvpFrameImpl KvpFrame
void kvp_frame_set_string(KvpFrame *frame, const gchar *path, const gchar *str)
Store a copy of the string at the indicated path.
void qof_book_destroy(QofBook *book)