tests: add test cases for gpiofind
authorBartosz Golaszewski <bartekgola@gmail.com>
Fri, 9 Jun 2017 07:42:04 +0000 (09:42 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Fri, 9 Jun 2017 08:50:43 +0000 (10:50 +0200)
Verify the correct behavior of gpiofind in two cases: when it can find
a GPIO line by name and when the requested line doesn't exist.

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

index 794b82556321557d59a2e5748c7cec70be7ab904..26210e6912af9e35e921d03b4fdbbd4d6d7cbc67 100644 (file)
@@ -25,6 +25,7 @@ gpiod_test_SOURCES =  gpiod-test.c \
 if WITH_TOOLS
 
 gpiod_test_SOURCES +=  tests-gpiodetect.c \
+                       tests-gpiofind.c \
                        tests-gpioinfo.c
 
 endif
diff --git a/tests/tests-gpiofind.c b/tests/tests-gpiofind.c
new file mode 100644 (file)
index 0000000..f2531c3
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Test cases for the gpiofind tool.
+ *
+ * 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-test.h"
+
+static void gpiofind_good(void)
+{
+       test_gpiotool_run("gpiofind", "gpio-mockup-B-7", (char *)NULL);
+       test_tool_wait();
+
+       TEST_ASSERT(test_tool_exited());
+       TEST_ASSERT_RET_OK(test_tool_exit_status());
+       TEST_ASSERT_NOT_NULL(test_tool_stdout());
+       TEST_ASSERT_STR_EQ(test_tool_stdout(), "gpiochip1 7\n");
+       TEST_ASSERT_NULL(test_tool_stderr());
+}
+TEST_DEFINE(gpiofind_good,
+           "tools: gpiofind - good",
+           TEST_FLAG_NAMED_LINES, { 4, 8 });
+
+static void gpiofind_not_found(void)
+{
+       test_gpiotool_run("gpiofind", "nonexistent", (char *)NULL);
+       test_tool_wait();
+
+       TEST_ASSERT(test_tool_exited());
+       TEST_ASSERT_EQ(test_tool_exit_status(), 1);
+       TEST_ASSERT_NULL(test_tool_stdout());
+       TEST_ASSERT_NULL(test_tool_stderr());
+}
+TEST_DEFINE(gpiofind_not_found,
+           "tools: gpiofind - not found",
+           TEST_FLAG_NAMED_LINES, { 4, 8 });