bf2b20e0686c6727c195578283f148bb3a540bc7
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-Gesture.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 <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <dali/internal/event/events/gesture-impl.h>
24
25 using namespace Dali;
26
27 void utc_dali_internal_gesture_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void utc_dali_internal_gesture_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 namespace
38 {
39
40 // TestGesture Struct (Gesture constructor is protected)
41 struct TestGesture : public Internal::Gesture
42 {
43 public:
44   TestGesture(Gesture::Type type, Gesture::State state)
45   : Gesture(type, state) {}
46
47   virtual ~TestGesture() {}
48 };
49
50 } // anon namespace
51
52 int UtcDaliGestureConstructorP(void)
53 {
54   TestApplication application; // Reset all test adapter return codes
55
56   Gesture empty;
57   DALI_TEST_CHECK( !empty );
58
59   Gesture pan( new TestGesture(Gesture::Pan, Gesture::Started) );
60   DALI_TEST_EQUALS(Gesture::Pan, pan.GetType(), TEST_LOCATION);
61   DALI_TEST_EQUALS(Gesture::Started, pan.GetState(), TEST_LOCATION);
62
63   Gesture pinch( new TestGesture(Gesture::Pinch, Gesture::Clear) );
64   DALI_TEST_EQUALS(Gesture::Pinch, pinch.GetType(), TEST_LOCATION);
65   DALI_TEST_EQUALS(Gesture::Clear, pinch.GetState(), TEST_LOCATION);
66
67   // Test copy constructor
68   Gesture pan2(pan);
69   DALI_TEST_EQUALS(Gesture::Pan, pan2.GetType(), TEST_LOCATION);
70   DALI_TEST_EQUALS(Gesture::Started, pan2.GetState(), TEST_LOCATION);
71   END_TEST;
72
73   // Test move constructor
74   const auto refCount = pan.GetObjectPtr()->ReferenceCount();
75   Gesture pan3( std::move( pan ) );
76   DALI_TEST_EQUALS(pan, Gesture(), TEST_LOCATION);
77   DALI_TEST_EQUALS(Gesture::Pan, pan3.GetType(), TEST_LOCATION);
78   DALI_TEST_EQUALS(pan3.GetBaseObject().ReferenceCount(), refCount, TEST_LOCATION);
79
80   END_TEST;
81 }
82
83 int UtcDaliGestureAssignmentP(void)
84 {
85   TestApplication application; // Reset all test adapter return codes
86
87   // Test Assignment operator
88   Gesture pan( new TestGesture(Gesture::Pan, Gesture::Finished) );
89   DALI_TEST_EQUALS(Gesture::Pan, pan.GetType(), TEST_LOCATION);
90   DALI_TEST_EQUALS(Gesture::Finished, pan.GetState(), TEST_LOCATION);
91
92   Gesture test( new TestGesture(Gesture::Pinch, Gesture::Started) );
93   DALI_TEST_EQUALS(Gesture::Pinch, test.GetType(), TEST_LOCATION);
94   DALI_TEST_EQUALS(Gesture::Started, test.GetState(), TEST_LOCATION);
95
96   // Copy assignment
97   test = pan;
98   DALI_TEST_EQUALS(Gesture::Pan, test.GetType(), TEST_LOCATION);
99   DALI_TEST_EQUALS(Gesture::Finished, test.GetState(), TEST_LOCATION);
100
101   // Move assignment
102   const auto refCount = pan.GetObjectPtr()->ReferenceCount();
103   Gesture pan3;
104   DALI_TEST_EQUALS(pan3, Gesture(), TEST_LOCATION);
105   pan3 = std::move(pan);
106   DALI_TEST_EQUALS(pan, Gesture(), TEST_LOCATION);
107   DALI_TEST_EQUALS(Gesture::Pan, pan3.GetType(), TEST_LOCATION);
108   DALI_TEST_EQUALS(pan3.GetBaseObject().ReferenceCount(), refCount, TEST_LOCATION);
109
110   END_TEST;
111 }
112
113 int UtcDaliGestureGetTypeP(void)
114 {
115   TestApplication application; // Reset all test adapter return codes
116
117   Gesture pan( new TestGesture(Gesture::Pan, Gesture::Started) );
118   DALI_TEST_EQUALS(Gesture::Pan, pan.GetType(), TEST_LOCATION);
119
120   END_TEST;
121 }
122
123 int UtcDaliGestureGetStateP(void)
124 {
125   TestApplication application; // Reset all test adapter return codes
126
127   Gesture pan( new TestGesture(Gesture::Pan, Gesture::Started) );
128   DALI_TEST_EQUALS(Gesture::Started, pan.GetState(), TEST_LOCATION);
129
130   GetImplementation(pan).SetState(Gesture::Finished);
131   DALI_TEST_EQUALS(Gesture::Finished, pan.GetState(), TEST_LOCATION);
132
133   END_TEST;
134 }
135
136 int UtcDaliGestureGetTimeP(void)
137 {
138   TestApplication application; // Reset all test adapter return codes
139
140   Gesture pan( new TestGesture(Gesture::Pan, Gesture::Started) );
141   DALI_TEST_EQUALS(0, pan.GetTime(), TEST_LOCATION);
142
143   GetImplementation(pan).SetTime(61282);
144   DALI_TEST_EQUALS(61282, pan.GetTime(), TEST_LOCATION);
145
146   END_TEST;
147 }
148