Move more public-api headers to devel-api. PART 3
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-SpotEffect.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/spot-effect.h>
23
24
25 using namespace Dali;
26
27 void spot_effect_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void spot_effect_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37
38 int UtcDaliSpotUninitializedEffect(void)
39 {
40   ToolkitTestApplication application;
41
42   Toolkit::SpotEffect effect;
43
44   try
45   {
46     // New() must be called to create a SpotEffect or it wont be valid.
47     effect.SetRadius( 0.5f );
48     DALI_TEST_CHECK( false );
49   }
50   catch (Dali::DaliException& e)
51   {
52     // Tests that a negative test of an assertion succeeds
53     DALI_TEST_PRINT_ASSERT( e );
54     DALI_TEST_CHECK(!effect);
55   }
56   END_TEST;
57 }
58
59 int UtcDaliSpotPropertyNamesEffect(void)
60 {
61   ToolkitTestApplication application;
62
63   Toolkit::SpotEffect effect = Toolkit::SpotEffect::New();
64
65   // Check the names, this names are used in the shaders code,
66   // if they change the shader code has to be updated
67   DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
68   DALI_TEST_EQUALS( effect.GetRadiusPropertyName(), "uRadius", TEST_LOCATION );
69   END_TEST;
70 }
71
72 int UtcDaliSpotDefaultValuesEffect(void)
73 {
74   ToolkitTestApplication application;
75
76   Toolkit::SpotEffect effect = Toolkit::SpotEffect::New();
77   DALI_TEST_CHECK( effect );
78
79   BufferImage image = CreateBufferImage();
80
81   ImageActor actor = ImageActor::New( image );
82   actor.SetSize( 100.0f, 100.0f );
83   actor.SetShaderEffect( effect );
84   Stage::GetCurrent().Add( actor );
85
86   application.SendNotification();
87   application.Render();
88
89   // Gets converted to opengl viewport coordinates
90   DALI_TEST_CHECK(
91       application.GetGlAbstraction().CheckUniformValue(
92           effect.GetCenterPropertyName().c_str(),
93           Vector2(0.0f, 0.0f) ) );
94
95   DALI_TEST_CHECK(
96       application.GetGlAbstraction().CheckUniformValue(
97           effect.GetRadiusPropertyName().c_str(),
98           0.0f ) );
99   END_TEST;
100 }
101
102 int UtcDaliSpotCustomValuesEffect(void)
103 {
104   ToolkitTestApplication application;
105
106   Toolkit::SpotEffect effect = Toolkit::SpotEffect::New();
107   DALI_TEST_CHECK( effect );
108
109   BufferImage image = CreateBufferImage();
110
111   ImageActor actor = ImageActor::New( image );
112   actor.SetSize( 100.0f, 100.0f );
113
114   effect.SetCenter( Vector2(480.0f, 800.0f) );
115   effect.SetRadius( 5.0f );
116
117   actor.SetShaderEffect( effect );
118   Stage::GetCurrent().Add( actor );
119
120   application.SendNotification();
121   application.Render();
122
123   // Gets converted to opengl viewport coordinates
124   DALI_TEST_CHECK(
125       application.GetGlAbstraction().CheckUniformValue(
126           effect.GetCenterPropertyName().c_str(),
127           Vector2(480.0f, 800.0f) ) );
128
129   DALI_TEST_CHECK(
130       application.GetGlAbstraction().CheckUniformValue(
131           effect.GetRadiusPropertyName().c_str(),
132           5.0f ) );
133   END_TEST;
134 }