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