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