2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
23 #include <toolkit-environment-variable.h> // for setting environment variable: DALI_DEBUG_RENDERING
26 using namespace Dali::Toolkit;
30 const char* TEST_IMAGE_FILE_NAME = "image_01.jpg";
31 const char* TEST_NPATCH_FILE_NAME = "image_01.9.jpg";
33 bool IsDebugVisual( Visual::Base& visual )
35 bool isDebugVisualType = false;
36 bool isGeometryLineType = false;
38 Property::Map propertyMap;
39 visual.CreatePropertyMap( propertyMap );
40 Property::Value* typeValue = propertyMap.Find( "rendererType", Property::STRING );
43 isDebugVisualType = ( typeValue->Get<std::string>() == "DEBUG" );
46 Actor actor = Actor::New();
47 visual.SetOnStage( actor );
48 Geometry geometry = actor.GetRendererAt( 0 ).GetGeometry();
49 isGeometryLineType = ( geometry.GetGeometryType() == Geometry::LINES );
51 return isDebugVisualType && isGeometryLineType;
55 void dali_debug_renderer_startup(void)
57 test_return_value = TET_UNDEF;
60 void dali_debug_renderer_cleanup(void)
62 test_return_value = TET_PASS;
65 int UtcDaliDebugVisualGetVisual1(void)
67 EnvironmentVariable::SetTestingEnvironmentVariable(true);
68 ToolkitTestApplication application;
69 tet_infoline( "UtcDaliDebugVisualGetVisual1: Request visual with a Property::Map" );
71 VisualFactory factory = VisualFactory::Get();
72 DALI_TEST_CHECK( factory );
74 // Test that color visual is replaced with debug visual
75 Property::Map propertyMap1;
76 propertyMap1.Insert("rendererType", "COLOR");
77 propertyMap1.Insert("mixColor", Color::BLUE);
78 Visual::Base colorVisual = factory.CreateVisual(propertyMap1);
79 DALI_TEST_CHECK( colorVisual );
80 DALI_TEST_CHECK( IsDebugVisual( colorVisual ) );
82 // Test that border visual is replaced with debug visual
83 Property::Map propertyMap2;
84 propertyMap2.Insert("rendererType", "BORDER");
85 propertyMap2.Insert("borderColor", Color::BLUE);
86 propertyMap2.Insert("borderSize", 2.f);
87 Visual::Base borderVisual = factory.CreateVisual(propertyMap2);
88 DALI_TEST_CHECK( borderVisual );
89 DALI_TEST_CHECK( IsDebugVisual( borderVisual ) );
91 // Test that gradient visual is replaced with debug visual
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::Base gradientVisual = factory.CreateVisual(propertyMap3);
108 DALI_TEST_CHECK( gradientVisual );
109 DALI_TEST_CHECK( IsDebugVisual( gradientVisual ) );
111 // Test that image visual is replaced with debug visual
112 Property::Map propertyMap4;
113 propertyMap4.Insert( "rendererType", "IMAGE" );
114 propertyMap4.Insert( "url", TEST_IMAGE_FILE_NAME );
115 Visual::Base imageVisual = factory.CreateVisual( propertyMap4 );
116 DALI_TEST_CHECK( imageVisual );
117 DALI_TEST_CHECK( IsDebugVisual( imageVisual ) );
119 // Test that n patch visual is replaced with debug visual
120 Property::Map propertyMap5;
121 propertyMap5.Insert( "rendererType", "IMAGE" );
122 propertyMap5.Insert( "url", TEST_NPATCH_FILE_NAME );
123 Visual::Base nPatchVisual = factory.CreateVisual( propertyMap4 );
124 DALI_TEST_CHECK( nPatchVisual );
125 DALI_TEST_CHECK( IsDebugVisual( nPatchVisual ) );
127 EnvironmentVariable::SetTestingEnvironmentVariable(false);
131 int UtcDaliDebugVisualGetVisual2(void)
133 EnvironmentVariable::SetTestingEnvironmentVariable(true);
134 ToolkitTestApplication application;
135 tet_infoline( "UtcDaliDebugVisualGetVisual2: Request visual with various parameters" );
137 VisualFactory factory = VisualFactory::Get();
138 DALI_TEST_CHECK( factory );
140 // Test that color visual is replaced with debug visual
141 Dali::Property::Map map;
142 map[ "rendererType" ] = "COLOR";
143 map[ "mixColor" ] = Color::CYAN;
145 Visual::Base colorVisual = factory.CreateVisual( map);
146 DALI_TEST_CHECK( colorVisual );
147 DALI_TEST_CHECK( IsDebugVisual( colorVisual ) );
149 // Test that border visual is replaced with debug visual
151 map[ "rendererType" ] = "BORDER";
152 map[ "borderColor" ] = Color::GREEN;
153 map[ "borderSize" ] = 2.f;
154 Visual::Base borderVisual = factory.CreateVisual( map );
155 DALI_TEST_CHECK( borderVisual );
156 DALI_TEST_CHECK( IsDebugVisual( borderVisual ) );
158 // Test that image visual is replaced with debug visual
159 Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
160 Visual::Base imageVisual = factory.CreateVisual( image );
161 DALI_TEST_CHECK( imageVisual );
162 DALI_TEST_CHECK( IsDebugVisual( imageVisual ) );
164 // Test that n patch visual is replaced with debug visual
165 Visual::Base nPatchVisual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
166 DALI_TEST_CHECK( nPatchVisual );
167 DALI_TEST_CHECK( IsDebugVisual( nPatchVisual ) );
169 EnvironmentVariable::SetTestingEnvironmentVariable(false);