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