706b1ffd68d7e7bb6851b6487b90e64d2fdae678
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / shader-effects / utc-Dali-BloomView.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
19 #include <stdlib.h>
20 #include <tet_api.h>
21
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/dali-toolkit.h>
24
25 #include <dali-toolkit-test-suite-utils.h>
26
27 using namespace Dali;
28 using namespace Dali::Toolkit;
29
30 static void Startup();
31 static void Cleanup();
32
33 extern "C" {
34   void (*tet_startup)() = Startup;
35   void (*tet_cleanup)() = Cleanup;
36 }
37
38 static void UtcDaliBloomViewUninitialized();
39 static void UtcDaliBloomViewNew();
40 static void UtcDaliBloomViewDownCast();
41 static void UtcDaliBloomViewPropertyNames();
42 static void UtcDaliBloomViewAddRemove();
43 static void UtcDaliBloomActivateDeactivate();
44
45 enum {
46   POSITIVE_TC_IDX = 0x01,
47   NEGATIVE_TC_IDX,
48 };
49
50 // Add test functionality for all APIs in the class (Positive and Negative)
51 extern "C" {
52   struct tet_testlist tet_testlist[] = {
53     { UtcDaliBloomViewUninitialized, NEGATIVE_TC_IDX },
54     { UtcDaliBloomViewNew, POSITIVE_TC_IDX },
55     { UtcDaliBloomViewDownCast, POSITIVE_TC_IDX },
56     { UtcDaliBloomViewPropertyNames, POSITIVE_TC_IDX },
57     { UtcDaliBloomViewAddRemove, POSITIVE_TC_IDX },
58     { UtcDaliBloomActivateDeactivate, POSITIVE_TC_IDX },
59     { NULL, 0 }
60   };
61 }
62
63 // Called only once before first test is run.
64 static void Startup()
65 {
66 }
67
68 // Called only once after last test is run
69 static void Cleanup()
70 {
71 }
72
73 // Negative test case for a method
74 static void UtcDaliBloomViewUninitialized()
75 {
76   ToolkitTestApplication application;
77   tet_infoline(" UtcDaliBloomViewUninitialized");
78
79   Toolkit::BloomView view;
80
81   try
82   {
83     // New() must be called to create a BloomView or it wont be valid.
84     Actor a = Actor::New();
85     view.Add( a );
86     DALI_TEST_CHECK( false );
87   }
88   catch (Dali::DaliException& e)
89   {
90     // Tests that a negative test of an assertion succeeds
91     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
92     DALI_TEST_CHECK(!view);
93   }
94 }
95
96 // Positive test case for a method
97 static void UtcDaliBloomViewNew()
98 {
99   ToolkitTestApplication application;
100   tet_infoline(" UtcDaliBloomViewNew");
101
102   Toolkit::BloomView view = Toolkit::BloomView::New();
103   DALI_TEST_CHECK( view );
104
105   Toolkit::BloomView view2 = Toolkit::BloomView::New(10, 1.0f, Pixel::RGB888, 0.5f, 0.5f);
106   DALI_TEST_CHECK( view2 );
107 }
108
109 // Positive test case for a method
110 static void UtcDaliBloomViewDownCast()
111 {
112   ToolkitTestApplication application;
113   tet_infoline(" UtcDaliBloomViewDownCast");
114
115   Toolkit::BloomView view = Toolkit::BloomView::New();
116   BaseHandle handle(view);
117
118   Toolkit::BloomView bloomView = Toolkit::BloomView::DownCast( handle );
119   DALI_TEST_CHECK( view );
120   DALI_TEST_CHECK( bloomView );
121   DALI_TEST_CHECK( bloomView == view );
122 }
123
124
125 // Positive test case for a method
126 static void UtcDaliBloomViewPropertyNames()
127 {
128   ToolkitTestApplication application;
129   tet_infoline(" UtcDaliBloomViewPropertyNames");
130
131   Toolkit::BloomView view = Toolkit::BloomView::New();
132   DALI_TEST_CHECK( view );
133
134   // Check the names, this names are used in the shader code,
135   // if they change in the shader code, then it has to be updated here.
136   DALI_TEST_EQUALS( view.GetBloomThresholdPropertyIndex(), view.GetPropertyIndex("uBloomThreshold"), TEST_LOCATION );
137   DALI_TEST_EQUALS( view.GetBlurStrengthPropertyIndex(), view.GetPropertyIndex("BlurStrengthProperty"), TEST_LOCATION );
138   DALI_TEST_EQUALS( view.GetBloomIntensityPropertyIndex(), view.GetPropertyIndex("uBloomIntensity"), TEST_LOCATION );
139   DALI_TEST_EQUALS( view.GetBloomSaturationPropertyIndex(), view.GetPropertyIndex("uBloomSaturation"), TEST_LOCATION );
140   DALI_TEST_EQUALS( view.GetImageIntensityPropertyIndex(), view.GetPropertyIndex("uImageIntensity"), TEST_LOCATION );
141   DALI_TEST_EQUALS( view.GetImageSaturationPropertyIndex(), view.GetPropertyIndex("uImageSaturation"), TEST_LOCATION );
142 }
143
144 // Positive test case for a method
145 static void UtcDaliBloomViewAddRemove()
146 {
147   ToolkitTestApplication application;
148   tet_infoline(" UtcDaliBloomViewAddRemove");
149
150   Toolkit::BloomView view = Toolkit::BloomView::New();
151   DALI_TEST_CHECK( view );
152
153   Actor actor = Actor::New();
154   DALI_TEST_CHECK( !actor.OnStage() );
155
156
157   view.SetParentOrigin(ParentOrigin::CENTER);
158   view.SetSize(Stage::GetCurrent().GetSize());
159   view.Add(actor);
160   Stage::GetCurrent().Add(view);
161
162   DALI_TEST_CHECK( actor.OnStage() );
163
164   view.Remove(actor);
165
166   DALI_TEST_CHECK( !actor.OnStage() );
167 }
168
169 // Positive test case for a method
170 static void UtcDaliBloomActivateDeactivate()
171 {
172   ToolkitTestApplication application;
173   tet_infoline(" UtcDaliBloomActivateDeactivate");
174
175   Toolkit::BloomView view = Toolkit::BloomView::New();
176   DALI_TEST_CHECK( view );
177
178   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
179   DALI_TEST_CHECK( 1u == taskList.GetTaskCount() );
180
181   view.SetParentOrigin(ParentOrigin::CENTER);
182   view.SetSize(Stage::GetCurrent().GetSize());
183   view.Add(Actor::New());
184   Stage::GetCurrent().Add(view);
185   view.Activate();
186
187   RenderTaskList taskList2 = Stage::GetCurrent().GetRenderTaskList();
188   DALI_TEST_CHECK( 1u != taskList2.GetTaskCount() );
189
190   view.Deactivate();
191
192   RenderTaskList taskList3 = Stage::GetCurrent().GetRenderTaskList();
193   DALI_TEST_CHECK( 1u == taskList3.GetTaskCount() );
194 }