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