From d46bd871bcd34b9e0d633ab15fd9a4747861616c Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Wed, 20 May 2020 15:43:39 -0400 Subject: fixed coding style in db tests and double callbacks in lookup_instances --- src/backenddb/plugin_merchantdb_postgres.c | 4 +- src/backenddb/test_merchantdb.c | 64 +++++++++++------------------- 2 files changed, 26 insertions(+), 42 deletions(-) (limited to 'src/backenddb') diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 670f1d00..874d33c9 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -472,9 +472,9 @@ lookup_instances_cb (void *cls, params, &lookup_accounts_cb, lic); - if (0 == lic->qs) + if (0 > lic->qs) { - /* find_accounts_cb() did not run, still notify about the + /* lookup_accounts_cb() did not run, still notify about the account-less instance! */ call_with_accounts (lic, 0, diff --git a/src/backenddb/test_merchantdb.c b/src/backenddb/test_merchantdb.c index a3f23d48..30a0d883 100644 --- a/src/backenddb/test_merchantdb.c +++ b/src/backenddb/test_merchantdb.c @@ -42,46 +42,33 @@ static struct TALER_MERCHANTDB_Plugin *plugin; static int instance_count; void -lookup_instances_callback (void *cls, const struct - TALER_MerchantPublicKeyP *merchant_pub, - const struct - TALER_MerchantPrivateKeyP *merchant_priv, const - struct - TALER_MERCHANTDB_InstanceSettings *is, - unsigned int accounts_length, const struct - TALER_MERCHANTDB_AccountDetails accounts[]) +lookup_instances_cb (void *cls, + const struct TALER_MerchantPublicKeyP *merchant_pub, + const struct TALER_MerchantPrivateKeyP *merchant_priv, + const struct TALER_MERCHANTDB_InstanceSettings *is, + unsigned int accounts_length, + const struct TALER_MERCHANTDB_AccountDetails accounts[]) { instance_count += 1; } int -check_products_equal (struct TALER_MERCHANTDB_ProductDetails *a, struct - TALER_MERCHANTDB_ProductDetails *b) +check_products_equal (struct TALER_MERCHANTDB_ProductDetails *a, + struct TALER_MERCHANTDB_ProductDetails *b) { - if (strcmp (a->description, b->description) != 0) - return 1; - if (json_equal (a->description_i18n, b->description_i18n) != 1) - return 1; - if (strcmp (a->unit, b->unit) != 0) - return 1; - if (TALER_amount_cmp_currency (&a->price, &b->price) != 0) - return 1; - if (TALER_amount_cmp (&a->price, &b->price) != 0) - return 1; - if (json_equal (a->taxes, b->taxes) != 1) - return 1; - if (a->total_stock != b->total_stock) - return 1; - if (a->total_sold != b->total_sold) - return 1; - if (a->total_lost != b->total_lost) - return 1; - if (json_equal (a->image, b->image) != 1) - return 1; - if (json_equal (a->address, b->address) != 1) - return 1; - if (a->next_restock.abs_value_us != b->next_restock.abs_value_us) + if ((0 != strcmp (a->description, b->description)) || + (1 != json_equal (a->description_i18n, b->description_i18n)) || + (0 != strcmp (a->unit, b->unit)) || + (0 != TALER_amount_cmp_currency (&a->price, &b->price)) || + (0 != TALER_amount_cmp (&a->price, &b->price)) || + (1 != json_equal (a->taxes, b->taxes)) || + (a->total_stock != b->total_stock) || + (a->total_sold != b->total_sold) || + (a->total_lost != b->total_lost) || + (1 != json_equal (a->image, b->image)) || + (1 != json_equal (a->address, b->address)) || + (a->next_restock.abs_value_us != b->next_restock.abs_value_us)) return 1; return 0; } @@ -111,7 +98,7 @@ run (void *cls) /* Test lookup instances- there should be nothing here */ instance_count = 0; if (0 > plugin->lookup_instances (plugin->cls, false, - lookup_instances_callback, cls)) + lookup_instances_cb, cls)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup instances failed\n"); @@ -146,7 +133,6 @@ run (void *cls) is.default_wire_fee_amortization = 1; is.default_wire_transfer_delay = GNUNET_TIME_relative_get_minute_ (); is.default_pay_delay = GNUNET_TIME_relative_get_second_ (); - if (0 > plugin->insert_instance (plugin->cls, &merchant_pub, &merchant_priv, &is)) { @@ -160,7 +146,7 @@ run (void *cls) /* Test lookup instances- is our new instance there? */ instance_count = 0; if (0 > plugin->lookup_instances (plugin->cls, false, - lookup_instances_callback, cls)) + lookup_instances_cb, cls)) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Lookup instances failed\n"); @@ -168,14 +154,13 @@ run (void *cls) plugin->drop_tables (plugin->cls); return; } - /* This test currently FAILS */ - /*if (instance_count != 1) + if (instance_count != 1) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Instance count doesn't match number of instances inserted\n"); result = 1; return; - }*/ + } /* Test update instance */ is.name = "Test - updated"; @@ -281,7 +266,6 @@ run (void *cls) } result = 0; - GNUNET_break (GNUNET_OK == plugin->drop_tables (plugin->cls)); TALER_MERCHANTDB_plugin_unload (plugin); -- cgit v1.2.3