diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | configure.ac | 6 | ||||
| -rw-r--r-- | test/Makefile.am | 27 | ||||
| -rw-r--r-- | test/check-grail.c | 23 | ||||
| -rw-r--r-- | test/check-mapping.c | 128 |
5 files changed, 187 insertions, 0 deletions
| @@ -80,3 +80,6 @@ core | |||
| 80 | patches | 80 | patches |
| 81 | tools/grail-gesture | 81 | tools/grail-gesture |
| 82 | utouch-grail.sym | 82 | utouch-grail.sym |
| 83 | test/*.log | ||
| 84 | test/*.xml | ||
| 85 | test/check-grail | ||
diff --git a/configure.ac b/configure.ac index b04766b..37fa429 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -26,6 +26,12 @@ PKG_CHECK_MODULES([MTDEV], [mtdev >= 1.1]) | |||
| 26 | PKG_CHECK_MODULES([EVEMU], [utouch-evemu >= 1.0.5]) | 26 | PKG_CHECK_MODULES([EVEMU], [utouch-evemu >= 1.0.5]) |
| 27 | PKG_CHECK_MODULES([FRAME], [utouch-frame >= 1.0]) | 27 | PKG_CHECK_MODULES([FRAME], [utouch-frame >= 1.0]) |
| 28 | 28 | ||
| 29 | # Check for TDD tools | ||
| 30 | PKG_CHECK_MODULES([CHECK], [check >= 0.9.8], | ||
| 31 | [have_check=yes], | ||
| 32 | AC_MSG_WARN([package 'check' not found: tests disabled])) | ||
| 33 | AM_CONDITIONAL([HAVE_CHECK],[test "x$have_check" = xyes]) | ||
| 34 | |||
| 29 | AC_CONFIG_FILES([Makefile | 35 | AC_CONFIG_FILES([Makefile |
| 30 | src/Makefile | 36 | src/Makefile |
| 31 | tools/Makefile | 37 | tools/Makefile |
diff --git a/test/Makefile.am b/test/Makefile.am index e69de29..106641d 100644 --- a/test/Makefile.am +++ b/test/Makefile.am | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | if HAVE_CHECK | ||
| 2 | test_targets = check-grail | ||
| 3 | else | ||
| 4 | test_targets = | ||
| 5 | endif | ||
| 6 | |||
| 7 | TESTS = $(test_targets) | ||
| 8 | noinst_PROGRAMS = $(test_targets) | ||
| 9 | |||
| 10 | check_grail_SOURCES = \ | ||
| 11 | check-mapping.c \ | ||
| 12 | check-grail.c | ||
| 13 | |||
| 14 | check_grail_CFLAGS = \ | ||
| 15 | -Wall -Wextra \ | ||
| 16 | -I$(top_srcdir) \ | ||
| 17 | -I$(top_srcdir)/include \ | ||
| 18 | $(CHECK_CFLAGS) | ||
| 19 | |||
| 20 | # | ||
| 21 | # Link against the (non-distributed) static lib to pick up the | ||
| 22 | # internal symbols. | ||
| 23 | # | ||
| 24 | check_grail_LDADD = \ | ||
| 25 | $(top_builddir)/src/.libs/libutouch-grail.a \ | ||
| 26 | $(CHECK_LIBS) \ | ||
| 27 | -lutouch-frame -lutouch-evemu -lmtdev -lm | ||
diff --git a/test/check-grail.c b/test/check-grail.c new file mode 100644 index 0000000..f3da133 --- /dev/null +++ b/test/check-grail.c | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | #include <check.h> | ||
| 2 | |||
| 3 | #define LOGFILE_PREFIX "" | ||
| 4 | |||
| 5 | extern Suite *make_mapping_suite(); | ||
| 6 | |||
| 7 | int main(int argc CK_ATTRIBUTE_UNUSED, char* argv[] CK_ATTRIBUTE_UNUSED) | ||
| 8 | { | ||
| 9 | Suite *s = suite_create("grail-test-suite"); | ||
| 10 | SRunner *sr = srunner_create(s); | ||
| 11 | int num_failed; | ||
| 12 | |||
| 13 | srunner_add_suite(sr, make_mapping_suite()); | ||
| 14 | |||
| 15 | srunner_set_log(sr, "check_grail.log"); | ||
| 16 | srunner_set_xml(sr, "check_grail.xml"); | ||
| 17 | srunner_run_all(sr, CK_NORMAL); | ||
| 18 | num_failed = srunner_ntests_failed(sr); | ||
| 19 | |||
| 20 | srunner_free(sr); | ||
| 21 | |||
| 22 | return num_failed; | ||
| 23 | } | ||
diff --git a/test/check-mapping.c b/test/check-mapping.c new file mode 100644 index 0000000..c99fcb7 --- /dev/null +++ b/test/check-mapping.c | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | #include <check.h> | ||
| 2 | #include <grail.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | #include <unistd.h> | ||
| 6 | #include <fcntl.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | #include <time.h> | ||
| 9 | #include <math.h> | ||
| 10 | |||
| 11 | struct test_data { | ||
| 12 | struct grail ge; | ||
| 13 | int fd; | ||
| 14 | struct grail_coord pos; | ||
| 15 | }; | ||
| 16 | |||
| 17 | static int near(const struct grail_coord *p, float x, float y) | ||
| 18 | { | ||
| 19 | double dx = p->x - x; | ||
| 20 | double dy = p->y - y; | ||
| 21 | return dx * dx + dy * dy < 1e-8 * (x * x + y * y); | ||
| 22 | } | ||
| 23 | |||
| 24 | static int tp_get_clients(struct grail *ge, | ||
| 25 | struct grail_client_info *clients, int max_clients, | ||
| 26 | const struct grail_coord *coords, int num_coords, | ||
| 27 | const grail_mask_t *types, int type_bytes) | ||
| 28 | { | ||
| 29 | memset(&clients[0], 0, sizeof(clients[0])); | ||
| 30 | memset(clients[0].mask, ~0, sizeof(clients[0].mask)); | ||
| 31 | clients[0].id.client = 345; | ||
| 32 | clients[0].id.root = 1; | ||
| 33 | clients[0].id.event = 2; | ||
| 34 | clients[0].id.child = 3; | ||
| 35 | ge = 0; | ||
| 36 | types = 0; | ||
| 37 | type_bytes = 0; | ||
| 38 | max_clients = 0; | ||
| 39 | coords = 0; | ||
| 40 | num_coords = 0; | ||
| 41 | return 1; | ||
| 42 | } | ||
| 43 | |||
| 44 | static void tp_event(struct grail *ge, const struct input_event *ev) | ||
| 45 | { | ||
| 46 | ge = 0; | ||
| 47 | ev = 0; | ||
| 48 | } | ||
| 49 | |||
| 50 | static void tp_gesture(struct grail *ge, const struct grail_event *ev) | ||
| 51 | { | ||
| 52 | struct test_data *data = ge->priv; | ||
| 53 | if (ev->type != GRAIL_TYPE_TAP1) | ||
| 54 | return; | ||
| 55 | data->pos.x = ev->prop[GRAIL_PROP_TAP_X]; | ||
| 56 | data->pos.y = ev->prop[GRAIL_PROP_TAP_Y]; | ||
| 57 | } | ||
| 58 | |||
| 59 | static int init_test_data(struct test_data *data, const char *path) | ||
| 60 | { | ||
| 61 | int ret; | ||
| 62 | |||
| 63 | memset(data, 0, sizeof(*data)); | ||
| 64 | |||
| 65 | data->ge.get_clients = tp_get_clients; | ||
| 66 | data->ge.event = tp_event; | ||
| 67 | data->ge.gesture = tp_gesture; | ||
| 68 | |||
| 69 | data->fd = open(path, O_RDONLY | O_NONBLOCK); | ||
| 70 | ret = grail_open(&data->ge, data->fd); | ||
| 71 | if(ret) | ||
| 72 | return ret; | ||
| 73 | return 0; | ||
| 74 | } | ||
| 75 | |||
| 76 | static void term_test_data(struct test_data *data) | ||
| 77 | { | ||
| 78 | grail_close(&data->ge, data->fd); | ||
| 79 | close(data->fd); | ||
| 80 | } | ||
| 81 | |||
| 82 | START_TEST(device_coordinates) | ||
| 83 | { | ||
| 84 | struct test_data data; | ||
| 85 | |||
| 86 | fail_if(init_test_data(&data, "io/evemu/one-tap.evemu")); | ||
| 87 | |||
| 88 | data.ge.priv = &data; | ||
| 89 | grail_pull(&data.ge, data.fd); | ||
| 90 | |||
| 91 | fail_unless(near(&data.pos, 17087, 14790)); | ||
| 92 | |||
| 93 | term_test_data(&data); | ||
| 94 | } | ||
| 95 | END_TEST | ||
| 96 | |||
| 97 | START_TEST(mapped_coordinates) | ||
| 98 | { | ||
| 99 | static const struct grail_coord min = { 0, 0 }, max = { 1.6, 1 }; | ||
| 100 | struct test_data data; | ||
| 101 | |||
| 102 | fail_if(init_test_data(&data, "io/evemu/one-tap.evemu")); | ||
| 103 | grail_set_bbox(&data.ge, &min, &max); | ||
| 104 | |||
| 105 | data.ge.priv = &data; | ||
| 106 | grail_pull(&data.ge, data.fd); | ||
| 107 | |||
| 108 | fail_unless(near(&data.pos, 0.834303, 0.451338)); | ||
| 109 | |||
| 110 | term_test_data(&data); | ||
| 111 | } | ||
| 112 | END_TEST | ||
| 113 | |||
| 114 | Suite *make_mapping_suite() | ||
| 115 | { | ||
| 116 | Suite *s = suite_create("grail-mapping"); | ||
| 117 | TCase *test; | ||
| 118 | |||
| 119 | test = tcase_create("device_coordinates"); | ||
| 120 | tcase_add_test(test, device_coordinates); | ||
| 121 | suite_add_tcase(s, test); | ||
| 122 | |||
| 123 | test = tcase_create("mapped_coordinates"); | ||
| 124 | tcase_add_test(test, mapped_coordinates); | ||
| 125 | suite_add_tcase(s, test); | ||
| 126 | |||
| 127 | return s; | ||
| 128 | } | ||
