2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <dali/public-api/dali-core.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/events/hover-event-integ.h>
25 #include <dali/integration-api/events/mouse-wheel-event-integ.h>
26 #include <dali/integration-api/events/key-event-integ.h>
28 #include <dali-test-suite-utils.h>
34 std::vector< std::string > MasterCallStack;
37 // TypeRegistry needs custom actor Implementations to have the same name (namespaces are ignored so we use one here)
41 struct TestCustomActor : public CustomActorImpl
47 : CustomActorImpl( true ), // requires touch
48 mDaliProperty( Property::INVALID_INDEX ),
49 mSizeSet( Vector3::ZERO ),
50 mTargetSize( Vector3::ZERO )
52 SetRequiresMouseWheelEvents(true);
58 virtual ~TestCustomActor()
62 void Initialize( const char* name = NULL )
64 mDaliProperty = Self().RegisterProperty( "Dali", std::string("no"), Property::READ_WRITE);
69 virtual void OnInitialize( const char* name ) {}
72 * Resets the call stack
77 mTargetSize = Vector3();
78 mMethodsCalled.clear();
81 void AddToCallStacks( const char* method )
83 mMethodsCalled.push_back( method );
85 // Combine Actor name with method string
86 std::string nameAndMethod( Self().GetName() );
87 if ( 0 == nameAndMethod.size() )
89 nameAndMethod = "Unknown: ";
93 nameAndMethod += ": ";
95 nameAndMethod += method;
97 MasterCallStack.push_back( nameAndMethod );
100 // From CustomActorImpl
101 virtual void OnStageConnection()
103 AddToCallStacks("OnStageConnection");
105 virtual void OnStageDisconnection()
107 AddToCallStacks("OnStageDisconnection");
109 virtual void OnChildAdd(Actor& child)
111 AddToCallStacks("OnChildAdd");
113 virtual void OnChildRemove(Actor& child)
115 AddToCallStacks("OnChildRemove");
117 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue )
119 AddToCallStacks("OnPropertySet");
121 virtual void OnSizeSet(const Vector3& targetSize)
123 mSizeSet = targetSize;
124 AddToCallStacks("OnSizeSet");
126 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
128 mTargetSize = targetSize;
129 AddToCallStacks("OnSizeAnimation");
131 virtual bool OnTouchEvent(const TouchEvent& event)
133 AddToCallStacks("OnTouchEvent");
136 virtual bool OnHoverEvent(const HoverEvent& event)
138 AddToCallStacks("OnHoverEvent");
141 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event)
143 AddToCallStacks("OnMouseWheelEvent");
146 virtual bool OnKeyEvent(const KeyEvent& event)
148 AddToCallStacks("OnKeyEvent");
151 virtual void OnKeyInputFocusGained()
153 AddToCallStacks("OnKeyInputFocusGained");
155 virtual void OnKeyInputFocusLost()
157 AddToCallStacks("OnKeyInputFocusLost");
159 virtual Actor GetChildByAlias(const std::string& actorAlias)
161 AddToCallStacks("GetChildByAlias");
163 if ("found" == actorAlias)
173 virtual Vector3 GetNaturalSize()
175 return Vector3( 0.0f, 0.0f, 0.0f );
178 void SetDaliProperty(std::string s)
180 Self().SetProperty(mDaliProperty, s) ;
183 Property::Index mDaliProperty;
184 std::vector< std::string > mMethodsCalled;
194 * Test custom actor handle
196 class TestCustomActor : public CustomActor
200 static TestCustomActor New()
202 Impl::TestCustomActor* impl = new Impl::TestCustomActor;
203 TestCustomActor custom( *impl ); // takes ownership
210 virtual ~TestCustomActor()
214 Impl::TestCustomActor& GetImpl()
216 return static_cast<Impl::TestCustomActor&>(GetImplementation());
219 std::vector< std::string >& GetMethodsCalled()
221 return GetImpl().mMethodsCalled;
224 void ResetCallStack()
226 GetImpl().ResetCallStack();
229 void SetDaliProperty(std::string s)
231 GetImpl().SetDaliProperty(s);
236 return GetImpl().mSizeSet;
239 Vector3 GetTargetSize()
241 return GetImpl().mTargetSize;
246 TestCustomActor( Impl::TestCustomActor& impl ) : CustomActor( impl )
253 using namespace Dali;
255 BaseHandle CreateActor()
257 return TestCustomActor::New();
260 Dali::TypeRegistration mType( typeid(TestCustomActor), typeid(Dali::CustomActor), CreateActor );
265 int UtcDaliCustomActorDoAction(void)
267 TestApplication application;
268 tet_infoline("Testing Dali::CustomActor::DoAction()");
270 TestCustomActor custom = TestCustomActor::New();
272 BaseHandle customActorObject = custom;
274 DALI_TEST_CHECK(customActorObject);
276 std::vector<Property::Value> attributes;
278 // Check that an invalid command is not performed
279 DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
281 // Check that the custom actor is visible
282 custom.SetVisible(true);
283 DALI_TEST_CHECK(custom.IsVisible() == true);
285 // Check the custom actor performed an action to hide itself
286 DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true);
288 // flush the queue and render once
289 application.SendNotification();
290 application.Render();
292 // Check that the custom actor is now invisible
293 DALI_TEST_CHECK(custom.IsVisible() == false);
295 // Check the custom actor performed an action to show itself
296 DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true);
298 // flush the queue and render once
299 application.SendNotification();
300 application.Render();
302 // Check that the custom actor is now visible
303 DALI_TEST_CHECK(custom.IsVisible() == true);