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;
38 POSITIVE_TC_IDX = 0x01,
42 #define MAX_NUMBER_OF_TESTS 10000
44 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
47 // Add test functionality for all APIs in the class (Positive and Negative)
48 TEST_FUNCTION( UtcDaliBendyUninitializedEffect, NEGATIVE_TC_IDX );
49 TEST_FUNCTION( UtcDaliBendyPropertyNamesEffect, POSITIVE_TC_IDX );
50 TEST_FUNCTION( UtcDaliBendyDefaultValuesEffect, POSITIVE_TC_IDX );
51 TEST_FUNCTION( UtcDaliBendyCustomValuesEffect, POSITIVE_TC_IDX );
53 // Called only once before first test is run.
58 // Called only once after last test is run
63 // Create bitmap image
64 BitmapImage CreateBitmapImage()
66 BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
68 PixelBuffer* pixbuf = image.GetBuffer();
70 // Using a 4x4 image gives a better blend with the GL implementation
72 for(size_t i=0; i<16; i++)
83 static void UtcDaliBendyUninitializedEffect()
85 ToolkitTestApplication application;
87 Toolkit::BendyEffect effect;
91 // New() must be called to create a BendyEffect or it wont be valid.
92 effect.SetRadius( 2.0f );
93 DALI_TEST_CHECK( false );
95 catch (Dali::DaliException& e)
97 // Tests that a negative test of an assertion succeeds
98 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
99 DALI_TEST_CHECK(!effect);
103 static void UtcDaliBendyPropertyNamesEffect()
105 ToolkitTestApplication application;
107 Toolkit::BendyEffect effect = Toolkit::BendyEffect::New();
109 // Check the names, this names are used in the shaders code,
110 // if they change the shader code has to be updated
111 DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
112 DALI_TEST_EQUALS( effect.GetDirectionPropertyName(), "uDirection", TEST_LOCATION );
113 DALI_TEST_EQUALS( effect.GetRadiusPropertyName(), "uRadius", TEST_LOCATION );
116 static void UtcDaliBendyDefaultValuesEffect()
118 ToolkitTestApplication application;
120 Toolkit::BendyEffect effect = Toolkit::BendyEffect::New();
121 DALI_TEST_CHECK( effect );
123 BitmapImage image = CreateBitmapImage();
125 ImageActor actor = ImageActor::New( image );
126 actor.SetSize( 100.0f, 100.0f );
127 actor.SetShaderEffect( effect );
128 Stage::GetCurrent().Add( actor );
130 application.SendNotification();
131 application.Render();
133 Vector2 leftCorner( Stage::GetCurrent().GetSize() * 0.5f );
134 leftCorner.x = -leftCorner.x;
136 // Gets converted to opengl viewport coordinates
138 application.GetGlAbstraction().CheckUniformValue(
139 effect.GetCenterPropertyName().c_str(),
143 application.GetGlAbstraction().CheckUniformValue(
144 effect.GetDirectionPropertyName().c_str(),
145 Vector2(0.0f, 0.0f) ) );
148 application.GetGlAbstraction().CheckUniformValue(
149 effect.GetRadiusPropertyName().c_str(),
153 static void UtcDaliBendyCustomValuesEffect()
155 ToolkitTestApplication application;
157 Toolkit::BendyEffect effect = Toolkit::BendyEffect::New();
158 DALI_TEST_CHECK( effect );
160 BitmapImage image = CreateBitmapImage();
162 ImageActor actor = ImageActor::New( image );
163 actor.SetSize( 100.0f, 100.0f );
165 Vector2 direction(1.0f, 1.0f);
166 effect.SetCenter( Vector2(480.0f, 800.0f) );
167 effect.SetDirection( direction );
168 effect.SetRadius( 2.0f );
170 actor.SetShaderEffect(effect);
171 Stage::GetCurrent().Add(actor);
173 application.SendNotification();
174 application.Render();
176 // Gets converted to opengl viewport coordinates
178 application.GetGlAbstraction().CheckUniformValue(
179 effect.GetCenterPropertyName().c_str(),
180 Vector2(240.0f, -400.0f) ) );
182 direction.Normalize();
183 direction.y *= -1.0f;
185 application.GetGlAbstraction().CheckUniformValue(
186 effect.GetDirectionPropertyName().c_str(),
190 application.GetGlAbstraction().CheckUniformValue(
191 effect.GetRadiusPropertyName().c_str(),