Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / utc-Dali-ShearEffect.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 using namespace Dali;
23
24 void shear_effect_startup(void)
25 {
26   test_return_value = TET_UNDEF;
27 }
28
29 void shear_effect_cleanup(void)
30 {
31   test_return_value = TET_PASS;
32 }
33
34 int UtcDaliShearEffectUninitialized(void)
35 {
36   ToolkitTestApplication application;
37
38   Toolkit::ShearEffect effect;
39
40   try
41   {
42     // New() must be called to create a ShearEffect or it wont be valid.
43     effect.SetAngleXAxis( 45.0f );
44     DALI_TEST_CHECK( false );
45   }
46   catch (Dali::DaliException& e)
47   {
48     // Tests that a negative test of an assertion succeeds
49     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
50     DALI_TEST_CHECK(!effect);
51   }
52   END_TEST;
53 }
54
55 int UtcDaliShearEffectPropertyNames(void)
56 {
57   ToolkitTestApplication application;
58
59   Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
60
61   // Check the names, these names are used in the shaders code,
62   // if they change the shader code has to be updated
63   DALI_TEST_EQUALS( effect.GetAngleXAxisPropertyName(), "uAngleXAxis", TEST_LOCATION );
64   DALI_TEST_EQUALS( effect.GetAngleYAxisPropertyName(), "uAngleYAxis", TEST_LOCATION );
65   DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
66   END_TEST;
67 }
68
69 namespace
70 {
71
72 /**
73  * Converts value to screen position in the same way that
74  * the core does under COORDINATE_TYPE_SCREEN_POSITION
75  *
76  * @param[in] value the input position value.
77  * @return The translated position value ready for gl.
78  */
79 Vector2 ToScreenPosition(Vector2 value)
80 {
81   Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
82   value.x = stageSize.x * 0.5f - value.x;
83   value.y = value.y - stageSize.y * 0.5f;
84
85   return value;
86 }
87
88 }// namespace
89
90 int UtcDaliShearEffectDefaultValues(void)
91 {
92   ToolkitTestApplication application;
93
94   Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
95   DALI_TEST_CHECK( effect );
96
97   BitmapImage image = CreateBitmapImage();
98
99   ImageActor actor = ImageActor::New( image );
100   actor.SetSize( 100.0f, 100.0f );
101
102   const float angleXAxis(0.0f);
103   const float angleYAxis(0.0f);
104   const Vector2 centerValue(0.0f, 0.0f);
105
106   actor.SetShaderEffect( effect );
107   Stage::GetCurrent().Add( actor );
108
109   application.SendNotification();
110   application.Render();
111
112   TestGlAbstraction& gl = application.GetGlAbstraction();
113   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleXAxisPropertyName().c_str(), angleXAxis ) );
114   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleYAxisPropertyName().c_str(), angleYAxis ) );
115   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), ToScreenPosition(centerValue) ) );
116   END_TEST;
117 }
118
119 int UtcDaliShearEffectCustomValues(void)
120 {
121   ToolkitTestApplication application;
122
123   Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
124   DALI_TEST_CHECK( effect );
125
126   BitmapImage image = CreateBitmapImage();
127
128   ImageActor actor = ImageActor::New( image );
129   actor.SetSize( 100.0f, 100.0f );
130
131   const float angleXAxis(10.0f);
132   const float angleYAxis(22.5f);
133   const Vector2 centerValue(50.0f, 100.0f);
134
135   effect.SetAngleXAxis( angleXAxis );
136   effect.SetAngleYAxis( angleYAxis );
137   effect.SetCenter( centerValue );
138
139   actor.SetShaderEffect(effect);
140   Stage::GetCurrent().Add(actor);
141
142   application.SendNotification();
143   application.Render();
144
145   TestGlAbstraction& gl = application.GetGlAbstraction();
146   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleXAxisPropertyName().c_str(), angleXAxis ) );
147   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleYAxisPropertyName().c_str(), angleYAxis ) );
148   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), ToScreenPosition(centerValue) ) );
149   END_TEST;
150 }