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