Adding debug methods for Control internals
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-Control-internal.cpp
1 /*
2  * Copyright (c) 2018 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/internal/controls/control/control-debug.h>
29
30
31 using namespace Dali;
32 using namespace Toolkit;
33
34
35 int UtcDaliControlActionOnVisual(void)
36 {
37   ToolkitTestApplication application;
38
39   tet_infoline( "Register an ImageVisual and perform image reload Action on it. Tests Actions are completed." );
40   Vector2 controlSize( 20.f, 30.f );
41
42   //Created DummyVisual
43   Property::Map settings;
44   Toolkit::Internal::DummyVisualPtr dummyVisualPtr = Toolkit::Internal::DummyVisual::New( settings );
45
46   DummyControl dummyControl = DummyControl::New( true );
47   Impl::DummyControl& dummyImpl = static_cast<Impl::DummyControl&>(dummyControl.GetImplementation());
48
49   tet_infoline( "Register test visual and stage control" );
50
51   Toolkit::Visual::Base visualBaseHandle = Toolkit::Visual::Base( dummyVisualPtr.Get() );
52   dummyImpl.RegisterVisual( DummyControl::Property::TEST_VISUAL, visualBaseHandle );
53   dummyControl.SetSize(200.f, 200.f);
54   Stage::GetCurrent().Add( dummyControl );
55
56   application.SendNotification();
57   application.Render();
58
59   tet_infoline( "Check action counter is 0 before DoAction" );
60   DALI_TEST_EQUALS( dummyVisualPtr->GetActionCounter() , 0, TEST_LOCATION );
61
62   tet_infoline( "Perform TEST_ACTION action on registered test visual. Should increase the action counter" );
63
64   Property::Map attributes;
65   DevelControl::DoAction( dummyControl, DummyControl::Property::TEST_VISUAL, Dali::Toolkit::Internal::DummyVisual::TEST_ACTION, attributes );
66
67   application.SendNotification();
68   DALI_TEST_EQUALS( dummyVisualPtr->GetActionCounter() , 1, TEST_LOCATION );
69
70   END_TEST;
71 }
72
73 int UtcDaliControlDebugHierarchy(void)
74 {
75   ToolkitTestApplication application;
76   tet_infoline( "Create a control hierarchy, and test that the debug produces output" );
77
78   auto tableView = Toolkit::TableView::New(1, 2);
79   tableView.AddChild( ImageView::New( TEST_RESOURCE_DIR "/gallery-small-1.jpg" ), TableView::CellPosition( 1, 1 ) );
80   tableView.AddChild( TextLabel::New("Stuff"), TableView::CellPosition( 1, 2 ) );
81
82   Stage::GetCurrent().Add( tableView );
83
84   Property::Value v(Matrix3::IDENTITY);
85   tableView.RegisterProperty( "SomeMatrix3", v);
86
87   std::ostringstream oss;
88   Dali::Toolkit::Internal::DumpControlHierarchy( oss, Stage::GetCurrent().GetRootLayer() );
89   DALI_TEST_CHECK( oss.str().length() != 0 );
90   tet_printf("Control hierarchy: \n%s\n", oss.str().c_str() );
91
92   END_TEST;
93 }