Conversion to Apache 2.0 license
[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 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 using namespace Dali;
29
30 void utc_dali_toolkit_iris_effect_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_toolkit_iris_effect_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40
41 int UtcDaliIrisEffectUninitialized(void)
42 {
43   ToolkitTestApplication application;
44
45   Toolkit::IrisEffect effect;
46
47   try
48   {
49     // New() must be called to create a IrisEffect or it wont be valid.
50     effect.SetRadius( 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 UtcDaliIrisEffectPropertyNames(void)
63 {
64   ToolkitTestApplication application;
65
66   Toolkit::IrisEffect effect = Toolkit::IrisEffect::New();
67
68   // Check the names, this names are used in the shaders code,
69   // if they change the shader code has to be updated
70   DALI_TEST_EQUALS( effect.GetRadiusPropertyName(), "uRadius", TEST_LOCATION );
71   DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
72   DALI_TEST_EQUALS( effect.GetBlendFactorPropertyName(), "uBlendFactor", TEST_LOCATION );
73   END_TEST;
74 }
75
76 int UtcDaliIrisEffectDefaultValues(void)
77 {
78   ToolkitTestApplication application;
79
80   Toolkit::IrisEffect effect = Toolkit::IrisEffect::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
88   const float radiusValue(0.0f);
89   const Vector2 centerValue(0.5f, 0.5f);
90   const float blendFactorValue(100.0f);
91
92   actor.SetShaderEffect( effect );
93   Stage::GetCurrent().Add( actor );
94
95   application.SendNotification();
96   application.Render();
97
98   TestGlAbstraction& gl = application.GetGlAbstraction();
99   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetRadiusPropertyName().c_str(), radiusValue ) );
100   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), centerValue ) );
101   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetBlendFactorPropertyName().c_str(), blendFactorValue ) );
102   END_TEST;
103 }
104
105 int UtcDaliIrisEffectCustomValues(void)
106 {
107   ToolkitTestApplication application;
108
109   Toolkit::IrisEffect effect = Toolkit::IrisEffect::New();
110   DALI_TEST_CHECK( effect );
111
112   BitmapImage image = CreateBitmapImage();
113
114   ImageActor actor = ImageActor::New( image );
115   actor.SetSize( 100.0f, 100.0f );
116
117   const float radiusValue(23.0f);
118   const Vector2 centerValue(0.2f, 0.7f);
119   const float blendFactorValue(10.0f);
120
121   effect.SetRadius( radiusValue );
122   effect.SetCenter( centerValue );
123   effect.SetBlendFactor( blendFactorValue );
124
125   actor.SetShaderEffect(effect);
126   Stage::GetCurrent().Add(actor);
127
128   application.SendNotification();
129   application.Render();
130
131   TestGlAbstraction& gl = application.GetGlAbstraction();
132   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetRadiusPropertyName().c_str(), radiusValue ) );
133   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), centerValue ) );
134   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetBlendFactorPropertyName().c_str(), blendFactorValue ) );
135   END_TEST;
136 }