mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[price-quotes] Fix version retrieval.
Plus there's no need for a "not found" version string because GncQuotes construction will throw if Finance::Quote isn't correctly installed. No object, nothing to call version() on.
This commit is contained in:
parent
97e730b8d8
commit
70c9d4c9e3
@ -81,6 +81,7 @@ public:
|
|||||||
virtual bool usable() const noexcept = 0;
|
virtual bool usable() const noexcept = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class GncQuotesImpl
|
class GncQuotesImpl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -94,7 +95,7 @@ public:
|
|||||||
void fetch (gnc_commodity *comm);
|
void fetch (gnc_commodity *comm);
|
||||||
void report (const char* source, const StrVec& commodities, bool verbose);
|
void report (const char* source, const StrVec& commodities, bool verbose);
|
||||||
|
|
||||||
const std::string& version() noexcept { return m_version.empty() ? not_found : m_version; }
|
const std::string& version() noexcept { return m_quotesource->get_version(); }
|
||||||
const QuoteSources& sources() noexcept { return m_sources; }
|
const QuoteSources& sources() noexcept { return m_sources; }
|
||||||
GList* sources_as_glist ();
|
GList* sources_as_glist ();
|
||||||
bool had_failures() noexcept { return !m_failures.empty(); }
|
bool had_failures() noexcept { return !m_failures.empty(); }
|
||||||
@ -110,7 +111,6 @@ private:
|
|||||||
GNCPrice* parse_one_quote(const bpt::ptree&, gnc_commodity*);
|
GNCPrice* parse_one_quote(const bpt::ptree&, gnc_commodity*);
|
||||||
|
|
||||||
std::unique_ptr<GncQuoteSource> m_quotesource;
|
std::unique_ptr<GncQuoteSource> m_quotesource;
|
||||||
std::string m_version;
|
|
||||||
QuoteSources m_sources;
|
QuoteSources m_sources;
|
||||||
QFVec m_failures;
|
QFVec m_failures;
|
||||||
QofBook *m_book;
|
QofBook *m_book;
|
||||||
@ -145,8 +145,8 @@ 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"},
|
c_fq_wrapper{std::string(gnc_path_get_bindir()) + "/finance-quote-wrapper"},
|
||||||
m_ready{false},
|
m_ready{false}, m_version{},
|
||||||
m_version{}, m_sources{}, m_api_key{}
|
m_sources{}, m_api_key{}
|
||||||
{
|
{
|
||||||
StrVec args{"-w", c_fq_wrapper, "-v"};
|
StrVec args{"-w", c_fq_wrapper, "-v"};
|
||||||
const std::string empty_string;
|
const std::string empty_string;
|
||||||
@ -173,6 +173,7 @@ m_version{}, m_sources{}, m_api_key{}
|
|||||||
err += version.empty() ? "" : version;
|
err += version.empty() ? "" : version;
|
||||||
throw(GncQuoteSourceError(err));
|
throw(GncQuoteSourceError(err));
|
||||||
}
|
}
|
||||||
|
m_version = std::move(version);
|
||||||
m_ready = true;
|
m_ready = true;
|
||||||
sources.erase(sources.begin());
|
sources.erase(sources.begin());
|
||||||
m_sources = std::move(sources);
|
m_sources = std::move(sources);
|
||||||
@ -245,7 +246,7 @@ GncFQQuoteSource::run_cmd (const StrVec& args, const std::string& json_string) c
|
|||||||
|
|
||||||
/* GncQuotes implementation */
|
/* GncQuotes implementation */
|
||||||
GncQuotesImpl::GncQuotesImpl() : m_quotesource{new GncFQQuoteSource},
|
GncQuotesImpl::GncQuotesImpl() : m_quotesource{new GncFQQuoteSource},
|
||||||
m_version{}, m_sources{}, m_failures{},
|
m_sources{}, m_failures{},
|
||||||
m_book{qof_session_get_book(gnc_get_current_session())},
|
m_book{qof_session_get_book(gnc_get_current_session())},
|
||||||
m_dflt_curr{gnc_default_currency()}
|
m_dflt_curr{gnc_default_currency()}
|
||||||
{
|
{
|
||||||
@ -255,7 +256,7 @@ GncQuotesImpl::GncQuotesImpl() : m_quotesource{new GncFQQuoteSource},
|
|||||||
}
|
}
|
||||||
|
|
||||||
GncQuotesImpl::GncQuotesImpl(QofBook* book) : m_quotesource{new GncFQQuoteSource},
|
GncQuotesImpl::GncQuotesImpl(QofBook* book) : m_quotesource{new GncFQQuoteSource},
|
||||||
m_version{}, m_sources{}, m_book{book},
|
m_sources{}, m_book{book},
|
||||||
m_dflt_curr{gnc_default_currency()}
|
m_dflt_curr{gnc_default_currency()}
|
||||||
{
|
{
|
||||||
if (!m_quotesource->usable())
|
if (!m_quotesource->usable())
|
||||||
@ -265,7 +266,7 @@ m_dflt_curr{gnc_default_currency()}
|
|||||||
|
|
||||||
GncQuotesImpl::GncQuotesImpl(QofBook* book, std::unique_ptr<GncQuoteSource> quote_source) :
|
GncQuotesImpl::GncQuotesImpl(QofBook* book, std::unique_ptr<GncQuoteSource> quote_source) :
|
||||||
m_quotesource{std::move(quote_source)},
|
m_quotesource{std::move(quote_source)},
|
||||||
m_version{}, m_sources{}, m_book{book}, m_dflt_curr{gnc_default_currency()}
|
m_sources{}, m_book{book}, m_dflt_curr{gnc_default_currency()}
|
||||||
{
|
{
|
||||||
if (!m_quotesource->usable())
|
if (!m_quotesource->usable())
|
||||||
return;
|
return;
|
||||||
|
@ -60,8 +60,6 @@ struct GncQuoteException : public std::runtime_error
|
|||||||
GncQuoteException(const std::string& msg) : std::runtime_error(msg) {}
|
GncQuoteException(const std::string& msg) : std::runtime_error(msg) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::string not_found = std::string ("Not Found");
|
|
||||||
|
|
||||||
class GncQuotesImpl;
|
class GncQuotesImpl;
|
||||||
|
|
||||||
class GncQuotes
|
class GncQuotes
|
||||||
|
@ -147,6 +147,11 @@ TEST_F(GncQuotesTest, online_wiggle)
|
|||||||
// EXPECT_EQ(GncQuoteError::QUOTE_FAILED, std::get<2>(failures[1]));
|
// EXPECT_EQ(GncQuoteError::QUOTE_FAILED, std::get<2>(failures[1]));
|
||||||
EXPECT_EQ(3u, gnc_pricedb_get_num_prices(pricedb));
|
EXPECT_EQ(3u, gnc_pricedb_get_num_prices(pricedb));
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
TEST_F(GncQuotesTest, fq_failure)
|
||||||
|
{
|
||||||
|
EXPECT_THROW(GncQuotes quotes;, GncQuoteException);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
TEST_F(GncQuotesTest, offline_wiggle)
|
TEST_F(GncQuotesTest, offline_wiggle)
|
||||||
@ -346,3 +351,9 @@ TEST_F(GncQuotesTest, no_date)
|
|||||||
EXPECT_STREQ("last", gnc_price_get_typestr(price));
|
EXPECT_STREQ("last", gnc_price_get_typestr(price));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(GncQuotesTest, test_version)
|
||||||
|
{
|
||||||
|
StrVec quote_vec, err_vec;
|
||||||
|
GncQuotesImpl quotes(m_book, std::make_unique<GncMockQuoteSource>(std::move(quote_vec), std::move(err_vec)));
|
||||||
|
EXPECT_STREQ("9.99", quotes.version().c_str());
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user