2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit-test-suite-utils.h>
29 static void Startup();
30 static void Cleanup();
33 void (*tet_startup)() = Startup;
34 void (*tet_cleanup)() = Cleanup;
38 POSITIVE_TC_IDX = 0x01,
42 #define MAX_NUMBER_OF_TESTS 10000
44 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
47 // Add test functionality for all APIs in the class (Positive and Negative)
48 TEST_FUNCTION( UtcDaliWaterEffectUninitialized, NEGATIVE_TC_IDX );
49 TEST_FUNCTION( UtcDaliWaterEffectPropertyNames, POSITIVE_TC_IDX );
50 TEST_FUNCTION( UtcDaliWaterEffectOutOfBounds, NEGATIVE_TC_IDX );
51 TEST_FUNCTION( UtcDaliWaterEffectDefaultValues, POSITIVE_TC_IDX );
52 TEST_FUNCTION( UtcDaliWaterEffectCustomValues, POSITIVE_TC_IDX );
53 TEST_FUNCTION( UtcDaliWaterEffectGetAmplitudePositive, POSITIVE_TC_IDX );
54 TEST_FUNCTION( UtcDaliWaterEffectGetAmplitudeNegative, NEGATIVE_TC_IDX );
55 TEST_FUNCTION( UtcDaliWaterEffectGetCenterPositive, POSITIVE_TC_IDX );
56 TEST_FUNCTION( UtcDaliWaterEffectGetCenterNegative, NEGATIVE_TC_IDX );
57 TEST_FUNCTION( UtcDaliWaterEffectGetPropagationPositive, POSITIVE_TC_IDX );
58 TEST_FUNCTION( UtcDaliWaterEffectGetPropagationNegative, NEGATIVE_TC_IDX );
60 // Called only once before first test is run.
65 // Called only once after last test is run
70 // Create bitmap image
71 BitmapImage CreateBitmapImage()
73 BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
75 PixelBuffer* pixbuf = image.GetBuffer();
77 // Using a 4x4 image gives a better blend with the GL implementation
79 for(size_t i=0; i<16; i++)
90 static void UtcDaliWaterEffectUninitialized()
92 ToolkitTestApplication application;
94 Toolkit::WaterEffect effect;
98 // New() must be called to create a RippleEffect or it wont be valid.
99 effect.SetAmplitude( 0, 0.5f );
100 DALI_TEST_CHECK( false );
102 catch (Dali::DaliException& e)
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);
110 static void UtcDaliWaterEffectPropertyNames()
112 ToolkitTestApplication application;
114 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
115 DALI_TEST_CHECK( effect );
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( effect.GetAmplitudePropertyName( 0 ), "uDrops[0].amplitude", TEST_LOCATION );
120 DALI_TEST_EQUALS( effect.GetCenterPropertyName( 0 ), "uDrops[0].center", TEST_LOCATION );
121 DALI_TEST_EQUALS( effect.GetPropagationPropertyName( 0 ), "uDrops[0].radius", TEST_LOCATION );
124 static void UtcDaliWaterEffectOutOfBounds()
126 ToolkitTestApplication application;
128 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
129 DALI_TEST_CHECK( effect );
133 // the highest index acceptable is (GetNumberOfWaves() - 1)
134 effect.SetAmplitude( effect.GetNumberOfWaves(), 0 );
135 DALI_TEST_CHECK( false );
137 catch (Dali::DaliException& e)
139 // Tests that a negative test of an assertion succeeds
140 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
141 DALI_TEST_CHECK( true );
145 static void UtcDaliWaterEffectDefaultValues()
147 ToolkitTestApplication application;
149 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
150 DALI_TEST_CHECK( effect );
152 // Check that the effect has the number of waves it was requested
153 DALI_TEST_CHECK( effect.GetNumberOfWaves() == 4 );
155 BitmapImage image = CreateBitmapImage();
157 ImageActor actor = ImageActor::New( image );
158 actor.SetSize( 100.0f, 100.0f );
159 actor.SetShaderEffect( effect );
160 Stage::GetCurrent().Add( actor );
162 application.SendNotification();
163 application.Render();
165 Vector2 topLeft( Stage::GetCurrent().GetSize() * 0.5f );
166 topLeft.y = -topLeft.y;
168 for ( unsigned int i = 0; i < effect.GetNumberOfWaves(); ++i )
171 application.GetGlAbstraction().CheckUniformValue(
172 effect.GetAmplitudePropertyName(i).c_str(),
175 application.GetGlAbstraction().CheckUniformValue(
176 effect.GetCenterPropertyName(i).c_str(),
179 application.GetGlAbstraction().CheckUniformValue(
180 effect.GetPropagationPropertyName(i).c_str(),
185 static void UtcDaliWaterEffectCustomValues()
187 ToolkitTestApplication application;
189 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
190 DALI_TEST_CHECK( effect );
192 BitmapImage image = CreateBitmapImage();
194 ImageActor actor = ImageActor::New( image );
195 actor.SetSize( 100.0f, 100.0f );
196 actor.SetShaderEffect( effect );
197 Stage::GetCurrent().Add( actor );
199 effect.SetAmplitude( 0, 0.5f );
200 effect.SetCenter( 0, Vector2 ( 10.0f, 10.0f ) );
201 effect.SetPropagation( 0, 2.0f );
203 application.SendNotification();
204 application.Render();
207 application.GetGlAbstraction().CheckUniformValue(
208 effect.GetAmplitudePropertyName(0).c_str(),
211 Vector2 centerPoint( Stage::GetCurrent().GetSize() * 0.5f );
212 centerPoint.y = -centerPoint.y;
215 application.GetGlAbstraction().CheckUniformValue(
216 effect.GetCenterPropertyName(0).c_str(),
217 Vector2( centerPoint.x - 10.0f, centerPoint.y + 10.0f ) ) );
219 application.GetGlAbstraction().CheckUniformValue(
220 effect.GetPropagationPropertyName(0).c_str(),
224 static void UtcDaliWaterEffectGetAmplitudePositive()
226 ToolkitTestApplication application;
228 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
229 DALI_TEST_CHECK( effect );
231 BitmapImage image = CreateBitmapImage();
233 ImageActor actor = ImageActor::New( image );
234 actor.SetSize( 100.0f, 100.0f );
235 actor.SetShaderEffect( effect );
236 Stage::GetCurrent().Add( actor );
238 float amplitude(0.5f);
239 DALI_TEST_CHECK(effect.GetAmplitude(0) != amplitude);
240 effect.SetAmplitude( 0, amplitude );
242 application.SendNotification();
243 application.Render();
245 DALI_TEST_EQUALS(amplitude, effect.GetAmplitude(0), TEST_LOCATION);
248 static void UtcDaliWaterEffectGetAmplitudeNegative()
250 ToolkitTestApplication application;
252 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
253 DALI_TEST_CHECK( effect );
255 BitmapImage image = CreateBitmapImage();
257 ImageActor actor = ImageActor::New( image );
258 actor.SetSize( 100.0f, 100.0f );
259 actor.SetShaderEffect( effect );
260 Stage::GetCurrent().Add( actor );
264 effect.GetAmplitude(9999);
265 tet_result(TET_FAIL);
267 catch(DaliException& exception)
269 if (exception.mCondition == "index < mNumberOfWaves")
271 tet_result(TET_PASS);
276 static void UtcDaliWaterEffectGetCenterPositive()
278 ToolkitTestApplication application;
280 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
281 DALI_TEST_CHECK( effect );
283 BitmapImage image = CreateBitmapImage();
285 ImageActor actor = ImageActor::New( image );
286 actor.SetSize( 100.0f, 100.0f );
287 actor.SetShaderEffect( effect );
288 Stage::GetCurrent().Add( actor );
290 Vector2 center(10.0f, 20.0f);
291 DALI_TEST_CHECK(effect.GetCenter(0) != center);
292 effect.SetCenter( 0, center );
294 application.SendNotification();
295 application.Render();
297 DALI_TEST_EQUALS(center, effect.GetCenter(0), TEST_LOCATION);
300 static void UtcDaliWaterEffectGetCenterNegative()
302 ToolkitTestApplication application;
304 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
305 DALI_TEST_CHECK( effect );
307 BitmapImage image = CreateBitmapImage();
309 ImageActor actor = ImageActor::New( image );
310 actor.SetSize( 100.0f, 100.0f );
311 actor.SetShaderEffect( effect );
312 Stage::GetCurrent().Add( actor );
316 effect.GetCenter(9999);
317 tet_result(TET_FAIL);
319 catch(DaliException& exception)
321 if (exception.mCondition == "index < mNumberOfWaves")
323 tet_result(TET_PASS);
328 static void UtcDaliWaterEffectGetPropagationPositive()
330 ToolkitTestApplication application;
332 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
333 DALI_TEST_CHECK( effect );
335 BitmapImage image = CreateBitmapImage();
337 ImageActor actor = ImageActor::New( image );
338 actor.SetSize( 100.0f, 100.0f );
339 actor.SetShaderEffect( effect );
340 Stage::GetCurrent().Add( actor );
342 float propagation(0.5f);
343 DALI_TEST_CHECK(effect.GetPropagation(0) != propagation);
344 effect.SetPropagation( 0, propagation );
346 application.SendNotification();
347 application.Render();
349 DALI_TEST_EQUALS(propagation, effect.GetPropagation(0), TEST_LOCATION);
352 static void UtcDaliWaterEffectGetPropagationNegative()
354 ToolkitTestApplication application;
356 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
357 DALI_TEST_CHECK( effect );
359 BitmapImage image = CreateBitmapImage();
361 ImageActor actor = ImageActor::New( image );
362 actor.SetSize( 100.0f, 100.0f );
363 actor.SetShaderEffect( effect );
364 Stage::GetCurrent().Add( actor );
368 effect.GetPropagation(9999);
369 tet_result(TET_FAIL);
371 catch(DaliException& exception)
373 if (exception.mCondition == "index < mNumberOfWaves")
375 tet_result(TET_PASS);