From: Tim Kourt <tim.a.kourt@linux.intel.com>
To: ell@lists.01.org
Subject: [PATCH 2/2] unit: Add l_uintset_foreach tests
Date: Wed, 06 Mar 2019 14:03:11 -0800 [thread overview]
Message-ID: <20190306220311.18897-2-tim.a.kourt@linux.intel.com> (raw)
In-Reply-To: <20190306220311.18897-1-tim.a.kourt@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 3583 bytes --]
---
unit/test-uintset.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 97 insertions(+), 1 deletion(-)
diff --git a/unit/test-uintset.c b/unit/test-uintset.c
index 42d9698..4488cd9 100644
--- a/unit/test-uintset.c
+++ b/unit/test-uintset.c
@@ -2,7 +2,7 @@
*
* Embedded Linux library
*
- * Copyright (C) 2015 Intel Corporation. All rights reserved.
+ * Copyright (C) 2015-2019 Intel Corporation. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -167,6 +167,101 @@ static void test_uintset_find_unused(const void *data)
l_uintset_free(set);
}
+static void uintset_foreach(uint32_t number, void *user_data)
+{
+ struct l_uintset *check = user_data;
+
+ l_uintset_take(check, number);
+}
+
+static void test_uintset_foreach(const void *data)
+{
+ struct l_uintset *set;
+ struct l_uintset *check;
+ int i;
+
+ set = l_uintset_new_from_range(0, 63);
+ check = l_uintset_new_from_range(0, 63);
+ assert(set);
+ assert(check);
+
+ for (i = 0; i < 64; i++) {
+ assert(l_uintset_put(set, i));
+ assert(l_uintset_put(check, i));
+ }
+
+ l_uintset_foreach(set, uintset_foreach, check);
+ assert(l_uintset_find_max(check) == 64);
+
+ l_uintset_free(set);
+ l_uintset_free(check);
+
+ set = l_uintset_new_from_range(0, 127);
+ check = l_uintset_new_from_range(0, 127);
+ assert(set);
+ assert(check);
+
+ assert(l_uintset_put(set, 127));
+ assert(l_uintset_put(check, 127));
+
+ l_uintset_foreach(set, uintset_foreach, check);
+ assert(l_uintset_find_max(check) == 128);
+
+ l_uintset_free(set);
+ l_uintset_free(check);
+
+ set = l_uintset_new_from_range(0, 191);
+ check = l_uintset_new_from_range(0, 191);
+ assert(set);
+ assert(check);
+
+ assert(l_uintset_put(set, 50));
+ assert(l_uintset_put(check, 50));
+ assert(l_uintset_put(set, 150));
+ assert(l_uintset_put(check, 150));
+
+ l_uintset_foreach(set, uintset_foreach, check);
+ assert(l_uintset_find_max(check) == 192);
+
+ l_uintset_free(set);
+ l_uintset_free(check);
+
+ set = l_uintset_new_from_range(0, 192);
+ check = l_uintset_new_from_range(0, 192);
+ assert(set);
+ assert(check);
+
+ assert(l_uintset_put(set, 0));
+ assert(l_uintset_put(check, 0));
+ assert(l_uintset_put(set, 63));
+ assert(l_uintset_put(check, 63));
+ assert(l_uintset_put(set, 120));
+ assert(l_uintset_put(check, 120));
+
+ l_uintset_foreach(set, uintset_foreach, check);
+ assert(l_uintset_find_max(check) == 193);
+
+ l_uintset_free(set);
+ l_uintset_free(check);
+
+ set = l_uintset_new_from_range(0, 192);
+ check = l_uintset_new_from_range(0, 192);
+ assert(set);
+ assert(check);
+
+ assert(l_uintset_put(set, 0));
+ assert(l_uintset_put(check, 0));
+
+ assert(l_uintset_put(set, 192));
+ assert(l_uintset_put(check, 192));
+
+ l_uintset_foreach(set, uintset_foreach, check);
+ assert(l_uintset_find_max(check) == 193);
+
+ l_uintset_free(set);
+ l_uintset_free(check);
+}
+
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
@@ -175,6 +270,7 @@ int main(int argc, char *argv[])
l_test_add("l_uintset sanity check #2", test_uintset_2, NULL);
l_test_add("l_uintset sanity check #3", test_uintset_3, NULL);
l_test_add("l_uintset sanity check #4", test_uintset_4, NULL);
+ l_test_add("l_uintset for each tests", test_uintset_foreach, NULL);
l_test_add("l_uintset find unused tests", test_uintset_find_unused,
NULL);
--
2.13.6
next prev parent reply other threads:[~2019-03-06 22:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-06 22:03 [PATCH 1/2] uintset: Add l_uintset_foreach Tim Kourt
2019-03-06 22:03 ` Tim Kourt [this message]
2019-03-07 16:03 ` Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190306220311.18897-2-tim.a.kourt@linux.intel.com \
--to=tim.a.kourt@linux.intel.com \
--cc=ell@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.