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;
39 POSITIVE_TC_IDX = 0x01,
43 #define MAX_NUMBER_OF_TESTS 10000
45 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
48 // Add test functionality for all APIs in the class (Positive and Negative)
49 TEST_FUNCTION( UtcDaliBendyUninitializedEffect, NEGATIVE_TC_IDX );
50 TEST_FUNCTION( UtcDaliBendyPropertyNamesEffect, POSITIVE_TC_IDX );
51 TEST_FUNCTION( UtcDaliBendyDefaultValuesEffect, POSITIVE_TC_IDX );
52 TEST_FUNCTION( UtcDaliBendyCustomValuesEffect, POSITIVE_TC_IDX );
54 // Called only once before first test is run.
59 // Called only once after last test is run
64 // Create bitmap image
65 BitmapImage CreateBitmapImage()
67 BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
69 PixelBuffer* pixbuf = image.GetBuffer();
71 // Using a 4x4 image gives a better blend with the GL implementation
73 for(size_t i=0; i<16; i++)
84 static void UtcDaliBendyUninitializedEffect()
86 ToolkitTestApplication application;
88 Toolkit::BendyEffect effect;
92 // New() must be called to create a BendyEffect or it wont be valid.
93 effect.SetRadius( 2.0f );
94 DALI_TEST_CHECK( false );
96 catch (Dali::DaliException& e)
98 // Tests that a negative test of an assertion succeeds
99 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
100 DALI_TEST_CHECK(!effect);
104 static void UtcDaliBendyPropertyNamesEffect()
106 ToolkitTestApplication application;
108 Toolkit::BendyEffect effect = Toolkit::BendyEffect::New();
110 // Check the names, this names are used in the shaders code,
111 // if they change the shader code has to be updated
112 DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
113 DALI_TEST_EQUALS( effect.GetDirectionPropertyName(), "uDirection", TEST_LOCATION );
114 DALI_TEST_EQUALS( effect.GetRadiusPropertyName(), "uRadius", TEST_LOCATION );
117 static void UtcDaliBendyDefaultValuesEffect()
119 ToolkitTestApplication application;
121 Toolkit::BendyEffect effect = Toolkit::BendyEffect::New();
122 DALI_TEST_CHECK( effect );
124 BitmapImage image = CreateBitmapImage();
126 ImageActor actor = ImageActor::New( image );
127 actor.SetSize( 100.0f, 100.0f );
128 actor.SetShaderEffect( effect );
129 Stage::GetCurrent().Add( actor );
131 application.SendNotification();
132 application.Render();
134 Vector2 topLeft( Stage::GetCurrent().GetSize() * 0.5f );
135 topLeft.y = -topLeft.y;
137 // Gets converted to opengl view space
139 application.GetGlAbstraction().CheckUniformValue(
140 effect.GetCenterPropertyName().c_str(),
144 application.GetGlAbstraction().CheckUniformValue(
145 effect.GetDirectionPropertyName().c_str(),
146 Vector2(0.0f, 0.0f) ) );
149 application.GetGlAbstraction().CheckUniformValue(
150 effect.GetRadiusPropertyName().c_str(),
154 static void UtcDaliBendyCustomValuesEffect()
156 ToolkitTestApplication application;
158 Toolkit::BendyEffect effect = Toolkit::BendyEffect::New();
159 DALI_TEST_CHECK( effect );
161 BitmapImage image = CreateBitmapImage();
163 ImageActor actor = ImageActor::New( image );
164 actor.SetSize( 100.0f, 100.0f );
166 Vector2 direction(1.0f, 1.0f);
167 effect.SetCenter( Vector2(480.0f, 800.0f) );
168 effect.SetDirection( direction );
169 effect.SetRadius( 2.0f );
171 actor.SetShaderEffect(effect);
172 Stage::GetCurrent().Add(actor);
174 application.SendNotification();
175 application.Render();
177 Vector2 bottomRight( Stage::GetCurrent().GetSize() * 0.5f );
178 bottomRight.x = -bottomRight.x;
180 // Gets converted to opengl viewport coordinates
182 application.GetGlAbstraction().CheckUniformValue(
183 effect.GetCenterPropertyName().c_str(),
186 direction.Normalize();
187 direction.x *= -1.0f;
189 application.GetGlAbstraction().CheckUniformValue(
190 effect.GetDirectionPropertyName().c_str(),
194 application.GetGlAbstraction().CheckUniformValue(
195 effect.GetRadiusPropertyName().c_str(),