summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/Makefile.am27
-rw-r--r--test/check-grail.c23
-rw-r--r--test/check-mapping.c128
3 files changed, 178 insertions, 0 deletions
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 @@
1if HAVE_CHECK
2test_targets = check-grail
3else
4test_targets =
5endif
6
7TESTS = $(test_targets)
8noinst_PROGRAMS = $(test_targets)
9
10check_grail_SOURCES = \
11 check-mapping.c \
12 check-grail.c
13
14check_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#
24check_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
5extern Suite *make_mapping_suite();
6
7int 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
11struct test_data {
12 struct grail ge;
13 int fd;
14 struct grail_coord pos;
15};
16
17static 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
24static 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
44static void tp_event(struct grail *ge, const struct input_event *ev)
45{
46 ge = 0;
47 ev = 0;
48}
49
50static 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
59static 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
76static void term_test_data(struct test_data *data)
77{
78 grail_close(&data->ge, data->fd);
79 close(data->fd);
80}
81
82START_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}
95END_TEST
96
97START_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}
112END_TEST
113
114Suite *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}