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