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