Merge Richard Cohen branch 'fix-test-leaks-from-get-random-string' into stable #1715

This commit is contained in:
Christopher Lam 2023-07-24 13:07:40 +08:00
commit cdc5b6a796
6 changed files with 31 additions and 20 deletions

View File

@ -76,12 +76,13 @@ test_string_fcn (GncAddress *address, const char *message,
void (*set) (GncAddress *, const char *str),
const char * (*get)(const GncAddress *))
{
char const *str = get_random_string ();
char *str = get_random_string ();
do_test (!gncAddressIsDirty (address), "test if start dirty");
set (address, str);
do_test (gncAddressIsDirty (address), "test dirty later");
do_test (g_strcmp0 (get (address), str) == 0, message);
g_free (str);
gncAddressClearDirty (address);
}

View File

@ -72,6 +72,7 @@ test_commodity(void)
do_test(
g_strcmp0(fullname, gnc_commodity_get_fullname(com)) == 0,
"fullnames equal test");
g_free (fullname);
do_test(
g_strcmp0(name_space, gnc_commodity_get_namespace(com)) == 0,
@ -80,10 +81,12 @@ test_commodity(void)
do_test(
g_strcmp0(mnemonic, gnc_commodity_get_mnemonic(com)) == 0,
"mnemonic equal test");
g_free (mnemonic);
do_test(
g_strcmp0(cusip, gnc_commodity_get_cusip(com)) == 0,
"cusip equal test");
g_free (cusip);
do_test(
gnc_commodity_get_fraction(com) == fraction,
@ -126,6 +129,10 @@ test_commodity(void)
com2 = gnc_commodity_new(book, fullname, name_space, mnemonic,
cusip, fraction);
g_free (fullname);
g_free (mnemonic);
g_free (cusip);
do_test(
gnc_commodity_equiv(com, com2), "commodity equiv");

View File

@ -111,16 +111,16 @@ test_customer (void)
g_list_free (list);
}
{
const char *str = get_random_string();
const char *res;
char *str = get_random_string();
res = NULL;
gncCustomerBeginEdit(customer);
gncCustomerSetName (customer, str);
gncCustomerCommitEdit(customer);
res = qof_object_printable (GNC_ID_CUSTOMER, customer);
const char *res = qof_object_printable (GNC_ID_CUSTOMER, customer);
do_test (res != NULL, "Printable NULL?");
do_test (g_strcmp0 (str, res) == 0, "Printable equals");
g_free (str);
}
do_test (gncCustomerGetJoblist (customer, TRUE) == NULL, "joblist empty");
@ -143,7 +143,7 @@ test_string_fcn (QofBook *book, const char *message,
const char * (*get)(const GncCustomer *))
{
GncCustomer *customer = gncCustomerCreate (book);
char const *str = get_random_string ();
char *str = get_random_string ();
do_test (!gncCustomerIsDirty (customer), "test if start dirty");
gncCustomerBeginEdit (customer);
@ -158,6 +158,7 @@ test_string_fcn (QofBook *book, const char *message,
*/
// do_test (!gncCustomerIsDirty (customer), "test dirty after commit");
do_test (g_strcmp0 (get (customer), str) == 0, message);
g_free (str);
gncCustomerSetActive (customer, FALSE);
count++;
}

View File

@ -117,15 +117,14 @@ test_employee (void)
g_list_free (list);
}
{
const char *str = get_random_string();
const char *res;
GncAddress *addr;
char *str = get_random_string();
addr = gncEmployeeGetAddr (employee);
GncAddress *addr = gncEmployeeGetAddr (employee);
gncAddressSetName (addr, str);
res = qof_object_printable (GNC_ID_EMPLOYEE, employee);
const char *res = qof_object_printable (GNC_ID_EMPLOYEE, employee);
do_test (res != NULL, "Printable NULL?");
do_test (g_strcmp0 (str, res) == 0, "Printable equals");
g_free (str);
}
qof_book_destroy (book);
@ -137,7 +136,7 @@ test_string_fcn (QofBook *book, const char *message,
const char * (*get)(const GncEmployee *))
{
GncEmployee *employee = gncEmployeeCreate (book);
char const *str = get_random_string ();
char *str = get_random_string ();
do_test (!gncEmployeeIsDirty (employee), "test if start dirty");
gncEmployeeBeginEdit (employee);
@ -152,6 +151,7 @@ test_string_fcn (QofBook *book, const char *message,
*/
// do_test (!gncEmployeeIsDirty (employee), "test dirty after commit");
do_test (g_strcmp0 (get (employee), str) == 0, message);
g_free (str);
gncEmployeeSetActive (employee, FALSE);
count++;
}

View File

@ -113,13 +113,13 @@ test_job (void)
}
#endif
{
const char *str = get_random_string();
const char *res;
char *str = get_random_string();
gncJobSetName (job, str);
res = qof_object_printable (GNC_ID_JOB, job);
const char *res = qof_object_printable (GNC_ID_JOB, job);
do_test (res != NULL, "Printable NULL?");
do_test (g_strcmp0 (str, res) == 0, "Printable equals");
g_free (str);
}
{
GList *list;
@ -154,7 +154,7 @@ test_string_fcn (QofBook *book, const char *message,
const char * (*get)(const GncJob *))
{
GncJob *job = gncJobCreate (book);
char const *str = get_random_string ();
char *str = get_random_string ();
do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test if start dirty");
gncJobBeginEdit (job);
@ -169,6 +169,7 @@ test_string_fcn (QofBook *book, const char *message,
*/
// do_test (!qof_instance_is_dirty (QOF_INSTANCE(job)), "test dirty after commit");
do_test (g_strcmp0 (get (job), str) == 0, message);
g_free (str);
gncJobSetActive (job, FALSE);
count++;
}

View File

@ -117,13 +117,13 @@ test_vendor (void)
g_list_free (list);
}
{
const char *str = get_random_string();
const char *res;
char *str = get_random_string();
gncVendorSetName (vendor, str);
res = qof_object_printable (GNC_ID_VENDOR, vendor);
const char *res = qof_object_printable (GNC_ID_VENDOR, vendor);
do_test (res != NULL, "Printable NULL?");
do_test (g_strcmp0 (str, res) == 0, "Printable equals");
g_free (str);
}
qof_book_destroy (book);
@ -135,7 +135,7 @@ test_string_fcn (QofBook *book, const char *message,
const char * (*get)(const GncVendor *))
{
GncVendor *vendor = gncVendorCreate (book);
char const *str = get_random_string ();
char *str = get_random_string ();
do_test (!gncVendorIsDirty (vendor), "test if start dirty");
gncVendorBeginEdit (vendor);
@ -150,6 +150,7 @@ test_string_fcn (QofBook *book, const char *message,
*/
// do_test (!gncVendorIsDirty (vendor), "test dirty after commit");
do_test (g_strcmp0 (get (vendor), str) == 0, message);
g_free (str);
gncVendorSetActive (vendor, FALSE);
count++;
}