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>
28 using namespace Dali::Toolkit;
32 const char* TEST_IMAGE_FILE_NAME = DALI_IMAGE_DIR "gallery_image_01.jpg";
35 static void Startup();
36 static void Cleanup();
39 void (*tet_startup)() = Startup;
40 void (*tet_cleanup)() = Cleanup;
43 static void UtcDaliDisplacementEffectUninitialized();
44 static void UtcDaliDisplacementEffectNew();
45 static void UtcDaliDisplacementEffectPropertyNames();
46 static void UtcDaliDisplacementEffectTestSetProperty();
49 POSITIVE_TC_IDX = 0x01,
53 // Add test functionality for all APIs in the class (Positive and Negative)
55 struct tet_testlist tet_testlist[] = {
56 { UtcDaliDisplacementEffectUninitialized, NEGATIVE_TC_IDX },
57 { UtcDaliDisplacementEffectNew, POSITIVE_TC_IDX },
58 { UtcDaliDisplacementEffectPropertyNames, POSITIVE_TC_IDX },
59 { UtcDaliDisplacementEffectTestSetProperty, POSITIVE_TC_IDX },
64 // Called only once before first test is run.
69 // Called only once after last test is run
74 // Negative test case for a method
75 static void UtcDaliDisplacementEffectUninitialized()
77 ToolkitTestApplication application;
78 tet_infoline("UtcDaliDisplacementEffectUninitialized");
80 Toolkit::DisplacementEffect effect;
84 // New() must be called to create a GaussianBlurView or it wont be valid.
85 effect.SetStateProperty( 1.0f );
86 DALI_TEST_CHECK( false );
88 catch (Dali::DaliException& e)
90 // Tests that a negative test of an assertion succeeds
91 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
92 DALI_TEST_CHECK(!effect);
96 // Positive test case for a method
97 static void UtcDaliDisplacementEffectNew()
99 ToolkitTestApplication application;
100 tet_infoline("UtcDaliDisplacementEffectNew");
102 Toolkit::DisplacementEffect effect = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::DISPLACED);
103 DALI_TEST_CHECK( effect );
105 Toolkit::DisplacementEffect effect2 = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::FIXED);
106 DALI_TEST_CHECK( effect2 );
109 // Positive test case for a method
110 static void UtcDaliDisplacementEffectPropertyNames()
112 ToolkitTestApplication application;
113 tet_infoline("UtcDaliDisplacementEffectPropertyNames");
115 Toolkit::DisplacementEffect effect = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::DISPLACED);
116 DALI_TEST_CHECK( effect );
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( effect.GetLightDirectionPropertyName(), "uLightDirection", TEST_LOCATION );
121 DALI_TEST_EQUALS( effect.GetAmbientLightColorPropertyName(), "uAmbientLightColor", TEST_LOCATION );
122 DALI_TEST_EQUALS( effect.GetDiffuseLightColorPropertyName(), "uDiffuseLightColor", TEST_LOCATION );
123 DALI_TEST_EQUALS( effect.GetLightingMultiplierPropertyName(), "uLightMultiplier", TEST_LOCATION );
124 DALI_TEST_EQUALS( effect.GetStatePropertyName(), "uState", TEST_LOCATION );
125 DALI_TEST_EQUALS( effect.GetHeightScalePropertyName(), "uHightScale", TEST_LOCATION );
126 DALI_TEST_EQUALS( effect.GetFixedNormalPropertyName(), "uFixedNormal", TEST_LOCATION );
129 // Positive test case for a method
130 static void UtcDaliDisplacementEffectTestSetProperty()
132 ToolkitTestApplication application;
133 tet_infoline("UtcDaliDisplacementEffectTestSetProperty");
135 Toolkit::DisplacementEffect effect = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::DISPLACED);
136 DALI_TEST_CHECK( effect );
138 ImageActor actor = ImageActor::New( Image::New(TEST_IMAGE_FILE_NAME) );
139 actor.SetSize( 100.0f, 100.0f );
140 actor.SetShaderEffect( effect );
141 Stage::GetCurrent().Add( actor );
143 Toolkit::DisplacementEffect effect2 = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::FIXED);
144 DALI_TEST_CHECK( effect );
146 ImageActor actor2 = ImageActor::New( Image::New(TEST_IMAGE_FILE_NAME) );
147 actor2.SetSize( 100.0f, 100.0f );
148 actor2.SetShaderEffect( effect2 );
149 Stage::GetCurrent().Add( actor2 );
151 Vector3 testVector3 = Vector3(45.0f, 55.0f, 65.0f);
152 float testFloat = 0.623f;
153 effect.SetLightDirection(testVector3);
154 effect.SetAmbientLightColorProperty(testVector3);
155 effect.SetDiffuseLightColorProperty(testVector3);
156 effect.SetStateProperty(testFloat);
157 effect.SetLightingMultiplierProperty(testFloat);
158 effect.SetHeightScaleProperty(testFloat);
160 effect2.SetFixedNormalProperty(testVector3);
162 application.SendNotification();
163 application.Render(0);
164 application.SendNotification();
165 application.Render();
167 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetLightDirectionPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
168 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetAmbientLightColorPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
169 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetDiffuseLightColorPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
170 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetStatePropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
171 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetLightingMultiplierPropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
172 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetHeightScalePropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
174 Vector3 normalizedVector3(testVector3);
175 normalizedVector3.Normalize();
176 DALI_TEST_EQUALS( effect2.GetProperty( effect2.GetPropertyIndex( effect2.GetFixedNormalPropertyName() ) ).Get<Vector3>(), normalizedVector3, TEST_LOCATION );