summaryrefslogtreecommitdiff
path: root/test/check-mapping.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2011-03-15 12:47:54 +0100
committerHenrik Rydberg <rydberg@euromail.se>2011-04-04 19:46:29 +0200
commitd55a299efd74431e98c8a4f24cffd07c95d419d6 (patch)
tree2dd5a3d3459308081a0da0fb0d01736fa3c700c7 /test/check-mapping.c
parent30800843fd45fd582d16b0a39f57e6d8a98e79bc (diff)
Introduce check test framework
Add the check test framework, and add a simple test to check point to point mappings. The tests use the device files as input. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'test/check-mapping.c')
-rw-r--r--test/check-mapping.c128
1 files changed, 128 insertions, 0 deletions
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}