UTC Builder coverage
[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 #include <dali-toolkit/devel-api/shader-effects/swirl-effect.h>
28
29
30 using namespace Dali;
31
32
33 void utc_dali_toolkit_swirl_effect_startup(void)
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void utc_dali_toolkit_swirl_effect_cleanup(void)
39 {
40   test_return_value = TET_PASS;
41 }
42
43 int UtcDaliSwirlUninitializedEffect(void)
44 {
45   ToolkitTestApplication application;
46
47   Toolkit::SwirlEffect effect;
48
49   try
50   {
51     // New() must be called to create a SwirlEffect or it wont be valid.
52     effect.SetRadius( 0.5f );
53     DALI_TEST_CHECK( false );
54   }
55   catch (Dali::DaliException& e)
56   {
57     // Tests that a negative test of an assertion succeeds
58     DALI_TEST_PRINT_ASSERT( e );
59     DALI_TEST_CHECK(!effect);
60   }
61   END_TEST;
62 }
63
64 int UtcDaliSwirlPropertyNamesEffect(void)
65 {
66   ToolkitTestApplication application;
67
68   Toolkit::SwirlEffect effect = Toolkit::SwirlEffect::New(false);
69
70   // Check the names, this names are used in the shaders code,
71   // if they change the shader code has to be updated
72   DALI_TEST_EQUALS( effect.GetAnglePropertyName(), "uAngle", TEST_LOCATION );
73   DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
74   DALI_TEST_EQUALS( effect.GetRadiusPropertyName(), "uRadius", TEST_LOCATION );
75   END_TEST;
76 }
77
78 int UtcDaliSwirlDefaultValuesEffect(void)
79 {
80   ToolkitTestApplication application;
81
82   Toolkit::SwirlEffect effect = Toolkit::SwirlEffect::New(true);
83   DALI_TEST_CHECK( effect );
84
85   BufferImage image = CreateBufferImage();
86
87   ImageActor actor = ImageActor::New( image );
88   actor.SetSize( 100.0f, 100.0f );
89   actor.SetShaderEffect( effect );
90   Stage::GetCurrent().Add( actor );
91
92   application.SendNotification();
93   application.Render();
94
95   // Gets converted to opengl viewport coordinates
96   DALI_TEST_CHECK(
97       application.GetGlAbstraction().CheckUniformValue(
98           effect.GetAnglePropertyName().c_str(),
99           0.0f ) );
100
101   DALI_TEST_CHECK(
102       application.GetGlAbstraction().CheckUniformValue(
103           effect.GetCenterPropertyName().c_str(),
104           Vector2(0.5f, 0.5f) ) );
105
106   DALI_TEST_CHECK(
107       application.GetGlAbstraction().CheckUniformValue(
108           effect.GetRadiusPropertyName().c_str(),
109           1.0f ) );
110   END_TEST;
111 }
112
113 int UtcDaliSwirlCustomValuesEffect(void)
114 {
115   ToolkitTestApplication application;
116
117   Toolkit::SwirlEffect effect = Toolkit::SwirlEffect::New(false);
118   DALI_TEST_CHECK( effect );
119
120   BufferImage image = CreateBufferImage();
121
122   ImageActor actor = ImageActor::New( image );
123   actor.SetSize( 100.0f, 100.0f );
124
125   effect.SetAngle( 1.0f );
126   effect.SetCenter( Vector2(0.3f, 0.7f) );
127   effect.SetRadius( 2.0f );
128
129   actor.SetShaderEffect( effect );
130   Stage::GetCurrent().Add( actor );
131
132   application.SendNotification();
133   application.Render();
134
135   // Gets converted to opengl viewport coordinates
136   DALI_TEST_CHECK(
137       application.GetGlAbstraction().CheckUniformValue(
138           effect.GetAnglePropertyName().c_str(),
139           1.0f ) );
140
141   DALI_TEST_CHECK(
142       application.GetGlAbstraction().CheckUniformValue(
143           effect.GetCenterPropertyName().c_str(),
144           Vector2(0.3f, 0.7f) ) );
145
146   DALI_TEST_CHECK(
147       application.GetGlAbstraction().CheckUniformValue(
148           effect.GetRadiusPropertyName().c_str(),
149           2.0f ) );
150   END_TEST;
151 }