bd68477f089aa11ad7ad299dac7dfcd5c63382ed
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / utc-Dali-DisplacementEffect.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 #include <iostream>
18 #include <stdlib.h>
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali-toolkit/dali-toolkit.h>
21
22 using namespace Dali;
23 using namespace Dali::Toolkit;
24
25 namespace
26 {
27 const char* TEST_IMAGE_FILE_NAME = "gallery_image_01.jpg";
28 } // namespace
29
30
31 void utc_displacement_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void utc_displacement_cleanup(void)
37 {
38   test_return_value = TET_PASS;
39 }
40
41 // Negative test case for a method
42 int UtcDaliDisplacementEffectUninitialized(void)
43 {
44   ToolkitTestApplication application;
45   tet_infoline("UtcDaliDisplacementEffectUninitialized");
46
47   Toolkit::DisplacementEffect effect;
48
49   try
50   {
51     // New() must be called to create a GaussianBlurView or it wont be valid.
52     effect.SetStateProperty( 1.0f );
53     DALI_TEST_CHECK( false );
54   }
55   catch (Dali::DaliException& e)
56   {
57     // Tests that a negative test of an assertion succeeds
58     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
59     DALI_TEST_CHECK(!effect);
60   }
61   END_TEST;
62 }
63
64 // Positive test case for a method
65 int UtcDaliDisplacementEffectNew(void)
66 {
67   ToolkitTestApplication application;
68   tet_infoline("UtcDaliDisplacementEffectNew");
69
70   Toolkit::DisplacementEffect effect = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::DISPLACED);
71   DALI_TEST_CHECK( effect );
72
73   Toolkit::DisplacementEffect effect2 = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::FIXED);
74   DALI_TEST_CHECK( effect2 );
75   END_TEST;
76 }
77
78 // Positive test case for a method
79 int UtcDaliDisplacementEffectPropertyNames(void)
80 {
81   ToolkitTestApplication application;
82   tet_infoline("UtcDaliDisplacementEffectPropertyNames");
83
84   Toolkit::DisplacementEffect effect = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::DISPLACED);
85   DALI_TEST_CHECK( effect );
86
87   // Check the names, this names are used in the shaders code,
88   // if they change the shader code has to be updated
89   DALI_TEST_EQUALS( effect.GetLightDirectionPropertyName(), "uLightDirection", TEST_LOCATION );
90   DALI_TEST_EQUALS( effect.GetAmbientLightColorPropertyName(), "uAmbientLightColor", TEST_LOCATION );
91   DALI_TEST_EQUALS( effect.GetDiffuseLightColorPropertyName(), "uDiffuseLightColor", TEST_LOCATION );
92   DALI_TEST_EQUALS( effect.GetLightingMultiplierPropertyName(), "uLightMultiplier", TEST_LOCATION );
93   DALI_TEST_EQUALS( effect.GetStatePropertyName(), "uState", TEST_LOCATION );
94   DALI_TEST_EQUALS( effect.GetHeightScalePropertyName(), "uHightScale", TEST_LOCATION );
95   DALI_TEST_EQUALS( effect.GetFixedNormalPropertyName(), "uFixedNormal", TEST_LOCATION );
96   END_TEST;
97 }
98
99 // Positive test case for a method
100 int UtcDaliDisplacementEffectTestSetProperty(void)
101 {
102   ToolkitTestApplication application;
103   tet_infoline("UtcDaliDisplacementEffectTestSetProperty");
104
105   Toolkit::DisplacementEffect effect = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::DISPLACED);
106   DALI_TEST_CHECK( effect );
107
108   ImageActor actor = ImageActor::New( Image::New(TEST_IMAGE_FILE_NAME) );
109   actor.SetSize( 100.0f, 100.0f );
110   actor.SetShaderEffect( effect );
111   Stage::GetCurrent().Add( actor );
112
113   Toolkit::DisplacementEffect effect2 = Toolkit::DisplacementEffect::New(Toolkit::DisplacementEffect::FIXED);
114   DALI_TEST_CHECK( effect );
115
116   ImageActor actor2 = ImageActor::New( Image::New(TEST_IMAGE_FILE_NAME) );
117   actor2.SetSize( 100.0f, 100.0f );
118   actor2.SetShaderEffect( effect2 );
119   Stage::GetCurrent().Add( actor2 );
120
121   Vector3 testVector3 = Vector3(45.0f, 55.0f, 65.0f);
122   float testFloat = 0.623f;
123   effect.SetLightDirection(testVector3);
124   effect.SetAmbientLightColorProperty(testVector3);
125   effect.SetDiffuseLightColorProperty(testVector3);
126   effect.SetStateProperty(testFloat);
127   effect.SetLightingMultiplierProperty(testFloat);
128   effect.SetHeightScaleProperty(testFloat);
129
130   effect2.SetFixedNormalProperty(testVector3);
131
132   application.SendNotification();
133   application.Render(0);
134   application.SendNotification();
135   application.Render();
136
137   DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetLightDirectionPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
138   DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetAmbientLightColorPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
139   DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetDiffuseLightColorPropertyName() ) ).Get<Vector3>(), testVector3, TEST_LOCATION );
140   DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetStatePropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
141   DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetLightingMultiplierPropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
142   DALI_TEST_EQUALS( effect.GetProperty( effect.GetPropertyIndex( effect.GetHeightScalePropertyName().c_str() ) ).Get<float>(), testFloat, TEST_LOCATION );
143
144   Vector3 normalizedVector3(testVector3);
145   normalizedVector3.Normalize();
146   DALI_TEST_EQUALS( effect2.GetProperty( effect2.GetPropertyIndex( effect2.GetFixedNormalPropertyName() ) ).Get<Vector3>(), normalizedVector3, TEST_LOCATION );
147   END_TEST;
148 }