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