Protecting test cases from memory scribbling
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / dummy-control.h
1 #ifndef DALI_TOOLKIT_TEST_DUMMY_CONTROL_H
2 #define DALI_TOOLKIT_TEST_DUMMY_CONTROL_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/dali-toolkit.h>
23
24 // EXTERNAL INCLUDES
25 #include <functional>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 class DummyControlImpl;
34 class TransitionData;
35
36 namespace Visual
37 {
38 class Base;
39 }
40
41 /**
42  * Control does not have a New method so use this dummy class for the handle.
43  */
44 class DummyControl : public Control
45 {
46 public:
47   enum PropertyRange
48   {
49     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0
50     PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000              ///< Reserve property index
51   };
52
53   struct Property
54   {
55     enum Type
56     {
57       TEST_VISUAL = PROPERTY_START_INDEX,
58       TEST_VISUAL2,
59       FOREGROUND_VISUAL,
60       FOCUS_VISUAL,
61       LABEL_VISUAL
62     };
63   };
64
65   DummyControl();
66   DummyControl(const DummyControl& control);
67   ~DummyControl();
68
69   static DummyControl New( bool override = false );
70
71   static DummyControl DownCast( BaseHandle handle );
72
73
74   DummyControl& operator=(const DummyControl& control);
75
76 public: // Not intended for application developers
77
78   DummyControl( DummyControlImpl& implementation );
79   DummyControl( Dali::Internal::CustomActor* internal );
80 };
81
82 /**
83  * Cannot create an instance of Internal::Control, so use this dummy class for the implementation.
84  * This class does not override any of Internal::Control's behaviour.
85  */
86 class DummyControlImpl : public Toolkit::Internal::Control
87 {
88 public:
89
90   static DummyControl New();
91
92 public:
93   inline void EnableGestureDetection(GestureType::Value type) { Internal::Control::EnableGestureDetection(type); }
94   inline void DisableGestureDetection(GestureType::Value type) { Internal::Control::DisableGestureDetection(type); }
95   inline PinchGestureDetector GetPinchGestureDetector() const { return Internal::Control::GetPinchGestureDetector(); }
96   inline PanGestureDetector GetPanGestureDetector() const { return Internal::Control::GetPanGestureDetector(); }
97   inline TapGestureDetector GetTapGestureDetector() const { return Internal::Control::GetTapGestureDetector(); }
98   inline LongPressGestureDetector GetLongPressGestureDetector() const { return Internal::Control::GetLongPressGestureDetector(); }
99
100   void RegisterVisual( Property::Index index, Toolkit::Visual::Base visual);
101   void RegisterVisual( Property::Index index, Toolkit::Visual::Base visual, bool enabled );
102   void UnregisterVisual( Property::Index index );
103   void EnableVisual( Property::Index index, bool enabled );
104   bool IsVisualEnabled( Property::Index index );
105   int GetVisualCount();
106   Toolkit::Visual::Base GetVisual( Property::Index index );
107   Animation CreateTransition( const Toolkit::TransitionData& transition );
108   void DoAction( Dali::Property::Index index, Dali::Property::Index action, const Dali::Property::Value attributes );
109
110   static void SetProperty( BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
111
112   static Property::Value GetProperty( BaseObject* object, Dali::Property::Index propertyIndex );
113
114   // Used to test signal connections
115   void CustomSlot1( Actor actor );
116
117   bool mCustomSlot1Called;
118   typedef std::vector<Property::Index> VisualIndices;
119   VisualIndices mRegisteredVisualIndices;
120
121 protected:
122
123   DummyControlImpl();
124
125   ~DummyControlImpl() override;
126 };
127
128 namespace Impl
129 {
130
131 /**
132  * Cannot create an instance of Internal::Control, so use this dummy class for the implementation.
133  * This class DOES override Internal::Control's behaviour.
134  */
135 class DummyControl : public Toolkit::DummyControlImpl
136 {
137 public:
138
139   typedef std::function<void( Size )> RelayoutCallbackFunc;
140
141   static Toolkit::DummyControl New();
142
143   void SetLayout( Property::Index visualIndex, Property::Map& map );
144
145   void SetRelayoutCallback( RelayoutCallbackFunc callback );
146
147 private:
148
149   DummyControl();
150
151   ~DummyControl() override;
152
153 private: // From Internal::Control
154
155   void OnInitialize() override;
156   bool OnAccessibilityActivated() override;
157   bool OnAccessibilityValueChange( bool isIncrease ) override;
158
159   void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override;
160   void OnPinch(const PinchGesture& pinch) override;
161   void OnPan(const PanGesture& pan) override;
162   void OnTap(const TapGesture& tap) override;
163   void OnLongPress(const LongPressGesture& longPress) override;
164   Vector3 GetNaturalSize() override;
165   bool OnKeyEvent(const KeyEvent& event) override;
166
167 private: // From CustomActorImpl
168
169   void OnSceneConnection( int depth ) override;
170   void OnSceneDisconnection() override;
171   void OnChildAdd(Actor& child) override;
172   void OnChildRemove(Actor& child) override;
173   void OnSizeSet(const Vector3& targetSize) override;
174   void OnSizeAnimation(Animation& animation, const Vector3& targetSize) override;
175   void OnKeyInputFocusGained() override;
176   void OnKeyInputFocusLost() override;
177   void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
178
179   DALI_INTERNAL DummyControl( const DummyControl& );
180   DALI_INTERNAL DummyControl& operator=( const DummyControl& );
181
182 public:
183
184   bool initializeCalled;
185   bool activatedCalled;
186   bool onAccValueChangeCalled;
187   bool themeChangeCalled;
188   bool fontChangeCalled;
189   bool pinchCalled;
190   bool panCalled;
191   bool tapCalled;
192   bool longPressCalled;
193   bool stageConnectionCalled;
194   bool stageDisconnectionCalled;
195   bool childAddCalled;
196   bool childRemoveCalled;
197   bool sizeSetCalled;
198   bool sizeAnimationCalled;
199   bool hoverEventCalled;
200   bool wheelEventCalled;
201   bool keyEventCalled;
202   bool keyInputFocusGained;
203   bool keyInputFocusLost;
204   static int constructorCount;
205   static int destructorCount;
206
207   Property::Map mLayouts;
208   RelayoutCallbackFunc mRelayoutCallback;
209
210 };
211
212 } // namespace Impl
213
214 } // namespace Toolkit
215
216 } // namespace Dali
217
218 #endif // DALI_TOOLKIT_TEST_DUMMY_CONTROL_H