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