Merge remote-tracking branch 'origin/tizen' into new_text
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / utc-Dali-BendyEffect.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 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22
23
24 using namespace Dali;
25
26
27 void bendy_effect_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void bendy_effect_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37
38 int UtcDaliBendyUninitializedEffect(void)
39 {
40   ToolkitTestApplication application;
41
42   Toolkit::BendyEffect effect;
43
44   try
45   {
46     // New() must be called to create a BendyEffect or it wont be valid.
47     effect.SetRadius( 2.0f );
48     DALI_TEST_CHECK( false );
49   }
50   catch (Dali::DaliException& e)
51   {
52     // Tests that a negative test of an assertion succeeds
53     DALI_TEST_PRINT_ASSERT( e );
54     DALI_TEST_CHECK(!effect);
55   }
56   END_TEST;
57 }
58
59 int UtcDaliBendyPropertyNamesEffect(void)
60 {
61   ToolkitTestApplication application;
62
63   Toolkit::BendyEffect effect = Toolkit::BendyEffect::New();
64
65   // Check the names, this names are used in the shaders code,
66   // if they change the shader code has to be updated
67   DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
68   DALI_TEST_EQUALS( effect.GetDirectionPropertyName(), "uDirection", TEST_LOCATION );
69   DALI_TEST_EQUALS( effect.GetRadiusPropertyName(), "uRadius", TEST_LOCATION );
70   END_TEST;
71 }
72
73 int UtcDaliBendyDefaultValuesEffect(void)
74 {
75   ToolkitTestApplication application;
76
77   Toolkit::BendyEffect effect = Toolkit::BendyEffect::New();
78   DALI_TEST_CHECK( effect );
79
80   BitmapImage image = CreateBitmapImage();
81
82   ImageActor actor = ImageActor::New( image );
83   actor.SetSize( 100.0f, 100.0f );
84   actor.SetShaderEffect( effect );
85   Stage::GetCurrent().Add( actor );
86
87   application.SendNotification();
88   application.Render();
89
90   Vector2 topLeft( Stage::GetCurrent().GetSize() * 0.5f );
91   topLeft.y = -topLeft.y;
92
93   // Gets converted to opengl view space
94   DALI_TEST_CHECK(
95       application.GetGlAbstraction().CheckUniformValue(
96           effect.GetCenterPropertyName().c_str(),
97           topLeft ) );
98
99   DALI_TEST_CHECK(
100       application.GetGlAbstraction().CheckUniformValue(
101           effect.GetDirectionPropertyName().c_str(),
102           Vector2(0.0f, 0.0f) ) );
103
104   DALI_TEST_CHECK(
105       application.GetGlAbstraction().CheckUniformValue(
106           effect.GetRadiusPropertyName().c_str(),
107           0.0f ) );
108   END_TEST;
109 }
110
111 int UtcDaliBendyCustomValuesEffect(void)
112 {
113   ToolkitTestApplication application;
114
115   Toolkit::BendyEffect effect = Toolkit::BendyEffect::New();
116   DALI_TEST_CHECK( effect );
117
118   BitmapImage image = CreateBitmapImage();
119
120   ImageActor actor = ImageActor::New( image );
121   actor.SetSize( 100.0f, 100.0f );
122
123   Vector2 direction(1.0f, 1.0f);
124   effect.SetCenter( Vector2(480.0f, 800.0f) );
125   effect.SetDirection( direction );
126   effect.SetRadius( 2.0f );
127
128   actor.SetShaderEffect(effect);
129   Stage::GetCurrent().Add(actor);
130
131   application.SendNotification();
132   application.Render();
133
134   Vector2 bottomRight( Stage::GetCurrent().GetSize() * 0.5f );
135   bottomRight.x = -bottomRight.x;
136
137   // Gets converted to opengl viewport coordinates
138   DALI_TEST_CHECK(
139       application.GetGlAbstraction().CheckUniformValue(
140           effect.GetCenterPropertyName().c_str(),
141           bottomRight ) );
142
143   direction.Normalize();
144   direction.x *= -1.0f;
145   DALI_TEST_CHECK(
146       application.GetGlAbstraction().CheckUniformValue(
147           effect.GetDirectionPropertyName().c_str(),
148           direction ) );
149
150   DALI_TEST_CHECK(
151       application.GetGlAbstraction().CheckUniformValue(
152           effect.GetRadiusPropertyName().c_str(),
153           2.0f ) );
154   END_TEST;
155 }