Builder templated constant expansion
[platform/core/uifw/dali-toolkit.git] / automated-tests / dali-test-suite / shader-effects / utc-Dali-DissolveEffect.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/dali-toolkit.h>
24
25 #include <dali-toolkit-test-suite-utils.h>
26
27 using namespace Dali;
28
29 static void Startup();
30 static void Cleanup();
31
32 extern "C" {
33   void (*tet_startup)() = Startup;
34   void (*tet_cleanup)() = Cleanup;
35 }
36
37 static void UtcDaliDissolveUninitializedEffect();
38 static void UtcDaliDissolvePropertyNamesEffect();
39 static void UtcDaliDissolveDefaultValuesEffect();
40 static void UtcDaliDissolveCustomValuesEffect();
41 static void UtcDaliSetEffectImageEffect();
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     { UtcDaliDissolveUninitializedEffect, NEGATIVE_TC_IDX },
52     { UtcDaliDissolvePropertyNamesEffect, POSITIVE_TC_IDX },
53     { UtcDaliDissolveDefaultValuesEffect, POSITIVE_TC_IDX },
54     { UtcDaliDissolveCustomValuesEffect, POSITIVE_TC_IDX },
55     { UtcDaliSetEffectImageEffect, POSITIVE_TC_IDX },
56     { NULL, 0 }
57   };
58 }
59
60 // Called only once before first test is run.
61 static void Startup()
62 {
63 }
64
65 // Called only once after last test is run
66 static void Cleanup()
67 {
68 }
69
70 // Create bitmap image
71 BitmapImage CreateBitmapImage()
72 {
73   BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
74
75   PixelBuffer* pixbuf = image.GetBuffer();
76
77   // Using a 4x4 image gives a better blend with the GL implementation
78   // than a 3x3 image
79   for(size_t i=0; i<16; i++)
80   {
81     pixbuf[i*4+0] = 0xFF;
82     pixbuf[i*4+1] = 0xFF;
83     pixbuf[i*4+2] = 0xFF;
84     pixbuf[i*4+3] = 0xFF;
85   }
86
87   return image;
88 }
89
90 static void UtcDaliDissolveUninitializedEffect()
91 {
92   ToolkitTestApplication application;
93
94   Toolkit::DissolveEffect effect;
95
96   try
97   {
98     // New() must be called to create a DissolveEffect or it wont be valid.
99     effect.SetDistortion( 2.0f );
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 UtcDaliDissolvePropertyNamesEffect()
111 {
112   ToolkitTestApplication application;
113
114   Toolkit::DissolveEffect effectHighPrecision = Toolkit::DissolveEffect::New();
115   Toolkit::DissolveEffect effectMediumPrecision = Toolkit::DissolveEffect::New( false );
116
117   // Check the names, this names are used in the shaders code,
118   // if they change the shader code has to be updated
119   DALI_TEST_EQUALS( effectHighPrecision.GetDistortionPropertyName(), "uPercentage", TEST_LOCATION );
120   DALI_TEST_EQUALS( effectMediumPrecision.GetDistortionPropertyName(), "uPercentage", TEST_LOCATION );
121 }
122
123 static void UtcDaliDissolveDefaultValuesEffect()
124 {
125   ToolkitTestApplication application;
126
127   Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
128   DALI_TEST_CHECK( effect );
129
130   BitmapImage image = CreateBitmapImage();
131
132   ImageActor actor = ImageActor::New( image );
133   actor.SetSize( 100.0f, 100.0f );
134   actor.SetShaderEffect( effect );
135   effect.SetCentralLine( Vector2(0.0,0.5), Vector2(1.0, -0.1) );
136   Stage::GetCurrent().Add( actor );
137
138   application.SendNotification();
139   application.Render();
140
141   Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
142   float value;
143   (effect.GetProperty(index)).Get( value );
144   DALI_TEST_EQUALS(value, 0.f, TEST_LOCATION );
145 }
146
147 static void UtcDaliDissolveCustomValuesEffect()
148 {
149   ToolkitTestApplication application;
150
151   Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
152   DALI_TEST_CHECK( effect );
153
154   BitmapImage image = CreateBitmapImage();
155
156   ImageActor actor = ImageActor::New( image );
157   actor.SetSize( 100.0f, 100.0f );
158
159   effect.SetDistortion( 0.5f );
160
161   actor.SetShaderEffect(effect);
162   Stage::GetCurrent().Add(actor);
163
164   application.SendNotification();
165   application.Render();
166
167   Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
168   float value;
169   (effect.GetProperty(index)).Get( value );
170   DALI_TEST_EQUALS(value, 0.5f, TEST_LOCATION );
171 }
172
173 static void UtcDaliSetEffectImageEffect()
174 {
175   ToolkitTestApplication application;
176
177   Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
178   DALI_TEST_CHECK( effect );
179
180   Image effectImage = CreateBitmapImage();
181   effect.SetEffectImage(effectImage);
182
183   BitmapImage image = CreateBitmapImage();
184
185   ImageActor actor = ImageActor::New( image );
186   actor.SetSize( 100.0f, 100.0f );
187   actor.SetShaderEffect( effect );
188   Stage::GetCurrent().Add( actor );
189
190   application.SendNotification();
191   application.Render();
192
193   Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
194   float value;
195   (effect.GetProperty(index)).Get( value );
196   DALI_TEST_EQUALS(value, 0.f, TEST_LOCATION );
197 }