Change the double tap and long press events on top of no text actions to highlight.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-DebugRendering.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 #include <unistd.h>
18
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
21 #include <dali-toolkit/internal/visuals/wireframe/wireframe-visual.h>
22 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
23 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
24 #include <dali/public-api/rendering/renderer.h>
25 #include <dali/public-api/rendering/geometry.h>
26
27 #include <dali-toolkit/dali-toolkit.h>
28
29 #include <toolkit-environment-variable.h> // for setting environment variable: DALI_DEBUG_RENDERING
30 #include "dummy-control.h"
31
32 using namespace Dali;
33 using namespace Dali::Toolkit;
34
35 namespace
36 {
37 const char* TEST_IMAGE_FILE_NAME =  "image_01.jpg";
38 const char* TEST_NPATCH_FILE_NAME =  "image_01.9.jpg";
39 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
40 const char* TEST_GIF_FILE_NAME = TEST_RESOURCE_DIR "/anim.gif";
41
42 const std::string DEFAULT_FONT_DIR( "/resources/fonts" );
43
44 void TestDebugVisual( Visual::Base& visual, Visual::Type actualType, Vector2 expectedNaturalSize )
45 {
46   DALI_TEST_CHECK( &typeid( Toolkit::Internal::WireframeVisual ) == &typeid( GetImplementation(visual) ) );
47
48   Vector2 naturalSize;
49   visual.GetNaturalSize( naturalSize );
50   DALI_TEST_EQUALS( naturalSize, expectedNaturalSize, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
51
52   Property::Map propertyMap;
53   visual.CreatePropertyMap( propertyMap );
54   Property::Value* typeValue = propertyMap.Find( Visual::Property::TYPE,  Property::INTEGER );
55   if ( typeValue )
56   {
57     DALI_TEST_CHECK( typeValue->Get<int>() == actualType );
58   }
59
60   DummyControl actor = DummyControl::New();
61   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(actor.GetImplementation());
62   dummyImpl.RegisterVisual( Control::CONTROL_PROPERTY_END_INDEX + 1, visual );
63   Stage::GetCurrent().Add( actor );
64
65   DALI_TEST_EQUALS( actor.GetRendererCount(), 1, TEST_LOCATION );
66   if( actor.GetRendererCount() > 0 )
67   {
68     Geometry geometry = actor.GetRendererAt( 0 ).GetGeometry();
69     DALI_TEST_CHECK( geometry.GetType() == Geometry::LINES );
70   }
71 }
72 }
73
74 void dali_debug_rendering_startup(void)
75 {
76   test_return_value = TET_UNDEF;
77 }
78
79 void dali_debug_rendering_cleanup(void)
80 {
81   test_return_value = TET_PASS;
82 }
83
84 int UtcDaliDebugRenderingGetVisual1(void)
85 {
86   EnvironmentVariable::SetTestingEnvironmentVariable(true);
87   ToolkitTestApplication application;
88   tet_infoline( "UtcDaliDebugRenderingGetVisual1:  Request visual with a Property::Map" );
89
90   VisualFactory factory = VisualFactory::Get();
91   DALI_TEST_CHECK( factory );
92
93   // Test that color visual is replaced with debug visual
94   Property::Map propertyMap1;
95   propertyMap1.Insert(Visual::Property::TYPE,  Visual::COLOR);
96   propertyMap1.Insert(ColorVisual::Property::MIX_COLOR,  Color::BLUE);
97   Visual::Base colorVisual = factory.CreateVisual(propertyMap1);
98   DALI_TEST_CHECK( colorVisual );
99   TestDebugVisual( colorVisual, Visual::COLOR, Vector2::ZERO );
100
101   // Test that border visual is replaced with debug visual
102   Property::Map propertyMap2;
103   propertyMap2.Insert(Visual::Property::TYPE,  Visual::BORDER);
104   propertyMap2.Insert(BorderVisual::Property::COLOR,  Color::BLUE);
105   propertyMap2.Insert(BorderVisual::Property::SIZE,  2.f);
106   Visual::Base borderVisual = factory.CreateVisual(propertyMap2);
107   DALI_TEST_CHECK( borderVisual );
108   TestDebugVisual( borderVisual, Visual::BORDER, Vector2::ZERO );
109
110   // Test that gradient visual is replaced with debug visual
111   Property::Map propertyMap3;
112   propertyMap3.Insert(Visual::Property::TYPE,  Visual::GRADIENT);
113   Vector2 start(-1.f, -1.f);
114   Vector2 end(1.f, 1.f);
115   propertyMap3.Insert(GradientVisual::Property::START_POSITION, start);
116   propertyMap3.Insert(GradientVisual::Property::END_POSITION, end);
117   propertyMap3.Insert(GradientVisual::Property::SPREAD_METHOD, GradientVisual::SpreadMethod::REPEAT);
118   Property::Array stopOffsets;
119   stopOffsets.PushBack( 0.2f );
120   stopOffsets.PushBack( 0.8f );
121   propertyMap3.Insert(GradientVisual::Property::STOP_OFFSET, stopOffsets);
122   Property::Array stopColors;
123   stopColors.PushBack( Color::RED );
124   stopColors.PushBack( Color::GREEN );
125   propertyMap3.Insert(GradientVisual::Property::STOP_COLOR, stopColors);
126   Visual::Base gradientVisual = factory.CreateVisual(propertyMap3);
127   DALI_TEST_CHECK( gradientVisual );
128   TestDebugVisual( gradientVisual, Visual::GRADIENT, Vector2::ZERO );
129
130   // Test that image visual is replaced with debug visual
131   Property::Map propertyMap4;
132   propertyMap4.Insert( Visual::Property::TYPE,  Visual::IMAGE );
133   propertyMap4.Insert( ImageVisual::Property::URL,  TEST_IMAGE_FILE_NAME );
134   propertyMap4.Insert( ImageVisual::Property::DESIRED_WIDTH,  50.f );
135   propertyMap4.Insert( ImageVisual::Property::DESIRED_HEIGHT,  100.f );
136   Visual::Base imageVisual = factory.CreateVisual( propertyMap4 );
137   DALI_TEST_CHECK( imageVisual );
138   TestDebugVisual( imageVisual, Visual::IMAGE, Vector2( 50.f, 100.f ) );
139
140   // Test that SVG visual is replaced with debug visual
141   // TEST_SVG_FILE:
142   //  <svg width="100" height="100">
143   //  <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
144   //  </svg>
145   Property::Map propertyMap5;
146   propertyMap5.Insert( Visual::Property::TYPE,  Visual::IMAGE );
147   propertyMap5.Insert( ImageVisual::Property::URL,  TEST_SVG_FILE_NAME );
148   Visual::Base svgVisual = factory.CreateVisual( propertyMap5 );
149   DALI_TEST_CHECK( svgVisual );
150   TestDebugVisual( svgVisual, Visual::IMAGE, Vector2(100.f, 100.f) );
151
152   // Test that AnimatedImageVisual is replaced with debug visual
153   // TEST_GIF_FILE: anim.gif
154   // resolution: 50*50, frame count: 4, frame delay: 0.2 second for each frame
155   Property::Map propertyMap6;
156   propertyMap6.Insert( Visual::Property::TYPE,  Visual::IMAGE );
157   propertyMap6.Insert( ImageVisual::Property::URL,  TEST_GIF_FILE_NAME );
158   Visual::Base animatedImageVisual = factory.CreateVisual( propertyMap6 );
159   DALI_TEST_CHECK( animatedImageVisual );
160   TestDebugVisual( animatedImageVisual, Visual::IMAGE, Vector2(50.f, 50.f) );
161
162   // Test that text visual is replaced with debug visual
163
164   // Load some fonts to get the same metrics on different platforms.
165   TextAbstraction::FontClient fontClient = TextAbstraction::FontClient::Get();
166   fontClient.SetDpi( 96u, 96u );
167
168   char* pathNamePtr = get_current_dir_name();
169   const std::string pathName( pathNamePtr );
170   free( pathNamePtr );
171
172   fontClient.GetFontId( pathName + DEFAULT_FONT_DIR + "/tizen/TizenSansRegular.ttf" );
173
174   Property::Map propertyMap7;
175   propertyMap7.Insert( Visual::Property::TYPE, DevelVisual::TEXT );
176   propertyMap7.Insert( TextVisual::Property::ENABLE_MARKUP, true );
177   propertyMap7.Insert( TextVisual::Property::TEXT, "<font family='TizenSans' size='12'>Hello world</font>" );
178   propertyMap7.Insert( TextVisual::Property::MULTI_LINE, true );
179
180   Visual::Base textVisual = factory.CreateVisual( propertyMap7 );
181   DALI_TEST_CHECK( textVisual );
182   DALI_TEST_CHECK( &typeid( Toolkit::Internal::WireframeVisual ) == &typeid( GetImplementation(textVisual) ) );
183
184   Vector2 naturalSize;
185   textVisual.GetNaturalSize( naturalSize );
186   DALI_TEST_EQUALS( naturalSize, Vector2( 80.f, 20.f ), Math::MACHINE_EPSILON_1000, TEST_LOCATION );
187
188   const float height = textVisual.GetHeightForWidth( 40.f );
189   DALI_TEST_EQUALS( height, 40.f, Math::MACHINE_EPSILON_1000, TEST_LOCATION );
190
191   EnvironmentVariable::SetTestingEnvironmentVariable(false);
192   END_TEST;
193 }
194
195 int UtcDaliDebugRenderingGetVisual2(void)
196 {
197   EnvironmentVariable::SetTestingEnvironmentVariable(true);
198   ToolkitTestApplication application;
199   tet_infoline( "UtcDaliDebugRenderingGetVisual2: Request visual with various parameters" );
200
201   VisualFactory factory = VisualFactory::Get();
202   DALI_TEST_CHECK( factory );
203
204   // Test that color visual is replaced with debug visual
205   Dali::Property::Map map;
206   map[ Visual::Property::TYPE ] = Visual::COLOR;
207   map[ ColorVisual::Property::MIX_COLOR ] = Color::CYAN;
208
209   Visual::Base colorVisual = factory.CreateVisual( map);
210   DALI_TEST_CHECK( colorVisual );
211   TestDebugVisual( colorVisual, Visual::COLOR, Vector2::ZERO );
212
213   // Test that border visual is replaced with debug visual
214   map.Clear();
215   map[ Visual::Property::TYPE ] = Visual::BORDER;
216   map[ BorderVisual::Property::COLOR  ] = Color::GREEN;
217   map[ BorderVisual::Property::SIZE   ] = 2.f;
218   Visual::Base borderVisual = factory.CreateVisual( map );
219   DALI_TEST_CHECK( borderVisual );
220   TestDebugVisual( borderVisual, Visual::BORDER, Vector2::ZERO );
221
222   // Test that image visual is replaced with debug visual
223   Image image = ResourceImage::New(TEST_IMAGE_FILE_NAME);
224   Visual::Base imageVisual = factory.CreateVisual( image );
225   DALI_TEST_CHECK( imageVisual );
226   TestDebugVisual( imageVisual, Visual::IMAGE, Vector2::ZERO);
227
228   // Test that n patch visual is replaced with debug visual
229   Visual::Base nPatchVisual = factory.CreateVisual( TEST_NPATCH_FILE_NAME, ImageDimensions() );
230   DALI_TEST_CHECK( nPatchVisual );
231   TestDebugVisual( nPatchVisual, Visual::IMAGE, Vector2::ZERO );
232
233   EnvironmentVariable::SetTestingEnvironmentVariable(false);
234   END_TEST;
235 }