2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
24 void shear_effect_startup(void)
26 test_return_value = TET_UNDEF;
29 void shear_effect_cleanup(void)
31 test_return_value = TET_PASS;
34 int UtcDaliShearEffectUninitialized(void)
36 ToolkitTestApplication application;
38 Toolkit::ShearEffect effect;
42 // New() must be called to create a ShearEffect or it wont be valid.
43 effect.SetAngleXAxis( 45.0f );
44 DALI_TEST_CHECK( false );
46 catch (Dali::DaliException& e)
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);
55 int UtcDaliShearEffectPropertyNames(void)
57 ToolkitTestApplication application;
59 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
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 );
73 * Converts value to screen position in the same way that
74 * the core does under COORDINATE_TYPE_SCREEN_POSITION
76 * @param[in] value the input position value.
77 * @return The translated position value ready for gl.
79 Vector2 ToScreenPosition(Vector2 value)
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;
90 int UtcDaliShearEffectDefaultValues(void)
92 ToolkitTestApplication application;
94 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
95 DALI_TEST_CHECK( effect );
97 BitmapImage image = CreateBitmapImage();
99 ImageActor actor = ImageActor::New( image );
100 actor.SetSize( 100.0f, 100.0f );
102 const float angleXAxis(0.0f);
103 const float angleYAxis(0.0f);
104 const Vector2 centerValue(0.0f, 0.0f);
106 actor.SetShaderEffect( effect );
107 Stage::GetCurrent().Add( actor );
109 application.SendNotification();
110 application.Render();
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) ) );
119 int UtcDaliShearEffectCustomValues(void)
121 ToolkitTestApplication application;
123 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
124 DALI_TEST_CHECK( effect );
126 BitmapImage image = CreateBitmapImage();
128 ImageActor actor = ImageActor::New( image );
129 actor.SetSize( 100.0f, 100.0f );
131 const float angleXAxis(10.0f);
132 const float angleYAxis(22.5f);
133 const Vector2 centerValue(50.0f, 100.0f);
135 effect.SetAngleXAxis( angleXAxis );
136 effect.SetAngleYAxis( angleYAxis );
137 effect.SetCenter( centerValue );
139 actor.SetShaderEffect(effect);
140 Stage::GetCurrent().Add(actor);
142 application.SendNotification();
143 application.Render();
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) ) );