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