41436d643402127ae50e852600d260efee7af051
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-SwirlEffect.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
31 void utc_dali_toolkit_swirl_effect_startup(void)
32 {
33   test_return_value = TET_UNDEF;
34 }
35
36 void utc_dali_toolkit_swirl_effect_cleanup(void)
37 {
38   test_return_value = TET_PASS;
39 }
40
41 int UtcDaliSwirlUninitializedEffect(void)
42 {
43   ToolkitTestApplication application;
44
45   Toolkit::SwirlEffect effect;
46
47   try
48   {
49     // New() must be called to create a SwirlEffect or it wont be valid.
50     effect.SetRadius( 0.5f );
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 UtcDaliSwirlPropertyNamesEffect(void)
63 {
64   ToolkitTestApplication application;
65
66   Toolkit::SwirlEffect effect = Toolkit::SwirlEffect::New(false);
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.GetAnglePropertyName(), "uAngle", TEST_LOCATION );
71   DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
72   DALI_TEST_EQUALS( effect.GetRadiusPropertyName(), "uRadius", TEST_LOCATION );
73   END_TEST;
74 }
75
76 int UtcDaliSwirlDefaultValuesEffect(void)
77 {
78   ToolkitTestApplication application;
79
80   Toolkit::SwirlEffect effect = Toolkit::SwirlEffect::New(true);
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   Stage::GetCurrent().Add( actor );
89
90   application.SendNotification();
91   application.Render();
92
93   // Gets converted to opengl viewport coordinates
94   DALI_TEST_CHECK(
95       application.GetGlAbstraction().CheckUniformValue(
96           effect.GetAnglePropertyName().c_str(),
97           0.0f ) );
98
99   DALI_TEST_CHECK(
100       application.GetGlAbstraction().CheckUniformValue(
101           effect.GetCenterPropertyName().c_str(),
102           Vector2(0.5f, 0.5f) ) );
103
104   DALI_TEST_CHECK(
105       application.GetGlAbstraction().CheckUniformValue(
106           effect.GetRadiusPropertyName().c_str(),
107           1.0f ) );
108   END_TEST;
109 }
110
111 int UtcDaliSwirlCustomValuesEffect(void)
112 {
113   ToolkitTestApplication application;
114
115   Toolkit::SwirlEffect effect = Toolkit::SwirlEffect::New(false);
116   DALI_TEST_CHECK( effect );
117
118   BitmapImage image = CreateBitmapImage();
119
120   ImageActor actor = ImageActor::New( image );
121   actor.SetSize( 100.0f, 100.0f );
122
123   effect.SetAngle( 1.0f );
124   effect.SetCenter( Vector2(0.3f, 0.7f) );
125   effect.SetRadius( 2.0f );
126
127   actor.SetShaderEffect( effect );
128   Stage::GetCurrent().Add( actor );
129
130   application.SendNotification();
131   application.Render();
132
133   // Gets converted to opengl viewport coordinates
134   DALI_TEST_CHECK(
135       application.GetGlAbstraction().CheckUniformValue(
136           effect.GetAnglePropertyName().c_str(),
137           1.0f ) );
138
139   DALI_TEST_CHECK(
140       application.GetGlAbstraction().CheckUniformValue(
141           effect.GetCenterPropertyName().c_str(),
142           Vector2(0.3f, 0.7f) ) );
143
144   DALI_TEST_CHECK(
145       application.GetGlAbstraction().CheckUniformValue(
146           effect.GetRadiusPropertyName().c_str(),
147           2.0f ) );
148   END_TEST;
149 }