Skip to content

Commit

Permalink
[utest-gnc-pricedb] add tests for gnc_price_list_equal
Browse files Browse the repository at this point in the history
Also need to change PWARN which causes test failure, to PINFO
  • Loading branch information
christopherlam committed Oct 18, 2021
1 parent de6ee25 commit 23e528f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
4 changes: 2 additions & 2 deletions libgnucash/engine/gnc-pricedb.c
Original file line number Diff line number Diff line change
Expand Up @@ -802,13 +802,13 @@ gnc_price_list_equal(PriceList *prices1, PriceList *prices2)

if (g_list_length (prices1) < g_list_length (prices2))
{
PWARN ("prices2 has extra prices");
PINFO ("prices2 has extra prices");
return FALSE;
}

if (g_list_length (prices1) > g_list_length (prices2))
{
PWARN ("prices1 has extra prices");
PINFO ("prices1 has extra prices");
return FALSE;
}

Expand Down
38 changes: 33 additions & 5 deletions libgnucash/engine/test/utest-gnc-pricedb.c
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,6 @@ test_gnc_price_list_destroy (Fixture *fixture, gconstpointer pData)
gboolean
gnc_price_list_equal(PriceList *prices1, PriceList *prices2)// Local: 1:0:0
*/
/* static void
test_gnc_price_list_equal (Fixture *fixture, gconstpointer pData)
{
}*/
typedef struct
{
GNCPriceDB *pricedb;
Expand Down Expand Up @@ -686,6 +682,38 @@ test_num_prices_helper (Fixture *fixture, gconstpointer pData)
guint
gnc_pricedb_get_num_prices(GNCPriceDB *db)// C: 2 in 1 Local: 0:0:0
*/

static void
test_gnc_price_list_equal (PriceDBFixture *fixture, gconstpointer pData)
{
PriceList *p1 = NULL;
PriceList *p2 = NULL;
Commodities *c = fixture->com;
gnc_commodity *aud = c->aud;

/* p1 and p2 are both NULL */
g_assert (gnc_price_list_equal (p1, p2));

p1 = gnc_pricedb_lookup_latest_any_currency(fixture->pricedb, aud);

/* p1 is PriceList, p2 is NULL */
g_assert (!gnc_price_list_equal (p1, p2));

p2 = p1;

/* p1 and p2 both point to the same PriceList */
g_assert (gnc_price_list_equal (p1, p2));

p2 = gnc_pricedb_lookup_latest_any_currency(fixture->pricedb, aud);

/* p1 and p2 are different PriceLists, but are identical in contents */
g_assert (p1 != p2);
g_assert (gnc_price_list_equal (p1, p2));

gnc_price_list_destroy (p1);
gnc_price_list_destroy (p2);
}

static void
test_gnc_pricedb_get_num_prices (PriceDBFixture *fixture, gconstpointer pData)
{
Expand Down Expand Up @@ -1649,7 +1677,7 @@ test_suite_gnc_pricedb (void)
// GNC_TEST_ADD (suitename, "gnc price list remove", Fixture, NULL, setup, test_gnc_price_list_remove, teardown);
// GNC_TEST_ADD (suitename, "price list destroy helper", Fixture, NULL, setup, test_price_list_destroy_helper, teardown);
// GNC_TEST_ADD (suitename, "gnc price list destroy", Fixture, NULL, setup, test_gnc_price_list_destroy, teardown);
// GNC_TEST_ADD (suitename, "gnc price list equal", Fixture, NULL, setup, test_gnc_price_list_equal, teardown);
GNC_TEST_ADD (suitename, "gnc price list equal", PriceDBFixture, NULL, setup, test_gnc_price_list_equal, teardown);
// GNC_TEST_ADD (suitename, "gnc pricedb init", Fixture, NULL, setup, test_gnc_pricedb_init, teardown);
// GNC_TEST_ADD (suitename, "gnc pricedb create", Fixture, NULL, setup, test_gnc_pricedb_create, teardown);
// GNC_TEST_ADD (suitename, "destroy pricedb currency hash data", Fixture, NULL, setup, test_destroy_pricedb_currency_hash_data, teardown);
Expand Down

0 comments on commit 23e528f

Please sign in to comment.