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.
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/shader-effects/displacement-effect.h>
25 using namespace Dali::Toolkit;
29 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
33 void utc_displacement_startup(void)
35 test_return_value = TET_UNDEF;
38 void utc_displacement_cleanup(void)
40 test_return_value = TET_PASS;
43 // Negative test case for a method
44 int UtcDaliDisplacementEffectUninitialized(void)
46 ToolkitTestApplication application;
47 tet_infoline("UtcDaliDisplacementEffectUninitialized");
49 Toolkit::DisplacementEffect effect;
53 // New() must be called to create a GaussianBlurView or it wont be valid.
54 effect.SetStateProperty( 1.0f );
55 DALI_TEST_CHECK( false );
57 catch (Dali::DaliException& e)
59 // Tests that a negative test of an assertion succeeds
60 DALI_TEST_PRINT_ASSERT( e );
61 DALI_TEST_CHECK(!effect);
66 // Positive test case for a method
67 int UtcDaliDisplacementEffectNew(void)
69 ToolkitTestApplication application;
70 tet_infoline("UtcDaliDisplacementEffectNew");
72 Toolkit::DisplacementEffect effect = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::DISPLACED);
73 DALI_TEST_CHECK( effect );
75 Toolkit::DisplacementEffect effect2 = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::FIXED);
76 DALI_TEST_CHECK( effect2 );
80 // Positive test case for a method
81 int UtcDaliDisplacementEffectPropertyNames(void)
83 ToolkitTestApplication application;
84 tet_infoline("UtcDaliDisplacementEffectPropertyNames");
86 Toolkit::DisplacementEffect effect = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::DISPLACED);
87 DALI_TEST_CHECK( effect );
89 // Check the names, this names are used in the shaders code,
90 // if they change the shader code has to be updated
91 DALI_TEST_EQUALS( effect.GetLightDirectionPropertyName(), "uLightDirection", TEST_LOCATION );
92 DALI_TEST_EQUALS( effect.GetAmbientLightColorPropertyName(), "uAmbientLightColor", TEST_LOCATION );
93 DALI_TEST_EQUALS( effect.GetDiffuseLightColorPropertyName(), "uDiffuseLightColor", TEST_LOCATION );
94 DALI_TEST_EQUALS( effect.GetLightingMultiplierPropertyName(), "uLightMultiplier", TEST_LOCATION );
95 DALI_TEST_EQUALS( effect.GetStatePropertyName(), "uState", TEST_LOCATION );
96 DALI_TEST_EQUALS( effect.GetHeightScalePropertyName(), "uHightScale", TEST_LOCATION );
97 DALI_TEST_EQUALS( effect.GetFixedNormalPropertyName(), "uFixedNormal", TEST_LOCATION );
101 // Positive test case for a method
102 int UtcDaliDisplacementEffectTestSetProperty(void)
104 ToolkitTestApplication application;
105 tet_infoline("UtcDaliDisplacementEffectTestSetProperty");
107 Toolkit::DisplacementEffect effect = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::DISPLACED);
108 DALI_TEST_CHECK( effect );
110 ImageActor actor = ImageActor::New( ResourceImage::New(TEST_IMAGE_FILE_NAME) );
111 actor.SetSize( 100.0f, 100.0f );
112 actor.SetShaderEffect( effect );
113 Stage::GetCurrent().Add( actor );
115 Toolkit::DisplacementEffect effect2 = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::FIXED);
116 DALI_TEST_CHECK( effect );
118 ImageActor actor2 = ImageActor::New( ResourceImage::New(TEST_IMAGE_FILE_NAME) );
119 actor2.SetSize( 100.0f, 100.0f );
120 actor2.SetShaderEffect( effect2 );
121 Stage::GetCurrent().Add( actor2 );
123 Vector3 testVector3 = Vector3(45.0f, 55.0f, 65.0f);
124 float testFloat = 0.623f;
125 effect.SetLightDirection(testVector3);
126 effect.SetAmbientLightColorProperty(testVector3);
127 effect.SetDiffuseLightColorProperty(testVector3);
128 effect.SetStateProperty(testFloat);
129 effect.SetLightingMultiplierProperty(testFloat);
130 effect.SetHeightScaleProperty(testFloat);
132 effect2.SetFixedNormalProperty(testVector3);
134 application.SendNotification();
135 application.Render(0);
136 application.SendNotification();
137 application.Render();
139 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetLightDirectionPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
140 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetAmbientLightColorPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
141 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetDiffuseLightColorPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
142 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetStatePropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
143 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetLightingMultiplierPropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
144 DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetHeightScalePropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
146 Vector3 normalizedVector3(testVector3);
147 normalizedVector3.Normalize();
148 DALI_TEST_EQUALS( effect2.GetProperty( effect2.GetPropertyIndex( effect2.GetFixedNormalPropertyName() ) ).Get<Vector3>(), normalizedVector3, TEST_LOCATION );