tests: add a couple line test cases
authorBartosz Golaszewski <bartekgola@gmail.com>
Wed, 22 Feb 2017 09:57:23 +0000 (10:57 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Wed, 22 Feb 2017 09:57:23 +0000 (10:57 +0100)
Add first test cases for GPIO lines.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
tests/unit/Makefile.am
tests/unit/tests-line.c [new file with mode: 0644]

index 260b22e612d0253102eb8617cf01b61cd3126e37..3e216cc488dd02cbb06a7f730dcba4a8f43a8877 100644 (file)
@@ -13,4 +13,4 @@ DEPENDENCIES = libgpiod.la
 
 check_PROGRAMS = gpiod-unit
 
-gpiod_unit_SOURCES = gpiod-unit.c tests-chip.c tests-iter.c
+gpiod_unit_SOURCES = gpiod-unit.c tests-chip.c tests-iter.c tests-line.c
diff --git a/tests/unit/tests-line.c b/tests/unit/tests-line.c
new file mode 100644 (file)
index 0000000..ef0db62
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * GPIO line test cases for libgpiod.
+ *
+ * Copyright (C) 2017 Bartosz Golaszewski <bartekgola@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License
+ * as published by the Free Software Foundation.
+ */
+
+#include "gpiod-unit.h"
+
+static void line_request_output(void)
+{
+       GU_CLEANUP(gu_release_line) struct gpiod_line *line_0 = NULL;
+       GU_CLEANUP(gu_release_line) struct gpiod_line *line_1 = NULL;
+       GU_CLEANUP(gu_close_chip) struct gpiod_chip *chip = NULL;
+       int status;
+
+       chip = gpiod_chip_open(gu_chip_path(0));
+       GU_ASSERT_NOT_NULL(chip);
+
+       line_0 = gpiod_chip_get_line(chip, 2);
+       line_1 = gpiod_chip_get_line(chip, 5);
+       GU_ASSERT_NOT_NULL(line_0);
+       GU_ASSERT_NOT_NULL(line_1);
+
+       status = gpiod_line_request_output(line_0, "gpiod-unit", false, 0);
+       GU_ASSERT_RET_OK(status);
+       status = gpiod_line_request_output(line_1, "gpiod-unit", false, 1);
+       GU_ASSERT_RET_OK(status);
+
+       GU_ASSERT_EQ(gpiod_line_get_value(line_0), 0);
+       GU_ASSERT_EQ(gpiod_line_get_value(line_1), 1);
+}
+GU_DEFINE_TEST(line_request_output,
+              "line_request_output()",
+              GU_LINES_UNNAMED, { 8 });
+
+static void line_set_value(void)
+{
+       GU_CLEANUP(gu_release_line) struct gpiod_line *line = NULL;
+       GU_CLEANUP(gu_close_chip) struct gpiod_chip *chip = NULL;
+       int status;
+
+       chip = gpiod_chip_open(gu_chip_path(0));
+       GU_ASSERT_NOT_NULL(chip);
+
+       line = gpiod_chip_get_line(chip, 2);
+       GU_ASSERT_NOT_NULL(line);
+
+       status = gpiod_line_request_output(line, "gpiod-unit", false, 0);
+       GU_ASSERT_RET_OK(status);
+
+       GU_ASSERT_RET_OK(gpiod_line_set_value(line, 1));
+       GU_ASSERT_EQ(gpiod_line_get_value(line), 1);
+       GU_ASSERT_RET_OK(gpiod_line_set_value(line, 0));
+       GU_ASSERT_EQ(gpiod_line_get_value(line), 0);
+}
+GU_DEFINE_TEST(line_set_value,
+              "line_set_value()",
+              GU_LINES_UNNAMED, { 8 });