~ubuntu-branches/ubuntu/trusty/geis/trusty

« back to all changes in this revision

Viewing changes to testsuite/geis2/gtest_gbe_construction_finished.cpp

  • Committer: Package Import Robot
  • Author(s): Chase Douglas
  • Date: 2012-07-30 08:51:42 UTC
  • Revision ID: package-import@ubuntu.com-20120730085142-jrc33ygjvt0ob1wl
Tags: upstream-2.2.11
ImportĀ upstreamĀ versionĀ 2.2.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "gtest_grail_backend.h"
 
2
#include "x11_mocks.h"
 
3
 
 
4
/*
 
5
  Check that GEIS_EVENT_ATTRIBUTE_CONSTRUCTION_FINISHED
 
6
  is properly filled.
 
7
 */
 
8
 
 
9
class ConstructionFinishedProperty : public Geis2GrailBackendBase
 
10
{
 
11
 protected:
 
12
  ConstructionFinishedProperty() : _subscription(nullptr),
 
13
    _got_update_with_construction_finished(false) {}
 
14
 
 
15
  void SendFirstBatchOfXInput2Events();
 
16
  void SendSecondBatchOfXInput2Events();
 
17
 
 
18
  virtual void OnEventInitComplete(GeisEvent event);
 
19
  virtual void OnEventGestureBegin(GeisEvent event);
 
20
  virtual void OnEventGestureUpdate(GeisEvent event);
 
21
 
 
22
  GeisSubscription _subscription;
 
23
  bool _got_update_with_construction_finished;
 
24
};
 
25
 
 
26
void ConstructionFinishedProperty::SendFirstBatchOfXInput2Events()
 
27
{
 
28
  xmock_server_time = 0;
 
29
 
 
30
  SendTouchEvent(XI_TouchBegin, 0, 123.0f, 456.0f);
 
31
  SendTouchEvent(XI_TouchBegin, 1, 222.0f, 456.0f);
 
32
 
 
33
  xmock_server_time = 5;
 
34
 
 
35
  SendTouchOwnershipEvent(0);
 
36
  SendTouchOwnershipEvent(1);
 
37
 
 
38
  SendTouchEvent(XI_TouchUpdate, 0, 123.0f, 466.0f);
 
39
  SendTouchEvent(XI_TouchUpdate, 1, 222.0f, 466.0f);
 
40
}
 
41
 
 
42
void ConstructionFinishedProperty::SendSecondBatchOfXInput2Events()
 
43
{
 
44
  /* Go past composition time (i.e. time window where new touches can be grouped
 
45
     with existing ones to make new gestures) */
 
46
  xmock_server_time = 70;
 
47
 
 
48
  SendTouchEvent(XI_TouchUpdate, 0, 123.0f, 466.0f);
 
49
  SendTouchEvent(XI_TouchUpdate, 1, 222.0f, 466.0f);
 
50
 
 
51
  xmock_server_time = 80;
 
52
 
 
53
  SendTouchEvent(XI_TouchEnd, 0, 123.0f, 476.0f);
 
54
  SendTouchEvent(XI_TouchEnd, 1, 222.0f, 476.0f);
 
55
}
 
56
 
 
57
void ConstructionFinishedProperty::OnEventInitComplete(GeisEvent event)
 
58
{
 
59
  _subscription = CreateFilteredSubscription(
 
60
      "My 2-touches Touch", 2, GEIS_GESTURE_TOUCH);
 
61
  ASSERT_NE(nullptr, _subscription);
 
62
}
 
63
 
 
64
void ConstructionFinishedProperty::OnEventGestureBegin(GeisEvent event)
 
65
{
 
66
  GeisAttr attr = geis_event_attr_by_name(event,
 
67
      GEIS_EVENT_ATTRIBUTE_CONSTRUCTION_FINISHED);
 
68
 
 
69
  GeisBoolean construction_finished = geis_attr_value_to_boolean(attr);
 
70
 
 
71
  ASSERT_EQ(GEIS_FALSE, construction_finished);
 
72
}
 
73
 
 
74
void ConstructionFinishedProperty::OnEventGestureUpdate(GeisEvent event)
 
75
{
 
76
  GeisAttr attr = geis_event_attr_by_name(event,
 
77
      GEIS_EVENT_ATTRIBUTE_CONSTRUCTION_FINISHED);
 
78
 
 
79
  GeisBoolean construction_finished = geis_attr_value_to_boolean(attr);
 
80
 
 
81
  GeisInteger timestamp;
 
82
  GetGestureTimestampInEvent(&timestamp, event);
 
83
 
 
84
  if (timestamp < 60)
 
85
  {
 
86
    /* below composition time. Construction cannot be finished just yet */
 
87
    ASSERT_EQ(GEIS_FALSE, construction_finished);
 
88
  }
 
89
  else
 
90
  {
 
91
    /* we're past composition time and therefore grail will
 
92
       send a slice with "construction finished" set to true.
 
93
       geis must follow suit. */
 
94
    ASSERT_EQ(GEIS_TRUE, construction_finished);
 
95
    _got_update_with_construction_finished = true;
 
96
  }
 
97
}
 
98
 
 
99
TEST_F(ConstructionFinishedProperty, Test)
 
100
{
 
101
  CreateXMockTouchScreenDevice();
 
102
 
 
103
  _geis = geis_new(GEIS_INIT_GRAIL_BACKEND,
 
104
                       GEIS_INIT_NO_ATOMIC_GESTURES,
 
105
                       nullptr);
 
106
  ASSERT_NE(nullptr, _geis);
 
107
 
 
108
  /* geis emits event stating that its initialization has finished */
 
109
  Run();
 
110
 
 
111
  /* begin XInput touches */
 
112
  SendFirstBatchOfXInput2Events();
 
113
 
 
114
  /* geis should receive an XAlarm event. geis updates grail time to 60.
 
115
     grail touches timeout (they get beyond composition time) which
 
116
     causes construction to finish.
 
117
   */
 
118
  Run();
 
119
 
 
120
  /* end XInput touches  */
 
121
  SendSecondBatchOfXInput2Events();
 
122
 
 
123
  /* gesture ends  */
 
124
  Run();
 
125
 
 
126
  ASSERT_TRUE(_got_update_with_construction_finished);
 
127
 
 
128
  if (_subscription)
 
129
    geis_subscription_delete(_subscription);
 
130
  geis_delete(_geis);
 
131
 
 
132
  DestroyXMockDevices();
 
133
}