Merge "Minor fixes for Text." into devel/master
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-DissolveEffect.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
21 // Need to override adaptor classes for toolkit test harness, so include
22 // test harness headers before dali headers.
23 #include <dali-toolkit-test-suite-utils.h>
24
25 #include <dali.h>
26 #include <dali-toolkit/dali-toolkit.h>
27 #include <dali-toolkit/devel-api/shader-effects/dissolve-effect.h>
28
29
30 using namespace Dali;
31
32 void utc_dali_toolkit_dissolve_effect_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void utc_dali_toolkit_dissolve_effect_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42
43 int UtcDaliDissolveUninitializedEffect(void)
44 {
45   ToolkitTestApplication application;
46
47   Toolkit::DissolveEffect effect;
48
49   try
50   {
51     // New() must be called to create a DissolveEffect or it wont be valid.
52     effect.SetDistortion( 2.0f );
53     DALI_TEST_CHECK( false );
54   }
55   catch (Dali::DaliException& e)
56   {
57     // Tests that a negative test of an assertion succeeds
58     DALI_TEST_PRINT_ASSERT( e );
59     DALI_TEST_CHECK(!effect);
60   }
61   END_TEST;
62 }
63
64 int UtcDaliDissolvePropertyNamesEffect(void)
65 {
66   ToolkitTestApplication application;
67
68   Toolkit::DissolveEffect effectHighPrecision = Toolkit::DissolveEffect::New();
69   Toolkit::DissolveEffect effectMediumPrecision = Toolkit::DissolveEffect::New( false );
70
71   // Check the names, this names are used in the shaders code,
72   // if they change the shader code has to be updated
73   DALI_TEST_EQUALS( effectHighPrecision.GetDistortionPropertyName(), "uPercentage", TEST_LOCATION );
74   DALI_TEST_EQUALS( effectMediumPrecision.GetDistortionPropertyName(), "uPercentage", TEST_LOCATION );
75   END_TEST;
76 }
77
78 int UtcDaliDissolveDefaultValuesEffect(void)
79 {
80   ToolkitTestApplication application;
81
82   Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
83   DALI_TEST_CHECK( effect );
84
85   BufferImage image = CreateBufferImage();
86
87   ImageActor actor = ImageActor::New( image );
88   actor.SetSize( 100.0f, 100.0f );
89   actor.SetShaderEffect( effect );
90   effect.SetCentralLine( Vector2(0.0,0.5), Vector2(1.0, -0.1) );
91   Stage::GetCurrent().Add( actor );
92
93   application.SendNotification();
94   application.Render();
95
96   Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
97   float value;
98   (effect.GetProperty(index)).Get( value );
99   DALI_TEST_EQUALS(value, 0.f, TEST_LOCATION );
100   END_TEST;
101 }
102
103 int UtcDaliDissolveCustomValuesEffect(void)
104 {
105   ToolkitTestApplication application;
106
107   Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
108   DALI_TEST_CHECK( effect );
109
110   BufferImage image = CreateBufferImage();
111
112   ImageActor actor = ImageActor::New( image );
113   actor.SetSize( 100.0f, 100.0f );
114
115   effect.SetDistortion( 0.5f );
116
117   actor.SetShaderEffect(effect);
118   Stage::GetCurrent().Add(actor);
119
120   application.SendNotification();
121   application.Render();
122
123   Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
124   float value;
125   (effect.GetProperty(index)).Get( value );
126   DALI_TEST_EQUALS(value, 0.5f, TEST_LOCATION );
127   END_TEST;
128 }
129
130 int UtcDaliSetEffectImageEffect(void)
131 {
132   ToolkitTestApplication application;
133
134   Toolkit::DissolveEffect effect = Toolkit::DissolveEffect::New();
135   DALI_TEST_CHECK( effect );
136
137   Image effectImage = CreateBufferImage();
138   effect.SetEffectImage(effectImage);
139
140   BufferImage image = CreateBufferImage();
141
142   ImageActor actor = ImageActor::New( image );
143   actor.SetSize( 100.0f, 100.0f );
144   actor.SetShaderEffect( effect );
145   Stage::GetCurrent().Add( actor );
146
147   application.SendNotification();
148   application.Render();
149
150   Property::Index index = effect.GetPropertyIndex( effect.GetDistortionPropertyName());
151   float value;
152   (effect.GetProperty(index)).Get( value );
153   DALI_TEST_EQUALS(value, 0.f, TEST_LOCATION );
154   END_TEST;
155 }