Dali 3D User Interface Engine
utc-Dali-DebugRenderer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 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  */
21 
22 #include <toolkit-environment-variable.h> // for setting environment variable: DALI_DEBUG_RENDERING
23 
24 using namespace Dali;
25 using namespace Dali::Toolkit;
26 
27 namespace
28 {
29 const char* TEST_IMAGE_FILE_NAME = "image_01.jpg";
30 const char* TEST_NPATCH_FILE_NAME = "image_01.9.jpg";
31 
33 {
34  bool isDebugRendererType = false;
35  bool isGeometryLineType = false;
36 
37  Property::Map propertyMap;
38  renderer.CreatePropertyMap( propertyMap );
39  Property::Value* typeValue = propertyMap.Find( "rendererType", Property::STRING );
40  if ( typeValue )
41  {
42  isDebugRendererType = ( typeValue->Get<std::string>() == "debug" );
43  }
44 
45  Actor actor = Actor::New();
46  renderer.SetOnStage( actor );
47  Geometry geometry = actor.GetRendererAt( 0 ).GetGeometry();
48  isGeometryLineType = ( geometry.GetGeometryType() == Geometry::LINES );
49 
50  return isDebugRendererType && isGeometryLineType;
51 }
52 }
53 
55 {
57 }
58 
60 {
62 }
63 
65 {
67  ToolkitTestApplication application;
68  tet_infoline( "UtcDaliDebugRendererGetRenderer1: Request renderer with a Property::Map" );
69 
71  DALI_TEST_CHECK( factory );
72 
73  // Test that color renderer is replaced with debug renderer
74  Property::Map propertyMap1;
75  propertyMap1.Insert("rendererType", "color");
76  propertyMap1.Insert("blendColor", Color::BLUE);
77  ControlRenderer colorRenderer = factory.GetControlRenderer(propertyMap1);
78  DALI_TEST_CHECK( colorRenderer );
79  DALI_TEST_CHECK( IsDebugRenderer( colorRenderer ) );
80 
81  // Test that border renderer is replaced with debug renderer
82  Property::Map propertyMap2;
83  propertyMap2.Insert("rendererType", "border");
84  propertyMap2.Insert("borderColor", Color::BLUE);
85  propertyMap2.Insert("borderSize", 2.f);
86  ControlRenderer borderRenderer = factory.GetControlRenderer(propertyMap2);
87  DALI_TEST_CHECK( borderRenderer );
88  DALI_TEST_CHECK( IsDebugRenderer( borderRenderer ) );
89 
90  // Test that gradient renderer is replaced with debug renderer
91  Property::Map propertyMap3;
92  propertyMap3.Insert("rendererType", "gradient");
93  Vector2 start(-1.f, -1.f);
94  Vector2 end(1.f, 1.f);
95  propertyMap3.Insert("gradientStartPosition", start);
96  propertyMap3.Insert("gradientEndPosition", end);
97  propertyMap3.Insert("gradientSpreadMethod", "repeat");
98  Property::Array stopOffsets;
99  stopOffsets.PushBack( 0.2f );
100  stopOffsets.PushBack( 0.8f );
101  propertyMap3.Insert("gradientStopOffset", stopOffsets);
102  Property::Array stopColors;
103  stopColors.PushBack( Color::RED );
104  stopColors.PushBack( Color::GREEN );
105  propertyMap3.Insert("gradientStopColor", stopColors);
106  ControlRenderer gradientRenderer = factory.GetControlRenderer(propertyMap3);
107  DALI_TEST_CHECK( gradientRenderer );
108  DALI_TEST_CHECK( IsDebugRenderer( gradientRenderer ) );
109 
110  // Test that image renderer is replaced with debug renderer
111  Property::Map propertyMap4;
112  propertyMap4.Insert( "rendererType", "image" );
113  propertyMap4.Insert( "imageUrl", TEST_IMAGE_FILE_NAME );
114  ControlRenderer imageRenderer = factory.GetControlRenderer( propertyMap4 );
115  DALI_TEST_CHECK( imageRenderer );
116  DALI_TEST_CHECK( IsDebugRenderer( imageRenderer ) );
117 
118  // Test that n patch renderer is replaced with debug renderer
119  Property::Map propertyMap5;
120  propertyMap5.Insert( "rendererType", "nPatch" );
121  propertyMap5.Insert( "imageUrl", TEST_NPATCH_FILE_NAME );
122  ControlRenderer nPatchRenderer = factory.GetControlRenderer( propertyMap4 );
123  DALI_TEST_CHECK( nPatchRenderer );
124  DALI_TEST_CHECK( IsDebugRenderer( nPatchRenderer ) );
125 
127  END_TEST;
128 }
129 
131 {
133  ToolkitTestApplication application;
134  tet_infoline( "UtcDaliDebugRendererGetRenderer2: Request renderer with various parameters" );
135 
137  DALI_TEST_CHECK( factory );
138 
139  // Test that color renderer is replaced with debug renderer
140  ControlRenderer colorRenderer = factory.GetControlRenderer(Color::CYAN);
141  DALI_TEST_CHECK( colorRenderer );
142  DALI_TEST_CHECK( IsDebugRenderer( colorRenderer ) );
143 
144  // Test that border renderer is replaced with debug renderer
145  ControlRenderer borderRenderer = factory.GetControlRenderer(2.f, Color::GREEN);
146  DALI_TEST_CHECK( borderRenderer );
147  DALI_TEST_CHECK( IsDebugRenderer( borderRenderer ) );
148 
149  // Test that image renderer is replaced with debug renderer
151  ControlRenderer imageRenderer = factory.GetControlRenderer( image );
152  DALI_TEST_CHECK( imageRenderer );
153  DALI_TEST_CHECK( IsDebugRenderer( imageRenderer ) );
154 
155  // Test that n patch renderer is replaced with debug renderer
156  ControlRenderer nPatchRenderer = factory.GetControlRenderer( TEST_NPATCH_FILE_NAME );
157  DALI_TEST_CHECK( nPatchRenderer );
158  DALI_TEST_CHECK( IsDebugRenderer( nPatchRenderer ) );
159 
161  END_TEST;
162 }
163 
165 {
167  ToolkitTestApplication application;
168  tet_infoline( "UtcDaliDebugRendererResetRenderer: Reset renderer with various parameters" );
169 
171  DALI_TEST_CHECK( factory );
172 
173  // Test that color renderer is replaced with debug renderer
174  ControlRenderer controlRenderer = factory.GetControlRenderer(Color::CYAN);
175  DALI_TEST_CHECK( controlRenderer );
176  DALI_TEST_CHECK( IsDebugRenderer( controlRenderer ) );
177 
178  Actor actor;
179  // Reset to render another color
180  // Test that color renderer is replaced with debug renderer
181  factory.ResetRenderer( controlRenderer, actor, Color::BLUE );
182  DALI_TEST_CHECK( IsDebugRenderer( controlRenderer ) );
183 
184  // Reset to render an image
185  // Test that image renderer is replaced with debug renderer
187  factory.ResetRenderer( controlRenderer, actor, image );
188  DALI_TEST_CHECK( IsDebugRenderer( controlRenderer ) );
189 
190  // Reset with a property map of border renderer
191  // Test that border renderer is replaced with debug renderer
192  Property::Map propertyMap;
193  propertyMap.Insert("rendererType", "border");
194  propertyMap.Insert("borderColor", Color::BLUE);
195  propertyMap.Insert("borderSize", 2.f);
196  factory.ResetRenderer( controlRenderer, actor, propertyMap );
197  DALI_TEST_CHECK( IsDebugRenderer( controlRenderer ) );
198 
200  END_TEST;
201 }
Dali Docs Home
Read more about Dali