2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
25 void shear_effect_startup(void)
27 test_return_value = TET_UNDEF;
30 void shear_effect_cleanup(void)
32 test_return_value = TET_PASS;
35 int UtcDaliShearEffectUninitialized(void)
37 ToolkitTestApplication application;
39 Toolkit::ShearEffect effect;
43 // New() must be called to create a ShearEffect or it wont be valid.
44 effect.SetAngleXAxis( 45.0f );
45 DALI_TEST_CHECK( false );
47 catch (Dali::DaliException& e)
49 // Tests that a negative test of an assertion succeeds
50 DALI_TEST_PRINT_ASSERT( e );
51 DALI_TEST_CHECK(!effect);
56 int UtcDaliShearEffectPropertyNames(void)
58 ToolkitTestApplication application;
60 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
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 );
74 * Converts value to screen position in the same way that
75 * the core does under COORDINATE_TYPE_SCREEN_POSITION
77 * @param[in] value the input position value.
78 * @return The translated position value ready for gl.
80 Vector2 ToScreenPosition(Vector2 value)
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;
91 int UtcDaliShearEffectDefaultValues(void)
93 ToolkitTestApplication application;
95 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
96 DALI_TEST_CHECK( effect );
98 BufferImage image = CreateBufferImage();
100 ImageActor actor = ImageActor::New( image );
101 actor.SetSize( 100.0f, 100.0f );
103 const float angleXAxis(0.0f);
104 const float angleYAxis(0.0f);
105 const Vector2 centerValue(0.0f, 0.0f);
107 actor.SetShaderEffect( effect );
108 Stage::GetCurrent().Add( actor );
110 application.SendNotification();
111 application.Render();
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) ) );
120 int UtcDaliShearEffectCustomValues(void)
122 ToolkitTestApplication application;
124 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
125 DALI_TEST_CHECK( effect );
127 BufferImage image = CreateBufferImage();
129 ImageActor actor = ImageActor::New( image );
130 actor.SetSize( 100.0f, 100.0f );
132 const float angleXAxis(10.0f);
133 const float angleYAxis(22.5f);
134 const Vector2 centerValue(50.0f, 100.0f);
136 effect.SetAngleXAxis( angleXAxis );
137 effect.SetAngleYAxis( angleYAxis );
138 effect.SetCenter( centerValue );
140 actor.SetShaderEffect(effect);
141 Stage::GetCurrent().Add(actor);
143 application.SendNotification();
144 application.Render();
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) ) );