text popup callbacks.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-DistanceFieldEffect.cpp
1 /*
2  * Copyright (c) 2014 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 #include <stdlib.h>
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/shader-effects/distance-field-effect.h>
23
24 using namespace Dali;
25
26 void utc_distance_field_effect_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void utc_distance_field_effect_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36 namespace
37 {
38 // Create buffer image
39 BufferImage CreateDistanceField()
40 {
41   BufferImage image = BufferImage::New(256, 256, Pixel::RGBA8888);
42   BufferImage distanceFieldImage = BufferImage::New(256, 256, Pixel::L8);
43
44   PixelBuffer* pixbuf = image.GetBuffer();
45
46   for(size_t i=0; i<16; i++)
47   {
48     pixbuf[i*4+0] = 0xFF;
49     pixbuf[i*4+1] = 0xFF;
50     pixbuf[i*4+2] = 0xFF;
51     pixbuf[i*4+3] = 0xFF;
52   }
53
54   // GenerateDistanceFieldMap(distanceFieldImage.GetBuffer(), Size(256, 256), pixbuf, Size(256, 256), 8, 4);
55
56   return distanceFieldImage;
57 }
58 }
59
60 int UtcDaliDistanceFieldEffectUninitialized(void)
61 {
62   ToolkitTestApplication application;
63
64   Toolkit::DistanceFieldEffect effect;
65
66   try
67   {
68     // New() must be called to create a DistanceField effect or it wont be valid.
69     effect.SetShadow( true );
70     DALI_TEST_CHECK( false );
71   }
72   catch (Dali::DaliException& e)
73   {
74     // Tests that a negative test of an assertion succeeds
75     DALI_TEST_PRINT_ASSERT( e );
76     DALI_TEST_CHECK(!effect);
77   }
78   END_TEST;
79 }
80
81 int UtcDaliDistanceFieldEffectPropertyNames(void)
82 {
83   ToolkitTestApplication application;
84
85   Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
86
87   // Check the names, this names are used in the shaders code,
88   // if they change the shader code has to be updated
89   DALI_TEST_EQUALS( effect.GetColorPropertyName(), "uColor", TEST_LOCATION );
90   DALI_TEST_EQUALS( effect.GetSmoothingPropertyName(), "uSmoothing", TEST_LOCATION );
91
92   // control flags
93   DALI_TEST_EQUALS( effect.GetOutlineEnablePropertyName(), "uDoOutline", TEST_LOCATION );
94   DALI_TEST_EQUALS( effect.GetGlowEnablePropertyName(), "uDoGlow", TEST_LOCATION );
95   DALI_TEST_EQUALS( effect.GetShadowEnablePropertyName(), "uDoShadow", TEST_LOCATION );
96
97   DALI_TEST_EQUALS( effect.GetGlowBoundaryPropertyName(), "uGlowBoundary", TEST_LOCATION );
98   DALI_TEST_EQUALS( effect.GetGlowColorPropertyName(), "uGlowColor", TEST_LOCATION );
99
100   DALI_TEST_EQUALS( effect.GetOutlineColorPropertyName(), "uOutlineColor", TEST_LOCATION );
101   DALI_TEST_EQUALS( effect.GetOutlineSizePropertyName(), "uOutlineParams", TEST_LOCATION );
102
103   DALI_TEST_EQUALS( effect.GetShadowColorPropertyName(), "uShadowColor", TEST_LOCATION );
104   DALI_TEST_EQUALS( effect.GetShadowOffsetPropertyName(), "uShadowOffset", TEST_LOCATION );
105
106   END_TEST;
107 }
108
109 int UtcDaliDistanceFieldEffectDefaultValues(void)
110 {
111   ToolkitTestApplication application;
112
113   Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
114   DALI_TEST_CHECK( effect );
115
116   BufferImage image = CreateDistanceField();
117
118   ImageActor actor = ImageActor::New( image );
119   actor.SetSize( 100.0f, 100.0f );
120   actor.SetShaderEffect( effect );
121   Stage::GetCurrent().Add( actor );
122
123   application.SendNotification();
124   application.Render();
125
126   DALI_TEST_CHECK(
127       application.GetGlAbstraction().CheckUniformValue(
128           effect.GetOutlineEnablePropertyName().c_str(),
129           0.0f ));
130
131   DALI_TEST_CHECK(
132       application.GetGlAbstraction().CheckUniformValue(
133           effect.GetGlowEnablePropertyName().c_str(),
134           0.0f ));
135
136   DALI_TEST_CHECK(
137       application.GetGlAbstraction().CheckUniformValue(
138           effect.GetShadowEnablePropertyName().c_str(),
139           0.0f ));
140   END_TEST;
141 }
142
143 int UtcDaliDistanceFieldEffectCustomValues(void)
144 {
145   ToolkitTestApplication application;
146
147   Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
148   DALI_TEST_CHECK( effect );
149
150   BufferImage image = CreateDistanceField();
151
152   ImageActor actor = ImageActor::New( image );
153   actor.SetSize( 100.0f, 100.0f );
154
155   effect.SetShadowColor(Color::YELLOW);
156   effect.SetGlowColor(Color::BLUE);
157
158   actor.SetShaderEffect( effect );
159   Stage::GetCurrent().Add( actor );
160
161   application.SendNotification();
162   application.Render();
163
164   // Gets converted to opengl viewport coordinates
165   DALI_TEST_CHECK(
166       application.GetGlAbstraction().CheckUniformValue(
167           effect.GetShadowColorPropertyName().c_str(),
168           Color::YELLOW ) );
169
170   DALI_TEST_CHECK(
171       application.GetGlAbstraction().CheckUniformValue(
172           effect.GetGlowColorPropertyName().c_str(),
173           Color::BLUE ) );
174   END_TEST;
175 }