mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-16 18:25:11 -06:00
[price-quotes] Implement mock quote source.
Note that because the non-default constructor exists only on GncQuotesImpl we must use that directly and violate the pimpl.
This commit is contained in:
parent
4dd3922871
commit
b8642e55d9
@ -43,6 +43,26 @@ gnc_default_currency(void)
|
||||
#include <gtest/gtest.h>
|
||||
#include "../gnc-quotes.cpp"
|
||||
|
||||
class GncMockQuoteSource final : public GncQuoteSource
|
||||
{
|
||||
const std::string m_version{"9.99"};
|
||||
const StrVec m_sources{"currency", "yahoo_json"};
|
||||
const StrVec m_quotes{
|
||||
"{\"EUR\":{\"symbol\":\"EUR\",\"currency\":\"USD\",\"success\":\"1\",\"inverted\":0,\"last\":1.0004},\"AAPL\":{\"eps\":6.05,\"success\":1,\"year_range\":\" 129.04 - 182.94\",\"currency\":\"USD\",\"exchange\":\"Sourced from Yahoo Finance (as JSON)\",\"volume\":73539475,\"close\":157.22,\"high\":158.39,\"open\":156.64,\"div_yield\":0.5660857,\"last\":157.96,\"isodate\":\"2022-09-01\",\"method\":\"yahoo_json\",\"name\":\"AAPL (Apple Inc.)\",\"pe\":26.10909,\"low\":154.67,\"type\":\"EQUITY\",\"symbol\":\"AAPL\",\"date\":\"09/01/2022\"},\"HPE\":{\"symbol\":\"HPE\",\"date\":\"09/01/2022\",\"low\":13.13,\"type\":\"EQUITY\",\"method\":\"yahoo_json\",\"name\":\"HPE (Hewlett Packard Enterprise Comp)\",\"isodate\":\"2022-09-01\",\"pe\":4.7921147,\"last\":13.37,\"high\":13.535,\"close\":13.6,\"open\":13.5,\"div_yield\":3.5294116,\"volume\":16370483,\"exchange\":\"Sourced from Yahoo Finance (as JSON)\",\"currency\":\"USD\",\"year_range\":\" 12.4 - 17.76\",\"eps\":2.79,\"success\":1},\"FKCM\":{\"success\":0,\"symbol\":\"FKCM\",\"errormsg\":\"Error retrieving quote for FKCM - no listing for this name found. Please check symbol and the two letter extension (if any)\"}}"
|
||||
};
|
||||
const StrVec m_errors{};
|
||||
public:
|
||||
virtual const std::string& get_version() const noexcept override { return m_version; }
|
||||
virtual const StrVec& get_sources() const noexcept override { return m_sources; }
|
||||
virtual QuoteResult get_quotes(const std::string&) const override;
|
||||
virtual bool usable() const noexcept override { return true; }
|
||||
};
|
||||
|
||||
QuoteResult
|
||||
GncMockQuoteSource::get_quotes(const std::string& json_string) const
|
||||
{
|
||||
return {0, m_quotes, m_errors};
|
||||
}
|
||||
class GncQuotesTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
@ -114,11 +134,19 @@ TEST_F(GncQuotesTest, quotable_commodities)
|
||||
}
|
||||
|
||||
#ifdef HAVE_F_Q
|
||||
TEST_F(GncQuotesTest, wiggle)
|
||||
TEST_F(GncQuotesTest, online_wiggle)
|
||||
{
|
||||
GncQuotes quotes;
|
||||
quotes.fetch(m_book);
|
||||
auto pricedb{gnc_pricedb_get_db(m_book)};
|
||||
EXPECT_EQ(3u, gnc_pricedb_get_num_prices(pricedb));
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
TEST_F(GncQuotesTest, offline_wiggle)
|
||||
{
|
||||
GncQuotesImpl quotes(m_book, std::make_unique<GncMockQuoteSource>());
|
||||
quotes.fetch(m_book);
|
||||
auto pricedb{gnc_pricedb_get_db(m_book)};
|
||||
EXPECT_EQ(3u, gnc_pricedb_get_num_prices(pricedb));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user