(Automated Tests) Use Scene instead of Stage
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-Control-internal.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21
22 #include <dali-toolkit-test-suite-utils.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <toolkit-text-utils.h>
25 #include <dummy-visual.h>
26 #include <../dali-toolkit/dali-toolkit-test-utils/dummy-control.h>
27 #include <dali-toolkit/devel-api/controls/control-devel.h>
28 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
29 #include <dali-toolkit/internal/controls/control/control-debug.h>
30
31
32 using namespace Dali;
33 using namespace Toolkit;
34
35
36 int UtcDaliControlActionOnVisual(void)
37 {
38   ToolkitTestApplication application;
39
40   tet_infoline( "Register an ImageVisual and perform image reload Action on it. Tests Actions are completed." );
41   Vector2 controlSize( 20.f, 30.f );
42
43   //Created DummyVisual
44   Property::Map settings;
45   Toolkit::Internal::DummyVisualPtr dummyVisualPtr = Toolkit::Internal::DummyVisual::New( settings );
46
47   DummyControl dummyControl = DummyControl::New( true );
48   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
49
50   tet_infoline( "Register test visual and stage control" );
51
52   Toolkit::Visual::Base visualBaseHandle = Toolkit::Visual::Base( dummyVisualPtr.Get() );
53   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visualBaseHandle );
54   dummyControl.SetProperty( Actor::Property::SIZE, Vector2(200.f, 200.f) );
55   application.GetScene().Add( dummyControl );
56
57   application.SendNotification();
58   application.Render();
59
60   tet_infoline( "Check action counter is 0 before DoAction" );
61   DALI_TEST_EQUALS( dummyVisualPtr->GetActionCounter() , 0, TEST_LOCATION );
62
63   tet_infoline( "Perform TEST_ACTION action on registered test visual. Should increase the action counter" );
64
65   Property::Map attributes;
66   DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::Internal::DummyVisual::TEST_ACTION, attributes );
67
68   application.SendNotification();
69   DALI_TEST_EQUALS( dummyVisualPtr->GetActionCounter() , 1, TEST_LOCATION );
70
71   END_TEST;
72 }
73
74 int UtcDaliControlDebugHierarchy(void)
75 {
76   ToolkitTestApplication application;
77   tet_infoline( "Create a control hierarchy, and test that the debug produces output" );
78
79   auto tableView = Toolkit::TableView::New(1, 2);
80   tableView.AddChild( ImageView::New( TEST_RESOURCE_DIR "/gallery-small-1.jpg" ), TableView::CellPosition( 1, 1 ) );
81   tableView.AddChild( TextLabel::New("Stuff"), TableView::CellPosition( 1, 2 ) );
82
83   application.GetScene().Add( tableView );
84
85   Property::Value v(Matrix3::IDENTITY);
86   tableView.RegisterProperty( "SomeMatrix3", v);
87
88   std::ostringstream oss;
89   Dali::Toolkit::Internal::DumpControlHierarchy( oss, application.GetScene().GetRootLayer() );
90   DALI_TEST_CHECK( oss.str().length() != 0 );
91   tet_printf("Control hierarchy: \n%s\n", oss.str().c_str() );
92
93   END_TEST;
94 }