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.
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/dali-toolkit.h>
25 #include <dali-toolkit-test-suite-utils.h>
29 static void Startup();
30 static void Cleanup();
33 void (*tet_startup)() = Startup;
34 void (*tet_cleanup)() = Cleanup;
37 static void UtcDaliShearEffectUninitialized();
38 static void UtcDaliShearEffectPropertyNames();
39 static void UtcDaliShearEffectDefaultValues();
40 static void UtcDaliShearEffectCustomValues();
43 POSITIVE_TC_IDX = 0x01,
47 // Add test functionality for all APIs in the class (Positive and Negative)
49 struct tet_testlist tet_testlist[] = {
50 { UtcDaliShearEffectUninitialized, NEGATIVE_TC_IDX },
51 { UtcDaliShearEffectPropertyNames, POSITIVE_TC_IDX },
52 { UtcDaliShearEffectDefaultValues, POSITIVE_TC_IDX },
53 { UtcDaliShearEffectCustomValues, POSITIVE_TC_IDX },
58 // Called only once before first test is run.
63 // Called only once after last test is run
68 // Create bitmap image
69 BitmapImage CreateBitmapImage()
71 BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
73 PixelBuffer* pixbuf = image.GetBuffer();
75 // Using a 4x4 image gives a better blend with the GL implementation
77 for(size_t i=0; i<16; i++)
88 static void UtcDaliShearEffectUninitialized()
90 ToolkitTestApplication application;
92 Toolkit::ShearEffect effect;
96 // New() must be called to create a ShearEffect or it wont be valid.
97 effect.SetAngleXAxis( 45.0f );
98 DALI_TEST_CHECK( false );
100 catch (Dali::DaliException& e)
102 // Tests that a negative test of an assertion succeeds
103 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
104 DALI_TEST_CHECK(!effect);
108 static void UtcDaliShearEffectPropertyNames()
110 ToolkitTestApplication application;
112 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
114 // Check the names, these names are used in the shaders code,
115 // if they change the shader code has to be updated
116 DALI_TEST_EQUALS( effect.GetAngleXAxisPropertyName(), "uAngleXAxis", TEST_LOCATION );
117 DALI_TEST_EQUALS( effect.GetAngleYAxisPropertyName(), "uAngleYAxis", TEST_LOCATION );
118 DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
122 * Converts value to screen position in the same way that
123 * the core does under COORDINATE_TYPE_SCREEN_POSITION
125 * @param[in] value the input position value.
126 * @return The translated position value ready for gl.
128 Vector2 ToScreenPosition(Vector2 value)
130 Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
131 value.x = stageSize.x * 0.5f - value.x;
132 value.y = value.y - stageSize.y * 0.5f;
137 static void UtcDaliShearEffectDefaultValues()
139 ToolkitTestApplication application;
141 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
142 DALI_TEST_CHECK( effect );
144 BitmapImage image = CreateBitmapImage();
146 ImageActor actor = ImageActor::New( image );
147 actor.SetSize( 100.0f, 100.0f );
149 const float angleXAxis(0.0f);
150 const float angleYAxis(0.0f);
151 const Vector2 centerValue(0.0f, 0.0f);
153 actor.SetShaderEffect( effect );
154 Stage::GetCurrent().Add( actor );
156 application.SendNotification();
157 application.Render();
159 TestGlAbstraction& gl = application.GetGlAbstraction();
160 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleXAxisPropertyName().c_str(), angleXAxis ) );
161 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleYAxisPropertyName().c_str(), angleYAxis ) );
162 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), ToScreenPosition(centerValue) ) );
165 static void UtcDaliShearEffectCustomValues()
167 ToolkitTestApplication application;
169 Toolkit::ShearEffect effect = Toolkit::ShearEffect::New();
170 DALI_TEST_CHECK( effect );
172 BitmapImage image = CreateBitmapImage();
174 ImageActor actor = ImageActor::New( image );
175 actor.SetSize( 100.0f, 100.0f );
177 const float angleXAxis(10.0f);
178 const float angleYAxis(22.5f);
179 const Vector2 centerValue(50.0f, 100.0f);
181 effect.SetAngleXAxis( angleXAxis );
182 effect.SetAngleYAxis( angleYAxis );
183 effect.SetCenter( centerValue );
185 actor.SetShaderEffect(effect);
186 Stage::GetCurrent().Add(actor);
188 application.SendNotification();
189 application.Render();
191 TestGlAbstraction& gl = application.GetGlAbstraction();
192 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleXAxisPropertyName().c_str(), angleXAxis ) );
193 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAngleYAxisPropertyName().c_str(), angleYAxis ) );
194 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), ToScreenPosition(centerValue) ) );