Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / shader-effects / utc-Dali-DistanceFieldEffect.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 <iostream>
18
19 #include <stdlib.h>
20 #include <tet_api.h>
21
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/public-api/shader-effects/distance-field-effect.h>
24 #include <dali-toolkit/dali-toolkit.h>
25
26 #include <dali-toolkit-test-suite-utils.h>
27
28 using namespace Dali;
29
30 static void Startup();
31 static void Cleanup();
32
33 extern "C" {
34   void (*tet_startup)() = Startup;
35   void (*tet_cleanup)() = Cleanup;
36 }
37
38 static void UtcDaliDistanceFieldEffectUninitialized();
39 static void UtcDaliDistanceFieldEffectPropertyNames();
40 static void UtcDaliDistanceFieldEffectDefaultValues();
41 static void UtcDaliDistanceFieldEffectCustomValues();
42
43 enum {
44   POSITIVE_TC_IDX = 0x01,
45   NEGATIVE_TC_IDX,
46 };
47
48 // Add test functionality for all APIs in the class (Positive and Negative)
49 extern "C" {
50   struct tet_testlist tet_testlist[] = {
51     { UtcDaliDistanceFieldEffectUninitialized, NEGATIVE_TC_IDX },
52     { UtcDaliDistanceFieldEffectPropertyNames, POSITIVE_TC_IDX },
53     { UtcDaliDistanceFieldEffectDefaultValues, POSITIVE_TC_IDX },
54     { UtcDaliDistanceFieldEffectCustomValues, POSITIVE_TC_IDX },
55     { NULL, 0 }
56   };
57 }
58
59 // Called only once before first test is run.
60 static void Startup()
61 {
62 }
63
64 // Called only once after last test is run
65 static void Cleanup()
66 {
67 }
68
69 // Create bitmap image
70 BitmapImage CreateDistanceField()
71 {
72   BitmapImage image = BitmapImage::New(256, 256, Pixel::RGBA8888);
73   BitmapImage distanceFieldImage = BitmapImage::New(256, 256, Pixel::L8);
74
75   PixelBuffer* pixbuf = image.GetBuffer();
76
77   for(size_t i=0; i<16; i++)
78   {
79     pixbuf[i*4+0] = 0xFF;
80     pixbuf[i*4+1] = 0xFF;
81     pixbuf[i*4+2] = 0xFF;
82     pixbuf[i*4+3] = 0xFF;
83   }
84
85   // GenerateDistanceFieldMap(distanceFieldImage.GetBuffer(), Size(256, 256), pixbuf, Size(256, 256), 8, 4);
86
87   return distanceFieldImage;
88 }
89
90 static void UtcDaliDistanceFieldEffectUninitialized()
91 {
92   ToolkitTestApplication application;
93
94   Toolkit::DistanceFieldEffect effect;
95
96   try
97   {
98     // New() must be called to create a DistanceField effect or it wont be valid.
99     effect.SetShadow( true );
100     DALI_TEST_CHECK( false );
101   }
102   catch (Dali::DaliException& e)
103   {
104     // Tests that a negative test of an assertion succeeds
105     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
106     DALI_TEST_CHECK(!effect);
107   }
108 }
109
110 static void UtcDaliDistanceFieldEffectPropertyNames()
111 {
112   ToolkitTestApplication application;
113
114   Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
115
116   // Check the names, this names are used in the shaders code,
117   // if they change the shader code has to be updated
118   DALI_TEST_EQUALS( effect.GetColorPropertyName(), "uColor", TEST_LOCATION );
119   DALI_TEST_EQUALS( effect.GetSmoothingPropertyName(), "uSmoothing", TEST_LOCATION );
120
121   // control flags
122   DALI_TEST_EQUALS( effect.GetOutlineEnablePropertyName(), "uDoOutline", TEST_LOCATION );
123   DALI_TEST_EQUALS( effect.GetGlowEnablePropertyName(), "uDoGlow", TEST_LOCATION );
124   DALI_TEST_EQUALS( effect.GetShadowEnablePropertyName(), "uDoShadow", TEST_LOCATION );
125
126   DALI_TEST_EQUALS( effect.GetGlowBoundaryPropertyName(), "uGlowBoundary", TEST_LOCATION );
127   DALI_TEST_EQUALS( effect.GetGlowColorPropertyName(), "uGlowColor", TEST_LOCATION );
128
129   DALI_TEST_EQUALS( effect.GetOutlineColorPropertyName(), "uOutlineColor", TEST_LOCATION );
130   DALI_TEST_EQUALS( effect.GetOutlineSizePropertyName(), "uOutlineParams", TEST_LOCATION );
131
132   DALI_TEST_EQUALS( effect.GetShadowColorPropertyName(), "uShadowColor", TEST_LOCATION );
133   DALI_TEST_EQUALS( effect.GetShadowOffsetPropertyName(), "uShadowOffset", TEST_LOCATION );
134
135 }
136
137 static void UtcDaliDistanceFieldEffectDefaultValues()
138 {
139   ToolkitTestApplication application;
140
141   Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
142   DALI_TEST_CHECK( effect );
143
144   BitmapImage image = CreateDistanceField();
145
146   ImageActor actor = ImageActor::New( image );
147   actor.SetSize( 100.0f, 100.0f );
148   actor.SetShaderEffect( effect );
149   Stage::GetCurrent().Add( actor );
150
151   application.SendNotification();
152   application.Render();
153
154   DALI_TEST_CHECK(
155       application.GetGlAbstraction().CheckUniformValue(
156           effect.GetOutlineEnablePropertyName().c_str(),
157           0.0f ));
158
159   DALI_TEST_CHECK(
160       application.GetGlAbstraction().CheckUniformValue(
161           effect.GetGlowEnablePropertyName().c_str(),
162           0.0f ));
163
164   DALI_TEST_CHECK(
165       application.GetGlAbstraction().CheckUniformValue(
166           effect.GetShadowEnablePropertyName().c_str(),
167           0.0f ));
168 }
169
170 static void UtcDaliDistanceFieldEffectCustomValues()
171 {
172   ToolkitTestApplication application;
173
174   Toolkit::DistanceFieldEffect effect = Toolkit::DistanceFieldEffect::New();
175   DALI_TEST_CHECK( effect );
176
177   BitmapImage image = CreateDistanceField();
178
179   ImageActor actor = ImageActor::New( image );
180   actor.SetSize( 100.0f, 100.0f );
181
182   effect.SetShadowColor(Color::YELLOW);
183   effect.SetGlowColor(Color::BLUE);
184
185   actor.SetShaderEffect( effect );
186   Stage::GetCurrent().Add( actor );
187
188   application.SendNotification();
189   application.Render();
190
191   // Gets converted to opengl viewport coordinates
192   DALI_TEST_CHECK(
193       application.GetGlAbstraction().CheckUniformValue(
194           effect.GetShadowColorPropertyName().c_str(),
195           Color::YELLOW ) );
196
197   DALI_TEST_CHECK(
198       application.GetGlAbstraction().CheckUniformValue(
199           effect.GetGlowColorPropertyName().c_str(),
200           Color::BLUE ) );
201 }
202