From cd3e90cd37df3300dfeab98e2c1e7d8b425f8dc5 Mon Sep 17 00:00:00 2001 From: Agnelo Vaz Date: Wed, 10 Oct 2018 11:02:46 +0100 Subject: [PATCH] Layouting nesting tests Change-Id: I4596fd700f38d64bdcc3b3c02d74a2b7c5d631fd --- automated-tests/src/dali-toolkit/CMakeLists.txt | 1 + .../src/dali-toolkit/utc-Dali-LayoutingNesting.cpp | 203 +++++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 automated-tests/src/dali-toolkit/utc-Dali-LayoutingNesting.cpp diff --git a/automated-tests/src/dali-toolkit/CMakeLists.txt b/automated-tests/src/dali-toolkit/CMakeLists.txt index ac4c3d5..7ad18b7 100755 --- a/automated-tests/src/dali-toolkit/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit/CMakeLists.txt @@ -27,6 +27,7 @@ SET(TC_SOURCES utc-Dali-KeyInputFocusManager.cpp utc-Dali-Layouting.cpp utc-Dali-LayoutingResizePolicy.cpp + utc-Dali-LayoutingNesting.cpp utc-Dali-PageTurnView.cpp utc-Dali-Scene3dView.cpp utc-Dali-Script.cpp diff --git a/automated-tests/src/dali-toolkit/utc-Dali-LayoutingNesting.cpp b/automated-tests/src/dali-toolkit/utc-Dali-LayoutingNesting.cpp new file mode 100644 index 0000000..155b54a --- /dev/null +++ b/automated-tests/src/dali-toolkit/utc-Dali-LayoutingNesting.cpp @@ -0,0 +1,203 @@ +/* + * Copyright (c) 2018 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include <../custom-layout.h> + +#include + +using namespace Dali; +using namespace Toolkit; + +namespace +{ + +// Turns the given control into a Root layout control and adds it to the stage. +void SetupRootLayoutControl( Control& rootControl ) +{ + rootControl = Control::New(); + auto absoluteLayout = AbsoluteLayout::New(); + DevelControl::SetLayout( rootControl, absoluteLayout ); + rootControl.SetName( "RootAbsoluteLayout" ); + Stage stage = Stage::GetCurrent(); + stage.Add( rootControl ); +} + +} // unnamed namespace + +void utc_dali_toolkit_layouting_nesting_startup(void) +{ + test_return_value = TET_UNDEF; +} + +void utc_dali_toolkit_layouting_nesting_cleanup(void) +{ + test_return_value = TET_PASS; +} + +// Test nesting of Layouts and Controls + +int UtcDaliLayoutingNesting_01(void) +{ + /* + + Root + | + Control (LinearLayout Horizontal) + | + Control (LayoutingRequired) + | + Control (LinearLayout Horizontal) + | + LeafControl + + */ + + ToolkitTestApplication application; + tet_infoline("UtcDaliLayoutingNesting_01 - Nesting a LinearLayout (MATCH_PARENT) containing a leaf control within a LinearLayout"); + + Stage stage = Stage::GetCurrent(); + + auto rootControl = Control::New(); + SetupRootLayoutControl( rootControl ); + + auto hbox = Control::New(); + auto hboxLayout = LinearLayout::New(); + hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL ); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "hBox" ); + hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 480 ); + hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 800 ); + + + auto vbox = Control::New(); + auto vboxLayout = LinearLayout::New(); + vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL ); + DevelControl::SetLayout( vbox, vboxLayout ); + vbox.SetName( "vBox" ); + vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + hbox.Add( vbox ); + + std::vector< Control > controls; + controls.push_back( CreateLeafControl( 40, 40 ) ); + + for( auto&& iter : controls ) + { + hbox.Add( iter ); + } + + rootControl.Add( hbox ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( hbox.GetProperty( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( vbox.GetProperty( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliLayoutingNesting_02(void) +{ + /* + + Root + | + Control (LinearLayout Horizontal) + | + Control (LayoutingRequired) + | + Control (LinearLayout Horizontal) + | | + LeafControl + + */ + + ToolkitTestApplication application; + tet_infoline("UtcDaliLayoutingNesting_02 - Nesting a LinearLayout (MATCH_PARENT) containing a leaf control within a LinearLayout"); + tet_infoline("Then change the parent's size and test child responded correctly"); + + Stage stage = Stage::GetCurrent(); + + auto rootControl = Control::New(); + SetupRootLayoutControl( rootControl ); + + auto hbox = Control::New(); + auto hboxLayout = LinearLayout::New(); + hboxLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL ); + DevelControl::SetLayout( hbox, hboxLayout ); + hbox.SetName( "hBox" ); + hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 480 ); + hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 800 ); + + + auto vbox = Control::New(); + auto vboxLayout = LinearLayout::New(); + vboxLayout.SetOrientation( LinearLayout::Orientation::VERTICAL ); + DevelControl::SetLayout( vbox, vboxLayout ); + vbox.SetName( "vBox" ); + vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + vbox.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT ); + hbox.Add( vbox ); + + std::vector< Control > controls; + controls.push_back( CreateLeafControl( 40, 40 ) ); + + for( auto&& iter : controls ) + { + hbox.Add( iter ); + } + + rootControl.Add( hbox ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( hbox.GetProperty( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( vbox.GetProperty( Actor::Property::SIZE ), Vector3( 480.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + hbox.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 400 ); + + // Ensure layouting happens + application.SendNotification(); + application.Render(); + + + DALI_TEST_EQUALS( hbox.GetProperty( Actor::Property::SIZE ), Vector3( 400.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( vbox.GetProperty( Actor::Property::SIZE ), Vector3( 400.0f, 800.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + DALI_TEST_EQUALS( controls[0].GetProperty( Actor::Property::SIZE ), Vector3( 40.0f, 40.0f, 0.0f ), 0.0001f, TEST_LOCATION ); + + END_TEST; +} \ No newline at end of file -- 2.7.4