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