2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali/integration-api/events/touch-event-integ.h>
24 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit-test-suite-utils.h>
29 using namespace Toolkit;
31 static void Startup();
32 static void Cleanup();
36 static bool gObjectCreatedCallBackCalled;
38 static void TestCallback(BaseHandle handle)
40 gObjectCreatedCallBackCalled = true;
45 void (*tet_startup)() = Startup;
46 void (*tet_cleanup)() = Cleanup;
50 POSITIVE_TC_IDX = 0x01,
54 #define MAX_NUMBER_OF_TESTS 10000
56 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
59 // Add test functionality for all APIs in the class (Positive and Negative)
60 TEST_FUNCTION( UtcDaliPopupNew, POSITIVE_TC_IDX );
61 TEST_FUNCTION( UtcDaliPopupDestructor, POSITIVE_TC_IDX );
62 TEST_FUNCTION( UtcDaliPopupDownCast, POSITIVE_TC_IDX );
63 TEST_FUNCTION( UtcDaliPopoupSetProperty, POSITIVE_TC_IDX );
64 TEST_FUNCTION( UtcDaliPopupSetBackgroundImage, POSITIVE_TC_IDX );
65 TEST_FUNCTION( UtcDaliPopupSetTitle, POSITIVE_TC_IDX );
66 TEST_FUNCTION( UtcDaliPopupSetTitleText, POSITIVE_TC_IDX );
67 TEST_FUNCTION( UtcDaliPopupAddButton, POSITIVE_TC_IDX );
68 TEST_FUNCTION( UtcDaliPopupSetState, POSITIVE_TC_IDX );
69 TEST_FUNCTION( UtcDaliPopupSetStateSlow, POSITIVE_TC_IDX );
70 TEST_FUNCTION( UtcDaliPopupShowHide, POSITIVE_TC_IDX );
71 TEST_FUNCTION( UtcDaliPopupShowHideTail, POSITIVE_TC_IDX );
72 TEST_FUNCTION( UtcDaliPopupOnTouchedOutside, POSITIVE_TC_IDX );
77 const int RENDER_FRAME_INTERVAL = 10; ///< Duration of each frame in ms.
78 const int RENDER_ANIMATION_TEST_DURATION_MS = 1000; ///< 1000ms to test animation
79 const int RENDER_ANIMATION_TEST_DURATION_FRAMES = RENDER_ANIMATION_TEST_DURATION_MS / RENDER_FRAME_INTERVAL; ///< equivalent frames.
80 const Vector3 DEFAULT_BUTTON_SIZE(100.0f, 50.0f, 0.0f);
81 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10.0f, 10.0f );
82 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10.0f, 10.0f );
85 * Counts how many descendents root Actor has, including
88 * @param[in] root The root actor to count from.
89 * @return The number of descendents including root actor itself.
91 int DescendentCount(const Actor& root)
93 unsigned int numChildren = root.GetChildCount();
97 for(unsigned int i=0; i<numChildren; ++i)
99 count += DescendentCount(root.GetChildAt(i));
105 bool HasAncestor(Actor child, Actor ancestor)
107 while(child && child != ancestor)
109 child = child.GetParent();
112 return (child == ancestor);
118 // Called only once before first test is run.
119 static void Startup()
123 // Called only once after last test is run
124 static void Cleanup()
128 static void UtcDaliPopupNew()
130 ToolkitTestApplication application;
131 tet_infoline(" UtcDaliPopupNew");
133 // Create the Popup actor
136 DALI_TEST_CHECK( !popup );
138 popup = Popup::New();
140 DALI_TEST_CHECK( popup );
144 DALI_TEST_CHECK( popup2 == popup );
146 //Additional check to ensure object is created by checking if it's registered
147 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
148 DALI_TEST_CHECK( registry );
150 gObjectCreatedCallBackCalled = false;
151 registry.ObjectCreatedSignal().Connect( &TestCallback );
153 Popup popup = Popup::New();
155 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
158 static void UtcDaliPopupDestructor()
160 ToolkitTestApplication application;
162 Popup* popup = new Popup();
165 DALI_TEST_CHECK( true );
168 static void UtcDaliPopupDownCast()
170 ToolkitTestApplication application;
172 Handle handle = Popup::New();
174 Popup popup = Popup::DownCast( handle );
176 DALI_TEST_CHECK( popup == handle );
179 static void UtcDaliPopoupSetProperty()
181 tet_infoline("UtcDaliPopoupSetProperty: ");
182 ToolkitTestApplication application;
184 Popup popup = Popup::New();
187 std::string testString = "Hello World";
188 popup.SetProperty(popup.GetPropertyIndex("title"), testString);
189 DALI_TEST_EQUALS( testString, popup.GetTitle().GetText(), TEST_LOCATION );
193 static void UtcDaliPopupSetBackgroundImage()
195 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
196 tet_infoline(" UtcDaliPopupSetBackgroundImage");
198 // Create the Popup actor
199 Popup popup = Popup::New();
200 Stage::GetCurrent().Add( popup );
202 ImageActor image = CreateSolidColorActor( Color::RED );
203 DALI_TEST_CHECK( !image.GetParent() );
204 popup.SetBackgroundImage(image);
205 DALI_TEST_CHECK( image.GetParent() );
208 static void UtcDaliPopupSetTitle()
210 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
211 tet_infoline(" UtcDaliPopupSetTitle");
213 // Create the Popup actor
214 Popup popup = Popup::New();
215 Stage::GetCurrent().Add( popup );
216 // Put in show state so it's layer is connected to popup (for ancestor check).
217 popup.SetState(Popup::POPUP_SHOW, 0.0f);
219 TextView titleActor = TextView::New();
220 titleActor.SetText("title");
222 DALI_TEST_CHECK( !popup.GetTitle() );
223 popup.SetTitle(titleActor);
224 DALI_TEST_CHECK( popup.GetTitle() == titleActor );
225 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "title") );
226 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
227 DALI_TEST_CHECK( HasAncestor(titleActor, popup) );
229 TextView titleActor2 = TextView::New();
230 titleActor2.SetText("anothertitle");
231 popup.SetTitle(titleActor2);
232 DALI_TEST_CHECK( popup.GetTitle() != titleActor );
233 DALI_TEST_CHECK( popup.GetTitle() == titleActor2 );
234 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "anothertitle") );
235 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
236 DALI_TEST_CHECK( HasAncestor(titleActor2, popup) );
239 static void UtcDaliPopupSetTitleText()
241 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
242 tet_infoline(" UtcDaliPopupSetTitleText");
244 // Create the Popup actor
245 Popup popup = Popup::New();
246 Stage::GetCurrent().Add( popup );
247 // Put in show state so it's layer is connected to popup (for ancestor check).
248 popup.SetState(Popup::POPUP_SHOW, 0.0f);
250 TextView titleActor = TextView::New();
251 titleActor.SetText("title");
253 DALI_TEST_CHECK( !popup.GetTitle() );
254 popup.SetTitle(titleActor);
255 DALI_TEST_CHECK( popup.GetTitle() == titleActor );
256 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "title") );
257 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
258 DALI_TEST_CHECK( HasAncestor(titleActor, popup) );
260 // this text should replace titleImage actor.
261 popup.SetTitle("newtext");
262 DALI_TEST_CHECK( popup.GetTitle() != titleActor );
263 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "newtext") );
264 // verify titleActor is no longer inside popup. (been displaced by newtext actor)
265 DALI_TEST_CHECK( !HasAncestor(titleActor, popup) );
268 static void UtcDaliPopupAddButton()
270 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
271 tet_infoline(" UtcDaliPopupAddButton");
273 // Create the Popup actor
274 Popup popup = Popup::New();
275 Stage::GetCurrent().Add( popup );
276 // Put in show state so it's layer is connected to popup (for ancestor check).
277 popup.SetState(Popup::POPUP_SHOW, 0.0f);
279 PushButton button = PushButton::New();
280 DALI_TEST_CHECK( !HasAncestor(button, popup) );
281 popup.AddButton(button);
282 // Hide and then re-show popup to cause button to be rearranged and added to popup.
283 popup.SetState( Popup::POPUP_HIDE, 0.0f );
284 popup.SetState( Popup::POPUP_SHOW, 0.0f );
285 DALI_TEST_CHECK( HasAncestor(button, popup) );
288 static void UtcDaliPopupSetState()
290 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
291 tet_infoline(" UtcDaliPopupSetState");
293 // Create the Popup actor
294 Popup popup = Popup::New();
295 Stage::GetCurrent().Add( popup );
297 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
298 popup.SetBackgroundImage(backgroundImage);
300 // Showing/Hiding popup, results in all child Actors being
301 // connected/disconnected from the stage.
302 DALI_TEST_CHECK( !backgroundImage.OnStage() );
303 popup.SetState(Popup::POPUP_SHOW, 0.0f);
304 DALI_TEST_CHECK( backgroundImage.OnStage() );
305 DALI_TEST_EQUALS( Popup::POPUP_SHOW, popup.GetState(), TEST_LOCATION );
306 popup.SetState(Popup::POPUP_HIDE, 0.0f);
307 DALI_TEST_CHECK( !backgroundImage.OnStage() );
308 DALI_TEST_EQUALS( Popup::POPUP_HIDE, popup.GetState(), TEST_LOCATION );
311 static void UtcDaliPopupSetStateSlow()
313 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
314 tet_infoline(" UtcDaliPopupSetStateSlow");
316 // Create the Popup actor
317 Popup popup = Popup::New();
318 Stage::GetCurrent().Add( popup );
320 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
321 popup.SetBackgroundImage(backgroundImage);
323 // Showing/Hiding popup, results in all child Actors being
324 // connected/disconnected from the stage.
325 DALI_TEST_CHECK( !backgroundImage.OnStage() );
326 popup.SetState(Popup::POPUP_SHOW, 0.0f);
327 DALI_TEST_CHECK( backgroundImage.OnStage() );
330 popup.SetState(Popup::POPUP_HIDE);
332 // Wait for a while (allow animation to complete), and then check state.
333 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
335 application.SendNotification();
336 application.Render(RENDER_FRAME_INTERVAL);
339 DALI_TEST_CHECK( !backgroundImage.OnStage() );
342 static bool gHidden = false;
344 static void OnPopupHidden()
349 static void UtcDaliPopupShowHide()
351 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
352 tet_infoline(" UtcDaliPopupShowHide");
354 // Create the Popup actor
355 Popup popup = Popup::New();
356 Stage::GetCurrent().Add( popup );
357 popup.HiddenSignal().Connect( &OnPopupHidden );
359 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
360 popup.SetBackgroundImage(backgroundImage);
362 PushButton button1 = PushButton::New();
363 PushButton button2 = PushButton::New();
364 button1.SetSize(DEFAULT_BUTTON_SIZE);
365 popup.AddButton(button1);
366 button2.SetSize(DEFAULT_BUTTON_SIZE);
367 popup.AddButton(button2);
369 // Showing/Hiding popup, results in all child Actors being
370 // connected/disconnected from the stage.
371 DALI_TEST_CHECK( !backgroundImage.OnStage() );
374 // Note: in most popup animation implementations show would result in
375 // popup being onstage immediately following Show(). However we can't
376 // assume for all. e.g. If one creates a animation with a delay.
379 // Wait for a while (allow animation to complete), and then check state.
380 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
382 application.SendNotification();
383 application.Render(RENDER_FRAME_INTERVAL);
386 DALI_TEST_CHECK( backgroundImage.OnStage() );
392 // Wait for a while (allow animation to complete), and then check state.
393 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
395 application.SendNotification();
396 application.Render(RENDER_FRAME_INTERVAL);
399 DALI_TEST_CHECK( !backgroundImage.OnStage() );
400 DALI_TEST_CHECK( gHidden );
403 static void UtcDaliPopupShowHideTail()
405 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
406 tet_infoline(" UtcDaliPopupShowHideTail");
408 // Create the Popup actor
409 Popup popup = Popup::New();
410 Stage::GetCurrent().Add( popup );
411 popup.SetState(Popup::POPUP_SHOW, 0.0f);
414 int withoutTailCount = DescendentCount(popup);
416 popup.ShowTail(ParentOrigin::BOTTOM_CENTER);
417 int withTailCount = DescendentCount(popup);
419 // There should be more actors if the Tail has been added.
420 DALI_TEST_CHECK( withTailCount > withoutTailCount );
424 int withoutTailCount2 = DescendentCount(popup);
426 DALI_TEST_CHECK( withTailCount > withoutTailCount2 );
429 static bool gTouchedOutside;
431 static void OnPopupTouchedOutside()
433 gTouchedOutside = true;
436 static void UtcDaliPopupOnTouchedOutside()
438 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
439 tet_infoline(" UtcDaliPopupOnTouchedOutside");
441 // Create the Popup actor
442 Popup popup = Popup::New();
443 Stage::GetCurrent().Add( popup );
444 popup.SetParentOrigin(ParentOrigin::CENTER);
445 popup.SetAnchorPoint(ParentOrigin::CENTER);
446 popup.SetState(Popup::POPUP_SHOW, 0.0f);
447 popup.OutsideTouchedSignal().Connect( &OnPopupTouchedOutside );
449 application.SendNotification();
450 application.Render();
452 gTouchedOutside = false;
453 Dali::Integration::TouchEvent event;
455 event = Dali::Integration::TouchEvent();
456 event.AddPoint( pointDownOutside );
457 application.ProcessEvent( event );
459 application.SendNotification();
460 application.Render();
462 event = Dali::Integration::TouchEvent();
463 event.AddPoint( pointUpOutside );
464 application.ProcessEvent( event );
466 application.SendNotification();
467 application.Render();
469 DALI_TEST_CHECK(gTouchedOutside);