Moved Gesture::State and -::Type to gesture-enumerations.h.
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-RotationGesture.cpp
1 /*
2  * Copyright (c) 2020 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/rotation-gesture/rotation-gesture-impl.h>
24
25 using namespace Dali;
26
27 void utc_dali_internal_rotation_gesture_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void utc_dali_internal_rotation_gesture_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 // Positive test case for a method
38 int UtcDaliRotationGestureConstructor(void)
39 {
40   TestApplication application; // Reset all test adapter return codes
41
42   RotationGesture gesture(new Internal::RotationGesture( GestureState::STARTED ));
43   DALI_TEST_EQUALS(GestureState::STARTED, gesture.GetState(), TEST_LOCATION);
44   DALI_TEST_EQUALS(0.0f, gesture.GetRotation().radian, TEST_LOCATION);
45   DALI_TEST_EQUALS(GestureType::ROTATION, gesture.GetType(), TEST_LOCATION);
46
47   RotationGesture gesture2(new Internal::RotationGesture( GestureState::CONTINUING ));
48   DALI_TEST_EQUALS(GestureState::CONTINUING, gesture2.GetState(), TEST_LOCATION);
49   DALI_TEST_EQUALS(0.0f, gesture2.GetRotation().radian, TEST_LOCATION);
50   DALI_TEST_EQUALS(GestureType::ROTATION, gesture2.GetType(), TEST_LOCATION);
51
52   RotationGesture gesture3(new Internal::RotationGesture( GestureState::FINISHED ));
53   DALI_TEST_EQUALS(GestureState::FINISHED, gesture3.GetState(), TEST_LOCATION);
54   DALI_TEST_EQUALS(0.0f, gesture3.GetRotation().radian, TEST_LOCATION);
55   DALI_TEST_EQUALS(GestureType::ROTATION, gesture3.GetType(), TEST_LOCATION);
56
57   // Test copy constructor
58   GetImplementation( gesture3 ).SetRotation( Radian( 3.0f ));
59
60   RotationGesture rotation(gesture3);
61   DALI_TEST_EQUALS(GestureState::FINISHED, rotation.GetState(), TEST_LOCATION);
62   DALI_TEST_EQUALS(3.0f, rotation.GetRotation().radian, TEST_LOCATION);
63   DALI_TEST_EQUALS(GestureType::ROTATION, rotation.GetType(), TEST_LOCATION);
64
65   // Test move constructor
66   const auto refCount = gesture.GetObjectPtr()->ReferenceCount();
67   RotationGesture gesture4( std::move( gesture ) );
68   DALI_TEST_CHECK(!gesture);
69   DALI_TEST_EQUALS(GestureType::ROTATION, gesture4.GetType(), TEST_LOCATION);
70   DALI_TEST_EQUALS(gesture4.GetBaseObject().ReferenceCount(), refCount, TEST_LOCATION);
71
72   END_TEST;
73 }
74
75 int UtcDaliRotationGestureAssignment(void)
76 {
77   // Test Assignment operator
78   RotationGesture gesture(new Internal::RotationGesture( GestureState::STARTED ));
79   DALI_TEST_EQUALS(GestureState::STARTED, gesture.GetState(), TEST_LOCATION);
80   DALI_TEST_EQUALS(0.0f, gesture.GetRotation().radian, TEST_LOCATION);
81   DALI_TEST_EQUALS(GestureType::ROTATION, gesture.GetType(), TEST_LOCATION);
82
83   RotationGesture gesture2(new Internal::RotationGesture( GestureState::CONTINUING ));
84   DALI_TEST_EQUALS(GestureState::CONTINUING, gesture2.GetState(), TEST_LOCATION);
85   DALI_TEST_EQUALS(0.0f, gesture2.GetRotation().radian, TEST_LOCATION);
86   DALI_TEST_EQUALS(GestureType::ROTATION, gesture2.GetType(), TEST_LOCATION);
87
88   GetImplementation( gesture2 ).SetRotation( Radian( 3.0f ));
89
90   gesture = gesture2;
91   DALI_TEST_EQUALS(GestureState::CONTINUING, gesture.GetState(), TEST_LOCATION);
92   DALI_TEST_EQUALS(3.0f, gesture.GetRotation().radian, TEST_LOCATION);
93   DALI_TEST_EQUALS(GestureType::ROTATION, gesture.GetType(), TEST_LOCATION);
94
95   // Move assignment
96   const auto refCount = gesture.GetObjectPtr()->ReferenceCount();
97   RotationGesture gesture3;
98   DALI_TEST_EQUALS(gesture3, Gesture(), TEST_LOCATION);
99   gesture3 = std::move(gesture);
100   DALI_TEST_CHECK(!gesture);
101   DALI_TEST_EQUALS(GestureType::ROTATION, gesture3.GetType(), TEST_LOCATION);
102   DALI_TEST_EQUALS(gesture3.GetBaseObject().ReferenceCount(), refCount, TEST_LOCATION);
103
104   END_TEST;
105 }
106
107 int UtcDaliRotationGestureSetGetRotationP(void)
108 {
109   RotationGesture gesture(new Internal::RotationGesture(GestureState::STARTED));
110   DALI_TEST_EQUALS(gesture.GetRotation(), Radian(), TEST_LOCATION);
111
112   GetImplementation(gesture).SetRotation(Dali::ANGLE_270);
113   DALI_TEST_EQUALS(gesture.GetRotation(), Dali::ANGLE_270, TEST_LOCATION);
114
115   END_TEST;
116 }
117
118 int UtcDaliRotationGestureSetGetScreenCenterPointP(void)
119 {
120   RotationGesture gesture(new Internal::RotationGesture(GestureState::STARTED));
121   DALI_TEST_EQUALS(gesture.GetScreenCenterPoint(), Vector2::ZERO, TEST_LOCATION);
122
123   GetImplementation(gesture).SetScreenCenterPoint(Vector2(123.0f,321.0f));
124   DALI_TEST_EQUALS(gesture.GetScreenCenterPoint(), Vector2(123.0f,321.0f), TEST_LOCATION);
125
126   END_TEST;
127 }
128
129 int UtcDaliRotationGestureSetGetLocalCenterPointP(void)
130 {
131   RotationGesture gesture(new Internal::RotationGesture(GestureState::STARTED));
132   DALI_TEST_EQUALS(gesture.GetLocalCenterPoint(), Vector2::ZERO, TEST_LOCATION);
133
134   GetImplementation(gesture).SetLocalCenterPoint(Vector2(123.0f,321.0f));
135   DALI_TEST_EQUALS(gesture.GetLocalCenterPoint(), Vector2(123.0f,321.0f), TEST_LOCATION);
136
137   END_TEST;
138 }