tests: add simple test cases for line iterators
authorBartosz Golaszewski <bartekgola@gmail.com>
Wed, 1 Mar 2017 17:14:10 +0000 (18:14 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Wed, 1 Mar 2017 17:14:10 +0000 (18:14 +0100)
We'll test them some more though after new functionalities in
gpio-mockup are released in kernel 4.11.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
tests/unit/tests-iter.c

index 07b15bf8f51f9dc130b1227cccc6f57e9308fd7a..719223297c82c07905c6bd702196348af23a0737 100644 (file)
@@ -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 });