Revert "License conversion from Flora to Apache 2.0"
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-IrisEffect.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 using namespace Dali;
28
29 void utc_dali_toolkit_iris_effect_startup(void)
30 {
31   test_return_value = TET_UNDEF;
32 }
33
34 void utc_dali_toolkit_iris_effect_cleanup(void)
35 {
36   test_return_value = TET_PASS;
37 }
38
39
40 int UtcDaliIrisEffectUninitialized(void)
41 {
42   ToolkitTestApplication application;
43
44   Toolkit::IrisEffect effect;
45
46   try
47   {
48     // New() must be called to create a IrisEffect or it wont be valid.
49     effect.SetRadius( 2.0f );
50     DALI_TEST_CHECK( false );
51   }
52   catch (Dali::DaliException& e)
53   {
54     // Tests that a negative test of an assertion succeeds
55     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
56     DALI_TEST_CHECK(!effect);
57   }
58   END_TEST;
59 }
60
61 int UtcDaliIrisEffectPropertyNames(void)
62 {
63   ToolkitTestApplication application;
64
65   Toolkit::IrisEffect effect = Toolkit::IrisEffect::New();
66
67   // Check the names, this names are used in the shaders code,
68   // if they change the shader code has to be updated
69   DALI_TEST_EQUALS( effect.GetRadiusPropertyName(), "uRadius", TEST_LOCATION );
70   DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
71   DALI_TEST_EQUALS( effect.GetBlendFactorPropertyName(), "uBlendFactor", TEST_LOCATION );
72   END_TEST;
73 }
74
75 int UtcDaliIrisEffectDefaultValues(void)
76 {
77   ToolkitTestApplication application;
78
79   Toolkit::IrisEffect effect = Toolkit::IrisEffect::New();
80   DALI_TEST_CHECK( effect );
81
82   BitmapImage image = CreateBitmapImage();
83
84   ImageActor actor = ImageActor::New( image );
85   actor.SetSize( 100.0f, 100.0f );
86
87   const float radiusValue(0.0f);
88   const Vector2 centerValue(0.5f, 0.5f);
89   const float blendFactorValue(100.0f);
90
91   actor.SetShaderEffect( effect );
92   Stage::GetCurrent().Add( actor );
93
94   application.SendNotification();
95   application.Render();
96
97   TestGlAbstraction& gl = application.GetGlAbstraction();
98   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetRadiusPropertyName().c_str(), radiusValue ) );
99   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), centerValue ) );
100   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetBlendFactorPropertyName().c_str(), blendFactorValue ) );
101   END_TEST;
102 }
103
104 int UtcDaliIrisEffectCustomValues(void)
105 {
106   ToolkitTestApplication application;
107
108   Toolkit::IrisEffect effect = Toolkit::IrisEffect::New();
109   DALI_TEST_CHECK( effect );
110
111   BitmapImage image = CreateBitmapImage();
112
113   ImageActor actor = ImageActor::New( image );
114   actor.SetSize( 100.0f, 100.0f );
115
116   const float radiusValue(23.0f);
117   const Vector2 centerValue(0.2f, 0.7f);
118   const float blendFactorValue(10.0f);
119
120   effect.SetRadius( radiusValue );
121   effect.SetCenter( centerValue );
122   effect.SetBlendFactor( blendFactorValue );
123
124   actor.SetShaderEffect(effect);
125   Stage::GetCurrent().Add(actor);
126
127   application.SendNotification();
128   application.Render();
129
130   TestGlAbstraction& gl = application.GetGlAbstraction();
131   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetRadiusPropertyName().c_str(), radiusValue ) );
132   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), centerValue ) );
133   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetBlendFactorPropertyName().c_str(), blendFactorValue ) );
134   END_TEST;
135 }