Adding new test harness
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-RippleEffect.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 #include <stdlib.h>
19
20 // Need to override adaptor classes for toolkit test harness, so include
21 // test harness headers before dali headers.
22 #include <dali-toolkit-test-suite-utils.h>
23
24 #include <dali.h>
25 #include <dali-toolkit/dali-toolkit.h>
26
27 using namespace Dali;
28
29 void utc_dali_toolkit_ripple_effect_startup(void)
30 {
31   test_return_value = TET_UNDEF;
32 }
33
34 void utc_dali_toolkit_ripple_effect_cleanup(void)
35 {
36   test_return_value = TET_PASS;
37 }
38
39
40 int UtcDaliRippleUninitializedEffect(void)
41 {
42   ToolkitTestApplication application;
43
44   Toolkit::RippleEffect effect;
45
46   try
47   {
48     // New() must be called to create a RippleEffect or it wont be valid.
49     effect.SetAmplitude( 0.5f );
50     DALI_TEST_CHECK( false );
51   }
52   catch (Dali::DaliException& e)
53   {
54     // Tests that a negative test of an assertion succeeds
55     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
56     DALI_TEST_CHECK(!effect);
57   }
58   END_TEST;
59 }
60
61 int UtcDaliRipplePropertyNamesEffect(void)
62 {
63   ToolkitTestApplication application;
64
65   Toolkit::RippleEffect effect = Toolkit::RippleEffect::New();
66
67   // Check the names, this names are used in the shaders code,
68   // if they change the shader code has to be updated
69   DALI_TEST_EQUALS( effect.GetAmplitudePropertyName(), "uAmplitude", TEST_LOCATION );
70   DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
71   DALI_TEST_EQUALS( effect.GetTimePropertyName(), "uTime", TEST_LOCATION );
72
73   END_TEST;
74 }
75
76 int UtcDaliRippleDefaultValuesEffect(void)
77 {
78   ToolkitTestApplication application;
79
80   Toolkit::RippleEffect effect = Toolkit::RippleEffect::New();
81   DALI_TEST_CHECK( effect );
82
83   BitmapImage image = CreateBitmapImage();
84
85   ImageActor actor = ImageActor::New( image );
86   actor.SetSize( 100.0f, 100.0f );
87   actor.SetShaderEffect( effect );
88   Stage::GetCurrent().Add( actor );
89
90   application.SendNotification();
91   application.Render();
92
93   DALI_TEST_CHECK(
94       application.GetGlAbstraction().CheckUniformValue(
95           effect.GetAmplitudePropertyName().c_str(),
96           0.0f ) );
97   DALI_TEST_CHECK(
98       application.GetGlAbstraction().CheckUniformValue(
99           effect.GetCenterPropertyName().c_str(),
100           Vector2( 0.0f, 0.0f ) ) );
101   DALI_TEST_CHECK(
102       application.GetGlAbstraction().CheckUniformValue(
103           effect.GetTimePropertyName().c_str(),
104           0.0f ) );
105   END_TEST;
106 }
107
108 int UtcDaliRippleCustomValuesEffect(void)
109 {
110   ToolkitTestApplication application;
111
112   Toolkit::RippleEffect effect = Toolkit::RippleEffect::New();
113   DALI_TEST_CHECK( effect );
114
115   BitmapImage image = CreateBitmapImage();
116
117   ImageActor actor = ImageActor::New( image );
118   actor.SetSize( 100.0f, 100.0f );
119
120   effect.SetAmplitude( 0.5f );
121   effect.SetCenter( Vector2( 10.0f, 10.0f ) );
122   effect.SetTime( 2.0f );
123
124   actor.SetShaderEffect( effect );
125   Stage::GetCurrent().Add( actor );
126
127   application.SendNotification();
128   application.Render();
129
130   DALI_TEST_CHECK(
131       application.GetGlAbstraction().CheckUniformValue(
132           effect.GetAmplitudePropertyName().c_str(),
133           0.5f ) );
134   DALI_TEST_CHECK(
135       application.GetGlAbstraction().CheckUniformValue(
136           effect.GetCenterPropertyName().c_str(),
137           Vector2( 10.0f, 10.0f ) ) );
138   DALI_TEST_CHECK(
139       application.GetGlAbstraction().CheckUniformValue(
140           effect.GetTimePropertyName().c_str(),
141           2.0f ) );
142   END_TEST;
143 }