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;
38 static void UtcDaliDissolveUninitializedEffect();
39 static void UtcDaliDissolvePropertyNamesEffect();
40 static void UtcDaliDissolveDefaultValuesEffect();
41 static void UtcDaliDissolveCustomValuesEffect();
42 static void UtcDaliSetEffectImageEffect();
45 POSITIVE_TC_IDX = 0x01,
49 // Add test functionality for all APIs in the class (Positive and Negative)
51 struct tet_testlist tet_testlist[] = {
52 { UtcDaliDissolveUninitializedEffect, NEGATIVE_TC_IDX },
53 { UtcDaliDissolvePropertyNamesEffect, POSITIVE_TC_IDX },
54 { UtcDaliDissolveDefaultValuesEffect, POSITIVE_TC_IDX },
55 { UtcDaliDissolveCustomValuesEffect, POSITIVE_TC_IDX },
56 { UtcDaliSetEffectImageEffect, POSITIVE_TC_IDX },
61 // Called only once before first test is run.
66 // Called only once after last test is run
71 // Create bitmap image
72 BitmapImage CreateBitmapImage()
74 BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
76 PixelBuffer* pixbuf = image.GetBuffer();
78 // Using a 4x4 image gives a better blend with the GL implementation
80 for(size_t i=0; i<16; i++)
91 static void UtcDaliDissolveUninitializedEffect()
93 ToolkitTestApplication application;
95 Toolkit::DissolveEffect effect;
99 // New() must be called to create a DissolveEffect or it wont be valid.
100 effect.SetDistortion( 2.0f );
101 DALI_TEST_CHECK( false );
103 catch (Dali::DaliException& e)
105 // Tests that a negative test of an assertion succeeds
106 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
107 DALI_TEST_CHECK(!effect);
111 static void UtcDaliDissolvePropertyNamesEffect()
113 ToolkitTestApplication application;
115 Toolkit::DissolveEffect effectHighPrecision = Toolkit::DissolveEffect::New();
116 Toolkit::DissolveEffect effectMediumPrecision = Toolkit::DissolveEffect::New( false );
118 // Check the names, this names are used in the shaders code,
119 // if they change the shader code has to be updated
120 DALI_TEST_EQUALS( effectHighPrecision.GetDistortionPropertyName(), "uPercentage", TEST_LOCATION );
121 DALI_TEST_EQUALS( effectMediumPrecision.GetDistortionPropertyName(), "uPercentage", TEST_LOCATION );
124 static void UtcDaliDissolveDefaultValuesEffect()
126 ToolkitTestApplication application;
128 Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
129 DALI_TEST_CHECK( effect );
131 BitmapImage image = CreateBitmapImage();
133 ImageActor actor = ImageActor::New( image );
134 actor.SetSize( 100.0f, 100.0f );
135 actor.SetShaderEffect( effect );
136 effect.SetCentralLine( Vector2(0.0,0.5), Vector2(1.0, -0.1) );
137 Stage::GetCurrent().Add( actor );
139 application.SendNotification();
140 application.Render();
142 Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
144 (effect.GetProperty(index)).Get( value );
145 DALI_TEST_EQUALS(value, 0.f, TEST_LOCATION );
148 static void UtcDaliDissolveCustomValuesEffect()
150 ToolkitTestApplication application;
152 Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
153 DALI_TEST_CHECK( effect );
155 BitmapImage image = CreateBitmapImage();
157 ImageActor actor = ImageActor::New( image );
158 actor.SetSize( 100.0f, 100.0f );
160 effect.SetDistortion( 0.5f );
162 actor.SetShaderEffect(effect);
163 Stage::GetCurrent().Add(actor);
165 application.SendNotification();
166 application.Render();
168 Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
170 (effect.GetProperty(index)).Get( value );
171 DALI_TEST_EQUALS(value, 0.5f, TEST_LOCATION );
174 static void UtcDaliSetEffectImageEffect()
176 ToolkitTestApplication application;
178 Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
179 DALI_TEST_CHECK( effect );
181 Image effectImage = CreateBitmapImage();
182 effect.SetEffectImage(effectImage);
184 BitmapImage image = CreateBitmapImage();
186 ImageActor actor = ImageActor::New( image );
187 actor.SetSize( 100.0f, 100.0f );
188 actor.SetShaderEffect( effect );
189 Stage::GetCurrent().Add( actor );
191 application.SendNotification();
192 application.Render();
194 Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
196 (effect.GetProperty(index)).Get( value );
197 DALI_TEST_EQUALS(value, 0.f, TEST_LOCATION );