53104677e120ae08427b9380f8fac81398b329d5
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-DebugVisual.cpp
1 /*
2  * Copyright (c) 2016 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 <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
20 #include <dali/public-api/rendering/renderer.h>
21 #include <dali/public-api/rendering/geometry.h>
22
23 #include <toolkit-environment-variable.h> // for setting environment variable: DALI_DEBUG_RENDERING
24
25 using namespace Dali;
26 using namespace Dali::Toolkit;
27
28 namespace
29 {
30 const char* TEST_IMAGE_FILE_NAME =  "image_01.jpg";
31 const char* TEST_NPATCH_FILE_NAME =  "image_01.9.jpg";
32
33 bool IsDebugVisual( Visual& renderer )
34 {
35   bool isDebugVisualType = false;
36   bool isGeometryLineType = false;
37
38   Property::Map propertyMap;
39   renderer.CreatePropertyMap( propertyMap );
40   Property::Value* typeValue = propertyMap.Find( "rendererType",  Property::STRING );
41   if ( typeValue )
42   {
43     isDebugVisualType = ( typeValue->Get<std::string>() == "DEBUG" );
44   }
45
46   Actor actor = Actor::New();
47   renderer.SetOnStage( actor );
48   Geometry geometry = actor.GetRendererAt( 0 ).GetGeometry();
49   isGeometryLineType = ( geometry.GetGeometryType() == Geometry::LINES );
50
51   return isDebugVisualType && isGeometryLineType;
52 }
53 }
54
55 void dali_debug_renderer_startup(void)
56 {
57   test_return_value = TET_UNDEF;
58 }
59
60 void dali_debug_renderer_cleanup(void)
61 {
62   test_return_value = TET_PASS;
63 }
64
65 int UtcDaliDebugVisualGetRenderer1(void)
66 {
67   EnvironmentVariable::SetTestingEnvironmentVariable(true);
68   ToolkitTestApplication application;
69   tet_infoline( "UtcDaliDebugVisualGetRenderer1:  Request renderer with a Property::Map" );
70
71   VisualFactory factory = VisualFactory::Get();
72   DALI_TEST_CHECK( factory );
73
74   // Test that color renderer is replaced with debug renderer
75   Property::Map propertyMap1;
76   propertyMap1.Insert("rendererType",  "COLOR");
77   propertyMap1.Insert("mixColor",  Color::BLUE);
78   Visual colorRenderer = factory.CreateVisual(propertyMap1);
79   DALI_TEST_CHECK( colorRenderer );
80   DALI_TEST_CHECK( IsDebugVisual( colorRenderer ) );
81
82   // Test that border renderer is replaced with debug renderer
83   Property::Map propertyMap2;
84   propertyMap2.Insert("rendererType",  "BORDER");
85   propertyMap2.Insert("borderColor",  Color::BLUE);
86   propertyMap2.Insert("borderSize",  2.f);
87   Visual borderRenderer = factory.CreateVisual(propertyMap2);
88   DALI_TEST_CHECK( borderRenderer );
89   DALI_TEST_CHECK( IsDebugVisual( borderRenderer ) );
90
91   // Test that gradient renderer is replaced with debug renderer
92   Property::Map propertyMap3;
93   propertyMap3.Insert("rendererType",  "GRADIENT");
94   Vector2 start(-1.f, -1.f);
95   Vector2 end(1.f, 1.f);
96   propertyMap3.Insert("startPosition", start);
97   propertyMap3.Insert("endPosition", end);
98   propertyMap3.Insert("spreadMethod", "REPEAT");
99   Property::Array stopOffsets;
100   stopOffsets.PushBack( 0.2f );
101   stopOffsets.PushBack( 0.8f );
102   propertyMap3.Insert("stopOffset", stopOffsets);
103   Property::Array stopColors;
104   stopColors.PushBack( Color::RED );
105   stopColors.PushBack( Color::GREEN );
106   propertyMap3.Insert("stopColor", stopColors);
107   Visual gradientRenderer = factory.CreateVisual(propertyMap3);
108   DALI_TEST_CHECK( gradientRenderer );
109   DALI_TEST_CHECK( IsDebugVisual( gradientRenderer ) );
110
111   // Test that image renderer is replaced with debug renderer
112   Property::Map propertyMap4;
113   propertyMap4.Insert( "rendererType",  "IMAGE" );
114   propertyMap4.Insert( "url",  TEST_IMAGE_FILE_NAME );
115   Visual imageRenderer = factory.CreateVisual( propertyMap4 );
116   DALI_TEST_CHECK( imageRenderer );
117   DALI_TEST_CHECK( IsDebugVisual( imageRenderer ) );
118
119   // Test that n patch renderer is replaced with debug renderer
120   Property::Map propertyMap5;
121   propertyMap5.Insert( "rendererType",  "IMAGE" );
122   propertyMap5.Insert( "url",  TEST_NPATCH_FILE_NAME );
123   Visual nPatchRenderer = factory.CreateVisual( propertyMap4 );
124   DALI_TEST_CHECK( nPatchRenderer );
125   DALI_TEST_CHECK( IsDebugVisual( nPatchRenderer ) );
126
127   EnvironmentVariable::SetTestingEnvironmentVariable(false);
128   END_TEST;
129 }
130
131 int UtcDaliDebugVisualGetRenderer2(void)
132 {
133   EnvironmentVariable::SetTestingEnvironmentVariable(true);
134   ToolkitTestApplication application;
135   tet_infoline( "UtcDaliDebugVisualGetRenderer2: Request renderer with various parameters" );
136
137   VisualFactory factory = VisualFactory::Get();
138   DALI_TEST_CHECK( factory );
139
140   // Test that color renderer is replaced with debug renderer
141   Dali::Property::Map map;
142   map[ "rendererType" ] = "COLOR";
143   map[ "mixColor" ] = Color::CYAN;
144
145   Visual colorRenderer = factory.CreateVisual( map);
146   DALI_TEST_CHECK( colorRenderer );
147   DALI_TEST_CHECK( IsDebugVisual( colorRenderer ) );
148
149   // Test that border renderer is replaced with debug renderer
150   map.Clear();
151   map[ "rendererType" ] = "BORDER";
152   map[ "borderColor"  ] = Color::GREEN;
153   map[ "borderSize"   ] = 2.f;
154   Visual borderRenderer = factory.CreateVisual( map );
155   DALI_TEST_CHECK( borderRenderer );
156   DALI_TEST_CHECK( IsDebugVisual( borderRenderer ) );
157
158   // Test that image renderer is replaced with debug renderer
159   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
160   Visual imageRenderer = factory.CreateVisual( image );
161   DALI_TEST_CHECK( imageRenderer );
162   DALI_TEST_CHECK( IsDebugVisual( imageRenderer ) );
163
164   // Test that n patch renderer is replaced with debug renderer
165   Visual nPatchRenderer = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
166   DALI_TEST_CHECK( nPatchRenderer );
167   DALI_TEST_CHECK( IsDebugVisual( nPatchRenderer ) );
168
169   EnvironmentVariable::SetTestingEnvironmentVariable(false);
170   END_TEST;
171 }