mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-20 11:48:30 -06:00
Use a std::unique_ptr<GncOptionDB> instead of a raw ptr.
Passing references to it to the gnc_register_option functions. Not tested yet with SWIG, might not work. Includes introducing fixtures to gtest-gnc-optiondb.cpp.
This commit is contained in:
parent
94628097e4
commit
6ccb9dbb9e
@ -63,6 +63,7 @@ private:
|
|||||||
std::function<void(void*)> m_set_ui_value;
|
std::function<void(void*)> m_set_ui_value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using GncOptionDBPtr = std::unique_ptr<GncOptionDB>;
|
||||||
/**
|
/**
|
||||||
* Create an empty option database.
|
* Create an empty option database.
|
||||||
*
|
*
|
||||||
@ -70,33 +71,29 @@ private:
|
|||||||
* that for Guile.
|
* that for Guile.
|
||||||
* @return A newly allocated GncOptionDB. Use delete to destroy it.
|
* @return A newly allocated GncOptionDB. Use delete to destroy it.
|
||||||
*/
|
*/
|
||||||
GncOptionDB *gnc_option_db_new(void);
|
GncOptionDBPtr gnc_option_db_new(void);
|
||||||
|
|
||||||
void gnc_register_string_option(GncOptionDB* db, const char* section,
|
void gnc_register_string_option(const GncOptionDBPtr& db, const char* section,
|
||||||
const char* name, const char* key,
|
const char* name, const char* key,
|
||||||
const char* doc_string, std::string value);
|
const char* doc_string, std::string value);
|
||||||
|
|
||||||
|
void gnc_register_text_option(const GncOptionDBPtr& db, const char* section,
|
||||||
void gnc_register_string_option(GncOptionDB* db, const char* section,
|
|
||||||
const char* name, const char* key,
|
const char* name, const char* key,
|
||||||
const char* doc_string, std::string value);
|
const char* doc_string, std::string value);
|
||||||
|
|
||||||
void gnc_register_text_option(GncOptionDB* db, const char* section,
|
void gnc_register_budget_option(const GncOptionDBPtr& db, const char* section,
|
||||||
const char* name, const char* key,
|
|
||||||
const char* doc_string, std::string value);
|
|
||||||
|
|
||||||
void gnc_register_budget_option(GncOptionDB* db, const char* section,
|
|
||||||
const char* name, const char* key,
|
const char* name, const char* key,
|
||||||
const char* doc_string, GncBudget* value);
|
const char* doc_string, GncBudget* value);
|
||||||
|
|
||||||
void gnc_register_commodity_option(GncOptionDB* db, const char* section,
|
void gnc_register_commodity_option(const GncOptionDBPtr& db, const char* section,
|
||||||
const char* name, const char* key,
|
const char* name, const char* key,
|
||||||
const char* doc_string,
|
const char* doc_string,
|
||||||
gnc_commodity* value);
|
gnc_commodity* value);
|
||||||
|
|
||||||
void gnc_register_currency_option(GncOptionDB* db, const char* section,
|
void gnc_register_currency_option(const GncOptionDBPtr& db, const char* section,
|
||||||
const char* name, const char* key,
|
const char* name, const char* key,
|
||||||
const char* doc_string, gnc_commodity* value);
|
const char* doc_string, gnc_commodity* value);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif //GNC_OPTIONDB_HPP_
|
#endif //GNC_OPTIONDB_HPP_
|
||||||
|
@ -24,44 +24,47 @@
|
|||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <gnc-optiondb.hpp>
|
#include <gnc-optiondb.hpp>
|
||||||
|
|
||||||
TEST(GncOptionDB, test_ctor)
|
class GncOptionDBTest : public ::testing::Test
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
GncOptionDBTest() : m_db{gnc_option_db_new()} {}
|
||||||
|
|
||||||
|
GncOptionDBPtr m_db;
|
||||||
|
};
|
||||||
|
|
||||||
|
TEST_F(GncOptionDBTest, test_ctor)
|
||||||
{
|
{
|
||||||
EXPECT_NO_THROW ({ GncOptionDB optiondb; });
|
EXPECT_NO_THROW ({ GncOptionDB optiondb; });
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(GncOptionDB, test_register_option)
|
TEST_F(GncOptionDBTest, test_register_option)
|
||||||
{
|
{
|
||||||
GncOptionDB optiondb;
|
|
||||||
GncOption option1{"foo", "bar", "baz", "Phony Option",
|
GncOption option1{"foo", "bar", "baz", "Phony Option",
|
||||||
std::string{"waldo"}};
|
std::string{"waldo"}};
|
||||||
optiondb.register_option("foo", std::move(option1));
|
m_db->register_option("foo", std::move(option1));
|
||||||
EXPECT_EQ(optiondb.num_sections(), 1);
|
EXPECT_EQ(m_db->num_sections(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(GncOptionDB, test_lookup_string_option)
|
TEST_F(GncOptionDBTest, test_lookup_string_option)
|
||||||
{
|
{
|
||||||
GncOptionDB optiondb;
|
|
||||||
GncOption option1{"foo", "bar", "baz", "Phony Option",
|
GncOption option1{"foo", "bar", "baz", "Phony Option",
|
||||||
std::string{"waldo"}};
|
std::string{"waldo"}};
|
||||||
optiondb.register_option("foo", std::move(option1));
|
m_db->register_option("foo", std::move(option1));
|
||||||
EXPECT_STREQ("waldo", optiondb.lookup_string_option("foo", "bar").c_str());
|
EXPECT_STREQ("waldo", m_db->lookup_string_option("foo", "bar").c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(GncOptionDB, test_unregister_option)
|
TEST_F(GncOptionDBTest, test_unregister_option)
|
||||||
{
|
{
|
||||||
GncOptionDB optiondb;
|
|
||||||
GncOption option1{"foo", "bar", "baz", "Phony Option",
|
GncOption option1{"foo", "bar", "baz", "Phony Option",
|
||||||
std::string{"waldo"}};
|
std::string{"waldo"}};
|
||||||
optiondb.register_option("foo", std::move(option1));
|
m_db->register_option("foo", std::move(option1));
|
||||||
optiondb.unregister_option("foo", "bar");
|
m_db->unregister_option("foo", "bar");
|
||||||
EXPECT_TRUE(optiondb.lookup_string_option("foo", "bar").empty());
|
EXPECT_TRUE(m_db->lookup_string_option("foo", "bar").empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(GncOptionDB, test_register_string_option)
|
TEST_F(GncOptionDBTest, test_register_string_option)
|
||||||
{
|
{
|
||||||
GncOptionDB* db = gnc_option_db_new();
|
gnc_register_string_option(m_db, "foo", "bar", "baz", "Phony Option",
|
||||||
gnc_register_string_option(db, "foo", "bar", "baz", "Phony Option",
|
|
||||||
std::string{"waldo"});
|
std::string{"waldo"});
|
||||||
EXPECT_STREQ("waldo", db->lookup_string_option("foo", "bar").c_str());
|
EXPECT_STREQ("waldo", m_db->lookup_string_option("foo", "bar").c_str());
|
||||||
delete db;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user