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 UtcDaliCarouselEffectUninitialized();
39 static void UtcDaliCarouselEffectPropertyNames();
40 static void UtcDaliCarouselEffectDefaultValues();
41 static void UtcDaliCarouselEffectCustomValues();
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 { UtcDaliCarouselEffectUninitialized, NEGATIVE_TC_IDX },
52 { UtcDaliCarouselEffectPropertyNames, POSITIVE_TC_IDX },
53 { UtcDaliCarouselEffectDefaultValues, POSITIVE_TC_IDX },
54 { UtcDaliCarouselEffectCustomValues, POSITIVE_TC_IDX },
59 // Called only once before first test is run.
64 // Called only once after last test is run
69 // Create bitmap image
70 BitmapImage CreateBitmapImage()
72 BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
74 PixelBuffer* pixbuf = image.GetBuffer();
76 // Using a 4x4 image gives a better blend with the GL implementation
78 for(size_t i=0; i<16; i++)
89 static void UtcDaliCarouselEffectUninitialized()
91 ToolkitTestApplication application;
93 Toolkit::CarouselEffect effect;
97 // New() must be called to create a CarouselEffect or it wont be valid.
98 effect.SetRadius( 100.0f );
99 DALI_TEST_CHECK( false );
101 catch (Dali::DaliException& e)
103 // Tests that a negative test of an assertion succeeds
104 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
105 DALI_TEST_CHECK(!effect);
109 static void UtcDaliCarouselEffectPropertyNames()
111 ToolkitTestApplication application;
113 Toolkit::CarouselEffect effect = Toolkit::CarouselEffect::New();
115 // Check the names, these names are used in the shaders code,
116 // if they change the shader code has to be updated
117 DALI_TEST_EQUALS( effect.GetRadiusPropertyName(), "uRadius", TEST_LOCATION );
118 DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
119 DALI_TEST_EQUALS( effect.GetAnglePerUnitPropertyName(), "uAnglePerUnit", TEST_LOCATION );
122 static void UtcDaliCarouselEffectDefaultValues()
124 ToolkitTestApplication application;
126 Toolkit::CarouselEffect effect = Toolkit::CarouselEffect::New();
127 DALI_TEST_CHECK( effect );
129 BitmapImage image = CreateBitmapImage();
131 ImageActor actor = ImageActor::New( image );
132 actor.SetSize( 100.0f, 100.0f );
134 const float radiusValue(0.0f);
135 const Vector2 centerValue(0.0f, 0.0f);
136 const Vector2 anglePerUnitValue(0.0f, 0.0f);
138 actor.SetShaderEffect( effect );
139 Stage::GetCurrent().Add( actor );
141 application.SendNotification();
142 application.Render();
144 TestGlAbstraction& gl = application.GetGlAbstraction();
145 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetRadiusPropertyName().c_str(), radiusValue ) );
146 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), centerValue ) );
147 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAnglePerUnitPropertyName().c_str(), anglePerUnitValue ) );
150 static void UtcDaliCarouselEffectCustomValues()
152 ToolkitTestApplication application;
154 Toolkit::CarouselEffect effect = Toolkit::CarouselEffect::New();
155 DALI_TEST_CHECK( effect );
157 BitmapImage image = CreateBitmapImage();
159 ImageActor actor = ImageActor::New( image );
160 actor.SetSize( 100.0f, 100.0f );
162 const float radiusValue(100.0f);
163 const Vector2 centerValue(150.0f, 200.0f);
164 const Vector2 anglePerUnitValue(0.1f, 0.25f);
166 effect.SetRadius( radiusValue );
167 effect.SetCenter( centerValue );
168 effect.SetAnglePerUnit( anglePerUnitValue );
170 actor.SetShaderEffect(effect);
171 Stage::GetCurrent().Add(actor);
173 application.SendNotification();
174 application.Render();
176 TestGlAbstraction& gl = application.GetGlAbstraction();
177 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetRadiusPropertyName().c_str(), radiusValue ) );
178 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), centerValue ) );
179 DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAnglePerUnitPropertyName().c_str(), anglePerUnitValue ) );