Skip to content

Commit

Permalink
[test-commodities.cpp] add some tests for gnc_quote_sources
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Feb 17, 2024
1 parent f0dc23a commit 9035391
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions libgnucash/engine/test/test-commodities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@
#include "test-engine-stuff.h"
#include "test-stuff.h"

static void
test_quote_sources ()
{
do_test (gnc_quote_source_num_entries(SOURCE_CURRENCY) == 1, "source currency = 1 source");
do_test (gnc_quote_source_lookup_by_ti (SOURCE_CURRENCY, 0) != nullptr, "lookup_by_ti currency exists");
do_test (gnc_quote_source_lookup_by_internal("currency") != nullptr, "lookup_by_internal: currency exists");
do_test (gnc_quote_source_lookup_by_internal("CURRENCY") != nullptr, "lookup_by_internal: CURRENCY exists"); // old internal name

do_test (gnc_quote_source_num_entries(SOURCE_UNKNOWN) == 0, "source unknown = 0 source");
do_test (gnc_quote_source_lookup_by_ti (SOURCE_UNKNOWN, 0) == nullptr, "lookup_by_ti unknown fails");

do_test (gnc_quote_source_num_entries((QuoteSourceType)500) == 0, "invalid = 0 entries");
do_test (gnc_quote_source_lookup_by_ti ((QuoteSourceType)500, 0) == nullptr, "lookup_by_ti invalid returns null, same as new_quote_sources");

gnc_quote_source_add_new ("test-source", true);

do_test (gnc_quote_source_num_entries(SOURCE_UNKNOWN) == 1, "source unknown = 1 source");
do_test (gnc_quote_source_lookup_by_ti (SOURCE_UNKNOWN, 0) != nullptr, "lookup_by_ti unknown exists");

do_test (gnc_quote_source_num_entries((QuoteSourceType)500) == 1, "invalid = 1 entry from new_quote_sources");
do_test (gnc_quote_source_lookup_by_ti ((QuoteSourceType)500, 0) != nullptr, "lookup_by_ti invalid returns new_quote_sources");

// internal name:
do_test (gnc_quote_source_lookup_by_internal("treasure") == nullptr, "lookup_by_internal: treasure doesn't exist");
}

static void
test_commodity(void)
{
Expand Down Expand Up @@ -205,6 +231,7 @@ main (int argc, char **argv)
gnc_commodity_table_register();

test_commodity();
test_quote_sources ();

print_test_results();

Expand Down

0 comments on commit 9035391

Please sign in to comment.