From 9c3ddcbc183a9a96f10cdb14f28258ea61f5f7c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zg=C3=BCr=20Kesim?= Date: Tue, 27 Jun 2023 18:57:05 +0200 Subject: added TALER_adult_age(struct TALER_AgeMask *mask) --- src/util/test_age_restriction.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/util/test_age_restriction.c') diff --git a/src/util/test_age_restriction.c b/src/util/test_age_restriction.c index 29e722acc..53cacc6d5 100644 --- a/src/util/test_age_restriction.c +++ b/src/util/test_age_restriction.c @@ -233,7 +233,7 @@ test_lowest (void) {.age = 22, .expected = 21 }, }; - for (uint8_t n = 0; n < 21; n++) + for (uint8_t n = 0; n < sizeof(test) / sizeof(test[0]); n++) { uint8_t l = TALER_get_lowest_age (&mask, test[n].age); printf ("lowest[%d] for age %d, expected lowest: %d, got: %d\n", @@ -246,6 +246,36 @@ test_lowest (void) } +enum GNUNET_GenericReturnValue +test_adult (void) +{ + struct { struct TALER_AgeMask mask; uint8_t expected; } + test[] = { + { .mask = {.bits = 1 | 1 << 2}, + .expected = 2 }, + { .mask = {.bits = 1 | 1 << 2 | 1 << 3}, + .expected = 3 }, + { .mask = {.bits = 1 | 1 << 3}, + .expected = 3 }, + { .mask = {.bits = 1 | 1 << 22}, + .expected = 22 }, + { .mask = {.bits = 1 | 1 << 10 | 1 << 16 | 1 << 22}, + .expected = 22 }, + }; + for (uint8_t n = 0; n < sizeof(test) / sizeof(test[0]); n++) + { + uint8_t l = TALER_adult_age (&test[n].mask); + printf ("adult[%d] for mask %s, expected: %d, got: %d\n", + n, TALER_age_mask_to_string (&test[n].mask), test[n].expected, l); + if (test[n].expected != l) + return GNUNET_SYSERR; + } + printf ("done with adult\n"); + + return GNUNET_OK; +} + + static struct TALER_AgeMask age_mask = { .bits = 1 | 1 << 8 | 1 << 10 | 1 << 12 | 1 << 14 | 1 << 16 | 1 << 18 | 1 << 21 }; @@ -381,6 +411,8 @@ main (int argc, } if (GNUNET_OK != test_dates ()) return 4; + if (GNUNET_OK != test_adult ()) + return 5; return 0; } -- cgit v1.2.3