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>
29 using namespace Dali::Toolkit;
33 const char* TEST_IMAGE_FILE_NAME = DALI_IMAGE_DIR "gallery_image_01.jpg";
36 static void Startup();
37 static void Cleanup();
40 void (*tet_startup)() = Startup;
41 void (*tet_cleanup)() = Cleanup;
44 static void UtcDaliDisplacementEffectUninitialized();
45 static void UtcDaliDisplacementEffectNew();
46 static void UtcDaliDisplacementEffectPropertyNames();
47 static void UtcDaliDisplacementEffectTestSetProperty();
50 POSITIVE_TC_IDX = 0x01,
54 // Add test functionality for all APIs in the class (Positive and Negative)
56 struct tet_testlist tet_testlist[] = {
57 { UtcDaliDisplacementEffectUninitialized, NEGATIVE_TC_IDX },
58 { UtcDaliDisplacementEffectNew, POSITIVE_TC_IDX },
59 { UtcDaliDisplacementEffectPropertyNames, POSITIVE_TC_IDX },
60 { UtcDaliDisplacementEffectTestSetProperty, POSITIVE_TC_IDX },
65 // Called only once before first test is run.
70 // Called only once after last test is run
75 // Negative test case for a method
76 static void UtcDaliDisplacementEffectUninitialized()
78 ToolkitTestApplication application;
79 tet_infoline("UtcDaliDisplacementEffectUninitialized");
81 Toolkit::DisplacementEffect effect;
85 // New() must be called to create a GaussianBlurView or it wont be valid.
86 effect.SetStateProperty( 1.0f );
87 DALI_TEST_CHECK( false );
89 catch (Dali::DaliException& e)
91 // Tests that a negative test of an assertion succeeds
92 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
93 DALI_TEST_CHECK(!effect);
97 // Positive test case for a method
98 static void UtcDaliDisplacementEffectNew()
100 ToolkitTestApplication application;
101 tet_infoline("UtcDaliDisplacementEffectNew");
103 Toolkit::DisplacementEffect effect = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::DISPLACED);
104 DALI_TEST_CHECK( effect );
106 Toolkit::DisplacementEffect effect2 = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::FIXED);
107 DALI_TEST_CHECK( effect2 );
110 // Positive test case for a method
111 static void UtcDaliDisplacementEffectPropertyNames()
113 ToolkitTestApplication application;
114 tet_infoline("UtcDaliDisplacementEffectPropertyNames");
116 Toolkit::DisplacementEffect effect = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::DISPLACED);
117 DALI_TEST_CHECK( effect );
119 // Check the names, this names are used in the shaders code,
120 // if they change the shader code has to be updated
121 DALI_TEST_EQUALS( effect.GetLightDirectionPropertyName(), "uLightDirection", TEST_LOCATION );
122 DALI_TEST_EQUALS( effect.GetAmbientLightColorPropertyName(), "uAmbientLightColor", TEST_LOCATION );
123 DALI_TEST_EQUALS( effect.GetDiffuseLightColorPropertyName(), "uDiffuseLightColor", TEST_LOCATION );
124 DALI_TEST_EQUALS( effect.GetLightingMultiplierPropertyName(), "uLightMultiplier", TEST_LOCATION );
125 DALI_TEST_EQUALS( effect.GetStatePropertyName(), "uState", TEST_LOCATION );
126 DALI_TEST_EQUALS( effect.GetHeightScalePropertyName(), "uHightScale", TEST_LOCATION );
127 DALI_TEST_EQUALS( effect.GetFixedNormalPropertyName(), "uFixedNormal", TEST_LOCATION );
130 // Positive test case for a method
131 static void UtcDaliDisplacementEffectTestSetProperty()
133 ToolkitTestApplication application;
134 tet_infoline("UtcDaliDisplacementEffectTestSetProperty");
136 Toolkit::DisplacementEffect effect = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::DISPLACED);
137 DALI_TEST_CHECK( effect );
139 ImageActor actor = ImageActor::New( Image::New(TEST_IMAGE_FILE_NAME) );
140 actor.SetSize( 100.0f, 100.0f );
141 actor.SetShaderEffect( effect );
142 Stage::GetCurrent().Add( actor );
144 Toolkit::DisplacementEffect effect2 = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::FIXED);
145 DALI_TEST_CHECK( effect );
147 ImageActor actor2 = ImageActor::New( Image::New(TEST_IMAGE_FILE_NAME) );
148 actor2.SetSize( 100.0f, 100.0f );
149 actor2.SetShaderEffect( effect2 );
150 Stage::GetCurrent().Add( actor2 );
152 Vector3 testVector3 = Vector3(45.0f, 55.0f, 65.0f);
153 float testFloat = 0.623f;
154 effect.SetLightDirection(testVector3);
155 effect.SetAmbientLightColorProperty(testVector3);
156 effect.SetDiffuseLightColorProperty(testVector3);
157 effect.SetStateProperty(testFloat);
158 effect.SetLightingMultiplierProperty(testFloat);
159 effect.SetHeightScaleProperty(testFloat);
161 effect2.SetFixedNormalProperty(testVector3);
163 application.SendNotification();
164 application.Render(0);
165 application.SendNotification();
166 application.Render();
168 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetLightDirectionPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
169 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetAmbientLightColorPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
170 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetDiffuseLightColorPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
171 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetStatePropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
172 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetLightingMultiplierPropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
173 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetHeightScalePropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
175 Vector3 normalizedVector3(testVector3);
176 normalizedVector3.Normalize();
177 DALI_TEST_EQUALS( effect2.GetProperty( effect2.GetPropertyIndex( effect2.GetFixedNormalPropertyName() ) ).Get<Vector3>(), normalizedVector3, TEST_LOCATION );