mirror of
https://github.com/Gnucash/gnucash.git
synced 2026-10-26 08:00:05 -05:00
[account.cpp] gnc_account_child_index non-child acct should return -1
bugfix from 6cac9d0ebb
This commit is contained in:
1 parent
65d573889b
commit
c3e4f374a9
2 files changed
+18
-1
No files matched your search
@@ -2952,7 +2952,8 @@ gnc_account_child_index (const Account *parent, const Account *child)
|
||||
g_return_val_if_fail(GNC_IS_ACCOUNT(parent), -1);
|
||||
g_return_val_if_fail(GNC_IS_ACCOUNT(child), -1);
|
||||
auto& children = GET_PRIVATE(parent)->children;
|
||||
return std::distance (children.begin(), std::find (children.begin(), children.end(), child));
|
||||
auto find_it = std::find (children.begin(), children.end(), child);
|
||||
return find_it == children.end() ? -1 : std::distance (children.begin(), find_it);
|
||||
}
|
||||
|
||||
Account *
|
||||
|
||||
@@ -1854,6 +1854,21 @@ test_gnc_account_append_remove_child (Fixture *fixture, gconstpointer pData)
|
||||
* gnc_account_child_index
|
||||
* gnc_account_nth_child
|
||||
*/
|
||||
|
||||
static void
|
||||
test_gnc_account_child_index (Fixture *fixture, gconstpointer pData)
|
||||
{
|
||||
auto root{gnc_account_get_root (fixture->acct)};
|
||||
g_assert_cmpint (gnc_account_child_index (root, fixture->acct), == , -1);
|
||||
|
||||
auto book{gnc_account_get_book (fixture->acct)};
|
||||
auto new_acct{xaccMallocAccount(book)};
|
||||
g_assert_cmpint (gnc_account_child_index (root, new_acct), == , -1);
|
||||
|
||||
gnc_account_append_child (root, new_acct);
|
||||
g_assert_cmpint (gnc_account_child_index (root, new_acct), == , 2);
|
||||
}
|
||||
|
||||
/* gnc_account_n_descendants
|
||||
gint
|
||||
gnc_account_n_descendants (const Account *account)// C: 12 in 6 */
|
||||
@@ -2860,6 +2875,7 @@ test_suite_account (void)
|
||||
GNC_TEST_ADD_FUNC (suitename, "xaccAccountOrder", test_xaccAccountOrder );
|
||||
GNC_TEST_ADD (suitename, "qofAccountSetParent", Fixture, &some_data, setup, test_qofAccountSetParent, teardown );
|
||||
GNC_TEST_ADD (suitename, "gnc account append/remove child", Fixture, NULL, setup, test_gnc_account_append_remove_child, teardown );
|
||||
GNC_TEST_ADD (suitename, "test_gnc_account_child_index", Fixture, &some_data, setup, test_gnc_account_child_index, teardown );
|
||||
GNC_TEST_ADD (suitename, "gnc account n descendants", Fixture, &some_data, setup, test_gnc_account_n_descendants, teardown );
|
||||
GNC_TEST_ADD (suitename, "gnc account get current depth", Fixture, &some_data, setup, test_gnc_account_get_current_depth, teardown );
|
||||
GNC_TEST_ADD (suitename, "gnc account get tree depth", Fixture, &complex, setup, test_gnc_account_get_tree_depth, teardown );
|
||||
|
||||
Reference in new issue
Block a user