[dali_2.3.19] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-ToolBar.cpp
index 4b03c11..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-toolkit/devel-api/controls/tool-bar/tool-bar.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;
@@ -32,6 +35,22 @@ static void TestCallback(BaseHandle handle)
 {
   gObjectCreatedCallBackCalled = true;
 }
+
+Actor CreateColorActor(const Vector4& color)
+{
+  DummyControl      solidColorActor = DummyControl::New();
+  DummyControlImpl& dummyImpl       = static_cast<DummyControlImpl&>(solidColorActor.GetImplementation());
+
+  VisualFactory       factory = VisualFactory::Get();
+  Dali::Property::Map map;
+  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;
+}
+
 } // namespace
 
 void dali_toolbar_startup(void)
@@ -44,7 +63,6 @@ void dali_toolbar_cleanup(void)
   test_return_value = TET_PASS;
 }
 
-
 int UtcDaliToolBarNew(void)
 {
   ToolkitTestApplication application;
@@ -52,57 +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 );
-
-  DALI_TEST_CHECK( toolbar );
-  END_TEST;
-}
-
-int UtcDaliToolBarSetBackground(void)
-{
-  ToolkitTestApplication application;
-  tet_infoline(" UtcDaliToolBarSetBackground");
-
-  try
-  {
-    ImageActor toolBarBackground = CreateSolidColorActor( Color::RED );
-
-    ToolBar toolbar = ToolBar::New();
-    toolbar.SetBackground( toolBarBackground );
-
-    Stage::GetCurrent().Add( toolbar );
-  }
-  catch( ... )
-  {
-    tet_result(TET_FAIL);
-  }
-
-  tet_result(TET_PASS);
+  toolbar     = ToolBar::DownCast(actor);
 
-  application.SendNotification(); // VCC To be removed!!
-  application.Render();     // VCC To be removed!!
+  DALI_TEST_CHECK(toolbar);
   END_TEST;
 }
 
@@ -113,48 +105,48 @@ int UtcDaliToolBarAddControl01(void)
 
   try
   {
-    ImageActor control1 = CreateSolidColorActor( Color::RED );
-    control1.SetSize( 100.f, 100.f );
-    ImageActor control2 = CreateSolidColorActor( Color::RED );
-    control2.SetSize( 100.f, 100.f );
-    ImageActor control3 = CreateSolidColorActor( Color::RED );
-    control3.SetSize( 100.f, 100.f );
-    ImageActor control4 = CreateSolidColorActor( Color::RED );
-    control4.SetSize( 100.f, 100.f );
-    ImageActor control5 = CreateSolidColorActor( Color::RED );
-    control5.SetSize( 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( 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));
 
-    ImageActor control6 = CreateSolidColorActor( Color::RED );
-    control6.SetSize( 100.f, 100.f );
-    ImageActor control7 = CreateSolidColorActor( Color::RED );
-    control7.SetSize( 100.f, 100.f );
-    ImageActor control8 = CreateSolidColorActor( Color::RED );
-    control8.SetSize( 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);
   }
@@ -172,23 +164,23 @@ int UtcDaliToolBarAddControl02(void)
 
   try
   {
-    ImageActor control = CreateSolidColorActor( 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);
   }
@@ -202,14 +194,14 @@ int UtcDaliToolBarRemoveControl01(void)
 
   try
   {
-    ImageActor control = CreateSolidColorActor( 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);
   }
@@ -225,37 +217,37 @@ int UtcDaliToolBarRemoveControl02(void)
 
   try
   {
-    ImageActor control01 = CreateSolidColorActor( Color::RED );
-    ImageActor control02 = CreateSolidColorActor( 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
   {
-    ImageActor control = CreateSolidColorActor( 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);
   }