Don't crash and do pass tests.

This commit is contained in:
John Ralls 2023-03-02 17:03:39 -08:00
parent af02dae286
commit bbfa378783
2 changed files with 10 additions and 9 deletions

View File

@ -2481,7 +2481,7 @@ set_kvp_string_path (Account *acc, std::vector<std::string> const & path,
g_return_if_fail(GNC_IS_ACCOUNT(acc));
xaccAccountBeginEdit(acc);
if (value)
if (value && *value)
{
GValue v = G_VALUE_INIT;
g_value_init (&v, G_TYPE_STRING);
@ -2510,7 +2510,7 @@ get_kvp_string_path (const Account *acc, std::vector<std::string> const & path,
*v = G_VALUE_INIT;
if (acc == NULL) return NULL; // how to check path is valid??
qof_instance_get_path_kvp (QOF_INSTANCE (acc), v, path);
return G_VALUE_HOLDS_STRING (&v) ? g_value_get_string (v) : NULL;
return G_VALUE_HOLDS_STRING (v) ? g_value_get_string (v) : NULL;
}
static const char*

View File

@ -19,6 +19,7 @@
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA gnu@gnu.org *
********************************************************************/
#include <cstddef>
#include <glib.h>
#include <config.h>
@ -1153,7 +1154,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (xaccAccountGetTaxUSCode (account), ==, "red");
xaccAccountSetTaxUSCode (account, "");
g_assert_cmpstr (xaccAccountGetTaxUSCode (account), ==, "");
g_assert_cmpstr (xaccAccountGetTaxUSCode (account), ==, nullptr);
xaccAccountSetTaxUSCode (account, " ");
g_assert_cmpstr (xaccAccountGetTaxUSCode (account), ==, " ");
@ -1171,7 +1172,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (xaccAccountGetTaxUSPayerNameSource (account), ==, "red");
xaccAccountSetTaxUSPayerNameSource (account, "");
g_assert_cmpstr (xaccAccountGetTaxUSPayerNameSource (account), ==, "");
g_assert_cmpstr (xaccAccountGetTaxUSPayerNameSource (account), ==, nullptr);
xaccAccountSetTaxUSPayerNameSource (account, " ");
g_assert_cmpstr (xaccAccountGetTaxUSPayerNameSource (account), ==, " ");
@ -1192,7 +1193,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (xaccAccountGetFilter (account), ==, "unset");
xaccAccountSetFilter (account, " unset ");
g_assert_cmpstr (xaccAccountGetFilter (account), ==, "unset");
g_assert_cmpstr (xaccAccountGetFilter (account), ==, " unset ");
xaccAccountSetFilter (account, "");
g_assert_cmpstr (xaccAccountGetFilter (account), ==, nullptr);
@ -1210,7 +1211,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (xaccAccountGetSortOrder (account), ==, "unset");
xaccAccountSetSortOrder (account, " unset ");
g_assert_cmpstr (xaccAccountGetSortOrder (account), ==, "unset");
g_assert_cmpstr (xaccAccountGetSortOrder (account), ==, " unset ");
xaccAccountSetSortOrder (account, "");
g_assert_cmpstr (xaccAccountGetSortOrder (account), ==, nullptr);
@ -1228,7 +1229,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (xaccAccountGetNotes (account), ==, "unset");
xaccAccountSetNotes (account, " unset ");
g_assert_cmpstr (xaccAccountGetNotes (account), ==, "unset");
g_assert_cmpstr (xaccAccountGetNotes (account), ==, " unset ");
xaccAccountSetNotes (account, "");
g_assert_cmpstr (xaccAccountGetNotes (account), ==, nullptr);
@ -1301,7 +1302,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (dxaccAccountGetPriceSrc (account), ==, "boo");
dxaccAccountSetPriceSrc (account, "");
g_assert_cmpstr (dxaccAccountGetPriceSrc (account), ==, "");
g_assert_cmpstr (dxaccAccountGetPriceSrc (account), ==, nullptr);
dxaccAccountSetPriceSrc (account, nullptr);
g_assert_cmpstr (dxaccAccountGetPriceSrc (account), ==, nullptr);
@ -1313,7 +1314,7 @@ test_gnc_account_kvp_setters_getters (Fixture *fixture, gconstpointer pData)
g_assert_cmpstr (dxaccAccountGetQuoteTZ (account), ==, "boo");
dxaccAccountSetQuoteTZ (account, "");
g_assert_cmpstr (dxaccAccountGetQuoteTZ (account), ==, "");
g_assert_cmpstr (dxaccAccountGetQuoteTZ (account), ==, nullptr);
dxaccAccountSetQuoteTZ (account, nullptr);
g_assert_cmpstr (dxaccAccountGetQuoteTZ (account), ==, nullptr);