Skip to content

Commit

Permalink
[utest-Account] test gnc_account_get_map_entry
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Sep 15, 2021
1 parent 73ad5b1 commit a5d101d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions libgnucash/engine/test/utest-Account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,52 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
xaccAccountDestroy (account);
}

static void
set_kvp_string_path (Account *acc, std::vector<std::string> const & path,
const char *value)
{
xaccAccountBeginEdit(acc);
if (value)
{
GValue v = G_VALUE_INIT;
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, value);
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, path);
g_value_unset (&v);
}
else
qof_instance_set_path_kvp (QOF_INSTANCE (acc), NULL, path);

xaccAccountCommitEdit(acc);
}

static void
test_gnc_account_get_map_entry (Fixture *fixture, gconstpointer pData)
{
Account *account = xaccMallocAccount (gnc_account_get_book (fixture->acct));

g_assert_cmpstr (gnc_account_get_map_entry (account, "one", NULL), ==, nullptr);
g_assert_cmpstr (gnc_account_get_map_entry (account, "one", "two"), ==, nullptr);

set_kvp_string_path (account, {"one"}, "uno");
g_assert_cmpstr (gnc_account_get_map_entry (account, "one", NULL), ==, "uno");
g_assert_cmpstr (gnc_account_get_map_entry (account, "one", "two"), ==, nullptr);

set_kvp_string_path (account, {"one", "two"}, "dos");
g_assert_cmpstr (gnc_account_get_map_entry (account, "one", "tw0"), ==, nullptr);
g_assert_cmpstr (gnc_account_get_map_entry (account, "one", "two"), ==, "dos");

set_kvp_string_path (account, {"one"}, nullptr);
g_assert_cmpstr (gnc_account_get_map_entry (account, "one", NULL), ==, nullptr);
g_assert_cmpstr (gnc_account_get_map_entry (account, "one", "two"), ==, nullptr);

set_kvp_string_path (account, {"one", "two"}, "dos");
g_assert_cmpstr (gnc_account_get_map_entry (account, "one", "two"), ==, "dos");

xaccAccountBeginEdit (account);
xaccAccountDestroy (account);
}

static void
test_gnc_account_insert_remove_split (Fixture *fixture, gconstpointer pData)
{
Expand Down Expand Up @@ -2703,6 +2749,7 @@ test_suite_account (void)
// GNC_TEST_ADD (suitename, "xaccAcctChildrenEqual", Fixture, NULL, setup, test_xaccAcctChildrenEqual, teardown );
// GNC_TEST_ADD (suitename, "xaccAccountEqual", Fixture, NULL, setup, test_xaccAccountEqual, teardown );
GNC_TEST_ADD (suitename, "gnc account kvp getters & setters", Fixture, NULL, setup, test_gnc_account_kvp_setters_getters, teardown );
GNC_TEST_ADD (suitename, "test_gnc_account_get_map_entry", Fixture, NULL, setup, test_gnc_account_get_map_entry, teardown );
GNC_TEST_ADD (suitename, "gnc account insert & remove split", Fixture, NULL, setup, test_gnc_account_insert_remove_split, teardown );
GNC_TEST_ADD (suitename, "xaccAccount Insert and Remove Lot", Fixture, &good_data, setup, test_xaccAccountInsertRemoveLot, teardown );
GNC_TEST_ADD (suitename, "xaccAccountRecomputeBalance", Fixture, &some_data, setup, test_xaccAccountRecomputeBalance, teardown );
Expand Down

0 comments on commit a5d101d

Please sign in to comment.