summaryrefslogtreecommitdiffstats
path: root/src/test/test-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-04-14 18:52:24 +0200
committerLennart Poettering <lennart@poettering.net>2020-07-01 11:17:28 +0200
commit1146b664e60cc16f9c3ab828029956739ae9552d (patch)
treeac8a95df6e71e8a0d6b3475512eb09943a592709 /src/test/test-util.c
parentlocale-util: add support for touch emoji (diff)
downloadsystemd-1146b664e60cc16f9c3ab828029956739ae9552d.tar.xz
systemd-1146b664e60cc16f9c3ab828029956739ae9552d.zip
macro: add new FOREACH_POINTER() macro magic
This allows us to iterate through a series of specified pointers. It's a bit like FOREACH_STRING(), but for all kinds of pointers.
Diffstat (limited to 'src/test/test-util.c')
-rw-r--r--src/test/test-util.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/test/test-util.c b/src/test/test-util.c
index 76dd72a598..d4a6c8f5c3 100644
--- a/src/test/test-util.c
+++ b/src/test/test-util.c
@@ -410,6 +410,85 @@ static void test_system_tasks_max_scale(void) {
assert_se(system_tasks_max_scale(UINT64_MAX/4, UINT64_MAX) == UINT64_MAX);
}
+static void test_foreach_pointer(void) {
+ int a, b, c, *i;
+ size_t k = 0;
+
+ FOREACH_POINTER(i, &a, &b, &c) {
+ switch (k) {
+
+ case 0:
+ assert_se(i == &a);
+ break;
+
+ case 1:
+ assert_se(i == &b);
+ break;
+
+ case 2:
+ assert_se(i == &c);
+ break;
+
+ default:
+ assert_not_reached("unexpected index");
+ break;
+ }
+
+ k++;
+ }
+
+ assert(k == 3);
+
+ FOREACH_POINTER(i, &b) {
+ assert(k == 3);
+ assert(i == &b);
+ k = 4;
+ }
+
+ assert(k == 4);
+
+ FOREACH_POINTER(i, NULL, &c, NULL, &b, NULL, &a, NULL) {
+ switch (k) {
+
+ case 4:
+ assert_se(i == NULL);
+ break;
+
+ case 5:
+ assert_se(i == &c);
+ break;
+
+ case 6:
+ assert_se(i == NULL);
+ break;
+
+ case 7:
+ assert_se(i == &b);
+ break;
+
+ case 8:
+ assert_se(i == NULL);
+ break;
+
+ case 9:
+ assert_se(i == &a);
+ break;
+
+ case 10:
+ assert_se(i == NULL);
+ break;
+
+ default:
+ assert_not_reached("unexpected index");
+ break;
+ }
+
+ k++;
+ }
+
+ assert(k == 11);
+}
+
int main(int argc, char *argv[]) {
test_setup_logging(LOG_INFO);
@@ -428,6 +507,7 @@ int main(int argc, char *argv[]) {
test_physical_memory_scale();
test_system_tasks_max();
test_system_tasks_max_scale();
+ test_foreach_pointer();
return 0;
}