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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali-toolkit-test-suite-utils.h>
30 using namespace Toolkit;
32 static void Startup();
33 static void Cleanup();
37 static bool gObjectCreatedCallBackCalled;
39 static void TestCallback(BaseHandle handle)
41 gObjectCreatedCallBackCalled = true;
46 void (*tet_startup)() = Startup;
47 void (*tet_cleanup)() = Cleanup;
51 POSITIVE_TC_IDX = 0x01,
55 #define MAX_NUMBER_OF_TESTS 10000
57 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
60 // Add test functionality for all APIs in the class (Positive and Negative)
61 TEST_FUNCTION( UtcDaliPopupNew, POSITIVE_TC_IDX );
62 TEST_FUNCTION( UtcDaliPopupDestructor, POSITIVE_TC_IDX );
63 TEST_FUNCTION( UtcDaliPopupDownCast, POSITIVE_TC_IDX );
64 TEST_FUNCTION( UtcDaliPopoupSetProperty, POSITIVE_TC_IDX );
65 TEST_FUNCTION( UtcDaliPopupSetBackgroundImage, POSITIVE_TC_IDX );
66 TEST_FUNCTION( UtcDaliPopupSetTitle, POSITIVE_TC_IDX );
67 TEST_FUNCTION( UtcDaliPopupSetTitleText, POSITIVE_TC_IDX );
68 TEST_FUNCTION( UtcDaliPopupAddButton, POSITIVE_TC_IDX );
69 TEST_FUNCTION( UtcDaliPopupSetState, POSITIVE_TC_IDX );
70 TEST_FUNCTION( UtcDaliPopupSetStateSlow, POSITIVE_TC_IDX );
71 TEST_FUNCTION( UtcDaliPopupShowHide, POSITIVE_TC_IDX );
72 TEST_FUNCTION( UtcDaliPopupShowHideTail, POSITIVE_TC_IDX );
73 TEST_FUNCTION( UtcDaliPopupOnTouchedOutside, POSITIVE_TC_IDX );
78 const int RENDER_FRAME_INTERVAL = 10; ///< Duration of each frame in ms.
79 const int RENDER_ANIMATION_TEST_DURATION_MS = 1000; ///< 1000ms to test animation
80 const int RENDER_ANIMATION_TEST_DURATION_FRAMES = RENDER_ANIMATION_TEST_DURATION_MS / RENDER_FRAME_INTERVAL; ///< equivalent frames.
81 const Vector3 DEFAULT_BUTTON_SIZE(100.0f, 50.0f, 0.0f);
82 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10.0f, 10.0f );
83 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10.0f, 10.0f );
86 * Counts how many descendents root Actor has, including
89 * @param[in] root The root actor to count from.
90 * @return The number of descendents including root actor itself.
92 int DescendentCount(const Actor& root)
94 unsigned int numChildren = root.GetChildCount();
98 for(unsigned int i=0; i<numChildren; ++i)
100 count += DescendentCount(root.GetChildAt(i));
106 bool HasAncestor(Actor child, Actor ancestor)
108 while(child && child != ancestor)
110 child = child.GetParent();
113 return (child == ancestor);
119 // Called only once before first test is run.
120 static void Startup()
124 // Called only once after last test is run
125 static void Cleanup()
129 static void UtcDaliPopupNew()
131 ToolkitTestApplication application;
132 tet_infoline(" UtcDaliPopupNew");
134 // Create the Popup actor
137 DALI_TEST_CHECK( !popup );
139 popup = Popup::New();
141 DALI_TEST_CHECK( popup );
145 DALI_TEST_CHECK( popup2 == popup );
147 //Additional check to ensure object is created by checking if it's registered
148 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
149 DALI_TEST_CHECK( registry );
151 gObjectCreatedCallBackCalled = false;
152 registry.ObjectCreatedSignal().Connect( &TestCallback );
154 Popup popup = Popup::New();
156 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
159 static void UtcDaliPopupDestructor()
161 ToolkitTestApplication application;
163 Popup* popup = new Popup();
166 DALI_TEST_CHECK( true );
169 static void UtcDaliPopupDownCast()
171 ToolkitTestApplication application;
173 Handle handle = Popup::New();
175 Popup popup = Popup::DownCast( handle );
177 DALI_TEST_CHECK( popup == handle );
180 static void UtcDaliPopoupSetProperty()
182 tet_infoline("UtcDaliPopoupSetProperty: ");
183 ToolkitTestApplication application;
185 Popup popup = Popup::New();
188 std::string testString = "Hello World";
189 popup.SetProperty(popup.GetPropertyIndex("title"), testString);
190 DALI_TEST_EQUALS( testString, popup.GetTitle().GetText(), TEST_LOCATION );
194 static void UtcDaliPopupSetBackgroundImage()
196 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
197 tet_infoline(" UtcDaliPopupSetBackgroundImage");
199 // Create the Popup actor
200 Popup popup = Popup::New();
201 Stage::GetCurrent().Add( popup );
203 ImageActor image = CreateSolidColorActor( Color::RED );
204 DALI_TEST_CHECK( !image.GetParent() );
205 popup.SetBackgroundImage(image);
206 DALI_TEST_CHECK( image.GetParent() );
209 static void UtcDaliPopupSetTitle()
211 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
212 tet_infoline(" UtcDaliPopupSetTitle");
214 // Create the Popup actor
215 Popup popup = Popup::New();
216 Stage::GetCurrent().Add( popup );
217 // Put in show state so it's layer is connected to popup (for ancestor check).
218 popup.SetState(Popup::POPUP_SHOW, 0.0f);
220 TextView titleActor = TextView::New();
221 titleActor.SetText("title");
223 DALI_TEST_CHECK( !popup.GetTitle() );
224 popup.SetTitle(titleActor);
225 DALI_TEST_CHECK( popup.GetTitle() == titleActor );
226 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "title") );
227 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
228 DALI_TEST_CHECK( HasAncestor(titleActor, popup) );
230 TextView titleActor2 = TextView::New();
231 titleActor2.SetText("anothertitle");
232 popup.SetTitle(titleActor2);
233 DALI_TEST_CHECK( popup.GetTitle() != titleActor );
234 DALI_TEST_CHECK( popup.GetTitle() == titleActor2 );
235 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "anothertitle") );
236 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
237 DALI_TEST_CHECK( HasAncestor(titleActor2, popup) );
240 static void UtcDaliPopupSetTitleText()
242 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
243 tet_infoline(" UtcDaliPopupSetTitleText");
245 // Create the Popup actor
246 Popup popup = Popup::New();
247 Stage::GetCurrent().Add( popup );
248 // Put in show state so it's layer is connected to popup (for ancestor check).
249 popup.SetState(Popup::POPUP_SHOW, 0.0f);
251 TextView titleActor = TextView::New();
252 titleActor.SetText("title");
254 DALI_TEST_CHECK( !popup.GetTitle() );
255 popup.SetTitle(titleActor);
256 DALI_TEST_CHECK( popup.GetTitle() == titleActor );
257 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "title") );
258 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
259 DALI_TEST_CHECK( HasAncestor(titleActor, popup) );
261 // this text should replace titleImage actor.
262 popup.SetTitle("newtext");
263 DALI_TEST_CHECK( popup.GetTitle() != titleActor );
264 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "newtext") );
265 // verify titleActor is no longer inside popup. (been displaced by newtext actor)
266 DALI_TEST_CHECK( !HasAncestor(titleActor, popup) );
269 static void UtcDaliPopupAddButton()
271 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
272 tet_infoline(" UtcDaliPopupAddButton");
274 // Create the Popup actor
275 Popup popup = Popup::New();
276 Stage::GetCurrent().Add( popup );
277 // Put in show state so it's layer is connected to popup (for ancestor check).
278 popup.SetState(Popup::POPUP_SHOW, 0.0f);
280 PushButton button = PushButton::New();
281 DALI_TEST_CHECK( !HasAncestor(button, popup) );
282 popup.AddButton(button);
283 // Hide and then re-show popup to cause button to be rearranged and added to popup.
284 popup.SetState( Popup::POPUP_HIDE, 0.0f );
285 popup.SetState( Popup::POPUP_SHOW, 0.0f );
286 DALI_TEST_CHECK( HasAncestor(button, popup) );
289 static void UtcDaliPopupSetState()
291 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
292 tet_infoline(" UtcDaliPopupSetState");
294 // Create the Popup actor
295 Popup popup = Popup::New();
296 Stage::GetCurrent().Add( popup );
298 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
299 popup.SetBackgroundImage(backgroundImage);
301 // Showing/Hiding popup, results in all child Actors being
302 // connected/disconnected from the stage.
303 DALI_TEST_CHECK( !backgroundImage.OnStage() );
304 popup.SetState(Popup::POPUP_SHOW, 0.0f);
305 DALI_TEST_CHECK( backgroundImage.OnStage() );
306 DALI_TEST_EQUALS( Popup::POPUP_SHOW, popup.GetState(), TEST_LOCATION );
307 popup.SetState(Popup::POPUP_HIDE, 0.0f);
308 DALI_TEST_CHECK( !backgroundImage.OnStage() );
309 DALI_TEST_EQUALS( Popup::POPUP_HIDE, popup.GetState(), TEST_LOCATION );
312 static void UtcDaliPopupSetStateSlow()
314 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
315 tet_infoline(" UtcDaliPopupSetStateSlow");
317 // Create the Popup actor
318 Popup popup = Popup::New();
319 Stage::GetCurrent().Add( popup );
321 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
322 popup.SetBackgroundImage(backgroundImage);
324 // Showing/Hiding popup, results in all child Actors being
325 // connected/disconnected from the stage.
326 DALI_TEST_CHECK( !backgroundImage.OnStage() );
327 popup.SetState(Popup::POPUP_SHOW, 0.0f);
328 DALI_TEST_CHECK( backgroundImage.OnStage() );
331 popup.SetState(Popup::POPUP_HIDE);
333 // Wait for a while (allow animation to complete), and then check state.
334 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
336 application.SendNotification();
337 application.Render(RENDER_FRAME_INTERVAL);
340 DALI_TEST_CHECK( !backgroundImage.OnStage() );
343 static bool gHidden = false;
345 static void OnPopupHidden()
350 static void UtcDaliPopupShowHide()
352 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
353 tet_infoline(" UtcDaliPopupShowHide");
355 // Create the Popup actor
356 Popup popup = Popup::New();
357 Stage::GetCurrent().Add( popup );
358 popup.HiddenSignal().Connect( &OnPopupHidden );
360 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
361 popup.SetBackgroundImage(backgroundImage);
363 PushButton button1 = PushButton::New();
364 PushButton button2 = PushButton::New();
365 button1.SetSize(DEFAULT_BUTTON_SIZE);
366 popup.AddButton(button1);
367 button2.SetSize(DEFAULT_BUTTON_SIZE);
368 popup.AddButton(button2);
370 // Showing/Hiding popup, results in all child Actors being
371 // connected/disconnected from the stage.
372 DALI_TEST_CHECK( !backgroundImage.OnStage() );
375 // Note: in most popup animation implementations show would result in
376 // popup being onstage immediately following Show(). However we can't
377 // assume for all. e.g. If one creates a animation with a delay.
380 // Wait for a while (allow animation to complete), and then check state.
381 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
383 application.SendNotification();
384 application.Render(RENDER_FRAME_INTERVAL);
387 DALI_TEST_CHECK( backgroundImage.OnStage() );
393 // Wait for a while (allow animation to complete), and then check state.
394 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
396 application.SendNotification();
397 application.Render(RENDER_FRAME_INTERVAL);
400 DALI_TEST_CHECK( !backgroundImage.OnStage() );
401 DALI_TEST_CHECK( gHidden );
404 static void UtcDaliPopupShowHideTail()
406 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
407 tet_infoline(" UtcDaliPopupShowHideTail");
409 // Create the Popup actor
410 Popup popup = Popup::New();
411 Stage::GetCurrent().Add( popup );
412 popup.SetState(Popup::POPUP_SHOW, 0.0f);
415 int withoutTailCount = DescendentCount(popup);
417 popup.ShowTail(ParentOrigin::BOTTOM_CENTER);
418 int withTailCount = DescendentCount(popup);
420 // There should be more actors if the Tail has been added.
421 DALI_TEST_CHECK( withTailCount > withoutTailCount );
425 int withoutTailCount2 = DescendentCount(popup);
427 DALI_TEST_CHECK( withTailCount > withoutTailCount2 );
430 static bool gTouchedOutside;
432 static void OnPopupTouchedOutside()
434 gTouchedOutside = true;
437 static void UtcDaliPopupOnTouchedOutside()
439 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
440 tet_infoline(" UtcDaliPopupOnTouchedOutside");
442 // Create the Popup actor
443 Popup popup = Popup::New();
444 Stage::GetCurrent().Add( popup );
445 popup.SetParentOrigin(ParentOrigin::CENTER);
446 popup.SetAnchorPoint(ParentOrigin::CENTER);
447 popup.SetState(Popup::POPUP_SHOW, 0.0f);
448 popup.OutsideTouchedSignal().Connect( &OnPopupTouchedOutside );
450 application.SendNotification();
451 application.Render();
453 gTouchedOutside = false;
454 Dali::Integration::TouchEvent event;
456 event = Dali::Integration::TouchEvent();
457 event.AddPoint( pointDownOutside );
458 application.ProcessEvent( event );
460 application.SendNotification();
461 application.Render();
463 event = Dali::Integration::TouchEvent();
464 event.AddPoint( pointUpOutside );
465 application.ProcessEvent( event );
467 application.SendNotification();
468 application.Render();
470 DALI_TEST_CHECK(gTouchedOutside);