Merge lp:~dandrader/grail/convert_tests into lp:grail

Proposed by Daniel d'Andrada
Status: Merged
Approved by: Daniel d'Andrada
Approved revision: no longer in the source branch.
Merged at revision: 251
Proposed branch: lp:~dandrader/grail/convert_tests
Merge into: lp:grail
Diff against target: 982 lines (+179/-523)
14 files modified
configure.ac (+1/-1)
debian/changelog (+3/-0)
debian/control (+1/-1)
src/handle.cpp (+1/-6)
src/touch.cpp (+2/-10)
test/regular/Makefile.am (+2/-3)
test/regular/frame_mock.cpp (+0/-254)
test/regular/frame_mock.h (+0/-66)
test/regular/grail-fixture.cpp (+133/-111)
test/regular/grail-fixture.h (+18/-20)
test/regular/intermittent_3touch.cpp (+1/-1)
test/regular/one-touch-gest-finished.cpp (+5/-24)
test/regular/pending-end.cpp (+9/-7)
test/regular/still-gest-finishes.cpp (+3/-19)
To merge this branch: bzr merge lp:~dandrader/grail/convert_tests
Reviewer Review Type Date Requested Status
Mathieu Trudel-Lapierre (community) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Stephen M. Webb (community) Approve
Review via email: mp+138253@code.launchpad.net

Commit message

Get rid of x11 specific code in grail implementation.

That way grail can be compiled with x11 dependencies and still process correctly frames that were generated via frame_backend.h instead of frame_x11.h.

Also use frame_backend.h instead of a frame mock in tests, which is a more realistic situation and also exercises the frame_backend.h API. It wouldn't be possible to do that if grail implementation still had frame_x11_* calls.

Description of the change

Get rid of x11 specific code in grail implementation.

That way grail can be compiled with x11 dependencies and still process correctly frames that were generated via frame_backend.h instead of frame_x11.h.

Also use frame_backend.h instead of a frame mock in tests, which is a more realistic situation and also exercises the frame_backend.h API. It wouldn't be possible to do that if grail implementation still had frame_x11_* calls.

To post a comment you must log in.
Revision history for this message
Stephen M. Webb (bregma) wrote :

OK

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~dandrader/grail/convert_tests updated
251. By Daniel d'Andrada

Get rid of x11 specific code in grail implementation.

That way grail can be compiled with x11 dependencies and still process correctly frames that were generated via frame_backend.h instead of frame_x11.h.

Also use frame_backend.h instead of a frame mock in tests, which is a more realistic situation and also exercises the frame_backend.h API. It wouldn't be possible to do that if grail implementation still had frame_x11_* calls.

Approved by Stephen M. Webb.

Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

Seems fine re: packaging; in this since, ack from me. I don't know why it conflicts in debian/changelog though.

Note that this would depwait until frame 2.5.0 is available in the archive.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2012-11-29 15:41:42 +0000
3+++ configure.ac 2012-12-06 18:31:20 +0000
4@@ -65,7 +65,7 @@
5 #################################
6 # check mandatory build dependencies
7
8-PKG_CHECK_MODULES([FRAME], [frame >= 2.2.0])
9+PKG_CHECK_MODULES([FRAME], [frame >= 2.5.0])
10
11 #################################
12 # debug builds
13
14=== modified file 'debian/changelog'
15--- debian/changelog 2012-12-04 11:32:11 +0000
16+++ debian/changelog 2012-12-06 18:31:20 +0000
17@@ -1,6 +1,9 @@
18 grail (3.0.9daily12.12.04-0ubuntu1) UNRELEASED; urgency=low
19
20 * Relicense under (L)GPL version 3 *only* (no +)
21+ * Updated libframe version dependency to 2.5.0
22+ * Use frame_backend.h instead of a frame mock in tests
23+ * Get rid of x11 specific code in grail implementation
24
25 -- Daniel d'Andrada <daniel.dandrada@canonical.com> Tue, 04 Dec 2012 09:31:28 -0200
26
27
28=== modified file 'debian/control'
29--- debian/control 2012-11-28 12:48:12 +0000
30+++ debian/control 2012-12-06 18:31:20 +0000
31@@ -4,7 +4,7 @@
32 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
33 Build-Depends: debhelper (>= 9),
34 dh-autoreconf,
35- libframe-dev (>= 2.4.4),
36+ libframe-dev (>= 2.5.0),
37 libx11-dev (>= 1.4.99),
38 libxext-dev (>= 1.3),
39 libxi-dev (>= 1.5.99.2),
40
41=== modified file 'src/handle.cpp'
42--- src/handle.cpp 2012-11-20 20:13:00 +0000
43+++ src/handle.cpp 2012-12-06 18:31:20 +0000
44@@ -30,9 +30,6 @@
45 #include <stdexcept>
46
47 #include <oif/frame.h>
48-#ifdef FRAME_X11_BACKEND
49- #include <oif/frame_x11.h>
50-#endif
51
52 #include "atomic-recognizer.h"
53 #include "event.h"
54@@ -154,9 +151,7 @@
55 if (frame_touch_get_state(touch) != UFTouchStateBegin)
56 continue;
57
58-#ifdef FRAME_X11_BACKEND
59- frame_x11_reject_touch(device, window_id, frame_touch_get_id(touch));
60-#endif
61+ frame_reject_touch(device, window_id, frame_touch_get_id(touch));
62 }
63 }
64
65
66=== modified file 'src/touch.cpp'
67--- src/touch.cpp 2012-11-20 20:13:00 +0000
68+++ src/touch.cpp 2012-12-06 18:31:20 +0000
69@@ -20,10 +20,6 @@
70
71 #include "touch.h"
72
73-#ifdef FRAME_X11_BACKEND
74- #include <oif/frame_x11.h>
75-#endif
76-
77 #include "log.h"
78
79 namespace oif {
80@@ -73,10 +69,8 @@
81
82 void Touch::Accept() {
83 LOG(Dbg) << "accepting touch " << id_ << "\n";
84-#ifdef FRAME_X11_BACKEND
85- if (frame_x11_accept_touch(device_, window_id_, id_) != UFStatusSuccess)
86+ if (frame_accept_touch(device_, window_id_, id_) != UFStatusSuccess)
87 LOG(Err) << "touch " << id_ << " failed to be accepted\n";
88-#endif
89
90 accepted_ = true;
91 }
92@@ -84,10 +78,8 @@
93 Touch::~Touch() {
94 if (!accepted_) {
95 LOG(Dbg) << "rejecting touch " << id_ << "\n";
96-#ifdef FRAME_X11_BACKEND
97- if (frame_x11_reject_touch(device_, window_id_, id_) != UFStatusSuccess)
98+ if (frame_reject_touch(device_, window_id_, id_) != UFStatusSuccess)
99 LOG(Err) << "touch " << id_ << " failed to be rejected\n";
100-#endif
101 }
102 }
103
104
105=== modified file 'test/regular/Makefile.am'
106--- test/regular/Makefile.am 2012-11-20 20:13:00 +0000
107+++ test/regular/Makefile.am 2012-12-06 18:31:20 +0000
108@@ -25,8 +25,6 @@
109
110 check_regular_SOURCES = \
111 grail.cpp \
112- frame_mock.cpp \
113- frame_mock.h \
114 grail-fixture.cpp \
115 grail-fixture.h \
116 intermittent_3touch.cpp \
117@@ -43,7 +41,8 @@
118 $(top_builddir)/src/.libs/libgrail.a \
119 $(top_builddir)/test/gtest/libgtest_grail.a \
120 $(COVERAGE_LIBS) \
121- $(GTEST_LIBS)
122+ $(GTEST_LIBS) \
123+ $(FRAME_LIBS)
124
125 check_regular_CPPFLAGS = \
126 --std=c++0x \
127
128=== removed file 'test/regular/frame_mock.cpp'
129--- test/regular/frame_mock.cpp 2012-11-21 13:31:12 +0000
130+++ test/regular/frame_mock.cpp 1970-01-01 00:00:00 +0000
131@@ -1,254 +0,0 @@
132-#include "frame_mock.h"
133-
134-extern "C" {
135-
136-/*****************************************************************************
137- * Event
138- *****************************************************************************/
139-
140-UFEventType frame_event_get_type(UFEvent self)
141-{
142- return self->type;
143-}
144-
145-UFStatus frame_event_get_property(UFEvent self, UFEventProperty property,
146- void *value)
147-{
148- UFStatus status = UFStatusErrorUnknownProperty;
149-
150- if (property == UFEventPropertyFrame && self->frame_ptr)
151- {
152- *((UFFrame*)value) = self->frame_ptr.get();
153- status = UFStatusSuccess;
154- }
155- else if (property == UFEventPropertyDevice && self->device_ptr)
156- {
157- *((UFDevice*)value) = self->device_ptr.get();
158- status = UFStatusSuccess;
159- }
160-
161- return status;
162-}
163-
164-uint64_t frame_event_get_time(UFEvent self)
165-{
166- return self->time;
167-}
168-
169-void frame_event_ref(UFEvent self)
170-{
171- ++self->ref_count;
172-}
173-
174-void frame_event_unref(UFEvent self)
175-{
176- --self->ref_count;
177-
178- if (self->ref_count == 0)
179- delete self;
180-}
181-
182-/*****************************************************************************
183- * Frame
184- *****************************************************************************/
185-
186-UFStatus frame_frame_get_touch_by_index(UFFrame self, unsigned int index,
187- UFTouch *touch)
188-{
189- UFStatus status;
190-
191- if (index < self->touches.size())
192- {
193- *touch = &(self->touches[index]);
194- status = UFStatusSuccess;
195- }
196- else
197- {
198- status = UFStatusErrorInvalidTouch;
199- }
200-
201- return status;
202-}
203-
204-UFStatus frame_frame_get_touch_by_id(UFFrame self, UFTouchId touch_id,
205- UFTouch* touch_pointer)
206-{
207- UFStatus status = UFStatusErrorInvalidTouch;
208-
209- for (struct UFTouch_ &touch : self->touches)
210- {
211- if (touch.id == touch_id)
212- {
213- *touch_pointer = &touch;
214- status = UFStatusSuccess;
215- break;
216- }
217- }
218-
219- return status;
220-}
221-
222-uint32_t frame_frame_get_num_touches(UFFrame self)
223-{
224- return self->touches.size();
225-}
226-
227-UFDevice frame_frame_get_device(UFFrame self)
228-{
229- return self->device_ptr.get();
230-}
231-
232-UFWindowId frame_frame_get_window_id(UFFrame self)
233-{
234- return self->window_id;
235-}
236-
237-/*****************************************************************************
238- * Touch
239- *****************************************************************************/
240-
241-UFStatus frame_touch_get_property(UFTouch self, UFTouchProperty property,
242- void *value)
243-{
244- UFStatus status;
245-
246- switch (property)
247- {
248- case UFTouchPropertyOwned:
249- *((int*)value) = self->owned;
250- status = UFStatusSuccess;
251- break;
252-
253- case UFTouchPropertyPendingEnd:
254- *((int*)value) = self->pending_end;
255- status = UFStatusSuccess;
256- break;
257-
258- default:
259- status = UFStatusErrorUnknownProperty;
260- }
261-
262- return status;
263-}
264-
265-UFTouchId frame_touch_get_id(UFTouch self)
266-{
267- return self->id;
268-}
269-
270-UFTouchState frame_touch_get_state(UFTouch self)
271-{
272- return self->state;
273-}
274-
275-float frame_touch_get_window_x(UFTouch self)
276-{
277- return self->window_x;
278-}
279-
280-float frame_touch_get_window_y(UFTouch self)
281-{
282- return self->window_y;
283-}
284-
285-float frame_touch_get_device_x(UFTouch self)
286-{
287- return self->device_x;
288-}
289-
290-float frame_touch_get_device_y(UFTouch self)
291-{
292- return self->device_y;
293-}
294-
295-uint64_t frame_touch_get_time(UFTouch self)
296-{
297- return self->time;
298-}
299-
300-uint64_t frame_touch_get_start_time(UFTouch self)
301-{
302- return self->start_time;
303-}
304-
305-/*****************************************************************************
306- * Device
307- *****************************************************************************/
308-
309-UFStatus frame_device_get_property(UFDevice self, UFDeviceProperty property,
310- void *value)
311-{
312- UFStatus status;
313-
314- switch (property)
315- {
316- case UFDevicePropertyDirect:
317- *((int*)value) = self->direct;
318- status = UFStatusSuccess;
319- break;
320-
321- default:
322- status = UFStatusErrorUnknownProperty;
323- }
324-
325- return status;
326-}
327-
328-UFStatus frame_device_get_axis_by_type(UFDevice self, UFAxisType axis_type,
329- UFAxis *axis_pointer)
330-{
331- UFStatus status = UFStatusErrorInvalidAxis;
332-
333- for (struct UFAxis_ &axis : self->axes)
334- {
335- if (axis.type == axis_type)
336- {
337- *axis_pointer = &axis;
338- status = UFStatusSuccess;
339- break;
340- }
341- }
342-
343- return status;
344-}
345-
346-float frame_device_get_window_resolution_x(UFDevice self)
347-{
348- return self->window_resolution_x;
349-}
350-
351-float frame_device_get_window_resolution_y(UFDevice self)
352-{
353- return self->window_resolution_y;
354-}
355-
356-/*****************************************************************************
357- * Axis
358- *****************************************************************************/
359-
360-float frame_axis_get_resolution(UFAxis self)
361-{
362- return self->resolution;
363-}
364-
365-/*****************************************************************************
366- * Frame X11
367- *****************************************************************************/
368-
369-#ifdef FRAME_X11_BACKEND
370-UFStatus frame_x11_accept_touch(UFDevice device, UFWindowId window,
371- UFTouchId touch_id)
372-{
373- device->x11_touch_acceptance[window][touch_id] = true;
374- return UFStatusSuccess;
375-}
376-
377-UFStatus frame_x11_reject_touch(UFDevice device, UFWindowId window,
378- UFTouchId touch_id)
379-{
380- device->x11_touch_acceptance[window][touch_id] = false;
381- return UFStatusSuccess;
382-}
383-#endif // FRAME_X11_BACKEND
384-
385-} // extern "C"
386
387=== removed file 'test/regular/frame_mock.h'
388--- test/regular/frame_mock.h 2012-11-21 13:31:12 +0000
389+++ test/regular/frame_mock.h 1970-01-01 00:00:00 +0000
390@@ -1,66 +0,0 @@
391-#ifndef FRAME_MOCK_H
392-#define FRAME_MOCK_H
393-
394-#include <oif/frame.h>
395-#include <map>
396-#include <vector>
397-#include <memory>
398-
399-extern "C" {
400-
401-struct UFHandle_
402-{
403- int fd;
404-};
405-
406-struct UFEvent_
407-{
408- UFEvent_() {ref_count = 1;}
409- UFEventType type;
410- std::shared_ptr<struct UFDevice_> device_ptr;
411- std::unique_ptr<struct UFFrame_> frame_ptr;
412- uint64_t time;
413- int ref_count;
414-};
415-
416-struct UFFrame_
417-{
418- std::shared_ptr<struct UFDevice_> device_ptr;
419- UFWindowId window_id;
420- std::vector<struct UFTouch_> touches;
421-};
422-
423-struct UFTouch_
424-{
425- UFTouchId id;
426- UFTouchState state;
427- float window_x;
428- float window_y;
429- float device_x;
430- float device_y;
431- uint64_t time;
432- uint64_t start_time;
433- int owned;
434- int pending_end;
435-};
436-
437-struct UFDevice_
438-{
439- int direct;
440- std::vector<struct UFAxis_> axes;
441- float window_resolution_x;
442- float window_resolution_y;
443-#ifdef FRAME_X11_BACKEND
444- std::map<UFWindowId, std::map<UFTouchId, bool> > x11_touch_acceptance;
445-#endif
446-};
447-
448-struct UFAxis_
449-{
450- UFAxisType type;
451- float resolution;
452-};
453-
454-} // extern "C"
455-
456-#endif
457
458=== modified file 'test/regular/grail-fixture.cpp'
459--- test/regular/grail-fixture.cpp 2012-07-23 13:11:21 +0000
460+++ test/regular/grail-fixture.cpp 2012-12-06 18:31:20 +0000
461@@ -1,72 +1,58 @@
462 #include "grail-fixture.h"
463
464-void GrailTest::SendFrameEvent(
465- uint64_t time,
466- UFWindowId window_id,
467- const struct UFTouch_ &touch_struct)
468-{
469- std::vector<struct UFTouch_> touches;
470- touches.push_back(touch_struct);
471- SendFrameEvent(time, window_id, touches);
472-}
473-
474-void GrailTest::SendFrameEvent(
475- uint64_t time,
476- UFWindowId window_id,
477- std::vector<struct UFTouch_> &touches)
478-{
479- UFFrame frame = new struct UFFrame_;
480- frame->device_ptr = device_ptr;
481- frame->window_id = window_id;
482- frame->touches = touches;
483-
484- UFEvent frame_event = new struct UFEvent_;
485- frame_event->type = UFEventTypeFrame;
486- frame_event->time = time;
487- frame_event->frame_ptr.reset(std::move(frame));
488-
489- grail_process_frame_event(grail_handle, frame_event);
490- frame_event_unref(frame_event);
491- frame_event = nullptr;
492+void GrailTest::SendFrameEvent(uint64_t time, UFBackendFrame frame)
493+{
494+ UFEvent event = frame_event_new();
495+ frame_event_set_type(event, UFEventTypeFrame);
496+ frame_event_set_frame(event, frame);
497+ frame_event_set_time(event, time);
498+
499+ grail_process_frame_event(grail_handle, event);
500+ frame_event_unref(event);
501+ event = nullptr;
502+
503+ if (previous_frame_)
504+ frame_backend_frame_delete(previous_frame_);
505+ previous_frame_ = frame;
506 }
507
508 void GrailTest::SendDeviceAddedEvent(uint64_t time)
509 {
510- UFEvent frame_event = new struct UFEvent_;
511- frame_event->type = UFEventTypeDeviceAdded;
512- frame_event->time = time;
513- frame_event->device_ptr = device_ptr;
514+ UFEvent event = frame_event_new();
515+ frame_event_set_type(event, UFEventTypeDeviceAdded);
516+ frame_event_set_time(event, time);
517+ frame_event_set_device(event, device_);
518
519- grail_process_frame_event(grail_handle, frame_event);
520- frame_event_unref(frame_event);
521- frame_event = nullptr;
522+ grail_process_frame_event(grail_handle, event);
523+ frame_event_unref(event);
524+ event = nullptr;
525 }
526
527-void GrailTest::FillFakeDeviceStruct()
528+void GrailTest::CreateFakeDevice()
529 {
530- struct UFAxis_ axis_x_struct;
531- axis_x_struct.type = UFAxisTypeX;
532- axis_x_struct.resolution = 3764.70;
533-
534- struct UFAxis_ axis_y_struct;
535- axis_y_struct.type = UFAxisTypeY;
536- axis_y_struct.resolution = 3764.70;
537-
538- device_ptr.reset(new struct UFDevice_);
539- device_ptr->direct = 1;
540- device_ptr->axes.push_back(axis_x_struct);
541- device_ptr->axes.push_back(axis_y_struct);
542+ device_ = frame_backend_device_new();
543+
544+ frame_backend_device_add_axis(device_,
545+ UFAxisTypeX,
546+ 0, 10000, 3764.70);
547+
548+ frame_backend_device_add_axis(device_,
549+ UFAxisTypeY,
550+ 0, 10000, 3764.70);
551+
552+ frame_backend_device_set_direct(device_, 1);
553+
554 /* pixels/m */
555- device_ptr->window_resolution_x = 3764.70;
556- device_ptr->window_resolution_y = 3764.70;
557+ frame_backend_device_set_window_resolution(device_, 3764.70, 3764.70);
558 }
559
560 UGSubscription GrailTest::CreateSubscription(
561 unsigned int num_touches, UGGestureTypeMask gesture_mask,
562- UFDevice device, UFWindowId window_id)
563+ UFWindowId window_id)
564 {
565 UGStatus status;
566 UGSubscription subscription = nullptr;
567+ UFDevice uf_device = frame_backend_device_get_device(device_);
568
569 status = grail_subscription_new(&subscription);
570 if (status != UGStatusSuccess)
571@@ -77,7 +63,7 @@
572
573 status = grail_subscription_set_property(subscription,
574 UGSubscriptionPropertyDevice,
575- &device);
576+ &uf_device);
577 if (status != UGStatusSuccess)
578 {
579 ADD_FAILURE() << "failed to set device subscription";
580@@ -150,75 +136,111 @@
581 BeginTouchWindowCoords(touch_id, touch_id * 10.0f, 0.0f);
582 }
583
584+namespace
585+{
586+void IncrementFrameActiveTouches(UFBackendFrame frame_backend)
587+{
588+ UFFrame frame = frame_backend_frame_get_frame(frame_backend);
589+ unsigned int active_touches;
590+ frame_frame_get_property(frame, UFFramePropertyActiveTouches, &active_touches);
591+ frame_backend_frame_set_active_touches(frame_backend, active_touches + 1);
592+}
593+
594+} // anonymous namespace
595+
596 void GrailTest::BeginTouchWindowCoords(int touch_id, float window_x, float window_y)
597 {
598- struct UFTouch_ touch_struct;
599- touch_struct.id = touch_id;
600- touch_struct.state = UFTouchStateBegin;
601- touch_struct.time = time;
602- touch_struct.start_time = touch_struct.time;
603- touch_struct.window_x = window_x;
604- touch_struct.window_y = window_y;
605- touch_struct.owned = 0;
606- touch_struct.pending_end = 0;
607-
608- touches.push_back(touch_struct);
609-
610- SendFrameEvent(time, fake_window_id, touches);
611-
612- // leave it in a neutral state for next uses of touches vector
613- touches[touches.size()-1].state = UFTouchStateUpdate;
614+ UFBackendTouch touch = frame_backend_touch_new();
615+ frame_backend_touch_set_id(touch, touch_id);
616+ frame_backend_touch_set_time(touch, time);
617+ frame_backend_touch_set_start_time(touch, time);
618+ frame_backend_touch_set_window_pos(touch, window_x, window_y);
619+ frame_backend_touch_set_owned(touch, 0);
620+ frame_backend_touch_set_pending_end(touch, 0);
621+
622+ UFBackendFrame frame;
623+ if (previous_frame_)
624+ frame = frame_backend_frame_create_next(previous_frame_);
625+ else
626+ frame = frame_backend_frame_new();
627+
628+ frame_backend_frame_set_device(frame, device_);
629+
630+ frame_backend_frame_give_touch(frame, &touch);
631+ IncrementFrameActiveTouches(frame);
632+ frame_backend_frame_set_window_id(frame, fake_window_id);
633+
634+ SendFrameEvent(time, frame);
635 }
636
637 void GrailTest::GiveTouchOwnership(int touch_id)
638 {
639- auto iterator = FindTouch(touch_id);
640- iterator->state = UFTouchStateUpdate;
641- iterator->owned = 1; // ownership will trigger delivery of grail events.
642- iterator->time = time;
643-
644- SendFrameEvent(time, fake_window_id, touches);
645-}
646-
647-void GrailTest::SetTouchWindowCoords(int touch_id, float window_x, float window_y)
648-{
649- auto iterator = FindTouch(touch_id);
650- iterator->window_x = window_x;
651- iterator->window_y = window_y;
652-}
653-
654-void GrailTest::UpdateTouches()
655-{
656- for (struct UFTouch_ &touch : touches)
657- {
658- touch.time = time;
659- }
660- SendFrameEvent(time, fake_window_id, touches);
661+ std::function<void(UFBackendTouch)> update_func =
662+ [](UFBackendTouch touch)
663+ {
664+ frame_backend_touch_set_owned(touch, 1);
665+ };
666+
667+ UpdateTouch(touch_id, update_func);
668+}
669+
670+void GrailTest::UpdateTouch(int touch_id,
671+ std::function< void(UFBackendTouch) >& update_func)
672+{
673+ assert(previous_frame_); // error would be in the test itself
674+
675+ UFBackendFrame frame = frame_backend_frame_create_next(previous_frame_);
676+ frame_backend_frame_set_device(frame, device_);
677+ frame_backend_frame_set_window_id(frame, fake_window_id);
678+
679+ UFStatus status;
680+ UFBackendTouch touch;
681+ status = frame_backend_frame_borrow_touch_by_id(frame, touch_id, &touch);
682+ ASSERT_EQ(UFStatusSuccess, status);
683+
684+ update_func(touch);
685+ frame_backend_touch_set_time(touch, time);
686+
687+ status = frame_backend_frame_give_touch(frame, &touch);
688+ ASSERT_EQ(UFStatusSuccess, status);
689+
690+ SendFrameEvent(time, frame);
691+}
692+
693+void GrailTest::SetTouchWindowCoords(UFBackendFrame frame,
694+ int touch_id, float window_x, float window_y)
695+{
696+ UFStatus status;
697+ UFBackendTouch touch;
698+ status = frame_backend_frame_borrow_touch_by_id(frame, touch_id, &touch);
699+ ASSERT_EQ(UFStatusSuccess, status);
700+
701+ frame_backend_touch_set_window_pos(touch, window_x, window_y);
702+
703+ status = frame_backend_frame_give_touch(frame, &touch);
704+ ASSERT_EQ(UFStatusSuccess, status);
705+}
706+
707+void GrailTest::SendTouchPendingEnd(int touch_id)
708+{
709+ std::function<void(UFBackendTouch)> update_func =
710+ [](UFBackendTouch touch)
711+ {
712+ frame_backend_touch_set_pending_end(touch, 1);
713+ };
714+
715+ UpdateTouch(touch_id, update_func);
716 }
717
718 void GrailTest::EndTouch(int touch_id)
719 {
720- auto iterator = FindTouch(touch_id);
721- iterator->state = UFTouchStateEnd;
722- iterator->time = time;
723-
724- SendFrameEvent(time, fake_window_id, touches);
725-
726- touches.erase(iterator);
727-}
728-
729-std::vector<struct UFTouch_>::iterator GrailTest::FindTouch(unsigned int touch_id)
730-{
731- std::vector<struct UFTouch_>::iterator it = touches.begin();
732-
733- while (it != touches.end())
734- {
735- if (it->id == touch_id)
736- return it;
737- ++it;
738- }
739-
740- return it;
741+ std::function<void(UFBackendTouch)> update_func =
742+ [](UFBackendTouch touch)
743+ {
744+ frame_backend_touch_set_ended(touch);
745+ };
746+
747+ UpdateTouch(touch_id, update_func);
748 }
749
750 void GrailTest::ProcessGrailEvents()
751
752=== modified file 'test/regular/grail-fixture.h'
753--- test/regular/grail-fixture.h 2012-08-27 21:52:42 +0000
754+++ test/regular/grail-fixture.h 2012-12-06 18:31:20 +0000
755@@ -3,8 +3,9 @@
756
757 #include <gtest/gtest.h>
758 #include <oif/grail.h>
759-#include "frame_mock.h"
760+#include <oif/frame_backend.h>
761
762+#include <functional>
763 #include <list>
764 #include <set>
765
766@@ -27,41 +28,38 @@
767 virtual void SetUp()
768 {
769 grail_handle = NULL;
770- FillFakeDeviceStruct();
771+ previous_frame_ = nullptr;
772+ CreateFakeDevice();
773 }
774
775 virtual void TearDown()
776 {
777 if (grail_handle)
778 grail_delete(grail_handle);
779+
780+ if (previous_frame_)
781+ frame_backend_frame_delete(previous_frame_);
782+
783+ frame_backend_device_delete(device_);
784 }
785
786 protected:
787
788 UGSubscription CreateSubscription(unsigned int num_touches,
789- UGGestureTypeMask gesture_mask, UFDevice device, UFWindowId window_id);
790+ UGGestureTypeMask gesture_mask, UFWindowId window_id);
791
792- void FillFakeDeviceStruct();
793- void SendDeviceAddedEvent();
794- void SendFrameEvent(
795- uint64_t time,
796- UFWindowId window_id,
797- const struct UFTouch_ &touch_struct);
798- void SendFrameEvent(
799- uint64_t time,
800- UFWindowId window_id,
801- std::vector<struct UFTouch_> &touches);
802+ void CreateFakeDevice();
803 void SendDeviceAddedEvent(uint64_t time);
804+ void SendFrameEvent(uint64_t time, UFBackendFrame frame);
805
806 void BeginTouch(int touch_id);
807 void BeginTouchWindowCoords(int touch_id, float window_x, float window_y);
808 void GiveTouchOwnership(int touch_id);
809- void SetTouchWindowCoords(int touch_id, float window_x, float window_y);
810- /* Updates the time of all touches in the "touches" vector and sends that vector
811- in a frame event to grail */
812- void UpdateTouches();
813+ void SetTouchWindowCoords(UFBackendFrame frame,
814+ int touch_id, float window_x, float window_y);
815+ void SendTouchPendingEnd(int touch_id);
816 void EndTouch(int touch_id);
817- std::vector<struct UFTouch_>::iterator FindTouch(unsigned int touch_id);
818+ void UpdateTouch(int touch_id, std::function< void(UFBackendTouch) >& update_func);
819
820 /* Fetches and processes all pending grail events, updating grail_gestures
821 list accordingly. */
822@@ -75,11 +73,11 @@
823 void PrintSlice(UGSlice slice);
824
825 UGHandle grail_handle;
826- std::shared_ptr<struct UFDevice_> device_ptr;
827+ UFBackendDevice device_;
828
829 uint64_t time;
830 UFWindowId fake_window_id;
831- std::vector<struct UFTouch_> touches;
832+ UFBackendFrame previous_frame_;
833
834 /*
835 A representation of the currently active gestures according to the grail events
836
837=== modified file 'test/regular/intermittent_3touch.cpp'
838--- test/regular/intermittent_3touch.cpp 2012-08-27 21:41:43 +0000
839+++ test/regular/intermittent_3touch.cpp 2012-12-06 18:31:20 +0000
840@@ -25,7 +25,7 @@
841 SendDeviceAddedEvent(time);
842
843 UGSubscription subscription =
844- CreateSubscription(3, UGGestureTypeTouch, device_ptr.get(), fake_window_id);
845+ CreateSubscription(3, UGGestureTypeTouch, fake_window_id);
846 if (!subscription) return;
847
848 time = 20531903;
849
850=== modified file 'test/regular/one-touch-gest-finished.cpp'
851--- test/regular/one-touch-gest-finished.cpp 2012-08-27 21:41:43 +0000
852+++ test/regular/one-touch-gest-finished.cpp 2012-12-06 18:31:20 +0000
853@@ -10,7 +10,7 @@
854 TEST_F(SingleTouchGestureTest, QuickTapEndsWithConstructionFinished)
855 {
856 UGStatus status;
857- UFWindowId fake_window_id = 321;
858+ fake_window_id = 321;
859 uint64_t time = 1234;
860
861 status = grail_new(&grail_handle);
862@@ -19,30 +19,14 @@
863 SendDeviceAddedEvent(time);
864
865 UGSubscription subscription =
866- CreateSubscription(1, UGGestureTypeTouch, device_ptr.get(), fake_window_id);
867+ CreateSubscription(1, UGGestureTypeTouch, fake_window_id);
868 if (!subscription) return;
869
870 time += 10;
871- struct UFTouch_ touch_struct;
872- touch_struct.id = 1;
873- touch_struct.state = UFTouchStateBegin;
874- touch_struct.window_x = 10.0f;
875- touch_struct.window_y = 10.0f;
876- touch_struct.device_x = 100.0f;
877- touch_struct.device_y = 100.0f;
878- touch_struct.time = time;
879- touch_struct.start_time = touch_struct.time;
880- touch_struct.owned = 0;
881- touch_struct.pending_end = 0;
882-
883- SendFrameEvent(time, fake_window_id, touch_struct);
884+ BeginTouch(1);
885
886 time += 10;
887- touch_struct.state = UFTouchStateUpdate;
888- touch_struct.owned = 1; // ownership will trigger delivery of grail events.
889- touch_struct.time = time;
890-
891- SendFrameEvent(time, fake_window_id, touch_struct);
892+ GiveTouchOwnership(1);
893
894 // There should now be two grail events, corresponding to the frame
895 // event that were sent, waiting to be processed.
896@@ -80,10 +64,7 @@
897 // now end the touch
898
899 time += 10;
900- touch_struct.state = UFTouchStateEnd;
901- touch_struct.time = time;
902-
903- SendFrameEvent(time, fake_window_id, touch_struct);
904+ EndTouch(1);
905
906 // An end event should come and its "construction finished" property should be true
907
908
909=== modified file 'test/regular/pending-end.cpp'
910--- test/regular/pending-end.cpp 2012-08-27 21:41:43 +0000
911+++ test/regular/pending-end.cpp 2012-12-06 18:31:20 +0000
912@@ -18,7 +18,7 @@
913
914 UGSubscription sub_3touch =
915 CreateSubscription(3, UGGestureTypeTouch | UGGestureTypeDrag | UGGestureTypePinch,
916- device_ptr.get(), fake_window_id);
917+ fake_window_id);
918 ASSERT_NE(nullptr, sub_3touch);
919
920 time = 13688369;
921@@ -41,15 +41,17 @@
922 for (int i=1; i<=4; ++i)
923 {
924 time += 100;
925- SetTouchWindowCoords(1, 30.0f, i*10.0f);
926- SetTouchWindowCoords(2, 40.0f, i*10.0f);
927- SetTouchWindowCoords(3, 50.0f, i*10.0f);
928- UpdateTouches();
929+ UFBackendFrame frame = frame_backend_frame_create_next(previous_frame_);
930+ frame_backend_frame_set_device(frame, device_);
931+ frame_backend_frame_set_window_id(frame, fake_window_id);
932+ SetTouchWindowCoords(frame, 1, 30.0f, i*10.0f);
933+ SetTouchWindowCoords(frame, 2, 40.0f, i*10.0f);
934+ SetTouchWindowCoords(frame, 3, 50.0f, i*10.0f);
935+ SendFrameEvent(time, frame);
936 }
937
938 time = 13688877;
939- FindTouch(1)->pending_end = 1;
940- UpdateTouches();
941+ SendTouchPendingEnd(1);
942
943 ProcessGrailEvents();
944 // no gesture slices yet since not all touches are owned
945
946=== modified file 'test/regular/still-gest-finishes.cpp'
947--- test/regular/still-gest-finishes.cpp 2012-08-27 21:41:43 +0000
948+++ test/regular/still-gest-finishes.cpp 2012-12-06 18:31:20 +0000
949@@ -19,30 +19,14 @@
950 SendDeviceAddedEvent(time);
951
952 UGSubscription subscription =
953- CreateSubscription(1, UGGestureTypeTouch, device_ptr.get(), fake_window_id);
954+ CreateSubscription(1, UGGestureTypeTouch, fake_window_id);
955 if (!subscription) return;
956
957 time += 10;
958- struct UFTouch_ touch_struct;
959- touch_struct.id = 1;
960- touch_struct.state = UFTouchStateBegin;
961- touch_struct.window_x = 10.0f;
962- touch_struct.window_y = 10.0f;
963- touch_struct.device_x = 100.0f;
964- touch_struct.device_y = 100.0f;
965- touch_struct.time = time;
966- touch_struct.start_time = touch_struct.time;
967- touch_struct.owned = 0;
968- touch_struct.pending_end = 0;
969-
970- SendFrameEvent(time, fake_window_id, touch_struct);
971+ BeginTouch(1);
972
973 time += 10;
974- touch_struct.state = UFTouchStateUpdate;
975- touch_struct.owned = 1; // ownership will trigger delivery of grail events.
976- touch_struct.time = time;
977-
978- SendFrameEvent(time, fake_window_id, touch_struct);
979+ GiveTouchOwnership(1); // ownership will trigger delivery of grail events.
980
981 // There should now be two grail events, corresponding to the frame
982 // event that were sent, waiting to be processed.

Subscribers

People subscribed via source and target branches