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