2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit-test-suite-utils.h>
30 static void Startup();
31 static void Cleanup();
34 void (*tet_startup)() = Startup;
35 void (*tet_cleanup)() = Cleanup;
39 POSITIVE_TC_IDX = 0x01,
43 #define MAX_NUMBER_OF_TESTS 10000
45 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
48 // Add test functionality for all APIs in the class (Positive and Negative)
49 TEST_FUNCTION( UtcDaliWaterEffectUninitialized, NEGATIVE_TC_IDX );
50 TEST_FUNCTION( UtcDaliWaterEffectPropertyNames, POSITIVE_TC_IDX );
51 TEST_FUNCTION( UtcDaliWaterEffectOutOfBounds, NEGATIVE_TC_IDX );
52 TEST_FUNCTION( UtcDaliWaterEffectDefaultValues, POSITIVE_TC_IDX );
53 TEST_FUNCTION( UtcDaliWaterEffectCustomValues, POSITIVE_TC_IDX );
54 TEST_FUNCTION( UtcDaliWaterEffectGetAmplitudePositive, POSITIVE_TC_IDX );
55 TEST_FUNCTION( UtcDaliWaterEffectGetAmplitudeNegative, NEGATIVE_TC_IDX );
56 TEST_FUNCTION( UtcDaliWaterEffectGetCenterPositive, POSITIVE_TC_IDX );
57 TEST_FUNCTION( UtcDaliWaterEffectGetCenterNegative, NEGATIVE_TC_IDX );
58 TEST_FUNCTION( UtcDaliWaterEffectGetPropagationPositive, POSITIVE_TC_IDX );
59 TEST_FUNCTION( UtcDaliWaterEffectGetPropagationNegative, NEGATIVE_TC_IDX );
61 // Called only once before first test is run.
66 // Called only once after last test is run
71 // Create bitmap image
72 BitmapImage CreateBitmapImage()
74 BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
76 PixelBuffer* pixbuf = image.GetBuffer();
78 // Using a 4x4 image gives a better blend with the GL implementation
80 for(size_t i=0; i<16; i++)
91 static void UtcDaliWaterEffectUninitialized()
93 ToolkitTestApplication application;
95 Toolkit::WaterEffect effect;
99 // New() must be called to create a RippleEffect or it wont be valid.
100 effect.SetAmplitude( 0, 0.5f );
101 DALI_TEST_CHECK( false );
103 catch (Dali::DaliException& e)
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);
111 static void UtcDaliWaterEffectPropertyNames()
113 ToolkitTestApplication application;
115 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
116 DALI_TEST_CHECK( effect );
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( effect.GetAmplitudePropertyName( 0 ), "uDrops[0].amplitude", TEST_LOCATION );
121 DALI_TEST_EQUALS( effect.GetCenterPropertyName( 0 ), "uDrops[0].center", TEST_LOCATION );
122 DALI_TEST_EQUALS( effect.GetPropagationPropertyName( 0 ), "uDrops[0].radius", TEST_LOCATION );
125 static void UtcDaliWaterEffectOutOfBounds()
127 ToolkitTestApplication application;
129 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
130 DALI_TEST_CHECK( effect );
134 // the highest index acceptable is (GetNumberOfWaves() - 1)
135 effect.SetAmplitude( effect.GetNumberOfWaves(), 0 );
136 DALI_TEST_CHECK( false );
138 catch (Dali::DaliException& e)
140 // Tests that a negative test of an assertion succeeds
141 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
142 DALI_TEST_CHECK( true );
146 static void UtcDaliWaterEffectDefaultValues()
148 ToolkitTestApplication application;
150 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
151 DALI_TEST_CHECK( effect );
153 // Check that the effect has the number of waves it was requested
154 DALI_TEST_CHECK( effect.GetNumberOfWaves() == 4 );
156 BitmapImage image = CreateBitmapImage();
158 ImageActor actor = ImageActor::New( image );
159 actor.SetSize( 100.0f, 100.0f );
160 actor.SetShaderEffect( effect );
161 Stage::GetCurrent().Add( actor );
163 application.SendNotification();
164 application.Render();
166 Vector2 topLeft( Stage::GetCurrent().GetSize() * 0.5f );
167 topLeft.y = -topLeft.y;
169 for ( unsigned int i = 0; i < effect.GetNumberOfWaves(); ++i )
172 application.GetGlAbstraction().CheckUniformValue(
173 effect.GetAmplitudePropertyName(i).c_str(),
176 application.GetGlAbstraction().CheckUniformValue(
177 effect.GetCenterPropertyName(i).c_str(),
180 application.GetGlAbstraction().CheckUniformValue(
181 effect.GetPropagationPropertyName(i).c_str(),
186 static void UtcDaliWaterEffectCustomValues()
188 ToolkitTestApplication application;
190 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
191 DALI_TEST_CHECK( effect );
193 BitmapImage image = CreateBitmapImage();
195 ImageActor actor = ImageActor::New( image );
196 actor.SetSize( 100.0f, 100.0f );
197 actor.SetShaderEffect( effect );
198 Stage::GetCurrent().Add( actor );
200 effect.SetAmplitude( 0, 0.5f );
201 effect.SetCenter( 0, Vector2 ( 10.0f, 10.0f ) );
202 effect.SetPropagation( 0, 2.0f );
204 application.SendNotification();
205 application.Render();
208 application.GetGlAbstraction().CheckUniformValue(
209 effect.GetAmplitudePropertyName(0).c_str(),
212 Vector2 centerPoint( Stage::GetCurrent().GetSize() * 0.5f );
213 centerPoint.y = -centerPoint.y;
216 application.GetGlAbstraction().CheckUniformValue(
217 effect.GetCenterPropertyName(0).c_str(),
218 Vector2( centerPoint.x - 10.0f, centerPoint.y + 10.0f ) ) );
220 application.GetGlAbstraction().CheckUniformValue(
221 effect.GetPropagationPropertyName(0).c_str(),
225 static void UtcDaliWaterEffectGetAmplitudePositive()
227 ToolkitTestApplication application;
229 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
230 DALI_TEST_CHECK( effect );
232 BitmapImage image = CreateBitmapImage();
234 ImageActor actor = ImageActor::New( image );
235 actor.SetSize( 100.0f, 100.0f );
236 actor.SetShaderEffect( effect );
237 Stage::GetCurrent().Add( actor );
239 float amplitude(0.5f);
240 DALI_TEST_CHECK(effect.GetAmplitude(0) != amplitude);
241 effect.SetAmplitude( 0, amplitude );
243 application.SendNotification();
244 application.Render();
246 DALI_TEST_EQUALS(amplitude, effect.GetAmplitude(0), TEST_LOCATION);
249 static void UtcDaliWaterEffectGetAmplitudeNegative()
251 ToolkitTestApplication application;
253 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
254 DALI_TEST_CHECK( effect );
256 BitmapImage image = CreateBitmapImage();
258 ImageActor actor = ImageActor::New( image );
259 actor.SetSize( 100.0f, 100.0f );
260 actor.SetShaderEffect( effect );
261 Stage::GetCurrent().Add( actor );
265 effect.GetAmplitude(9999);
266 tet_result(TET_FAIL);
268 catch(DaliException& exception)
270 if (exception.mCondition == "index < mNumberOfWaves")
272 tet_result(TET_PASS);
277 static void UtcDaliWaterEffectGetCenterPositive()
279 ToolkitTestApplication application;
281 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
282 DALI_TEST_CHECK( effect );
284 BitmapImage image = CreateBitmapImage();
286 ImageActor actor = ImageActor::New( image );
287 actor.SetSize( 100.0f, 100.0f );
288 actor.SetShaderEffect( effect );
289 Stage::GetCurrent().Add( actor );
291 Vector2 center(10.0f, 20.0f);
292 DALI_TEST_CHECK(effect.GetCenter(0) != center);
293 effect.SetCenter( 0, center );
295 application.SendNotification();
296 application.Render();
298 DALI_TEST_EQUALS(center, effect.GetCenter(0), TEST_LOCATION);
301 static void UtcDaliWaterEffectGetCenterNegative()
303 ToolkitTestApplication application;
305 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
306 DALI_TEST_CHECK( effect );
308 BitmapImage image = CreateBitmapImage();
310 ImageActor actor = ImageActor::New( image );
311 actor.SetSize( 100.0f, 100.0f );
312 actor.SetShaderEffect( effect );
313 Stage::GetCurrent().Add( actor );
317 effect.GetCenter(9999);
318 tet_result(TET_FAIL);
320 catch(DaliException& exception)
322 if (exception.mCondition == "index < mNumberOfWaves")
324 tet_result(TET_PASS);
329 static void UtcDaliWaterEffectGetPropagationPositive()
331 ToolkitTestApplication application;
333 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
334 DALI_TEST_CHECK( effect );
336 BitmapImage image = CreateBitmapImage();
338 ImageActor actor = ImageActor::New( image );
339 actor.SetSize( 100.0f, 100.0f );
340 actor.SetShaderEffect( effect );
341 Stage::GetCurrent().Add( actor );
343 float propagation(0.5f);
344 DALI_TEST_CHECK(effect.GetPropagation(0) != propagation);
345 effect.SetPropagation( 0, propagation );
347 application.SendNotification();
348 application.Render();
350 DALI_TEST_EQUALS(propagation, effect.GetPropagation(0), TEST_LOCATION);
353 static void UtcDaliWaterEffectGetPropagationNegative()
355 ToolkitTestApplication application;
357 Toolkit::WaterEffect effect = Toolkit::WaterEffect::New(4);
358 DALI_TEST_CHECK( effect );
360 BitmapImage image = CreateBitmapImage();
362 ImageActor actor = ImageActor::New( image );
363 actor.SetSize( 100.0f, 100.0f );
364 actor.SetShaderEffect( effect );
365 Stage::GetCurrent().Add( actor );
369 effect.GetPropagation(9999);
370 tet_result(TET_FAIL);
372 catch(DaliException& exception)
374 if (exception.mCondition == "index < mNumberOfWaves")
376 tet_result(TET_PASS);