Revert "[Tizen] Add Integration API to Create public event type"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-TouchEvent.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <dali-test-suite-utils.h>
19 #include <dali/integration-api/events/touch-integ.h>
20 #include <dali/public-api/dali-core.h>
21 #include <stdlib.h>
22
23 #include <iostream>
24
25 void utc_dali_touch_event_startup(void)
26 {
27   test_return_value = TET_UNDEF;
28 }
29
30 void utc_dali_touch_event_cleanup(void)
31 {
32   test_return_value = TET_PASS;
33 }
34
35 namespace
36 {
37 TouchPoint GenerateTouchPoint()
38 {
39   return TouchPoint(1, PointState::STARTED, 100.0f, 200.0f);
40 }
41 } // namespace
42
43 int UtcDaliTouchEventConstructorP(void)
44 {
45   TouchEvent touchEvent;
46   DALI_TEST_CHECK(!touchEvent);
47   END_TEST;
48 }
49
50 int UtcDaliTouchEventCopyConstructorP(void)
51 {
52   TouchEvent touchEvent = Integration::NewTouchEvent(123u, GenerateTouchPoint());
53   DALI_TEST_CHECK(touchEvent);
54
55   const auto refCount = touchEvent.GetBaseObject().ReferenceCount();
56
57   TouchEvent touchEvent2(touchEvent);
58   DALI_TEST_CHECK(touchEvent);
59   DALI_TEST_CHECK(touchEvent2);
60   DALI_TEST_EQUALS(touchEvent, touchEvent2, TEST_LOCATION);
61   DALI_TEST_EQUALS(refCount + 1, touchEvent.GetBaseObject().ReferenceCount(), TEST_LOCATION);
62
63   END_TEST;
64 }
65
66 int UtcDaliTouchEventMoveConstructorP(void)
67 {
68   TouchEvent touchEvent = Integration::NewTouchEvent(123u, GenerateTouchPoint());
69   DALI_TEST_CHECK(touchEvent);
70
71   const auto refCount = touchEvent.GetBaseObject().ReferenceCount();
72
73   TouchEvent touchEvent2(std::move(touchEvent));
74   DALI_TEST_CHECK(!touchEvent);
75   DALI_TEST_CHECK(touchEvent2);
76   DALI_TEST_EQUALS(refCount, touchEvent2.GetBaseObject().ReferenceCount(), TEST_LOCATION);
77
78   END_TEST;
79 }
80
81 int UtcDaliTouchEventCopyAssignmentP(void)
82 {
83   TouchEvent touchEvent = Integration::NewTouchEvent(123u, GenerateTouchPoint());
84   DALI_TEST_CHECK(touchEvent);
85
86   const auto refCount = touchEvent.GetBaseObject().ReferenceCount();
87
88   TouchEvent touchEvent2;
89   DALI_TEST_CHECK(!touchEvent2);
90
91   touchEvent2 = touchEvent;
92   DALI_TEST_CHECK(touchEvent);
93   DALI_TEST_CHECK(touchEvent2);
94   DALI_TEST_EQUALS(touchEvent, touchEvent2, TEST_LOCATION);
95   DALI_TEST_EQUALS(refCount + 1, touchEvent.GetBaseObject().ReferenceCount(), TEST_LOCATION);
96
97   END_TEST;
98 }
99
100 int UtcDaliTouchEventMoveAssignmentP(void)
101 {
102   TouchEvent touchEvent = Integration::NewTouchEvent(123u, GenerateTouchPoint());
103   DALI_TEST_CHECK(touchEvent);
104
105   const auto refCount = touchEvent.GetBaseObject().ReferenceCount();
106
107   TouchEvent touchEvent2;
108   DALI_TEST_CHECK(!touchEvent2);
109
110   touchEvent2 = std::move(touchEvent);
111   DALI_TEST_CHECK(!touchEvent);
112   DALI_TEST_CHECK(touchEvent2);
113   DALI_TEST_EQUALS(refCount, touchEvent2.GetBaseObject().ReferenceCount(), TEST_LOCATION);
114
115   END_TEST;
116 }
117
118 int UtcDaliTouchEventCopyConstructorWithPointP(void)
119 {
120   Dali::Integration::Point point;
121
122   Vector2 touchPoint(10.0, 20.0);
123   point.SetDeviceId(1);
124   point.SetState(PointState::DOWN);
125   point.SetScreenPosition(Vector2(touchPoint.x, touchPoint.y));
126
127   TouchEvent touchEvent = Integration::NewTouchEvent(123u, point);
128   DALI_TEST_CHECK(touchEvent);
129
130   const auto refCount = touchEvent.GetBaseObject().ReferenceCount();
131
132   TouchEvent touchEvent2(touchEvent);
133   DALI_TEST_CHECK(touchEvent);
134   DALI_TEST_CHECK(touchEvent2);
135   DALI_TEST_EQUALS(touchEvent, touchEvent2, TEST_LOCATION);
136   DALI_TEST_EQUALS(refCount + 1, touchEvent.GetBaseObject().ReferenceCount(), TEST_LOCATION);
137
138   END_TEST;
139 }
140
141 int UtcDaliTouchEventMoveConstructorWithPointP(void)
142 {
143   Dali::Integration::Point point;
144
145   Vector2 touchPoint(10.0, 20.0);
146   point.SetDeviceId(1);
147   point.SetState(PointState::DOWN);
148   point.SetScreenPosition(Vector2(touchPoint.x, touchPoint.y));
149
150   TouchEvent touchEvent = Integration::NewTouchEvent(123u, point);
151   DALI_TEST_CHECK(touchEvent);
152
153   const auto refCount = touchEvent.GetBaseObject().ReferenceCount();
154
155   TouchEvent touchEvent2(std::move(touchEvent));
156   DALI_TEST_CHECK(!touchEvent);
157   DALI_TEST_CHECK(touchEvent2);
158   DALI_TEST_EQUALS(refCount, touchEvent2.GetBaseObject().ReferenceCount(), TEST_LOCATION);
159
160   END_TEST;
161 }