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>
22 #include <dali-toolkit/devel-api/shader-effects/shear-effect.h>
26 void shear_effect_startup(void)
28 test_return_value = TET_UNDEF;
31 void shear_effect_cleanup(void)
33 test_return_value = TET_PASS;
36 int UtcDaliShearEffectUninitialized(void)
38 ToolkitTestApplication application;
40 Toolkit::ShearEffect effect;
44 // New() must be called to create a ShearEffect or it wont be valid.
45 effect.SetAngleXAxis( 45.0f );
46 DALI_TEST_CHECK( false );
48 catch (Dali::DaliException& e)
50 // Tests that a negative test of an assertion succeeds
51 DALI_TEST_PRINT_ASSERT( e );
52 DALI_TEST_CHECK(!effect);
57 int UtcDaliShearEffectPropertyNames(void)
59 ToolkitTestApplication application;
61 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
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 );
75 * Converts value to screen position in the same way that
76 * the core does under COORDINATE_TYPE_SCREEN_POSITION
78 * @param[in] value the input position value.
79 * @return The translated position value ready for gl.
81 Vector2 ToScreenPosition(Vector2 value)
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;
92 int UtcDaliShearEffectDefaultValues(void)
94 ToolkitTestApplication application;
96 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
97 DALI_TEST_CHECK( effect );
99 BufferImage image = CreateBufferImage();
101 ImageActor actor = ImageActor::New( image );
102 actor.SetSize( 100.0f, 100.0f );
104 const float angleXAxis(0.0f);
105 const float angleYAxis(0.0f);
106 const Vector2 centerValue(0.0f, 0.0f);
108 actor.SetShaderEffect( effect );
109 Stage::GetCurrent().Add( actor );
111 application.SendNotification();
112 application.Render();
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) ) );
121 int UtcDaliShearEffectCustomValues(void)
123 ToolkitTestApplication application;
125 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
126 DALI_TEST_CHECK( effect );
128 BufferImage image = CreateBufferImage();
130 ImageActor actor = ImageActor::New( image );
131 actor.SetSize( 100.0f, 100.0f );
133 const float angleXAxis(10.0f);
134 const float angleYAxis(22.5f);
135 const Vector2 centerValue(50.0f, 100.0f);
137 effect.SetAngleXAxis( angleXAxis );
138 effect.SetAngleYAxis( angleYAxis );
139 effect.SetCenter( centerValue );
141 actor.SetShaderEffect(effect);
142 Stage::GetCurrent().Add(actor);
144 application.SendNotification();
145 application.Render();
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) ) );