[Account.cpp] small modification xaccAccountSetLastNum

if last-num is empty-string, remove the slot. this makes the behaviour
consistent with other slots.
This commit is contained in:
Christopher Lam
2024-10-13 08:34:56 +08:00
parent d13f930a8c
commit ecabcef084
2 changed files with 11 additions and 6 deletions

View File

@@ -4812,13 +4812,18 @@ xaccAccountGetLastNum (const Account *acc)
void
xaccAccountSetLastNum (Account *acc, const char *num)
{
GValue v = G_VALUE_INIT;
g_return_if_fail(GNC_IS_ACCOUNT(acc));
g_value_init (&v, G_TYPE_STRING);
g_value_set_static_string (&v, num);
xaccAccountBeginEdit (acc);
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {"last-num"});
if (num && *num)
{
GValue v = G_VALUE_INIT;
g_value_init (&v, G_TYPE_STRING);
g_value_set_static_string (&v, num);
qof_instance_set_path_kvp (QOF_INSTANCE (acc), &v, {"last-num"});
g_value_unset (&v);
}
else
qof_instance_set_path_kvp (QOF_INSTANCE (acc), nullptr, {"last-num"});
mark_account (acc);
xaccAccountCommitEdit (acc);
}

View File

@@ -1107,7 +1107,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (xaccAccountGetLastNum (account), ==, "red");
xaccAccountSetLastNum (account, "");
g_assert_cmpstr (xaccAccountGetLastNum (account), ==, "");
g_assert_cmpstr (xaccAccountGetLastNum (account), ==, nullptr);
xaccAccountSetLastNum (account, " ");
g_assert_cmpstr (xaccAccountGetLastNum (account), ==, " ");