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 UtcDaliIrisEffectUninitialized();
38 static void UtcDaliIrisEffectPropertyNames();
39 static void UtcDaliIrisEffectDefaultValues();
40 static void UtcDaliIrisEffectCustomValues();
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 { UtcDaliIrisEffectUninitialized, NEGATIVE_TC_IDX },
51 { UtcDaliIrisEffectPropertyNames, POSITIVE_TC_IDX },
52 { UtcDaliIrisEffectDefaultValues, POSITIVE_TC_IDX },
53 { UtcDaliIrisEffectCustomValues, 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 UtcDaliIrisEffectUninitialized()
90 ToolkitTestApplication application;
92 Toolkit::IrisEffect effect;
96 // New() must be called to create a IrisEffect or it wont be valid.
97 effect.SetRadius( 2.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 UtcDaliIrisEffectPropertyNames()
110 ToolkitTestApplication application;
112 Toolkit::IrisEffect effect = Toolkit::IrisEffect::New();
114 // Check the names, this names are used in the shaders code,
115 // if they change the shader code has to be updated
116 DALI_TEST_EQUALS( effect.GetRadiusPropertyName(), "uRadius", TEST_LOCATION );
117 DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
118 DALI_TEST_EQUALS( effect.GetBlendFactorPropertyName(), "uBlendFactor", TEST_LOCATION );
121 static void UtcDaliIrisEffectDefaultValues()
123 ToolkitTestApplication application;
125 Toolkit::IrisEffect effect = Toolkit::IrisEffect::New();
126 DALI_TEST_CHECK( effect );
128 BitmapImage image = CreateBitmapImage();
130 ImageActor actor = ImageActor::New( image );
131 actor.SetSize( 100.0f, 100.0f );
133 const float radiusValue(0.0f);
134 const Vector2 centerValue(0.5f, 0.5f);
135 const float blendFactorValue(100.0f);
137 actor.SetShaderEffect( effect );
138 Stage::GetCurrent().Add( actor );
140 application.SendNotification();
141 application.Render();
143 TestGlAbstraction& gl = application.GetGlAbstraction();
144 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetRadiusPropertyName().c_str(), radiusValue ) );
145 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), centerValue ) );
146 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetBlendFactorPropertyName().c_str(), blendFactorValue ) );
149 static void UtcDaliIrisEffectCustomValues()
151 ToolkitTestApplication application;
153 Toolkit::IrisEffect effect = Toolkit::IrisEffect::New();
154 DALI_TEST_CHECK( effect );
156 BitmapImage image = CreateBitmapImage();
158 ImageActor actor = ImageActor::New( image );
159 actor.SetSize( 100.0f, 100.0f );
161 const float radiusValue(23.0f);
162 const Vector2 centerValue(0.2f, 0.7f);
163 const float blendFactorValue(10.0f);
165 effect.SetRadius( radiusValue );
166 effect.SetCenter( centerValue );
167 effect.SetBlendFactor( blendFactorValue );
169 actor.SetShaderEffect(effect);
170 Stage::GetCurrent().Add(actor);
172 application.SendNotification();
173 application.Render();
175 TestGlAbstraction& gl = application.GetGlAbstraction();
176 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetRadiusPropertyName().c_str(), radiusValue ) );
177 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), centerValue ) );
178 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetBlendFactorPropertyName().c_str(), blendFactorValue ) );