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.
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/dali-toolkit.h>
26 #include <dali-toolkit-test-suite-utils.h>
30 static void Startup();
31 static void Cleanup();
34 void (*tet_startup)() = Startup;
35 void (*tet_cleanup)() = Cleanup;
38 static void UtcDaliShearEffectUninitialized();
39 static void UtcDaliShearEffectPropertyNames();
40 static void UtcDaliShearEffectDefaultValues();
41 static void UtcDaliShearEffectCustomValues();
44 POSITIVE_TC_IDX = 0x01,
48 // Add test functionality for all APIs in the class (Positive and Negative)
50 struct tet_testlist tet_testlist[] = {
51 { UtcDaliShearEffectUninitialized, NEGATIVE_TC_IDX },
52 { UtcDaliShearEffectPropertyNames, POSITIVE_TC_IDX },
53 { UtcDaliShearEffectDefaultValues, POSITIVE_TC_IDX },
54 { UtcDaliShearEffectCustomValues, POSITIVE_TC_IDX },
59 // Called only once before first test is run.
64 // Called only once after last test is run
69 // Create bitmap image
70 BitmapImage CreateBitmapImage()
72 BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
74 PixelBuffer* pixbuf = image.GetBuffer();
76 // Using a 4x4 image gives a better blend with the GL implementation
78 for(size_t i=0; i<16; i++)
89 static void UtcDaliShearEffectUninitialized()
91 ToolkitTestApplication application;
93 Toolkit::ShearEffect effect;
97 // New() must be called to create a ShearEffect or it wont be valid.
98 effect.SetAngleXAxis( 45.0f );
99 DALI_TEST_CHECK( false );
101 catch (Dali::DaliException& e)
103 // Tests that a negative test of an assertion succeeds
104 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
105 DALI_TEST_CHECK(!effect);
109 static void UtcDaliShearEffectPropertyNames()
111 ToolkitTestApplication application;
113 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
115 // Check the names, these names are used in the shaders code,
116 // if they change the shader code has to be updated
117 DALI_TEST_EQUALS( effect.GetAngleXAxisPropertyName(), "uAngleXAxis", TEST_LOCATION );
118 DALI_TEST_EQUALS( effect.GetAngleYAxisPropertyName(), "uAngleYAxis", TEST_LOCATION );
119 DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
123 * Converts value to screen position in the same way that
124 * the core does under COORDINATE_TYPE_SCREEN_POSITION
126 * @param[in] value the input position value.
127 * @return The translated position value ready for gl.
129 Vector2 ToScreenPosition(Vector2 value)
131 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
132 value.x = stageSize.x * 0.5f - value.x;
133 value.y = value.y - stageSize.y * 0.5f;
138 static void UtcDaliShearEffectDefaultValues()
140 ToolkitTestApplication application;
142 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
143 DALI_TEST_CHECK( effect );
145 BitmapImage image = CreateBitmapImage();
147 ImageActor actor = ImageActor::New( image );
148 actor.SetSize( 100.0f, 100.0f );
150 const float angleXAxis(0.0f);
151 const float angleYAxis(0.0f);
152 const Vector2 centerValue(0.0f, 0.0f);
154 actor.SetShaderEffect( effect );
155 Stage::GetCurrent().Add( actor );
157 application.SendNotification();
158 application.Render();
160 TestGlAbstraction& gl = application.GetGlAbstraction();
161 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleXAxisPropertyName().c_str(), angleXAxis ) );
162 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleYAxisPropertyName().c_str(), angleYAxis ) );
163 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), ToScreenPosition(centerValue) ) );
166 static void UtcDaliShearEffectCustomValues()
168 ToolkitTestApplication application;
170 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
171 DALI_TEST_CHECK( effect );
173 BitmapImage image = CreateBitmapImage();
175 ImageActor actor = ImageActor::New( image );
176 actor.SetSize( 100.0f, 100.0f );
178 const float angleXAxis(10.0f);
179 const float angleYAxis(22.5f);
180 const Vector2 centerValue(50.0f, 100.0f);
182 effect.SetAngleXAxis( angleXAxis );
183 effect.SetAngleYAxis( angleYAxis );
184 effect.SetCenter( centerValue );
186 actor.SetShaderEffect(effect);
187 Stage::GetCurrent().Add(actor);
189 application.SendNotification();
190 application.Render();
192 TestGlAbstraction& gl = application.GetGlAbstraction();
193 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleXAxisPropertyName().c_str(), angleXAxis ) );
194 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleYAxisPropertyName().c_str(), angleYAxis ) );
195 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), ToScreenPosition(centerValue) ) );