Add Wayland support.
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / shader-effects / utc-Dali-DissolveEffect.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
20 #include <stdlib.h>
21 #include <tet_api.h>
22
23 #include <dali/public-api/dali-core.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 UtcDaliDissolveUninitializedEffect();
39 static void UtcDaliDissolvePropertyNamesEffect();
40 static void UtcDaliDissolveDefaultValuesEffect();
41 static void UtcDaliDissolveCustomValuesEffect();
42 static void UtcDaliSetEffectImageEffect();
43
44 enum {
45   POSITIVE_TC_IDX = 0x01,
46   NEGATIVE_TC_IDX,
47 };
48
49 // Add test functionality for all APIs in the class (Positive and Negative)
50 extern "C" {
51   struct tet_testlist tet_testlist[] = {
52     { UtcDaliDissolveUninitializedEffect, NEGATIVE_TC_IDX },
53     { UtcDaliDissolvePropertyNamesEffect, POSITIVE_TC_IDX },
54     { UtcDaliDissolveDefaultValuesEffect, POSITIVE_TC_IDX },
55     { UtcDaliDissolveCustomValuesEffect, POSITIVE_TC_IDX },
56     { UtcDaliSetEffectImageEffect, POSITIVE_TC_IDX },
57     { NULL, 0 }
58   };
59 }
60
61 // Called only once before first test is run.
62 static void Startup()
63 {
64 }
65
66 // Called only once after last test is run
67 static void Cleanup()
68 {
69 }
70
71 // Create bitmap image
72 BitmapImage CreateBitmapImage()
73 {
74   BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
75
76   PixelBuffer* pixbuf = image.GetBuffer();
77
78   // Using a 4x4 image gives a better blend with the GL implementation
79   // than a 3x3 image
80   for(size_t i=0; i<16; i++)
81   {
82     pixbuf[i*4+0] = 0xFF;
83     pixbuf[i*4+1] = 0xFF;
84     pixbuf[i*4+2] = 0xFF;
85     pixbuf[i*4+3] = 0xFF;
86   }
87
88   return image;
89 }
90
91 static void UtcDaliDissolveUninitializedEffect()
92 {
93   ToolkitTestApplication application;
94
95   Toolkit::DissolveEffect effect;
96
97   try
98   {
99     // New() must be called to create a DissolveEffect or it wont be valid.
100     effect.SetDistortion( 2.0f );
101     DALI_TEST_CHECK( false );
102   }
103   catch (Dali::DaliException& e)
104   {
105     // Tests that a negative test of an assertion succeeds
106     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
107     DALI_TEST_CHECK(!effect);
108   }
109 }
110
111 static void UtcDaliDissolvePropertyNamesEffect()
112 {
113   ToolkitTestApplication application;
114
115   Toolkit::DissolveEffect effectHighPrecision = Toolkit::DissolveEffect::New();
116   Toolkit::DissolveEffect effectMediumPrecision = Toolkit::DissolveEffect::New( false );
117
118   // Check the names, this names are used in the shaders code,
119   // if they change the shader code has to be updated
120   DALI_TEST_EQUALS( effectHighPrecision.GetDistortionPropertyName(), "uPercentage", TEST_LOCATION );
121   DALI_TEST_EQUALS( effectMediumPrecision.GetDistortionPropertyName(), "uPercentage", TEST_LOCATION );
122 }
123
124 static void UtcDaliDissolveDefaultValuesEffect()
125 {
126   ToolkitTestApplication application;
127
128   Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
129   DALI_TEST_CHECK( effect );
130
131   BitmapImage image = CreateBitmapImage();
132
133   ImageActor actor = ImageActor::New( image );
134   actor.SetSize( 100.0f, 100.0f );
135   actor.SetShaderEffect( effect );
136   effect.SetCentralLine( Vector2(0.0,0.5), Vector2(1.0, -0.1) );
137   Stage::GetCurrent().Add( actor );
138
139   application.SendNotification();
140   application.Render();
141
142   Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
143   float value;
144   (effect.GetProperty(index)).Get( value );
145   DALI_TEST_EQUALS(value, 0.f, TEST_LOCATION );
146 }
147
148 static void UtcDaliDissolveCustomValuesEffect()
149 {
150   ToolkitTestApplication application;
151
152   Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
153   DALI_TEST_CHECK( effect );
154
155   BitmapImage image = CreateBitmapImage();
156
157   ImageActor actor = ImageActor::New( image );
158   actor.SetSize( 100.0f, 100.0f );
159
160   effect.SetDistortion( 0.5f );
161
162   actor.SetShaderEffect(effect);
163   Stage::GetCurrent().Add(actor);
164
165   application.SendNotification();
166   application.Render();
167
168   Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
169   float value;
170   (effect.GetProperty(index)).Get( value );
171   DALI_TEST_EQUALS(value, 0.5f, TEST_LOCATION );
172 }
173
174 static void UtcDaliSetEffectImageEffect()
175 {
176   ToolkitTestApplication application;
177
178   Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
179   DALI_TEST_CHECK( effect );
180
181   Image effectImage = CreateBitmapImage();
182   effect.SetEffectImage(effectImage);
183
184   BitmapImage image = CreateBitmapImage();
185
186   ImageActor actor = ImageActor::New( image );
187   actor.SetSize( 100.0f, 100.0f );
188   actor.SetShaderEffect( effect );
189   Stage::GetCurrent().Add( actor );
190
191   application.SendNotification();
192   application.Render();
193
194   Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
195   float value;
196   (effect.GetProperty(index)).Get( value );
197   DALI_TEST_EQUALS(value, 0.f, TEST_LOCATION );
198 }