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 UtcDaliDissolveUninitializedEffect();
38 static void UtcDaliDissolvePropertyNamesEffect();
39 static void UtcDaliDissolveDefaultValuesEffect();
40 static void UtcDaliDissolveCustomValuesEffect();
41 static void UtcDaliSetEffectImageEffect();
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 { UtcDaliDissolveUninitializedEffect, NEGATIVE_TC_IDX },
52 { UtcDaliDissolvePropertyNamesEffect, POSITIVE_TC_IDX },
53 { UtcDaliDissolveDefaultValuesEffect, POSITIVE_TC_IDX },
54 { UtcDaliDissolveCustomValuesEffect, POSITIVE_TC_IDX },
55 { UtcDaliSetEffectImageEffect, POSITIVE_TC_IDX },
60 // Called only once before first test is run.
65 // Called only once after last test is run
70 // Create bitmap image
71 BitmapImage CreateBitmapImage()
73 BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
75 PixelBuffer* pixbuf = image.GetBuffer();
77 // Using a 4x4 image gives a better blend with the GL implementation
79 for(size_t i=0; i<16; i++)
90 static void UtcDaliDissolveUninitializedEffect()
92 ToolkitTestApplication application;
94 Toolkit::DissolveEffect effect;
98 // New() must be called to create a DissolveEffect or it wont be valid.
99 effect.SetDistortion( 2.0f );
100 DALI_TEST_CHECK( false );
102 catch (Dali::DaliException& e)
104 // Tests that a negative test of an assertion succeeds
105 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
106 DALI_TEST_CHECK(!effect);
110 static void UtcDaliDissolvePropertyNamesEffect()
112 ToolkitTestApplication application;
114 Toolkit::DissolveEffect effectHighPrecision = Toolkit::DissolveEffect::New();
115 Toolkit::DissolveEffect effectMediumPrecision = Toolkit::DissolveEffect::New( false );
117 // Check the names, this names are used in the shaders code,
118 // if they change the shader code has to be updated
119 DALI_TEST_EQUALS( effectHighPrecision.GetDistortionPropertyName(), "uPercentage", TEST_LOCATION );
120 DALI_TEST_EQUALS( effectMediumPrecision.GetDistortionPropertyName(), "uPercentage", TEST_LOCATION );
123 static void UtcDaliDissolveDefaultValuesEffect()
125 ToolkitTestApplication application;
127 Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
128 DALI_TEST_CHECK( effect );
130 BitmapImage image = CreateBitmapImage();
132 ImageActor actor = ImageActor::New( image );
133 actor.SetSize( 100.0f, 100.0f );
134 actor.SetShaderEffect( effect );
135 effect.SetCentralLine( Vector2(0.0,0.5), Vector2(1.0, -0.1) );
136 Stage::GetCurrent().Add( actor );
138 application.SendNotification();
139 application.Render();
141 Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
143 (effect.GetProperty(index)).Get( value );
144 DALI_TEST_EQUALS(value, 0.f, TEST_LOCATION );
147 static void UtcDaliDissolveCustomValuesEffect()
149 ToolkitTestApplication application;
151 Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
152 DALI_TEST_CHECK( effect );
154 BitmapImage image = CreateBitmapImage();
156 ImageActor actor = ImageActor::New( image );
157 actor.SetSize( 100.0f, 100.0f );
159 effect.SetDistortion( 0.5f );
161 actor.SetShaderEffect(effect);
162 Stage::GetCurrent().Add(actor);
164 application.SendNotification();
165 application.Render();
167 Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
169 (effect.GetProperty(index)).Get( value );
170 DALI_TEST_EQUALS(value, 0.5f, TEST_LOCATION );
173 static void UtcDaliSetEffectImageEffect()
175 ToolkitTestApplication application;
177 Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
178 DALI_TEST_CHECK( effect );
180 Image effectImage = CreateBitmapImage();
181 effect.SetEffectImage(effectImage);
183 BitmapImage image = CreateBitmapImage();
185 ImageActor actor = ImageActor::New( image );
186 actor.SetSize( 100.0f, 100.0f );
187 actor.SetShaderEffect( effect );
188 Stage::GetCurrent().Add( actor );
190 application.SendNotification();
191 application.Render();
193 Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
195 (effect.GetProperty(index)).Get( value );
196 DALI_TEST_EQUALS(value, 0.f, TEST_LOCATION );