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