[test] Properly destroy resources on end of tests

This fixes memory leaks that are only present in testing code.
Not very useful on itself, but it does make it easier to fix memory
leaks and other AddressSanitizer problems in actual gnucash code later.
This commit is contained in:
Maarten Bosmans 2023-03-17 21:16:01 +01:00
parent ed3fe00880
commit 0d86be6d2a
5 changed files with 23 additions and 12 deletions

View File

@ -270,6 +270,7 @@ TEST_F(GncQuotesTest, fetch_one_commodity)
gnc_price_get_value(price)));
EXPECT_STREQ("Finance::Quote", gnc_price_get_source_string(price));
EXPECT_STREQ("last", gnc_price_get_typestr(price));
gnc_price_unref(price);
}
TEST_F(GncQuotesTest, fetch_one_currency)
@ -300,6 +301,7 @@ TEST_F(GncQuotesTest, fetch_one_currency)
gnc_price_get_value(price)));
EXPECT_STREQ("Finance::Quote", gnc_price_get_source_string(price));
EXPECT_STREQ("last", gnc_price_get_typestr(price));
gnc_price_unref(price);
}
TEST_F(GncQuotesTest, no_currency)
@ -366,6 +368,7 @@ TEST_F(GncQuotesTest, no_date)
gnc_price_get_value(price)));
EXPECT_STREQ("Finance::Quote", gnc_price_get_source_string(price));
EXPECT_STREQ("last", gnc_price_get_typestr(price));
gnc_price_unref(price);
}
TEST_F(GncQuotesTest, test_version)

View File

@ -55,6 +55,7 @@ TEST_F(QofQueryCoreTest, construct_predicate_string)
EXPECT_EQ (QOF_STRING_MATCH_NORMAL, pdata->options);
EXPECT_STREQ ("Test", pdata->matchstring);
EXPECT_EQ (FALSE, pdata->is_regex);
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
}
TEST_F(QofQueryCoreTest, construct_predicate_date)
@ -69,6 +70,7 @@ TEST_F(QofQueryCoreTest, construct_predicate_date)
EXPECT_EQ (QOF_COMPARE_LT, pdata->pd.how);
EXPECT_EQ (QOF_DATE_MATCH_DAY, pdata->options);
EXPECT_EQ (1524772012, pdata->date);
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
}
TEST_F(QofQueryCoreTest, construct_predicate_numeric)
@ -83,6 +85,7 @@ TEST_F(QofQueryCoreTest, construct_predicate_numeric)
EXPECT_EQ (QOF_COMPARE_LTE, pdata->pd.how);
EXPECT_EQ (QOF_NUMERIC_MATCH_CREDIT, pdata->options);
EXPECT_TRUE (gnc_numeric_eq({ 500, 100 }, pdata->amount));
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
}
TEST_F(QofQueryCoreTest, construct_predicate_guid)
@ -98,6 +101,7 @@ TEST_F(QofQueryCoreTest, construct_predicate_guid)
EXPECT_EQ (QOF_GUID_MATCH_ANY, pdata->options);
EXPECT_TRUE (guid_equal (guid, (const GncGUID*)pdata->guids->data));
EXPECT_EQ (NULL, pdata->guids->next);
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
}
TEST_F(QofQueryCoreTest, construct_predicate_int32)
@ -110,6 +114,7 @@ TEST_F(QofQueryCoreTest, construct_predicate_int32)
EXPECT_STREQ (QOF_TYPE_INT32, pdata->pd.type_name);
EXPECT_EQ (QOF_COMPARE_EQUAL, pdata->pd.how);
EXPECT_EQ (-613, pdata->val);
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
}
TEST_F(QofQueryCoreTest, query_construct_predicate_int64)
@ -122,6 +127,7 @@ TEST_F(QofQueryCoreTest, query_construct_predicate_int64)
EXPECT_STREQ (QOF_TYPE_INT64, pdata->pd.type_name);
EXPECT_EQ (QOF_COMPARE_GT, pdata->pd.how);
EXPECT_EQ (1000000, pdata->val);
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
}
TEST_F(QofQueryCoreTest, construct_predicate_double)
@ -134,6 +140,7 @@ TEST_F(QofQueryCoreTest, construct_predicate_double)
EXPECT_STREQ (QOF_TYPE_DOUBLE, pdata->pd.type_name);
EXPECT_EQ (QOF_COMPARE_GTE, pdata->pd.how);
EXPECT_EQ (10.05, pdata->val);
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
}
TEST_F(QofQueryCoreTest, construct_predicate_boolean)
@ -146,6 +153,7 @@ TEST_F(QofQueryCoreTest, construct_predicate_boolean)
EXPECT_STREQ (QOF_TYPE_BOOLEAN, pdata->pd.type_name);
EXPECT_EQ (QOF_COMPARE_NEQ, pdata->pd.how);
EXPECT_EQ (TRUE, pdata->val);
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
}
TEST_F(QofQueryCoreTest, construct_predicate_char)
@ -159,6 +167,7 @@ TEST_F(QofQueryCoreTest, construct_predicate_char)
EXPECT_EQ (QOF_COMPARE_EQUAL, pdata->pd.how);
EXPECT_EQ (QOF_CHAR_MATCH_ANY, pdata->options);
EXPECT_STREQ ("Foo", pdata->char_list);
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
}
TEST_F(QofQueryCoreTest, date_predicate_copy)
@ -170,11 +179,12 @@ TEST_F(QofQueryCoreTest, date_predicate_copy)
1524772012
);
pdata2 = (query_date_def*) qof_query_core_predicate_copy ((QofQueryPredData*)pdata);
EXPECT_STREQ (pdata2->pd.type_name, pdata->pd.type_name);
EXPECT_EQ (pdata2->pd.how, pdata->pd.how);
EXPECT_EQ (pdata2->options, pdata->options);
EXPECT_EQ (pdata2->date, pdata->date);
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
qof_query_core_predicate_free ((QofQueryPredData*) pdata2);
}
TEST_F(QofQueryCoreTest, date_predicate_get_date)
@ -186,9 +196,9 @@ TEST_F(QofQueryCoreTest, date_predicate_get_date)
QOF_DATE_MATCH_DAY,
1524772012
);
EXPECT_TRUE (qof_query_date_predicate_get_date(pdata, &date));
EXPECT_EQ (1524772012, date);
qof_query_core_predicate_free (pdata);
}
TEST_F(QofQueryCoreTest, numeric_predicate_get_date)
@ -200,6 +210,6 @@ TEST_F(QofQueryCoreTest, numeric_predicate_get_date)
QOF_NUMERIC_MATCH_CREDIT,
{ 1000, 100 }
);
EXPECT_FALSE (qof_query_date_predicate_get_date(pdata, &date));
qof_query_core_predicate_free (pdata);
}

View File

@ -80,8 +80,7 @@ run_test (void)
/*****/
qof_session_end (sess);
qof_session_destroy (sess);
}
int

View File

@ -79,7 +79,7 @@ test_lot_kvp ()
g_assert_cmpstr (gnc_lot_get_notes (lot), ==, NULL);
gnc_lot_destroy (lot);
qof_session_end (sess);
qof_session_destroy (sess);
}
static void
@ -108,7 +108,7 @@ run_test (void)
* XXX not implemented
*/
success ("automatic lot scrubbing lightly tested and seem to work");
qof_session_end (sess);
qof_session_destroy (sess);
}

View File

@ -36,12 +36,12 @@ test_trans_query (Transaction *trans, gpointer data)
{
QofBook *book = QOF_BOOK(data);
GList *list;
QofQuery *q;
q = make_trans_query (trans, ALL_QT);
QofQuery *q = make_trans_query (trans, ALL_QT);
qof_query_set_book (q, book);
list = xaccQueryGetTransactions (q, QUERY_TXN_MATCH_ANY);
qof_query_destroy (q);
if (g_list_length (list) != 1)
{
failure_args ("test number returned", __FILE__, __LINE__,
@ -59,7 +59,6 @@ test_trans_query (Transaction *trans, gpointer data)
}
success ("found right transaction");
qof_query_destroy (q);
g_list_free (list);
return 0;
@ -80,7 +79,7 @@ run_test (void)
xaccAccountTreeForEachTransaction (root, test_trans_query, book);
qof_session_end (session);
qof_session_destroy (session);
}
int