Moved Gesture::State and -::Type to gesture-enumerations.h.
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-LongPressGesture.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/long-press-gesture/long-press-gesture-impl.h>
24
25 using namespace Dali;
26
27 void utc_dali_internal_long_press_gesture_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void utc_dali_internal_long_press_gesture_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 int UtcDaliLongPressGestureConstructorP(void)
38 {
39   TestApplication application;
40
41   LongPressGesture gesture(new Internal::LongPressGesture( GestureState::STARTED ));
42   DALI_TEST_EQUALS(1u, gesture.GetNumberOfTouches(), TEST_LOCATION);
43   DALI_TEST_EQUALS(GestureType::LONG_PRESS, gesture.GetType(), TEST_LOCATION);
44
45   // Test Copy constructor
46   GetImplementation( gesture ).SetNumberOfTouches( 5u );
47
48   LongPressGesture gesture2(gesture);
49   DALI_TEST_EQUALS(5u, gesture2.GetNumberOfTouches(), TEST_LOCATION);
50   DALI_TEST_EQUALS(GestureType::LONG_PRESS, gesture2.GetType(), TEST_LOCATION);
51   DALI_TEST_EQUALS(GestureState::STARTED, gesture2.GetState(), TEST_LOCATION);
52
53   // Test move constructor
54   const auto refCount = gesture.GetObjectPtr()->ReferenceCount();
55   LongPressGesture gesture3( std::move( gesture ) );
56   DALI_TEST_EQUALS(gesture, LongPressGesture(), TEST_LOCATION);
57   DALI_TEST_EQUALS(GestureType::LONG_PRESS, gesture3.GetType(), TEST_LOCATION);
58   DALI_TEST_EQUALS(gesture3.GetBaseObject().ReferenceCount(), refCount, TEST_LOCATION);
59
60   END_TEST;
61 }
62
63 int UtcDaliLongPressGestureAssignmentP(void)
64 {
65   // Test Assignment operator
66   LongPressGesture gesture(new Internal::LongPressGesture( GestureState::STARTED ));
67   DALI_TEST_EQUALS(1u, gesture.GetNumberOfTouches(), TEST_LOCATION);
68   DALI_TEST_EQUALS(GestureType::LONG_PRESS, gesture.GetType(), TEST_LOCATION);
69
70   GetImplementation( gesture ).SetNumberOfTouches( 5u );
71
72   LongPressGesture gesture2(new Internal::LongPressGesture( GestureState::FINISHED ));
73   DALI_TEST_EQUALS(GestureState::FINISHED, gesture2.GetState(), TEST_LOCATION);
74   gesture2 = gesture;
75   DALI_TEST_EQUALS(5u, gesture2.GetNumberOfTouches(), TEST_LOCATION);
76   DALI_TEST_EQUALS(GestureType::LONG_PRESS, gesture2.GetType(), TEST_LOCATION);
77   DALI_TEST_EQUALS(GestureState::STARTED, gesture2.GetState(), TEST_LOCATION);
78
79   // Move assignment
80   const auto refCount = gesture.GetObjectPtr()->ReferenceCount();
81   LongPressGesture gesture3;
82   DALI_TEST_EQUALS(gesture3, Gesture(), TEST_LOCATION);
83   gesture3 = std::move(gesture);
84   DALI_TEST_EQUALS(gesture, Gesture(), TEST_LOCATION);
85   DALI_TEST_EQUALS(GestureType::LONG_PRESS, gesture3.GetType(), TEST_LOCATION);
86   DALI_TEST_EQUALS(gesture3.GetBaseObject().ReferenceCount(), refCount, TEST_LOCATION);
87
88   END_TEST;
89 }
90
91 int UtcDaliLongPressGestureGetNumberOfTouchesP(void)
92 {
93   TestApplication application;
94
95   LongPressGesture gesture(new Internal::LongPressGesture(GestureState::STARTED));
96   DALI_TEST_EQUALS(gesture.GetNumberOfTouches(), 1, TEST_LOCATION);
97
98   GetImplementation(gesture).SetNumberOfTouches(4);
99   DALI_TEST_EQUALS(gesture.GetNumberOfTouches(), 4, TEST_LOCATION);
100
101   END_TEST;
102 }
103
104 int UtcDaliLongPressGestureGetScreenPointP(void)
105 {
106   TestApplication application;
107
108   LongPressGesture gesture(new Internal::LongPressGesture(GestureState::STARTED));
109   DALI_TEST_EQUALS(gesture.GetScreenPoint(), Vector2::ZERO , TEST_LOCATION);
110   DALI_TEST_EQUALS(gesture.GetLocalPoint(), Vector2::ZERO , TEST_LOCATION);
111
112   GetImplementation(gesture).SetScreenPoint(Vector2(100.0f, 300.0f));
113   DALI_TEST_EQUALS(gesture.GetScreenPoint(), Vector2(100.0f, 300.0f), TEST_LOCATION);
114   DALI_TEST_EQUALS(gesture.GetLocalPoint(), Vector2::ZERO , TEST_LOCATION);
115
116   END_TEST;
117 }
118
119 int UtcDaliLongPressGestureGetLocalPointP(void)
120 {
121   TestApplication application;
122
123   LongPressGesture gesture(new Internal::LongPressGesture(GestureState::STARTED));
124   DALI_TEST_EQUALS(gesture.GetLocalPoint(), Vector2::ZERO , TEST_LOCATION);
125   DALI_TEST_EQUALS(gesture.GetScreenPoint(), Vector2::ZERO , TEST_LOCATION);
126
127   GetImplementation(gesture).SetLocalPoint(Vector2(100.0f, 300.0f));
128   DALI_TEST_EQUALS(gesture.GetLocalPoint(), Vector2(100.0f, 300.0f), TEST_LOCATION);
129   DALI_TEST_EQUALS(gesture.GetScreenPoint(), Vector2::ZERO , TEST_LOCATION);
130
131   END_TEST;
132 }