From: Bartosz Golaszewski Date: Fri, 24 Feb 2017 11:20:07 +0000 (+0100) Subject: tests: test case for gpiod_foreach_chip_noclose() X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=955d35dd5bc901e6de7f0a76e8240362ac793896;p=qemu-gpiodev%2Flibgpiod.git tests: test case for gpiod_foreach_chip_noclose() Add a test for the noclose variants of the chip iterator routines. Signed-off-by: Bartosz Golaszewski --- diff --git a/tests/unit/tests-iter.c b/tests/unit/tests-iter.c index 1fc30fe..07b15bf 100644 --- a/tests/unit/tests-iter.c +++ b/tests/unit/tests-iter.c @@ -38,3 +38,51 @@ static void chip_iter(void) } GU_DEFINE_TEST(chip_iter, "gpiod_chip iterator", GU_LINES_UNNAMED, { 8, 8, 8 }); + +static void chip_iter_noclose(void) +{ + GU_CLEANUP(gu_free_chip_iter_noclose) + struct gpiod_chip_iter *iter = NULL; + GU_CLEANUP(gu_close_chip) struct gpiod_chip *chipA; + GU_CLEANUP(gu_close_chip) struct gpiod_chip *chipB; + GU_CLEANUP(gu_close_chip) struct gpiod_chip *chipC; + struct gpiod_chip *chip; + bool A, B, C; + + A = B = C = false; + + iter = gpiod_chip_iter_new(); + GU_ASSERT_NOT_NULL(iter); + + gpiod_foreach_chip_noclose(iter, chip) { + GU_ASSERT(!gpiod_chip_iter_err(iter)); + + if (strcmp(gpiod_chip_label(chip), "gpio-mockup-A") == 0) { + A = true; + chipA = chip; + } else if (strcmp(gpiod_chip_label(chip), + "gpio-mockup-B") == 0) { + B = true; + chipB = chip; + } else if (strcmp(gpiod_chip_label(chip), + "gpio-mockup-C") == 0) { + C = true; + chipC = chip; + } + } + + GU_ASSERT(A); + GU_ASSERT(B); + GU_ASSERT(C); + + gpiod_chip_iter_free_noclose(iter); + iter = NULL; + + /* See if the chips are still open and usable. */ + GU_ASSERT_STR_EQ(gpiod_chip_label(chipA), "gpio-mockup-A"); + GU_ASSERT_STR_EQ(gpiod_chip_label(chipB), "gpio-mockup-B"); + GU_ASSERT_STR_EQ(gpiod_chip_label(chipC), "gpio-mockup-C"); +} +GU_DEFINE_TEST(chip_iter_noclose, + "gpiod_chip iterator noclose", + GU_LINES_UNNAMED, { 8, 8, 8 });