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.
20 // Need to override adaptor classes for toolkit test harness, so include
21 // test harness headers before dali headers.
22 #include <dali-toolkit-test-suite-utils.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali-toolkit/dali-toolkit.h>
29 using namespace Toolkit;
31 void utc_dali_toolkit_popup_startup(void)
33 test_return_value = TET_UNDEF;
36 void utc_dali_toolkit_popup_cleanup(void)
38 test_return_value = TET_PASS;
43 static bool gObjectCreatedCallBackCalled;
45 static void TestCallback(BaseHandle handle)
47 gObjectCreatedCallBackCalled = true;
50 const int RENDER_FRAME_INTERVAL = 10; ///< Duration of each frame in ms.
51 const int RENDER_ANIMATION_TEST_DURATION_MS = 1000; ///< 1000ms to test animation
52 const int RENDER_ANIMATION_TEST_DURATION_FRAMES = RENDER_ANIMATION_TEST_DURATION_MS / RENDER_FRAME_INTERVAL; ///< equivalent frames.
53 const Vector3 DEFAULT_BUTTON_SIZE(100.0f, 50.0f, 0.0f);
54 const Dali::TouchPoint pointDownOutside( 0, TouchPoint::Down, 10.0f, 10.0f );
55 const Dali::TouchPoint pointUpOutside( 0, TouchPoint::Up, 10.0f, 10.0f );
58 * Counts how many descendents root Actor has, including
61 * @param[in] root The root actor to count from.
62 * @return The number of descendents including root actor itself.
64 int DescendentCount(const Actor& root)
66 unsigned int numChildren = root.GetChildCount();
70 for(unsigned int i=0; i<numChildren; ++i)
72 count += DescendentCount(root.GetChildAt(i));
78 bool HasAncestor(Actor child, Actor ancestor)
80 while(child && child != ancestor)
82 child = child.GetParent();
85 return (child == ancestor);
89 static bool gHidden = false;
91 static void OnPopupHidden()
96 static bool gTouchedOutside;
98 static void OnPopupTouchedOutside()
100 gTouchedOutside = true;
106 int UtcDaliPopupNew(void)
108 ToolkitTestApplication application;
109 tet_infoline(" UtcDaliPopupNew");
111 // Create the Popup actor
114 DALI_TEST_CHECK( !popup );
116 popup = Popup::New();
118 DALI_TEST_CHECK( popup );
122 DALI_TEST_CHECK( popup2 == popup );
124 //Additional check to ensure object is created by checking if it's registered
125 ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
126 DALI_TEST_CHECK( registry );
128 gObjectCreatedCallBackCalled = false;
129 registry.ObjectCreatedSignal().Connect( &TestCallback );
131 Popup popup = Popup::New();
133 DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
137 int UtcDaliPopupDestructor(void)
139 ToolkitTestApplication application;
141 Popup* popup = new Popup();
144 DALI_TEST_CHECK( true );
148 int UtcDaliPopupDownCast(void)
150 ToolkitTestApplication application;
152 Handle handle = Popup::New();
154 Popup popup = Popup::DownCast( handle );
156 DALI_TEST_CHECK( popup == handle );
160 int UtcDaliPopoupSetProperty(void)
162 tet_infoline("UtcDaliPopoupSetProperty: ");
163 ToolkitTestApplication application;
165 Popup popup = Popup::New();
168 std::string testString = "Hello World";
169 popup.SetProperty(popup.GetPropertyIndex("title"), testString);
170 DALI_TEST_EQUALS( testString, popup.GetTitle().GetText(), TEST_LOCATION );
175 int UtcDaliPopupSetBackgroundImage(void)
177 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
178 tet_infoline(" UtcDaliPopupSetBackgroundImage");
180 // Create the Popup actor
181 Popup popup = Popup::New();
182 Stage::GetCurrent().Add( popup );
184 ImageActor image = CreateSolidColorActor( Color::RED );
185 DALI_TEST_CHECK( !image.GetParent() );
186 popup.SetBackgroundImage(image);
187 DALI_TEST_CHECK( image.GetParent() );
191 int UtcDaliPopupSetTitle(void)
193 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
194 tet_infoline(" UtcDaliPopupSetTitle");
196 // Create the Popup actor
197 Popup popup = Popup::New();
198 Stage::GetCurrent().Add( popup );
199 // Put in show state so it's layer is connected to popup (for ancestor check).
200 popup.SetState(Popup::POPUP_SHOW, 0.0f);
202 TextView titleActor = TextView::New();
203 titleActor.SetText("title");
205 DALI_TEST_CHECK( !popup.GetTitle() );
206 popup.SetTitle(titleActor);
207 DALI_TEST_CHECK( popup.GetTitle() == titleActor );
208 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "title") );
209 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
210 DALI_TEST_CHECK( HasAncestor(titleActor, popup) );
212 TextView titleActor2 = TextView::New();
213 titleActor2.SetText("anothertitle");
214 popup.SetTitle(titleActor2);
215 DALI_TEST_CHECK( popup.GetTitle() != titleActor );
216 DALI_TEST_CHECK( popup.GetTitle() == titleActor2 );
217 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "anothertitle") );
218 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
219 DALI_TEST_CHECK( HasAncestor(titleActor2, popup) );
223 int UtcDaliPopupSetTitleText(void)
225 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
226 tet_infoline(" UtcDaliPopupSetTitleText");
228 // Create the Popup actor
229 Popup popup = Popup::New();
230 Stage::GetCurrent().Add( popup );
231 // Put in show state so it's layer is connected to popup (for ancestor check).
232 popup.SetState(Popup::POPUP_SHOW, 0.0f);
234 TextView titleActor = TextView::New();
235 titleActor.SetText("title");
237 DALI_TEST_CHECK( !popup.GetTitle() );
238 popup.SetTitle(titleActor);
239 DALI_TEST_CHECK( popup.GetTitle() == titleActor );
240 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "title") );
241 // verify titleActor is actually inside popup, and not elsewhere on stage, or off even.
242 DALI_TEST_CHECK( HasAncestor(titleActor, popup) );
244 // this text should replace titleImage actor.
245 popup.SetTitle("newtext");
246 DALI_TEST_CHECK( popup.GetTitle() != titleActor );
247 DALI_TEST_CHECK( (popup.GetTitle()) && (popup.GetTitle().GetText() == "newtext") );
248 // verify titleActor is no longer inside popup. (been displaced by newtext actor)
249 DALI_TEST_CHECK( !HasAncestor(titleActor, popup) );
253 int UtcDaliPopupAddButton(void)
255 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
256 tet_infoline(" UtcDaliPopupAddButton");
258 // Create the Popup actor
259 Popup popup = Popup::New();
260 Stage::GetCurrent().Add( popup );
261 // Put in show state so it's layer is connected to popup (for ancestor check).
262 popup.SetState(Popup::POPUP_SHOW, 0.0f);
264 PushButton button = PushButton::New();
265 DALI_TEST_CHECK( !HasAncestor(button, popup) );
266 popup.AddButton(button);
267 // Hide and then re-show popup to cause button to be rearranged and added to popup.
268 popup.SetState( Popup::POPUP_HIDE, 0.0f );
269 popup.SetState( Popup::POPUP_SHOW, 0.0f );
270 DALI_TEST_CHECK( HasAncestor(button, popup) );
274 int UtcDaliPopupSetState(void)
276 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
277 tet_infoline(" UtcDaliPopupSetState");
279 // Create the Popup actor
280 Popup popup = Popup::New();
281 Stage::GetCurrent().Add( popup );
283 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
284 popup.SetBackgroundImage(backgroundImage);
286 // Showing/Hiding popup, results in all child Actors being
287 // connected/disconnected from the stage.
288 DALI_TEST_CHECK( !backgroundImage.OnStage() );
289 popup.SetState(Popup::POPUP_SHOW, 0.0f);
290 DALI_TEST_CHECK( backgroundImage.OnStage() );
291 DALI_TEST_EQUALS( Popup::POPUP_SHOW, popup.GetState(), TEST_LOCATION );
292 popup.SetState(Popup::POPUP_HIDE, 0.0f);
293 DALI_TEST_CHECK( !backgroundImage.OnStage() );
294 DALI_TEST_EQUALS( Popup::POPUP_HIDE, popup.GetState(), TEST_LOCATION );
298 int UtcDaliPopupSetStateSlow(void)
300 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
301 tet_infoline(" UtcDaliPopupSetStateSlow");
303 // Create the Popup actor
304 Popup popup = Popup::New();
305 Stage::GetCurrent().Add( popup );
307 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
308 popup.SetBackgroundImage(backgroundImage);
310 // Showing/Hiding popup, results in all child Actors being
311 // connected/disconnected from the stage.
312 DALI_TEST_CHECK( !backgroundImage.OnStage() );
313 popup.SetState(Popup::POPUP_SHOW, 0.0f);
314 DALI_TEST_CHECK( backgroundImage.OnStage() );
317 popup.SetState(Popup::POPUP_HIDE);
319 // Wait for a while (allow animation to complete), and then check state.
320 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
322 application.SendNotification();
323 application.Render(RENDER_FRAME_INTERVAL);
326 DALI_TEST_CHECK( !backgroundImage.OnStage() );
332 int UtcDaliPopupShowHide(void)
334 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
335 tet_infoline(" UtcDaliPopupShowHide");
337 // Create the Popup actor
338 Popup popup = Popup::New();
339 Stage::GetCurrent().Add( popup );
340 popup.HiddenSignal().Connect( &OnPopupHidden );
342 ImageActor backgroundImage = CreateSolidColorActor( Color::RED );
343 popup.SetBackgroundImage(backgroundImage);
345 PushButton button1 = PushButton::New();
346 PushButton button2 = PushButton::New();
347 button1.SetSize(DEFAULT_BUTTON_SIZE);
348 popup.AddButton(button1);
349 button2.SetSize(DEFAULT_BUTTON_SIZE);
350 popup.AddButton(button2);
352 // Showing/Hiding popup, results in all child Actors being
353 // connected/disconnected from the stage.
354 DALI_TEST_CHECK( !backgroundImage.OnStage() );
357 // Note: in most popup animation implementations show would result in
358 // popup being onstage immediately following Show(). However we can't
359 // assume for all. e.g. If one creates a animation with a delay.
362 // Wait for a while (allow animation to complete), and then check state.
363 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
365 application.SendNotification();
366 application.Render(RENDER_FRAME_INTERVAL);
369 DALI_TEST_CHECK( backgroundImage.OnStage() );
375 // Wait for a while (allow animation to complete), and then check state.
376 for(int i = 0; i < RENDER_ANIMATION_TEST_DURATION_FRAMES; i++)
378 application.SendNotification();
379 application.Render(RENDER_FRAME_INTERVAL);
382 DALI_TEST_CHECK( !backgroundImage.OnStage() );
383 DALI_TEST_CHECK( gHidden );
387 int UtcDaliPopupShowHideTail(void)
389 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
390 tet_infoline(" UtcDaliPopupShowHideTail");
392 // Create the Popup actor
393 Popup popup = Popup::New();
394 Stage::GetCurrent().Add( popup );
395 popup.SetState(Popup::POPUP_SHOW, 0.0f);
398 int withoutTailCount = DescendentCount(popup);
400 popup.ShowTail(ParentOrigin::BOTTOM_CENTER);
401 int withTailCount = DescendentCount(popup);
403 // There should be more actors if the Tail has been added.
404 DALI_TEST_CHECK( withTailCount > withoutTailCount );
408 int withoutTailCount2 = DescendentCount(popup);
410 DALI_TEST_CHECK( withTailCount > withoutTailCount2 );
414 int UtcDaliPopupOnTouchedOutside(void)
416 ToolkitTestApplication application; // Exceptions require ToolkitTestApplication
417 tet_infoline(" UtcDaliPopupOnTouchedOutside");
419 // Create the Popup actor
420 Popup popup = Popup::New();
421 Stage::GetCurrent().Add( popup );
422 popup.SetParentOrigin(ParentOrigin::CENTER);
423 popup.SetAnchorPoint(ParentOrigin::CENTER);
424 popup.SetState(Popup::POPUP_SHOW, 0.0f);
425 popup.OutsideTouchedSignal().Connect( &OnPopupTouchedOutside );
427 application.SendNotification();
428 application.Render();
430 gTouchedOutside = false;
431 Dali::Integration::TouchEvent event;
433 event = Dali::Integration::TouchEvent();
434 event.AddPoint( pointDownOutside );
435 application.ProcessEvent( event );
437 application.SendNotification();
438 application.Render();
440 event = Dali::Integration::TouchEvent();
441 event.AddPoint( pointUpOutside );
442 application.ProcessEvent( event );
444 application.SendNotification();
445 application.Render();
447 DALI_TEST_CHECK(gTouchedOutside);