mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Merge Maarten Bosmans's 'memleak-fixes' into stable.
This commit is contained in:
commit
df878c6a3d
@ -123,7 +123,7 @@ private:
|
|||||||
class GncFQQuoteSource final : public GncQuoteSource
|
class GncFQQuoteSource final : public GncQuoteSource
|
||||||
{
|
{
|
||||||
const bfs::path c_cmd;
|
const bfs::path c_cmd;
|
||||||
const std::string c_fq_wrapper;
|
std::string c_fq_wrapper;
|
||||||
std::string m_version;
|
std::string m_version;
|
||||||
StrVec m_sources;
|
StrVec m_sources;
|
||||||
std::string m_api_key;
|
std::string m_api_key;
|
||||||
@ -146,11 +146,12 @@ static const std::string empty_string{};
|
|||||||
|
|
||||||
GncFQQuoteSource::GncFQQuoteSource() :
|
GncFQQuoteSource::GncFQQuoteSource() :
|
||||||
c_cmd{bp::search_path("perl")},
|
c_cmd{bp::search_path("perl")},
|
||||||
c_fq_wrapper{std::string(gnc_path_get_bindir()) + "/finance-quote-wrapper"},
|
|
||||||
m_version{}, m_sources{}, m_api_key{}
|
m_version{}, m_sources{}, m_api_key{}
|
||||||
{
|
{
|
||||||
|
char *bindir = gnc_path_get_bindir();
|
||||||
|
c_fq_wrapper = std::string(bindir) + "/finance-quote-wrapper";
|
||||||
|
g_free(bindir);
|
||||||
StrVec args{"-w", c_fq_wrapper, "-v"};
|
StrVec args{"-w", c_fq_wrapper, "-v"};
|
||||||
const std::string empty_string;
|
|
||||||
auto [rv, sources, errors] = run_cmd(args, empty_string);
|
auto [rv, sources, errors] = run_cmd(args, empty_string);
|
||||||
if (rv)
|
if (rv)
|
||||||
{
|
{
|
||||||
|
@ -90,10 +90,15 @@ protected:
|
|||||||
m_book{qof_session_get_book(gnc_get_current_session())}
|
m_book{qof_session_get_book(gnc_get_current_session())}
|
||||||
{
|
{
|
||||||
qof_init();
|
qof_init();
|
||||||
gnc_commodity_table_register();
|
|
||||||
gnc_pricedb_register();
|
/* By setting an empty commodity table on the book before registering
|
||||||
|
* the commodity_table type we avoid adding the default commodities */
|
||||||
auto comm_table{gnc_commodity_table_new()};
|
auto comm_table{gnc_commodity_table_new()};
|
||||||
qof_book_set_data(m_book, GNC_COMMODITY_TABLE, comm_table);
|
qof_book_set_data(m_book, GNC_COMMODITY_TABLE, comm_table);
|
||||||
|
|
||||||
|
gnc_commodity_table_register();
|
||||||
|
gnc_pricedb_register();
|
||||||
|
|
||||||
auto eur = gnc_commodity_new(m_book, "Euro", "ISO4217", "EUR", NULL, 100);
|
auto eur = gnc_commodity_new(m_book, "Euro", "ISO4217", "EUR", NULL, 100);
|
||||||
auto source{gnc_quote_source_lookup_by_internal("currency")};
|
auto source{gnc_quote_source_lookup_by_internal("currency")};
|
||||||
gnc_commodity_begin_edit(eur);
|
gnc_commodity_begin_edit(eur);
|
||||||
@ -101,8 +106,7 @@ protected:
|
|||||||
gnc_commodity_set_quote_source(eur, source);
|
gnc_commodity_set_quote_source(eur, source);
|
||||||
gnc_commodity_commit_edit(eur);
|
gnc_commodity_commit_edit(eur);
|
||||||
gnc_commodity_table_insert(comm_table, eur);
|
gnc_commodity_table_insert(comm_table, eur);
|
||||||
auto usd = gnc_commodity_new(m_book, "United States Dollar", "CURRENCY",
|
auto usd = gnc_commodity_new(m_book, "United States Dollar", "CURRENCY", "USD", NULL, 100);
|
||||||
"USD", NULL, 100);
|
|
||||||
gnc_commodity_table_insert(comm_table, usd);
|
gnc_commodity_table_insert(comm_table, usd);
|
||||||
source = gnc_quote_source_lookup_by_internal("yahoo_json");
|
source = gnc_quote_source_lookup_by_internal("yahoo_json");
|
||||||
auto aapl = gnc_commodity_new(m_book, "Apple", "NASDAQ", "AAPL", NULL, 1);
|
auto aapl = gnc_commodity_new(m_book, "Apple", "NASDAQ", "AAPL", NULL, 1);
|
||||||
@ -111,8 +115,7 @@ protected:
|
|||||||
gnc_commodity_set_quote_source(aapl, source);
|
gnc_commodity_set_quote_source(aapl, source);
|
||||||
gnc_commodity_commit_edit(aapl);
|
gnc_commodity_commit_edit(aapl);
|
||||||
gnc_commodity_table_insert(comm_table, aapl);
|
gnc_commodity_table_insert(comm_table, aapl);
|
||||||
auto hpe = gnc_commodity_new(m_book, "Hewlett Packard", "NYSE", "HPE",
|
auto hpe = gnc_commodity_new(m_book, "Hewlett Packard", "NYSE", "HPE", NULL, 1);
|
||||||
NULL, 1);
|
|
||||||
gnc_commodity_begin_edit(hpe);
|
gnc_commodity_begin_edit(hpe);
|
||||||
gnc_commodity_set_quote_flag(hpe, TRUE);
|
gnc_commodity_set_quote_flag(hpe, TRUE);
|
||||||
gnc_commodity_set_quote_source(hpe, source);
|
gnc_commodity_set_quote_source(hpe, source);
|
||||||
@ -124,10 +127,13 @@ protected:
|
|||||||
gnc_commodity_set_quote_source(fkcm, source);
|
gnc_commodity_set_quote_source(fkcm, source);
|
||||||
gnc_commodity_commit_edit(fkcm);
|
gnc_commodity_commit_edit(fkcm);
|
||||||
gnc_commodity_table_insert(comm_table, fkcm);
|
gnc_commodity_table_insert(comm_table, fkcm);
|
||||||
gnc_quote_source_set_fq_installed("TestSuite", g_list_prepend(nullptr, (void*)"yahoo_json"));
|
GList *sources = g_list_prepend(nullptr, (void*)"yahoo_json");
|
||||||
|
gnc_quote_source_set_fq_installed("TestSuite", sources);
|
||||||
|
g_list_free(sources);
|
||||||
}
|
}
|
||||||
~GncQuotesTest() {
|
~GncQuotesTest() {
|
||||||
gnc_clear_current_session();
|
gnc_clear_current_session();
|
||||||
|
qof_close();
|
||||||
}
|
}
|
||||||
|
|
||||||
QofSession* m_session;
|
QofSession* m_session;
|
||||||
@ -269,6 +275,7 @@ TEST_F(GncQuotesTest, fetch_one_commodity)
|
|||||||
gnc_price_get_value(price)));
|
gnc_price_get_value(price)));
|
||||||
EXPECT_STREQ("Finance::Quote", gnc_price_get_source_string(price));
|
EXPECT_STREQ("Finance::Quote", gnc_price_get_source_string(price));
|
||||||
EXPECT_STREQ("last", gnc_price_get_typestr(price));
|
EXPECT_STREQ("last", gnc_price_get_typestr(price));
|
||||||
|
gnc_price_unref(price);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GncQuotesTest, fetch_one_currency)
|
TEST_F(GncQuotesTest, fetch_one_currency)
|
||||||
@ -299,6 +306,7 @@ TEST_F(GncQuotesTest, fetch_one_currency)
|
|||||||
gnc_price_get_value(price)));
|
gnc_price_get_value(price)));
|
||||||
EXPECT_STREQ("Finance::Quote", gnc_price_get_source_string(price));
|
EXPECT_STREQ("Finance::Quote", gnc_price_get_source_string(price));
|
||||||
EXPECT_STREQ("last", gnc_price_get_typestr(price));
|
EXPECT_STREQ("last", gnc_price_get_typestr(price));
|
||||||
|
gnc_price_unref(price);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GncQuotesTest, no_currency)
|
TEST_F(GncQuotesTest, no_currency)
|
||||||
@ -365,6 +373,7 @@ TEST_F(GncQuotesTest, no_date)
|
|||||||
gnc_price_get_value(price)));
|
gnc_price_get_value(price)));
|
||||||
EXPECT_STREQ("Finance::Quote", gnc_price_get_source_string(price));
|
EXPECT_STREQ("Finance::Quote", gnc_price_get_source_string(price));
|
||||||
EXPECT_STREQ("last", gnc_price_get_typestr(price));
|
EXPECT_STREQ("last", gnc_price_get_typestr(price));
|
||||||
|
gnc_price_unref(price);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(GncQuotesTest, test_version)
|
TEST_F(GncQuotesTest, test_version)
|
||||||
|
@ -99,9 +99,11 @@ GncSqlColumnTableEntry::add_objectref_guid_to_query (QofIdTypeConst obj_name,
|
|||||||
auto inst = get_row_value_from_object<QofInstance*>(obj_name, pObject);
|
auto inst = get_row_value_from_object<QofInstance*>(obj_name, pObject);
|
||||||
if (inst == nullptr) return;
|
if (inst == nullptr) return;
|
||||||
auto guid = qof_instance_get_guid (inst);
|
auto guid = qof_instance_get_guid (inst);
|
||||||
if (guid != nullptr)
|
if (guid != nullptr) {
|
||||||
vec.emplace_back (std::make_pair (std::string{m_col_name},
|
gchar *guid_s = guid_to_string(guid);
|
||||||
quote_string(guid_to_string(guid))));
|
vec.emplace_back (std::make_pair (std::string{m_col_name}, quote_string(guid_s)));
|
||||||
|
g_free(guid_s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -356,9 +358,9 @@ GncSqlColumnTableEntryImpl<CT_GUID>::add_to_query(QofIdTypeConst obj_name,
|
|||||||
|
|
||||||
if (s != nullptr)
|
if (s != nullptr)
|
||||||
{
|
{
|
||||||
|
gchar *guid_s = guid_to_string(s);
|
||||||
vec.emplace_back (std::make_pair (std::string{m_col_name},
|
vec.emplace_back (std::make_pair (std::string{m_col_name}, quote_string(guid_s)));
|
||||||
quote_string(guid_to_string(s))));
|
g_free(guid_s);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,12 +205,8 @@ double_to_string (double value)
|
|||||||
static void
|
static void
|
||||||
add_text_to_node (xmlNodePtr node, const gchar* type, gchar* val)
|
add_text_to_node (xmlNodePtr node, const gchar* type, gchar* val)
|
||||||
{
|
{
|
||||||
gchar* newtype = g_strdup (type);
|
|
||||||
gchar* newval = g_strdup (val);
|
|
||||||
xmlSetProp (node, BAD_CAST "type", BAD_CAST type);
|
xmlSetProp (node, BAD_CAST "type", BAD_CAST type);
|
||||||
xmlNodeSetContent (node, checked_char_cast (val));
|
xmlNodeSetContent (node, checked_char_cast (val));
|
||||||
g_free (newtype);
|
|
||||||
g_free (newval);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_kvp_slot (const char* key, KvpValue* value, void* data);
|
static void add_kvp_slot (const char* key, KvpValue* value, void* data);
|
||||||
|
@ -8,6 +8,12 @@
|
|||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* Variant of EXPECT_STREQ that calls g_free()
|
||||||
|
* on its first argument after the check */
|
||||||
|
#define EXPECT_STREQ_GFREE(a, b) do { char *p_; EXPECT_STREQ(p_ = (a), (b)); g_free(p_); } while (0)
|
||||||
|
|
||||||
|
|
||||||
struct PathTest : public testing::Test
|
struct PathTest : public testing::Test
|
||||||
{
|
{
|
||||||
PathTest() : m_prefix{nullptr} {}
|
PathTest() : m_prefix{nullptr} {}
|
||||||
@ -26,21 +32,24 @@ struct PathTest : public testing::Test
|
|||||||
{
|
{
|
||||||
if (m_prefix)
|
if (m_prefix)
|
||||||
g_free(m_prefix);
|
g_free(m_prefix);
|
||||||
|
/* Clear the statically allocated exe string */
|
||||||
|
gnc_gbr_set_exe(NULL);
|
||||||
}
|
}
|
||||||
char *m_prefix;
|
char *m_prefix;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TEST_F(PathTest, gnc_path_get_prefix)
|
TEST_F(PathTest, gnc_path_get_prefix)
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_BINRELOC
|
#ifdef ENABLE_BINRELOC
|
||||||
EXPECT_STREQ(gnc_path_get_prefix(), m_prefix);
|
EXPECT_STREQ_GFREE(gnc_path_get_prefix(), m_prefix);
|
||||||
#else
|
#else
|
||||||
g_setenv("GNC_UNINSTALLED", "1", TRUE);
|
g_setenv("GNC_UNINSTALLED", "1", TRUE);
|
||||||
g_setenv("GNC_BUILDDIR", m_prefix, 1);
|
g_setenv("GNC_BUILDDIR", m_prefix, 1);
|
||||||
EXPECT_STREQ(gnc_path_get_prefix(), m_prefix);
|
EXPECT_STREQ_GFREE(gnc_path_get_prefix(), m_prefix);
|
||||||
g_unsetenv("GNC_UNINSTALLED");
|
g_unsetenv("GNC_UNINSTALLED");
|
||||||
g_unsetenv("GNC_BUILDDIR");
|
g_unsetenv("GNC_BUILDDIR");
|
||||||
EXPECT_STREQ(gnc_path_get_prefix(), PREFIX);
|
EXPECT_STREQ_GFREE(gnc_path_get_prefix(), PREFIX);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,16 +59,16 @@ TEST_F(PathTest, gnc_path_get_bindir)
|
|||||||
gchar *binpath = g_build_filename(m_prefix, dirname, NULL);
|
gchar *binpath = g_build_filename(m_prefix, dirname, NULL);
|
||||||
g_free(dirname);
|
g_free(dirname);
|
||||||
#ifdef ENABLE_BINRELOC
|
#ifdef ENABLE_BINRELOC
|
||||||
EXPECT_STREQ(gnc_path_get_bindir(), binpath);
|
EXPECT_STREQ_GFREE(gnc_path_get_bindir(), binpath);
|
||||||
g_free(binpath);
|
g_free(binpath);
|
||||||
#else
|
#else
|
||||||
g_setenv("GNC_UNINSTALLED", "1", TRUE);
|
g_setenv("GNC_UNINSTALLED", "1", TRUE);
|
||||||
g_setenv("GNC_BUILDDIR", m_prefix, 1);
|
g_setenv("GNC_BUILDDIR", m_prefix, 1);
|
||||||
EXPECT_STREQ(gnc_path_get_bindir(), binpath);
|
EXPECT_STREQ_GFREE(gnc_path_get_bindir(), binpath);
|
||||||
g_free(binpath);
|
g_free(binpath);
|
||||||
g_unsetenv("GNC_UNINSTALLED");
|
g_unsetenv("GNC_UNINSTALLED");
|
||||||
g_unsetenv("GNC_BUILDDIR");
|
g_unsetenv("GNC_BUILDDIR");
|
||||||
EXPECT_STREQ(gnc_path_get_bindir(), BINDIR);
|
EXPECT_STREQ_GFREE(gnc_path_get_bindir(), BINDIR);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,16 +78,16 @@ TEST_F(PathTest, gnc_path_get_libdir)
|
|||||||
gchar *libpath = g_build_filename(m_prefix, dirname, NULL);
|
gchar *libpath = g_build_filename(m_prefix, dirname, NULL);
|
||||||
g_free(dirname);
|
g_free(dirname);
|
||||||
#ifdef ENABLE_BINRELOC
|
#ifdef ENABLE_BINRELOC
|
||||||
EXPECT_STREQ(gnc_path_get_libdir(), libpath);
|
EXPECT_STREQ_GFREE(gnc_path_get_libdir(), libpath);
|
||||||
g_free(libpath);
|
g_free(libpath);
|
||||||
#else
|
#else
|
||||||
g_setenv("GNC_UNINSTALLED", "1", TRUE);
|
g_setenv("GNC_UNINSTALLED", "1", TRUE);
|
||||||
g_setenv("GNC_BUILDDIR", m_prefix, 1);
|
g_setenv("GNC_BUILDDIR", m_prefix, 1);
|
||||||
EXPECT_STREQ(gnc_path_get_libdir(), libpath);
|
EXPECT_STREQ_GFREE(gnc_path_get_libdir(), libpath);
|
||||||
g_free(libpath);
|
g_free(libpath);
|
||||||
g_unsetenv("GNC_UNINSTALLED");
|
g_unsetenv("GNC_UNINSTALLED");
|
||||||
g_unsetenv("GNC_BUILDDIR");
|
g_unsetenv("GNC_BUILDDIR");
|
||||||
EXPECT_STREQ(gnc_path_get_libdir(), LIBDIR);
|
EXPECT_STREQ_GFREE(gnc_path_get_libdir(), LIBDIR);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,16 +97,16 @@ TEST_F(PathTest, gnc_path_get_datadir)
|
|||||||
gchar *datapath = g_build_filename(m_prefix, dirname, NULL);
|
gchar *datapath = g_build_filename(m_prefix, dirname, NULL);
|
||||||
g_free(dirname);
|
g_free(dirname);
|
||||||
#ifdef ENABLE_BINRELOC
|
#ifdef ENABLE_BINRELOC
|
||||||
EXPECT_STREQ(gnc_path_get_datadir(), datapath);
|
EXPECT_STREQ_GFREE(gnc_path_get_datadir(), datapath);
|
||||||
g_free(datapath);
|
g_free(datapath);
|
||||||
#else
|
#else
|
||||||
g_setenv("GNC_UNINSTALLED", "1", TRUE);
|
g_setenv("GNC_UNINSTALLED", "1", TRUE);
|
||||||
g_setenv("GNC_BUILDDIR", m_prefix, 1);
|
g_setenv("GNC_BUILDDIR", m_prefix, 1);
|
||||||
EXPECT_STREQ(gnc_path_get_datadir(), datapath);
|
EXPECT_STREQ_GFREE(gnc_path_get_datadir(), datapath);
|
||||||
g_free(datapath);
|
g_free(datapath);
|
||||||
g_unsetenv("GNC_UNINSTALLED");
|
g_unsetenv("GNC_UNINSTALLED");
|
||||||
g_unsetenv("GNC_BUILDDIR");
|
g_unsetenv("GNC_BUILDDIR");
|
||||||
EXPECT_STREQ(gnc_path_get_datadir(), DATADIR);
|
EXPECT_STREQ_GFREE(gnc_path_get_datadir(), DATADIR);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,17 +116,17 @@ TEST_F(PathTest, gnc_path_get_sysconfdir)
|
|||||||
gchar *sysconfpath = g_build_filename(m_prefix, dirname, PROJECT_NAME, NULL);
|
gchar *sysconfpath = g_build_filename(m_prefix, dirname, PROJECT_NAME, NULL);
|
||||||
g_free(dirname);
|
g_free(dirname);
|
||||||
#ifdef ENABLE_BINRELOC
|
#ifdef ENABLE_BINRELOC
|
||||||
EXPECT_STREQ(gnc_path_get_pkgsysconfdir(), sysconfpath);
|
EXPECT_STREQ_GFREE(gnc_path_get_pkgsysconfdir(), sysconfpath);
|
||||||
g_free(sysconfpath);
|
g_free(sysconfpath);
|
||||||
#else
|
#else
|
||||||
g_setenv("GNC_UNINSTALLED", "1", TRUE);
|
g_setenv("GNC_UNINSTALLED", "1", TRUE);
|
||||||
g_setenv("GNC_BUILDDIR", m_prefix, 1);
|
g_setenv("GNC_BUILDDIR", m_prefix, 1);
|
||||||
EXPECT_STREQ(gnc_path_get_pkgsysconfdir(), sysconfpath);
|
EXPECT_STREQ_GFREE(gnc_path_get_pkgsysconfdir(), sysconfpath);
|
||||||
g_free(sysconfpath);
|
g_free(sysconfpath);
|
||||||
g_unsetenv("GNC_UNINSTALLED");
|
g_unsetenv("GNC_UNINSTALLED");
|
||||||
g_unsetenv("GNC_BUILDDIR");
|
g_unsetenv("GNC_BUILDDIR");
|
||||||
sysconfpath = g_build_filename(SYSCONFDIR, PROJECT_NAME, NULL);
|
sysconfpath = g_build_filename(SYSCONFDIR, PROJECT_NAME, NULL);
|
||||||
EXPECT_STREQ(gnc_path_get_pkgsysconfdir(), sysconfpath);
|
EXPECT_STREQ_GFREE(gnc_path_get_pkgsysconfdir(), sysconfpath);
|
||||||
g_free(sysconfpath);
|
g_free(sysconfpath);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -99,26 +99,6 @@ KvpValueImpl::get_type() const noexcept
|
|||||||
return KvpValue::Type::INVALID;
|
return KvpValue::Type::INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
KvpFrame *
|
|
||||||
KvpValueImpl::replace_frame_nc (KvpFrame * new_value) noexcept
|
|
||||||
{
|
|
||||||
if (datastore.type() != type_id<KvpFrame *>())
|
|
||||||
return {};
|
|
||||||
auto ret = boost::get<KvpFrame *>(datastore);
|
|
||||||
datastore = new_value;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
GList *
|
|
||||||
KvpValueImpl::replace_glist_nc (GList * new_value) noexcept
|
|
||||||
{
|
|
||||||
if (datastore.type() != type_id<GList *>())
|
|
||||||
return {};
|
|
||||||
auto ret = boost::get<GList *>(datastore);
|
|
||||||
datastore = new_value;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct to_string_visitor : boost::static_visitor<void>
|
struct to_string_visitor : boost::static_visitor<void>
|
||||||
{
|
{
|
||||||
std::ostringstream & output;
|
std::ostringstream & output;
|
||||||
|
@ -100,22 +100,6 @@ struct KvpValueImpl
|
|||||||
*/
|
*/
|
||||||
~KvpValueImpl() noexcept;
|
~KvpValueImpl() noexcept;
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces the frame within this KvpValueImpl.
|
|
||||||
*
|
|
||||||
* If this KvpValueImpl doesn't contain a KvpFrame, nullptr
|
|
||||||
* is returned. Otherwise, the old KvpFrame * is returned.
|
|
||||||
*/
|
|
||||||
KvpFrame * replace_frame_nc (KvpFrame *) noexcept;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Replaces the glist within this KvpValueImpl.
|
|
||||||
*
|
|
||||||
* If this KvpValueImpl doesn't contain a GList, nullptr
|
|
||||||
* is returned. Otherwise, the old GList * is returned.
|
|
||||||
*/
|
|
||||||
GList * replace_glist_nc (GList *) noexcept;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds another value to this KvpValueImpl.
|
* Adds another value to this KvpValueImpl.
|
||||||
*
|
*
|
||||||
|
@ -29,7 +29,19 @@
|
|||||||
#include "../qofquerycore-p.h"
|
#include "../qofquerycore-p.h"
|
||||||
#include <gtest/gtest.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;
|
query_string_def *pdata;
|
||||||
pdata = (query_string_def*)qof_query_string_predicate(
|
pdata = (query_string_def*)qof_query_string_predicate(
|
||||||
@ -43,9 +55,10 @@ TEST(qof_query_construct_predicate, string)
|
|||||||
EXPECT_EQ (QOF_STRING_MATCH_NORMAL, pdata->options);
|
EXPECT_EQ (QOF_STRING_MATCH_NORMAL, pdata->options);
|
||||||
EXPECT_STREQ ("Test", pdata->matchstring);
|
EXPECT_STREQ ("Test", pdata->matchstring);
|
||||||
EXPECT_EQ (FALSE, pdata->is_regex);
|
EXPECT_EQ (FALSE, pdata->is_regex);
|
||||||
|
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(qof_query_construct_predicate, date)
|
TEST_F(QofQueryCoreTest, construct_predicate_date)
|
||||||
{
|
{
|
||||||
query_date_def *pdata;
|
query_date_def *pdata;
|
||||||
pdata = (query_date_def*)qof_query_date_predicate(
|
pdata = (query_date_def*)qof_query_date_predicate(
|
||||||
@ -57,9 +70,10 @@ TEST(qof_query_construct_predicate, date)
|
|||||||
EXPECT_EQ (QOF_COMPARE_LT, pdata->pd.how);
|
EXPECT_EQ (QOF_COMPARE_LT, pdata->pd.how);
|
||||||
EXPECT_EQ (QOF_DATE_MATCH_DAY, pdata->options);
|
EXPECT_EQ (QOF_DATE_MATCH_DAY, pdata->options);
|
||||||
EXPECT_EQ (1524772012, pdata->date);
|
EXPECT_EQ (1524772012, pdata->date);
|
||||||
|
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(qof_query_construct_predicate, numeric)
|
TEST_F(QofQueryCoreTest, construct_predicate_numeric)
|
||||||
{
|
{
|
||||||
query_numeric_def *pdata;
|
query_numeric_def *pdata;
|
||||||
pdata = (query_numeric_def*)qof_query_numeric_predicate(
|
pdata = (query_numeric_def*)qof_query_numeric_predicate(
|
||||||
@ -71,9 +85,10 @@ TEST(qof_query_construct_predicate, numeric)
|
|||||||
EXPECT_EQ (QOF_COMPARE_LTE, pdata->pd.how);
|
EXPECT_EQ (QOF_COMPARE_LTE, pdata->pd.how);
|
||||||
EXPECT_EQ (QOF_NUMERIC_MATCH_CREDIT, pdata->options);
|
EXPECT_EQ (QOF_NUMERIC_MATCH_CREDIT, pdata->options);
|
||||||
EXPECT_TRUE (gnc_numeric_eq({ 500, 100 }, pdata->amount));
|
EXPECT_TRUE (gnc_numeric_eq({ 500, 100 }, pdata->amount));
|
||||||
|
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(qof_query_construct_predicate, guid)
|
TEST_F(QofQueryCoreTest, construct_predicate_guid)
|
||||||
{
|
{
|
||||||
GncGUID *guid = guid_new();
|
GncGUID *guid = guid_new();
|
||||||
GList *guidlist = g_list_prepend (NULL, guid);
|
GList *guidlist = g_list_prepend (NULL, guid);
|
||||||
@ -86,9 +101,10 @@ TEST(qof_query_construct_predicate, guid)
|
|||||||
EXPECT_EQ (QOF_GUID_MATCH_ANY, pdata->options);
|
EXPECT_EQ (QOF_GUID_MATCH_ANY, pdata->options);
|
||||||
EXPECT_TRUE (guid_equal (guid, (const GncGUID*)pdata->guids->data));
|
EXPECT_TRUE (guid_equal (guid, (const GncGUID*)pdata->guids->data));
|
||||||
EXPECT_EQ (NULL, pdata->guids->next);
|
EXPECT_EQ (NULL, pdata->guids->next);
|
||||||
|
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(qof_query_construct_predicate, int32)
|
TEST_F(QofQueryCoreTest, construct_predicate_int32)
|
||||||
{
|
{
|
||||||
query_int32_def *pdata;
|
query_int32_def *pdata;
|
||||||
pdata = (query_int32_def*)qof_query_int32_predicate(
|
pdata = (query_int32_def*)qof_query_int32_predicate(
|
||||||
@ -98,9 +114,10 @@ TEST(qof_query_construct_predicate, int32)
|
|||||||
EXPECT_STREQ (QOF_TYPE_INT32, pdata->pd.type_name);
|
EXPECT_STREQ (QOF_TYPE_INT32, pdata->pd.type_name);
|
||||||
EXPECT_EQ (QOF_COMPARE_EQUAL, pdata->pd.how);
|
EXPECT_EQ (QOF_COMPARE_EQUAL, pdata->pd.how);
|
||||||
EXPECT_EQ (-613, pdata->val);
|
EXPECT_EQ (-613, pdata->val);
|
||||||
|
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(qof_query_construct_predicate, int64)
|
TEST_F(QofQueryCoreTest, query_construct_predicate_int64)
|
||||||
{
|
{
|
||||||
query_int64_def *pdata;
|
query_int64_def *pdata;
|
||||||
pdata = (query_int64_def*)qof_query_int64_predicate(
|
pdata = (query_int64_def*)qof_query_int64_predicate(
|
||||||
@ -110,9 +127,10 @@ TEST(qof_query_construct_predicate, int64)
|
|||||||
EXPECT_STREQ (QOF_TYPE_INT64, pdata->pd.type_name);
|
EXPECT_STREQ (QOF_TYPE_INT64, pdata->pd.type_name);
|
||||||
EXPECT_EQ (QOF_COMPARE_GT, pdata->pd.how);
|
EXPECT_EQ (QOF_COMPARE_GT, pdata->pd.how);
|
||||||
EXPECT_EQ (1000000, pdata->val);
|
EXPECT_EQ (1000000, pdata->val);
|
||||||
|
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(qof_query_construct_predicate, double)
|
TEST_F(QofQueryCoreTest, construct_predicate_double)
|
||||||
{
|
{
|
||||||
query_double_def *pdata;
|
query_double_def *pdata;
|
||||||
pdata = (query_double_def*)qof_query_double_predicate(
|
pdata = (query_double_def*)qof_query_double_predicate(
|
||||||
@ -122,9 +140,10 @@ TEST(qof_query_construct_predicate, double)
|
|||||||
EXPECT_STREQ (QOF_TYPE_DOUBLE, pdata->pd.type_name);
|
EXPECT_STREQ (QOF_TYPE_DOUBLE, pdata->pd.type_name);
|
||||||
EXPECT_EQ (QOF_COMPARE_GTE, pdata->pd.how);
|
EXPECT_EQ (QOF_COMPARE_GTE, pdata->pd.how);
|
||||||
EXPECT_EQ (10.05, pdata->val);
|
EXPECT_EQ (10.05, pdata->val);
|
||||||
|
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(qof_query_construct_predicate, boolean)
|
TEST_F(QofQueryCoreTest, construct_predicate_boolean)
|
||||||
{
|
{
|
||||||
query_boolean_def *pdata;
|
query_boolean_def *pdata;
|
||||||
pdata = (query_boolean_def*)qof_query_boolean_predicate(
|
pdata = (query_boolean_def*)qof_query_boolean_predicate(
|
||||||
@ -134,9 +153,10 @@ TEST(qof_query_construct_predicate, boolean)
|
|||||||
EXPECT_STREQ (QOF_TYPE_BOOLEAN, pdata->pd.type_name);
|
EXPECT_STREQ (QOF_TYPE_BOOLEAN, pdata->pd.type_name);
|
||||||
EXPECT_EQ (QOF_COMPARE_NEQ, pdata->pd.how);
|
EXPECT_EQ (QOF_COMPARE_NEQ, pdata->pd.how);
|
||||||
EXPECT_EQ (TRUE, pdata->val);
|
EXPECT_EQ (TRUE, pdata->val);
|
||||||
|
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(qof_query_construct_predicate, char)
|
TEST_F(QofQueryCoreTest, construct_predicate_char)
|
||||||
{
|
{
|
||||||
query_char_def *pdata;
|
query_char_def *pdata;
|
||||||
pdata = (query_char_def*)qof_query_char_predicate(
|
pdata = (query_char_def*)qof_query_char_predicate(
|
||||||
@ -147,11 +167,11 @@ TEST(qof_query_construct_predicate, char)
|
|||||||
EXPECT_EQ (QOF_COMPARE_EQUAL, pdata->pd.how);
|
EXPECT_EQ (QOF_COMPARE_EQUAL, pdata->pd.how);
|
||||||
EXPECT_EQ (QOF_CHAR_MATCH_ANY, pdata->options);
|
EXPECT_EQ (QOF_CHAR_MATCH_ANY, pdata->options);
|
||||||
EXPECT_STREQ ("Foo", pdata->char_list);
|
EXPECT_STREQ ("Foo", pdata->char_list);
|
||||||
|
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(qof_query_core_predicate_copy, date)
|
TEST_F(QofQueryCoreTest, date_predicate_copy)
|
||||||
{
|
{
|
||||||
qof_query_core_init();
|
|
||||||
query_date_def *pdata, *pdata2;
|
query_date_def *pdata, *pdata2;
|
||||||
pdata = (query_date_def*)qof_query_date_predicate(
|
pdata = (query_date_def*)qof_query_date_predicate(
|
||||||
QOF_COMPARE_LT,
|
QOF_COMPARE_LT,
|
||||||
@ -159,16 +179,16 @@ TEST(qof_query_core_predicate_copy, date)
|
|||||||
1524772012
|
1524772012
|
||||||
);
|
);
|
||||||
pdata2 = (query_date_def*) qof_query_core_predicate_copy ((QofQueryPredData*)pdata);
|
pdata2 = (query_date_def*) qof_query_core_predicate_copy ((QofQueryPredData*)pdata);
|
||||||
|
|
||||||
EXPECT_STREQ (pdata2->pd.type_name, pdata->pd.type_name);
|
EXPECT_STREQ (pdata2->pd.type_name, pdata->pd.type_name);
|
||||||
EXPECT_EQ (pdata2->pd.how, pdata->pd.how);
|
EXPECT_EQ (pdata2->pd.how, pdata->pd.how);
|
||||||
EXPECT_EQ (pdata2->options, pdata->options);
|
EXPECT_EQ (pdata2->options, pdata->options);
|
||||||
EXPECT_EQ (pdata2->date, pdata->date);
|
EXPECT_EQ (pdata2->date, pdata->date);
|
||||||
|
qof_query_core_predicate_free ((QofQueryPredData*) pdata);
|
||||||
|
qof_query_core_predicate_free ((QofQueryPredData*) pdata2);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(qof_query_core_predicate_get_date, date)
|
TEST_F(QofQueryCoreTest, date_predicate_get_date)
|
||||||
{
|
{
|
||||||
qof_query_core_init();
|
|
||||||
time64 date;
|
time64 date;
|
||||||
QofQueryPredData *pdata;
|
QofQueryPredData *pdata;
|
||||||
pdata = qof_query_date_predicate(
|
pdata = qof_query_date_predicate(
|
||||||
@ -176,14 +196,13 @@ TEST(qof_query_core_predicate_get_date, date)
|
|||||||
QOF_DATE_MATCH_DAY,
|
QOF_DATE_MATCH_DAY,
|
||||||
1524772012
|
1524772012
|
||||||
);
|
);
|
||||||
|
|
||||||
EXPECT_TRUE (qof_query_date_predicate_get_date(pdata, &date));
|
EXPECT_TRUE (qof_query_date_predicate_get_date(pdata, &date));
|
||||||
EXPECT_EQ (1524772012, date);
|
EXPECT_EQ (1524772012, date);
|
||||||
|
qof_query_core_predicate_free (pdata);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(qof_query_core_predicate_get_date, numeric)
|
TEST_F(QofQueryCoreTest, numeric_predicate_get_date)
|
||||||
{
|
{
|
||||||
qof_query_core_init();
|
|
||||||
time64 date;
|
time64 date;
|
||||||
QofQueryPredData *pdata;
|
QofQueryPredData *pdata;
|
||||||
pdata = qof_query_numeric_predicate(
|
pdata = qof_query_numeric_predicate(
|
||||||
@ -191,6 +210,6 @@ TEST(qof_query_core_predicate_get_date, numeric)
|
|||||||
QOF_NUMERIC_MATCH_CREDIT,
|
QOF_NUMERIC_MATCH_CREDIT,
|
||||||
{ 1000, 100 }
|
{ 1000, 100 }
|
||||||
);
|
);
|
||||||
|
|
||||||
EXPECT_FALSE (qof_query_date_predicate_get_date(pdata, &date));
|
EXPECT_FALSE (qof_query_date_predicate_get_date(pdata, &date));
|
||||||
|
qof_query_core_predicate_free (pdata);
|
||||||
}
|
}
|
||||||
|
@ -80,8 +80,7 @@ run_test (void)
|
|||||||
|
|
||||||
/*****/
|
/*****/
|
||||||
|
|
||||||
qof_session_end (sess);
|
qof_session_destroy (sess);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -28,9 +28,13 @@
|
|||||||
#include <guid.hpp>
|
#include <guid.hpp>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "cashobjects.h"
|
#include "cashobjects.h"
|
||||||
|
#include "qofid.h"
|
||||||
#include "test-stuff.h"
|
#include "test-stuff.h"
|
||||||
#include "test-engine-stuff.h"
|
#include "test-engine-stuff.h"
|
||||||
#include "qof.h"
|
#include "qof.h"
|
||||||
@ -50,13 +54,17 @@ static void test_null_guid(void)
|
|||||||
guid_free(gp);
|
guid_free(gp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
free_entry (QofInstance* inst, void* data)
|
||||||
|
{
|
||||||
|
g_object_unref (G_OBJECT(inst));
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
run_test (void)
|
run_test (void)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
QofSession *sess;
|
QofSession *sess;
|
||||||
QofBook *book;
|
QofBook *book;
|
||||||
QofInstance *ent;
|
|
||||||
QofCollection *col;
|
QofCollection *col;
|
||||||
QofIdType type;
|
QofIdType type;
|
||||||
GncGUID guid;
|
GncGUID guid;
|
||||||
@ -68,12 +76,10 @@ run_test (void)
|
|||||||
col = qof_book_get_collection (book, "asdf");
|
col = qof_book_get_collection (book, "asdf");
|
||||||
type = qof_collection_get_type (col);
|
type = qof_collection_get_type (col);
|
||||||
|
|
||||||
for (i = 0; i < NENT; i++)
|
for (int i = 0; i < NENT; i++)
|
||||||
{
|
{
|
||||||
ent = static_cast<QofInstance*>(g_object_new(QOF_TYPE_INSTANCE, NULL));
|
|
||||||
guid_replace(&guid);
|
guid_replace(&guid);
|
||||||
ent = static_cast<QofInstance*>(g_object_new(QOF_TYPE_INSTANCE,
|
auto ent = QOF_INSTANCE(g_object_new(QOF_TYPE_INSTANCE, "guid", &guid, NULL));
|
||||||
"guid", &guid, NULL));
|
|
||||||
do_test ((NULL == qof_collection_lookup_entity (col, &guid)),
|
do_test ((NULL == qof_collection_lookup_entity (col, &guid)),
|
||||||
"duplicate guid");
|
"duplicate guid");
|
||||||
ent->e_type = type;
|
ent->e_type = type;
|
||||||
@ -83,6 +89,7 @@ run_test (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Make valgrind happy -- destroy the session. */
|
/* Make valgrind happy -- destroy the session. */
|
||||||
|
qof_collection_foreach(col, free_entry, nullptr);
|
||||||
qof_session_destroy(sess);
|
qof_session_destroy(sess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,19 +30,6 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
TEST (KvpValueTest, Replace_Frame)
|
|
||||||
{
|
|
||||||
auto f1 = new KvpFrameImpl;
|
|
||||||
std::unique_ptr<KvpValueImpl> v1 {new KvpValueImpl {f1}};
|
|
||||||
auto f2 = new KvpFrameImpl;
|
|
||||||
EXPECT_EQ (f1, v1->replace_frame_nc (f2));
|
|
||||||
v1->set (5.2);
|
|
||||||
/*f1 and f2 should be deleted now*/
|
|
||||||
f1 = new KvpFrameImpl;
|
|
||||||
EXPECT_EQ (nullptr, v1->replace_frame_nc (f1));
|
|
||||||
delete f1;
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST (KvpValueTest, Equality)
|
TEST (KvpValueTest, Equality)
|
||||||
{
|
{
|
||||||
std::unique_ptr<KvpValueImpl> v1 {new KvpValueImpl { (int64_t)1}};
|
std::unique_ptr<KvpValueImpl> v1 {new KvpValueImpl { (int64_t)1}};
|
||||||
|
@ -79,7 +79,7 @@ test_lot_kvp ()
|
|||||||
g_assert_cmpstr (gnc_lot_get_notes (lot), ==, NULL);
|
g_assert_cmpstr (gnc_lot_get_notes (lot), ==, NULL);
|
||||||
|
|
||||||
gnc_lot_destroy (lot);
|
gnc_lot_destroy (lot);
|
||||||
qof_session_end (sess);
|
qof_session_destroy (sess);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -108,7 +108,7 @@ run_test (void)
|
|||||||
* XXX not implemented
|
* XXX not implemented
|
||||||
*/
|
*/
|
||||||
success ("automatic lot scrubbing lightly tested and seem to work");
|
success ("automatic lot scrubbing lightly tested and seem to work");
|
||||||
qof_session_end (sess);
|
qof_session_destroy (sess);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,12 +36,12 @@ test_trans_query (Transaction *trans, gpointer data)
|
|||||||
{
|
{
|
||||||
QofBook *book = QOF_BOOK(data);
|
QofBook *book = QOF_BOOK(data);
|
||||||
GList *list;
|
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);
|
qof_query_set_book (q, book);
|
||||||
|
|
||||||
list = xaccQueryGetTransactions (q, QUERY_TXN_MATCH_ANY);
|
list = xaccQueryGetTransactions (q, QUERY_TXN_MATCH_ANY);
|
||||||
|
qof_query_destroy (q);
|
||||||
|
|
||||||
if (g_list_length (list) != 1)
|
if (g_list_length (list) != 1)
|
||||||
{
|
{
|
||||||
failure_args ("test number returned", __FILE__, __LINE__,
|
failure_args ("test number returned", __FILE__, __LINE__,
|
||||||
@ -59,7 +59,6 @@ test_trans_query (Transaction *trans, gpointer data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
success ("found right transaction");
|
success ("found right transaction");
|
||||||
qof_query_destroy (q);
|
|
||||||
g_list_free (list);
|
g_list_free (list);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -80,7 +79,7 @@ run_test (void)
|
|||||||
|
|
||||||
xaccAccountTreeForEachTransaction (root, test_trans_query, book);
|
xaccAccountTreeForEachTransaction (root, test_trans_query, book);
|
||||||
|
|
||||||
qof_session_end (session);
|
qof_session_destroy (session);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user