Skip to content

Commit

Permalink
[test] Use test fixture to initialize and destroy resources
Browse files Browse the repository at this point in the history
  • Loading branch information
mkbosmans committed Apr 2, 2023
1 parent 35aeed4 commit ed3fe00
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
1 change: 1 addition & 0 deletions libgnucash/app-utils/test/gtest-gnc-quotes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class GncQuotesTest : public ::testing::Test
}
~GncQuotesTest() {
gnc_clear_current_session();
qof_close();
}

QofSession* m_session;
Expand Down
3 changes: 3 additions & 0 deletions libgnucash/core-utils/test/gtest-path-utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ struct PathTest : public testing::Test
{
if (m_prefix)
g_free(m_prefix);
/* Clear the statically allocated exe string */
gnc_gbr_set_exe(NULL);
}
char *m_prefix;
};


TEST_F(PathTest, gnc_path_get_prefix)
{
#ifdef ENABLE_BINRELOC
Expand Down
39 changes: 24 additions & 15 deletions libgnucash/engine/test/gtest-qofquerycore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@
#include "../qofquerycore-p.h"
#include <gtest/gtest.h>

TEST(qof_query_construct_predicate, string)

class QofQueryCoreTest : public ::testing::Test {
protected:
QofQueryCoreTest() {
qof_query_core_init();
}
~QofQueryCoreTest() {
qof_query_core_shutdown();
}
};


TEST_F(QofQueryCoreTest, construct_predicate_string)
{
query_string_def *pdata;
pdata = (query_string_def*)qof_query_string_predicate(
Expand All @@ -45,7 +57,7 @@ TEST(qof_query_construct_predicate, string)
EXPECT_EQ (FALSE, pdata->is_regex);
}

TEST(qof_query_construct_predicate, date)
TEST_F(QofQueryCoreTest, construct_predicate_date)
{
query_date_def *pdata;
pdata = (query_date_def*)qof_query_date_predicate(
Expand All @@ -59,7 +71,7 @@ TEST(qof_query_construct_predicate, date)
EXPECT_EQ (1524772012, pdata->date);
}

TEST(qof_query_construct_predicate, numeric)
TEST_F(QofQueryCoreTest, construct_predicate_numeric)
{
query_numeric_def *pdata;
pdata = (query_numeric_def*)qof_query_numeric_predicate(
Expand All @@ -73,7 +85,7 @@ TEST(qof_query_construct_predicate, numeric)
EXPECT_TRUE (gnc_numeric_eq({ 500, 100 }, pdata->amount));
}

TEST(qof_query_construct_predicate, guid)
TEST_F(QofQueryCoreTest, construct_predicate_guid)
{
GncGUID *guid = guid_new();
GList *guidlist = g_list_prepend (NULL, guid);
Expand All @@ -88,7 +100,7 @@ TEST(qof_query_construct_predicate, guid)
EXPECT_EQ (NULL, pdata->guids->next);
}

TEST(qof_query_construct_predicate, int32)
TEST_F(QofQueryCoreTest, construct_predicate_int32)
{
query_int32_def *pdata;
pdata = (query_int32_def*)qof_query_int32_predicate(
Expand All @@ -100,7 +112,7 @@ TEST(qof_query_construct_predicate, int32)
EXPECT_EQ (-613, pdata->val);
}

TEST(qof_query_construct_predicate, int64)
TEST_F(QofQueryCoreTest, query_construct_predicate_int64)
{
query_int64_def *pdata;
pdata = (query_int64_def*)qof_query_int64_predicate(
Expand All @@ -112,7 +124,7 @@ TEST(qof_query_construct_predicate, int64)
EXPECT_EQ (1000000, pdata->val);
}

TEST(qof_query_construct_predicate, double)
TEST_F(QofQueryCoreTest, construct_predicate_double)
{
query_double_def *pdata;
pdata = (query_double_def*)qof_query_double_predicate(
Expand All @@ -124,7 +136,7 @@ TEST(qof_query_construct_predicate, double)
EXPECT_EQ (10.05, pdata->val);
}

TEST(qof_query_construct_predicate, boolean)
TEST_F(QofQueryCoreTest, construct_predicate_boolean)
{
query_boolean_def *pdata;
pdata = (query_boolean_def*)qof_query_boolean_predicate(
Expand All @@ -136,7 +148,7 @@ TEST(qof_query_construct_predicate, boolean)
EXPECT_EQ (TRUE, pdata->val);
}

TEST(qof_query_construct_predicate, char)
TEST_F(QofQueryCoreTest, construct_predicate_char)
{
query_char_def *pdata;
pdata = (query_char_def*)qof_query_char_predicate(
Expand All @@ -149,9 +161,8 @@ TEST(qof_query_construct_predicate, char)
EXPECT_STREQ ("Foo", pdata->char_list);
}

TEST(qof_query_core_predicate_copy, date)
TEST_F(QofQueryCoreTest, date_predicate_copy)
{
qof_query_core_init();
query_date_def *pdata, *pdata2;
pdata = (query_date_def*)qof_query_date_predicate(
QOF_COMPARE_LT,
Expand All @@ -166,9 +177,8 @@ TEST(qof_query_core_predicate_copy, date)
EXPECT_EQ (pdata2->date, pdata->date);
}

TEST(qof_query_core_predicate_get_date, date)
TEST_F(QofQueryCoreTest, date_predicate_get_date)
{
qof_query_core_init();
time64 date;
QofQueryPredData *pdata;
pdata = qof_query_date_predicate(
Expand All @@ -181,9 +191,8 @@ TEST(qof_query_core_predicate_get_date, date)
EXPECT_EQ (1524772012, date);
}

TEST(qof_query_core_predicate_get_date, numeric)
TEST_F(QofQueryCoreTest, numeric_predicate_get_date)
{
qof_query_core_init();
time64 date;
QofQueryPredData *pdata;
pdata = qof_query_numeric_predicate(
Expand Down

0 comments on commit ed3fe00

Please sign in to comment.