tests: add misc test cases
authorBartosz Golaszewski <bartekgola@gmail.com>
Thu, 2 Mar 2017 09:37:38 +0000 (10:37 +0100)
committerBartosz Golaszewski <bartekgola@gmail.com>
Thu, 2 Mar 2017 09:37:38 +0000 (10:37 +0100)
Add test cases for err handling and gpiod_version_string().

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

index 6b49d33a81dfec09ac2c41565153d597031af81d..629c667d9d717e106de90c4ce590399610e0449a 100644 (file)
@@ -17,4 +17,5 @@ gpiod_unit_SOURCES =  gpiod-unit.c \
                        tests-chip.c \
                        tests-iter.c \
                        tests-line.c \
+                       tests-misc.c \
                        tests-simple-api.c
diff --git a/tests/unit/tests-misc.c b/tests/unit/tests-misc.c
new file mode 100644 (file)
index 0000000..72e7f4d
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Misc 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"
+
+#include <errno.h>
+
+static void version_string(void)
+{
+       /* Check that gpiod_version_string() returns an actual string. */
+       GU_ASSERT_NOT_NULL(gpiod_version_string());
+       GU_ASSERT(strlen(gpiod_version_string()) > 0);
+}
+GU_DEFINE_TEST(version_string,
+              "gpiod_version_string()",
+              GU_LINES_UNNAMED, { 1 });
+
+static void error_handling(void)
+{
+       struct gpiod_chip *chip;
+       int err;
+
+       chip = gpiod_chip_open("/dev/nonexistent_gpiochip");
+       GU_ASSERT_NULL(chip);
+
+       err = gpiod_errno();
+       GU_ASSERT_EQ(err, ENOENT);
+
+       GU_ASSERT_NOT_NULL(gpiod_strerror(err));
+       GU_ASSERT(strlen(gpiod_strerror(err)) > 0);
+       GU_ASSERT_STR_EQ(gpiod_strerror(err), gpiod_last_strerror());
+}
+GU_DEFINE_TEST(error_handling,
+              "error handling",
+              GU_LINES_UNNAMED, { 1 });