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/dali.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali/integration-api/events/mouse-wheel-event-integ.h>
25 #include <dali/integration-api/events/key-event-integ.h>
27 #include <dali-test-suite-utils.h>
33 std::vector< std::string > MasterCallStack;
36 // TypeRegistry needs custom actor Implementations to have the same name (namespaces are ignored so we use one here)
40 struct TestCustomActor : public CustomActorImpl
46 : CustomActorImpl( true ), // requires touch
47 mDaliProperty( Property::INVALID_INDEX ),
48 mSizeSet( Vector3::ZERO ),
49 mTargetSize( Vector3::ZERO )
51 SetRequiresMouseWheelEvents(true);
57 virtual ~TestCustomActor()
61 void Initialize( const char* name = NULL )
63 mDaliProperty = Self().RegisterProperty( "Dali", std::string("no"), Property::READ_WRITE);
68 virtual void OnInitialize( const char* name ) {}
71 * Resets the call stack
76 mTargetSize = Vector3();
77 mMethodsCalled.clear();
80 void AddToCallStacks( const char* method )
82 mMethodsCalled.push_back( method );
84 // Combine Actor name with method string
85 std::string nameAndMethod( Self().GetName() );
86 if ( 0 == nameAndMethod.size() )
88 nameAndMethod = "Unknown: ";
92 nameAndMethod += ": ";
94 nameAndMethod += method;
96 MasterCallStack.push_back( nameAndMethod );
99 // From CustomActorImpl
100 virtual void OnStageConnection()
102 AddToCallStacks("OnStageConnection");
104 virtual void OnStageDisconnection()
106 AddToCallStacks("OnStageDisconnection");
108 virtual void OnChildAdd(Actor& child)
110 AddToCallStacks("OnChildAdd");
112 virtual void OnChildRemove(Actor& child)
114 AddToCallStacks("OnChildRemove");
116 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue )
118 AddToCallStacks("OnPropertySet");
120 virtual void OnSizeSet(const Vector3& targetSize)
122 mSizeSet = targetSize;
123 AddToCallStacks("OnSizeSet");
125 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
127 mTargetSize = targetSize;
128 AddToCallStacks("OnSizeAnimation");
130 virtual bool OnTouchEvent(const TouchEvent& event)
132 AddToCallStacks("OnTouchEvent");
135 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event)
137 AddToCallStacks("OnMouseWheelEvent");
140 virtual bool OnKeyEvent(const KeyEvent& event)
142 AddToCallStacks("OnKeyEvent");
145 virtual void OnKeyInputFocusGained()
147 AddToCallStacks("OnKeyInputFocusGained");
149 virtual void OnKeyInputFocusLost()
151 AddToCallStacks("OnKeyInputFocusLost");
153 virtual Actor GetChildByAlias(const std::string& actorAlias)
155 AddToCallStacks("GetChildByAlias");
157 if ("found" == actorAlias)
167 void SetDaliProperty(std::string s)
169 Self().SetProperty(mDaliProperty, s) ;
172 Property::Index mDaliProperty;
173 std::vector< std::string > mMethodsCalled;
183 * Test custom actor handle
185 class TestCustomActor : public CustomActor
189 static TestCustomActor New()
191 Impl::TestCustomActor* impl = new Impl::TestCustomActor;
192 TestCustomActor custom( *impl ); // takes ownership
199 virtual ~TestCustomActor()
203 Impl::TestCustomActor& GetImpl()
205 return static_cast<Impl::TestCustomActor&>(GetImplementation());
208 std::vector< std::string >& GetMethodsCalled()
210 return GetImpl().mMethodsCalled;
213 void ResetCallStack()
215 GetImpl().ResetCallStack();
218 void SetDaliProperty(std::string s)
220 GetImpl().SetDaliProperty(s);
225 return GetImpl().mSizeSet;
228 Vector3 GetTargetSize()
230 return GetImpl().mTargetSize;
235 TestCustomActor( Impl::TestCustomActor& impl ) : CustomActor( impl )
242 using namespace Dali;
244 BaseHandle CreateActor()
246 return TestCustomActor::New();
249 Dali::TypeRegistration mType( typeid(TestCustomActor), typeid(Dali::CustomActor), CreateActor );
254 int UtcDaliCustomActorDoAction(void)
256 TestApplication application;
257 tet_infoline("Testing Dali::CustomActor::DoAction()");
259 TestCustomActor custom = TestCustomActor::New();
261 BaseHandle customActorObject = custom;
263 DALI_TEST_CHECK(customActorObject);
265 std::vector<Property::Value> attributes;
267 // Check that an invalid command is not performed
268 DALI_TEST_CHECK(customActorObject.DoAction("invalidCommand", attributes) == false);
270 // Check that the custom actor is visible
271 custom.SetVisible(true);
272 DALI_TEST_CHECK(custom.IsVisible() == true);
274 // Check the custom actor performed an action to hide itself
275 DALI_TEST_CHECK(customActorObject.DoAction("hide", attributes) == true);
277 // flush the queue and render once
278 application.SendNotification();
279 application.Render();
281 // Check that the custom actor is now invisible
282 DALI_TEST_CHECK(custom.IsVisible() == false);
284 // Check the custom actor performed an action to show itself
285 DALI_TEST_CHECK(customActorObject.DoAction("show", attributes) == true);
287 // flush the queue and render once
288 application.SendNotification();
289 application.Render();
291 // Check that the custom actor is now visible
292 DALI_TEST_CHECK(custom.IsVisible() == true);