gnucash maint: Multiple changes pushed
Christopher Lam
clam at code.gnucash.org
Mon Oct 18 10:42:23 EDT 2021
Updated via https://github.com/Gnucash/gnucash/commit/b480600d (commit)
via https://github.com/Gnucash/gnucash/commit/23e528f5 (commit)
from https://github.com/Gnucash/gnucash/commit/de6ee25e (commit)
commit b480600dc89f7befe00bf68d35e2c014e52041ca
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Mon Oct 18 22:30:40 2021 +0800
[gnc-pricedb] gnc_price_list_equal: avoid 4 g_list_length calls
diff --git a/libgnucash/engine/gnc-pricedb.c b/libgnucash/engine/gnc-pricedb.c
index caefdbca2..8e4abc405 100644
--- a/libgnucash/engine/gnc-pricedb.c
+++ b/libgnucash/engine/gnc-pricedb.c
@@ -796,26 +796,30 @@ gnc_price_list_destroy(PriceList *prices)
gboolean
gnc_price_list_equal(PriceList *prices1, PriceList *prices2)
{
- GList *n1, *n2;
+ GList *n1 = prices1;
+ GList *n2 = prices2;
if (prices1 == prices2) return TRUE;
- if (g_list_length (prices1) < g_list_length (prices2))
+ while (n1 || n2)
{
- PINFO ("prices2 has extra prices");
- return FALSE;
- }
-
- if (g_list_length (prices1) > g_list_length (prices2))
- {
- PINFO ("prices1 has extra prices");
- return FALSE;
- }
-
- for (n1 = prices1, n2 = prices2; n1 ; n1 = n1->next, n2 = n2->next)
+ if (!n1)
+ {
+ PINFO ("prices2 has extra prices");
+ return FALSE;
+ }
+ if (!n2)
+ {
+ PINFO ("prices1 has extra prices");
+ return FALSE;
+ }
if (!gnc_price_equal (n1->data, n2->data))
return FALSE;
+ n1 = n1->next;
+ n2 = n2->next;
+ };
+
return TRUE;
}
commit 23e528f51ade50566dd25d7b2f8f6ed8babfcaf4
Author: Christopher Lam <christopher.lck at gmail.com>
Date: Mon Oct 18 22:25:21 2021 +0800
[utest-gnc-pricedb] add tests for gnc_price_list_equal
Also need to change PWARN which causes test failure, to PINFO
diff --git a/libgnucash/engine/gnc-pricedb.c b/libgnucash/engine/gnc-pricedb.c
index 1b15a5e08..caefdbca2 100644
--- a/libgnucash/engine/gnc-pricedb.c
+++ b/libgnucash/engine/gnc-pricedb.c
@@ -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;
}
diff --git a/libgnucash/engine/test/utest-gnc-pricedb.c b/libgnucash/engine/test/utest-gnc-pricedb.c
index eb1728b2b..2bd3b172d 100644
--- a/libgnucash/engine/test/utest-gnc-pricedb.c
+++ b/libgnucash/engine/test/utest-gnc-pricedb.c
@@ -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;
@@ -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)
{
@@ -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);
Summary of changes:
libgnucash/engine/gnc-pricedb.c | 30 +++++++++++++----------
libgnucash/engine/test/utest-gnc-pricedb.c | 38 ++++++++++++++++++++++++++----
2 files changed, 50 insertions(+), 18 deletions(-)
More information about the gnucash-changes
mailing list