From: Bartosz Golaszewski Date: Wed, 1 Mar 2017 17:14:10 +0000 (+0100) Subject: tests: add simple test cases for line iterators X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=a39be20651b61794c3cd9071490b01f56631db69;p=qemu-gpiodev%2Flibgpiod.git tests: add simple test cases for line iterators We'll test them some more though after new functionalities in gpio-mockup are released in kernel 4.11. Signed-off-by: Bartosz Golaszewski --- diff --git a/tests/unit/tests-iter.c b/tests/unit/tests-iter.c index 07b15bf..7192232 100644 --- a/tests/unit/tests-iter.c +++ b/tests/unit/tests-iter.c @@ -86,3 +86,51 @@ static void chip_iter_noclose(void) GU_DEFINE_TEST(chip_iter_noclose, "gpiod_chip iterator noclose", GU_LINES_UNNAMED, { 8, 8, 8 }); + +static void line_iter(void) +{ + GU_CLEANUP(gu_close_chip) struct gpiod_chip *chip = NULL; + struct gpiod_line_iter iter; + struct gpiod_line *line; + unsigned int i = 0; + + chip = gpiod_chip_open(gu_chip_path(0)); + GU_ASSERT_NOT_NULL(chip); + + gpiod_line_iter_init(&iter, chip); + + gpiod_foreach_line(&iter, line) { + GU_ASSERT(!gpiod_line_iter_err(&iter)); + GU_ASSERT_EQ(i, gpiod_line_offset(line)); + i++; + } + + GU_ASSERT_EQ(8, i); +} +GU_DEFINE_TEST(line_iter, "line iterator", + GU_LINES_UNNAMED, { 8 }); + +static void line_iter_static_initializer(void) +{ + GU_CLEANUP(gu_close_chip) struct gpiod_chip *chip = NULL; + struct gpiod_line *line; + unsigned int i = 0; + + chip = gpiod_chip_open(gu_chip_path(0)); + GU_ASSERT_NOT_NULL(chip); + + { + struct gpiod_line_iter iter = GPIOD_LINE_ITER_INITIALIZER(chip); + + gpiod_foreach_line(&iter, line) { + GU_ASSERT(!gpiod_line_iter_err(&iter)); + GU_ASSERT_EQ(i, gpiod_line_offset(line)); + i++; + } + } + + GU_ASSERT_EQ(8, i); +} +GU_DEFINE_TEST(line_iter_static_initializer, + "line iterator static initializer", + GU_LINES_UNNAMED, { 8 });