From 8c46433f8a57e1d227197268719572a633ee16e2 Mon Sep 17 00:00:00 2001 From: Bartosz Golaszewski Date: Thu, 2 Mar 2017 10:37:38 +0100 Subject: [PATCH] tests: add misc test cases Add test cases for err handling and gpiod_version_string(). Signed-off-by: Bartosz Golaszewski --- tests/unit/Makefile.am | 1 + tests/unit/tests-misc.c | 42 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/unit/tests-misc.c diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am index 6b49d33..629c667 100644 --- a/tests/unit/Makefile.am +++ b/tests/unit/Makefile.am @@ -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 index 0000000..72e7f4d --- /dev/null +++ b/tests/unit/tests-misc.c @@ -0,0 +1,42 @@ +/* + * Misc test cases for libgpiod. + * + * Copyright (C) 2017 Bartosz Golaszewski + * + * 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 + +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 }); -- 2.30.2