[dali_2.3.19] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ToolBar.cpp
index 029654d..85f1ceb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  */
 
-#include <iostream>
-#include <stdlib.h>
 #include <dali-toolkit-test-suite-utils.h>
 #include <dali-toolkit/dali-toolkit.h>
-#include <dali/integration-api/events/touch-event-integ.h>
 #include <dali-toolkit/devel-api/controls/tool-bar/tool-bar.h>
-#include <dali-toolkit/devel-api/controls/visual-factory/visual-factory.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali/integration-api/events/touch-event-integ.h>
+#include <stdlib.h>
+#include <iostream>
+#include "dummy-control.h"
 
 using namespace Dali;
 using namespace Toolkit;
@@ -35,16 +36,17 @@ static void TestCallback(BaseHandle handle)
   gObjectCreatedCallBackCalled = true;
 }
 
-Actor CreateColorActor( const Vector4& color )
+Actor CreateColorActor(const Vector4& color)
 {
-  Actor solidColorActor = Actor::New();
+  DummyControl      solidColorActor = DummyControl::New();
+  DummyControlImpl& dummyImpl       = static_cast<DummyControlImpl&>(solidColorActor.GetImplementation());
 
-  VisualFactory factory = VisualFactory::Get();
+  VisualFactory       factory = VisualFactory::Get();
   Dali::Property::Map map;
-  map[ "rendererType" ] = "COLOR";
-  map[ "mixColor" ] = color;
-  Visual colorRenderer = factory.CreateVisual( map );
-  colorRenderer.SetOnStage( solidColorActor );
+  map[Toolkit::Visual::Property::TYPE]  = Visual::COLOR;
+  map[ColorVisual::Property::MIX_COLOR] = color;
+  Visual::Base colorVisual              = factory.CreateVisual(map);
+  dummyImpl.RegisterVisual(Control::CONTROL_PROPERTY_END_INDEX + 1, colorVisual);
 
   return solidColorActor;
 }
@@ -61,7 +63,6 @@ void dali_toolbar_cleanup(void)
   test_return_value = TET_PASS;
 }
 
-
 int UtcDaliToolBarNew(void)
 {
   ToolkitTestApplication application;
@@ -69,31 +70,31 @@ int UtcDaliToolBarNew(void)
 
   ToolBar toolbar;
 
-  DALI_TEST_CHECK( !toolbar );
+  DALI_TEST_CHECK(!toolbar);
 
   toolbar = ToolBar::New();
 
-  DALI_TEST_CHECK( toolbar );
+  DALI_TEST_CHECK(toolbar);
 
   ToolBar toolbar2(toolbar);
 
-  DALI_TEST_CHECK( toolbar2 == toolbar );
+  DALI_TEST_CHECK(toolbar2 == toolbar);
 
   //Additional check to ensure object is created by checking if it's registered
-  ObjectRegistry registry = Stage::GetCurrent().GetObjectRegistry();
-  DALI_TEST_CHECK( registry );
+  ObjectRegistry registry = application.GetCore().GetObjectRegistry();
+  DALI_TEST_CHECK(registry);
 
   gObjectCreatedCallBackCalled = false;
   registry.ObjectCreatedSignal().Connect(&TestCallback);
   {
     ToolBar toolbar = ToolBar::New();
   }
-  DALI_TEST_CHECK( gObjectCreatedCallBackCalled );
+  DALI_TEST_CHECK(gObjectCreatedCallBackCalled);
 
   Actor actor = toolbar;
-  toolbar == ToolBar::DownCast( actor );
+  toolbar     = ToolBar::DownCast(actor);
 
-  DALI_TEST_CHECK( toolbar );
+  DALI_TEST_CHECK(toolbar);
   END_TEST;
 }
 
@@ -104,48 +105,48 @@ int UtcDaliToolBarAddControl01(void)
 
   try
   {
-    Actor control1 = CreateColorActor( Color::RED );
-    control1.SetSize( Vector2( 100.f, 100.f ) );
-    Actor control2 = CreateColorActor( Color::RED );
-    control2.SetSize( Vector2( 100.f, 100.f ) );
-    Actor control3 = CreateColorActor( Color::RED );
-    control3.SetSize( Vector2( 100.f, 100.f ) );
-    Actor control4 = CreateColorActor( Color::RED );
-    control4.SetSize( Vector2( 100.f, 100.f ) );
-    Actor control5 = CreateColorActor( Color::RED );
-    control5.SetSize( Vector2( 100.f, 100.f ) );
+    Actor control1 = CreateColorActor(Color::RED);
+    control1.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
+    Actor control2 = CreateColorActor(Color::RED);
+    control2.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
+    Actor control3 = CreateColorActor(Color::RED);
+    control3.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
+    Actor control4 = CreateColorActor(Color::RED);
+    control4.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
+    Actor control5 = CreateColorActor(Color::RED);
+    control5.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
 
     ToolBar toolbar = ToolBar::New();
-    toolbar.SetSize( Vector2( 600.f, 100.f ) );
+    toolbar.SetProperty(Actor::Property::SIZE, Vector2(600.f, 100.f));
 
     application.Render();
     application.SendNotification();
     application.Render();
     application.SendNotification();
 
-    toolbar.Add( control1 );
-    toolbar.AddControl( control2, 0.1f, Alignment::HorizontalLeft, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
-    toolbar.AddControl( control3, 0.1f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
-    toolbar.AddControl( control4, 0.1f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
-    toolbar.AddControl( control5, 0.1f, Alignment::HorizontalRight, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
+    toolbar.Add(control1);
+    toolbar.AddControl(control2, 0.1f, Alignment::HORIZONTAL_LEFT, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
+    toolbar.AddControl(control3, 0.1f, Alignment::HORIZONTAL_CENTER, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
+    toolbar.AddControl(control4, 0.1f, Alignment::HORIZONTAL_CENTER, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
+    toolbar.AddControl(control5, 0.1f, Alignment::HORIZONTAL_RIGHT, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
 
-    Actor control6 = CreateColorActor( Color::RED );
-    control6.SetSize( Vector2( 100.f, 100.f ) );
-    Actor control7 = CreateColorActor( Color::RED );
-    control7.SetSize( Vector2( 100.f, 100.f ) );
-    Actor control8 = CreateColorActor( Color::RED );
-    control8.SetSize( Vector2( 100.f, 100.f ) );
+    Actor control6 = CreateColorActor(Color::RED);
+    control6.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
+    Actor control7 = CreateColorActor(Color::RED);
+    control7.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
+    Actor control8 = CreateColorActor(Color::RED);
+    control8.SetProperty(Actor::Property::SIZE, Vector2(100.f, 100.f));
 
     application.Render();
     application.SendNotification();
     application.Render();
     application.SendNotification();
 
-    toolbar.AddControl( control6, 0.4f, Alignment::HorizontalLeft, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
-    toolbar.AddControl( control7, 0.2f, Alignment::HorizontalCenter, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
-    toolbar.AddControl( control8, 0.2f, Alignment::HorizontalRight, Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
+    toolbar.AddControl(control6, 0.4f, Alignment::HORIZONTAL_LEFT, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
+    toolbar.AddControl(control7, 0.2f, Alignment::HORIZONTAL_CENTER, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
+    toolbar.AddControl(control8, 0.2f, Alignment::HORIZONTAL_RIGHT, Alignment::Padding(1.f, 1.f, 1.f, 1.f));
   }
-  catch( ... )
+  catch(...)
   {
     tet_result(TET_FAIL);
   }
@@ -163,23 +164,23 @@ int UtcDaliToolBarAddControl02(void)
 
   try
   {
-    Actor control = CreateColorActor( Color::RED );
+    Actor control = CreateColorActor(Color::RED);
 
     ToolBar toolbar = ToolBar::New();
 
-    toolbar.AddControl( control, 0.1f, static_cast<Alignment::Type>( 99 ), Alignment::Padding( 1.f, 1.f, 1.f, 1.f ) );
+    toolbar.AddControl(control, 0.1f, static_cast<Alignment::Type>(99), Alignment::Padding(1.f, 1.f, 1.f, 1.f));
   }
-  catch( DaliException e )
+  catch(DaliException e)
   {
     daliAssert = true;
     tet_result(TET_PASS);
   }
-  catch( ... )
+  catch(...)
   {
     tet_result(TET_FAIL);
   }
 
-  if( !daliAssert )
+  if(!daliAssert)
   {
     tet_result(TET_FAIL);
   }
@@ -193,14 +194,14 @@ int UtcDaliToolBarRemoveControl01(void)
 
   try
   {
-    Actor control = CreateColorActor( Color::RED );
+    Actor control = CreateColorActor(Color::RED);
 
     ToolBar toolbar = ToolBar::New();
-    toolbar.AddControl( control, 0.1f, Alignment::HorizontalLeft );
+    toolbar.AddControl(control, 0.1f, Alignment::HORIZONTAL_LEFT);
 
-    toolbar.RemoveControl( control );
+    toolbar.RemoveControl(control);
   }
-  catch( ... )
+  catch(...)
   {
     tet_result(TET_FAIL);
   }
@@ -216,37 +217,37 @@ int UtcDaliToolBarRemoveControl02(void)
 
   try
   {
-    Actor control01 = CreateColorActor( Color::RED );
-    Actor control02 = CreateColorActor( Color::RED );
+    Actor control01 = CreateColorActor(Color::RED);
+    Actor control02 = CreateColorActor(Color::RED);
 
     ToolBar toolbar01 = ToolBar::New();
     ToolBar toolbar02 = ToolBar::New();
-    toolbar01.AddControl( control01, 0.1f, Alignment::HorizontalLeft );
-    toolbar02.AddControl( control02, 0.1f, Alignment::HorizontalLeft );
+    toolbar01.AddControl(control01, 0.1f, Alignment::HORIZONTAL_LEFT);
+    toolbar02.AddControl(control02, 0.1f, Alignment::HORIZONTAL_LEFT);
 
-    toolbar02.RemoveControl( control01 );
+    toolbar02.RemoveControl(control01);
   }
-  catch( Dali::DaliException& e )
+  catch(Dali::DaliException& e)
   {
-    DALI_TEST_PRINT_ASSERT( e );
+    DALI_TEST_PRINT_ASSERT(e);
     DALI_TEST_EQUALS(e.condition, "false", TEST_LOCATION);
   }
-  catch( ... )
+  catch(...)
   {
     tet_result(TET_FAIL);
   }
 
   try
   {
-    Actor control = CreateColorActor( Color::RED );
+    Actor control = CreateColorActor(Color::RED);
 
     ToolBar toolbar = ToolBar::New();
-    toolbar.AddControl( control, 0.1f, Alignment::HorizontalLeft );
+    toolbar.AddControl(control, 0.1f, Alignment::HORIZONTAL_LEFT);
 
-    toolbar.RemoveControl( control );
-    toolbar.RemoveControl( control );
+    toolbar.RemoveControl(control);
+    toolbar.RemoveControl(control);
   }
-  catch( ... )
+  catch(...)
   {
     tet_result(TET_FAIL);
   }