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