[PATCH libevdev v2 5/5] Add name-resolver unit tests
David Herrmann
dh.herrmann at gmail.com
Mon Oct 28 17:16:47 CET 2013
A bunch of tests for the new name resolver.
Signed-off-by: David Herrmann <dh.herrmann at gmail.com>
---
test/Makefile.am | 1 +
test/test-event-codes.c | 140 ++++++++++++++++++++++++++++++++++++++++++++++++
test/test-main.c | 2 +
3 files changed, 143 insertions(+)
create mode 100644 test/test-event-codes.c
diff --git a/test/Makefile.am b/test/Makefile.am
index c18b277..a232f86 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -23,6 +23,7 @@ AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include -I$(top_builddir)/libevdev
test_libevdev_SOURCES = \
test-main.c \
test-event-names.c \
+ test-event-codes.c \
test-libevdev-init.c \
test-libevdev-has-event.c \
test-int-queue.c \
diff --git a/test/test-event-codes.c b/test/test-event-codes.c
new file mode 100644
index 0000000..b5d374b
--- /dev/null
+++ b/test/test-event-codes.c
@@ -0,0 +1,140 @@
+/*
+ * Copyright © 2013 David Herrmann <dh.herrmann at gmail.com>
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include <config.h>
+#include <libevdev/libevdev-int.h>
+#include "test-common.h"
+
+START_TEST(test_type_codes)
+{
+ ck_assert(libevdev_event_type_from_name("EV_SYN", -1) == EV_SYN);
+ ck_assert(libevdev_event_type_from_name("EV_KEY", -1) == EV_KEY);
+ ck_assert(libevdev_event_type_from_name("EV_REL", -1) == EV_REL);
+ ck_assert(libevdev_event_type_from_name("EV_ABS", -1) == EV_ABS);
+ ck_assert(libevdev_event_type_from_name("EV_MSC", -1) == EV_MSC);
+ ck_assert(libevdev_event_type_from_name("EV_SND", -1) == EV_SND);
+ ck_assert(libevdev_event_type_from_name("EV_SW", -1) == EV_SW);
+ ck_assert(libevdev_event_type_from_name("EV_LED", -1) == EV_LED);
+ ck_assert(libevdev_event_type_from_name("EV_REP", -1) == EV_REP);
+ ck_assert(libevdev_event_type_from_name("EV_FF", -1) == EV_FF);
+ ck_assert(libevdev_event_type_from_name("EV_FF_STATUS", -1) == EV_FF_STATUS);
+ ck_assert(libevdev_event_type_from_name("EV_MAX", -1) == EV_MAX);
+
+ ck_assert(libevdev_event_type_from_name("EV_SYNTAX", 6) == EV_SYN);
+ ck_assert(libevdev_event_type_from_name("EV_REPTILE", 6) == EV_REP);
+}
+END_TEST
+
+START_TEST(test_type_prefix)
+{
+ ck_assert(libevdev_event_type_from_prefix("SYN_", -1) == EV_SYN);
+ ck_assert(libevdev_event_type_from_prefix("KEY_", -1) == EV_KEY);
+ ck_assert(libevdev_event_type_from_prefix("REL_", -1) == EV_REL);
+ ck_assert(libevdev_event_type_from_prefix("ABS_", -1) == EV_ABS);
+ ck_assert(libevdev_event_type_from_prefix("MSC_", -1) == EV_MSC);
+ ck_assert(libevdev_event_type_from_prefix("SND_", -1) == EV_SND);
+ ck_assert(libevdev_event_type_from_prefix("SW_", -1) == EV_SW);
+ ck_assert(libevdev_event_type_from_prefix("LED_", -1) == EV_LED);
+ ck_assert(libevdev_event_type_from_prefix("REP_", -1) == EV_REP);
+ ck_assert(libevdev_event_type_from_prefix("FF_", -1) == EV_FF);
+ ck_assert(libevdev_event_type_from_prefix("FF_STATUS_", -1) == EV_FF_STATUS);
+
+ ck_assert(libevdev_event_type_from_prefix("SYN_REPORT", -1) == EV_SYN);
+ ck_assert(libevdev_event_type_from_prefix("SYN_REPTILE", 4) == EV_SYN);
+ ck_assert(libevdev_event_type_from_prefix("FF_STATUS", -1) == EV_FF);
+ ck_assert(libevdev_event_type_from_prefix("FF_S", -1) == EV_FF);
+
+ ck_assert(libevdev_event_type_from_prefix("SYN_", 4) == EV_SYN);
+}
+END_TEST
+
+START_TEST(test_type_invalid)
+{
+ ck_assert(libevdev_event_type_from_name("EV_Syn", -1) == -1);
+ ck_assert(libevdev_event_type_from_name("ev_SYN", -1) == -1);
+ ck_assert(libevdev_event_type_from_name("SYN", -1) == -1);
+
+ ck_assert(libevdev_event_type_from_name("EV_SYN", 5) == -1);
+ ck_assert(libevdev_event_type_from_name("EV_SYNTAX", -1) == -1);
+ ck_assert(libevdev_event_type_from_name("EV_REPTILE", 7) == -1);
+
+ ck_assert(libevdev_event_type_from_prefix("MAX_", -1) == -1);
+ ck_assert(libevdev_event_type_from_prefix("MAX", -1) == -1);
+ ck_assert(libevdev_event_type_from_prefix("EV_SYN", -1) == -1);
+ ck_assert(libevdev_event_type_from_prefix("EV_SYN_", -1) == -1);
+ ck_assert(libevdev_event_type_from_prefix("SYN", -1) == -1);
+ ck_assert(libevdev_event_type_from_prefix("SYN_", 3) == -1);
+}
+END_TEST
+
+START_TEST(test_key_codes)
+{
+ ck_assert(libevdev_event_code_from_name("SYN_REPORT", -1) == SYN_REPORT);
+ ck_assert(libevdev_event_code_from_name("ABS_X", -1) == ABS_X);
+ ck_assert(libevdev_event_code_from_name("BTN_A", -1) == BTN_A);
+ ck_assert(libevdev_event_code_from_name("KEY_A", -1) == KEY_A);
+ ck_assert(libevdev_event_code_from_name("REL_X", -1) == REL_X);
+ ck_assert(libevdev_event_code_from_name("ABS_YXZ", 5) == ABS_Y);
+ ck_assert(libevdev_event_code_from_name("SYN_DROPPED", -1) == SYN_DROPPED);
+ ck_assert(libevdev_event_code_from_name("KEY_RESERVED", -1) == KEY_RESERVED);
+ ck_assert(libevdev_event_code_from_name("BTN_0", -1) == BTN_0);
+ ck_assert(libevdev_event_code_from_name("KEY_0", -1) == KEY_0);
+ ck_assert(libevdev_event_code_from_name("FF_GAIN", -1) == FF_GAIN);
+ ck_assert(libevdev_event_code_from_name("FF_STATUS_MAX", -1) == FF_STATUS_MAX);
+ ck_assert(libevdev_event_code_from_name("SW_MAX", -1) == SW_MAX);
+}
+END_TEST
+
+START_TEST(test_key_invalid)
+{
+ ck_assert(libevdev_event_code_from_name("EV_ABS", -1) == -1);
+ ck_assert(libevdev_event_code_from_name("ABS_X", 4) == -1);
+ ck_assert(libevdev_event_code_from_name("ABS_XY", -1) == -1);
+ ck_assert(libevdev_event_code_from_name("BTN_GAMEPAD", -1) == -1);
+ ck_assert(libevdev_event_code_from_name("BUS_PCI", -1) == -1);
+ ck_assert(libevdev_event_code_from_name("FF_STATUS", -1) == -1);
+ ck_assert(libevdev_event_code_from_name("FF_STATUS_", -1) == -1);
+ ck_assert(libevdev_event_code_from_name("ID_BUS", -1) == -1);
+ ck_assert(libevdev_event_code_from_name("SND_CNT", -1) == -1);
+ ck_assert(libevdev_event_code_from_name("SW_CNT", -1) == -1);
+}
+END_TEST
+
+Suite *
+event_code_suite(void)
+{
+ Suite *s = suite_create("Event codes");
+
+ TCase *tc = tcase_create("type tests");
+ tcase_add_test(tc, test_type_codes);
+ tcase_add_test(tc, test_type_prefix);
+ tcase_add_test(tc, test_type_invalid);
+ suite_add_tcase(s, tc);
+
+ tc = tcase_create("key tests");
+ tcase_add_test(tc, test_key_codes);
+ tcase_add_test(tc, test_key_invalid);
+ suite_add_tcase(s, tc);
+
+ return s;
+}
+
diff --git a/test/test-main.c b/test/test-main.c
index c6efaf6..73d79c9 100644
--- a/test/test-main.c
+++ b/test/test-main.c
@@ -24,6 +24,7 @@
#include <check.h>
extern Suite *event_name_suite(void);
+extern Suite *event_code_suite(void);
extern Suite *libevdev_init_test(void);
extern Suite *queue_suite(void);
extern Suite *libevdev_has_event_test(void);
@@ -39,6 +40,7 @@ int main(int argc, char **argv)
srunner_add_suite(sr, libevdev_init_test());
srunner_add_suite(sr, queue_suite());
srunner_add_suite(sr, event_name_suite());
+ srunner_add_suite(sr, event_code_suite());
srunner_add_suite(sr, uinput_suite());
srunner_run_all(sr, CK_NORMAL);
--
1.8.4.1
More information about the Input-tools
mailing list