From d6b49bbc89e899feb66ff1bafbcf6179c720b029 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Wed, 2 Aug 2023 23:15:32 +0800 Subject: [PATCH] [utest-gnc-pricedb.c] tests gnc_pricedb_price_list_insert especially skipping adding duplicate price --- libgnucash/engine/test/utest-gnc-pricedb.c | 37 +++++++++++++++++++--- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/libgnucash/engine/test/utest-gnc-pricedb.c b/libgnucash/engine/test/utest-gnc-pricedb.c index 735ee6a43c..4ac3de9cec 100644 --- a/libgnucash/engine/test/utest-gnc-pricedb.c +++ b/libgnucash/engine/test/utest-gnc-pricedb.c @@ -362,10 +362,6 @@ test_price_list_is_duplicate (Fixture *fixture, gconstpointer pData) gboolean gnc_price_list_insert(PriceList **prices, GNCPrice *p, gboolean check_dupl)// Local: 3:0:0 */ -/* static void -test_gnc_price_list_insert (Fixture *fixture, gconstpointer pData) -{ -}*/ /* gnc_price_list_remove gboolean gnc_price_list_remove(PriceList **prices, GNCPrice *p)// Local: 1:0:0 @@ -682,6 +678,37 @@ guint gnc_pricedb_get_num_prices(GNCPriceDB *db)// C: 2 in 1 Local: 0:0:0 */ +static void +test_gnc_price_list_insert (PriceDBFixture *fixture, gconstpointer pData) +{ + GNCPriceDB *db = fixture->pricedb; + Commodities *c = fixture->com; + QofBook *book = qof_instance_get_book(QOF_INSTANCE(db)); + + g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 42); + + // nop because 12/4/09 already exists + gnc_pricedb_add_price (db, construct_price(book, c->usd, c->aud, + gnc_dmy2time64(12, 4, 2009), + PRICE_SOURCE_USER_PRICE, + gnc_numeric_create(131190, 10000))); + g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 42); + + // num_prices increases because because 14/4/09 doesn't exist yet + gnc_pricedb_add_price (db, construct_price(book, c->usd, c->aud, + gnc_dmy2time64(14, 4, 2009), + PRICE_SOURCE_USER_PRICE, + gnc_numeric_create(131190, 10000))); + g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 43); + + // nop because because 14/4/09 already exists + gnc_pricedb_add_price (db, construct_price(book, c->usd, c->aud, + gnc_dmy2time64(14, 4, 2009), + PRICE_SOURCE_USER_PRICE, + gnc_numeric_create(131190, 10000))); + g_assert_cmpint (gnc_pricedb_get_num_prices(fixture->pricedb), ==, 43); +} + static void test_gnc_price_list_equal (PriceDBFixture *fixture, gconstpointer pData) { @@ -1672,7 +1699,7 @@ test_suite_gnc_pricedb (void) // GNC_TEST_ADD (suitename, "gnc price equal", Fixture, NULL, setup, test_gnc_price_equal, teardown); // GNC_TEST_ADD (suitename, "compare prices by date", Fixture, NULL, setup, test_compare_prices_by_date, teardown); // GNC_TEST_ADD (suitename, "price list is duplicate", Fixture, NULL, setup, test_price_list_is_duplicate, teardown); -// GNC_TEST_ADD (suitename, "gnc price list insert", Fixture, NULL, setup, test_gnc_price_list_insert, teardown); +GNC_TEST_ADD (suitename, "gnc price list insert", PriceDBFixture, NULL, setup, test_gnc_price_list_insert, teardown); // 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);