[dali_2.3.23] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-RenderTaskList.cpp
1 /*
2  * Copyright (c) 2020 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 <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
20 #include <stdlib.h>
21
22 #include <iostream>
23
24 using namespace Dali;
25
26 void utc_dali_render_task_list_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void utc_dali_render_task_list_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36 int UtcDaliRenderTaskListDefaultConstructor(void)
37 {
38   TestApplication application;
39
40   tet_infoline("Testing RenderTaskList::RenderTaskList()");
41
42   RenderTaskList taskList;
43
44   DALI_TEST_CHECK(!taskList);
45   END_TEST;
46 }
47
48 int UtcDaliRenderTaskListCopyConstructor(void)
49 {
50   TestApplication application;
51
52   tet_infoline("Testing RenderTaskList::RenderTaskList(const RenderTaskList& handle)");
53
54   RenderTaskList taskList1;
55
56   RenderTaskList taskList2(taskList1);
57
58   DALI_TEST_CHECK(!taskList2);
59   END_TEST;
60 }
61
62 int UtcDaliRenderTaskListAssignment(void)
63 {
64   TestApplication application;
65
66   tet_infoline("Testing RenderTaskList::RenderTaskList(const RenderTaskList& handle)");
67
68   RenderTaskList taskList1;
69
70   RenderTaskList taskList2;
71
72   taskList1 = taskList2;
73
74   DALI_TEST_CHECK(!taskList1);
75   END_TEST;
76 }
77
78 int UtcDaliRenderTaskListMoveConstructor(void)
79 {
80   TestApplication application;
81
82   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
83   DALI_TEST_CHECK(taskList);
84   DALI_TEST_EQUALS(2, taskList.GetBaseObject().ReferenceCount(), TEST_LOCATION);
85   DALI_TEST_CHECK(1u == taskList.GetTaskCount());
86
87   RenderTaskList move = std::move(taskList);
88   DALI_TEST_CHECK(move);
89   DALI_TEST_EQUALS(2, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
90   DALI_TEST_CHECK(1u == move.GetTaskCount());
91   DALI_TEST_CHECK(!taskList);
92
93   END_TEST;
94 }
95
96 int UtcDaliRenderTaskListMoveAssignment(void)
97 {
98   TestApplication application;
99
100   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
101   DALI_TEST_CHECK(taskList);
102   DALI_TEST_EQUALS(2, taskList.GetBaseObject().ReferenceCount(), TEST_LOCATION);
103   DALI_TEST_CHECK(1u == taskList.GetTaskCount());
104
105   RenderTaskList move;
106   move = std::move(taskList);
107   DALI_TEST_CHECK(move);
108   DALI_TEST_EQUALS(2, move.GetBaseObject().ReferenceCount(), TEST_LOCATION);
109   DALI_TEST_CHECK(1u == move.GetTaskCount());
110   DALI_TEST_CHECK(!taskList);
111
112   END_TEST;
113 }
114
115 int UtcDaliRenderTaskListDownCast(void)
116 {
117   TestApplication application;
118
119   tet_infoline("Testing RenderTaskList::DownCast()");
120
121   BaseHandle base = application.GetScene().GetRenderTaskList();
122
123   RenderTaskList taskList = RenderTaskList::DownCast(base);
124
125   DALI_TEST_CHECK(taskList);
126
127   // Try calling a method
128   DALI_TEST_CHECK(1u == taskList.GetTaskCount());
129   END_TEST;
130 }
131
132 int UtcDaliRenderTaskListCreateTask(void)
133 {
134   TestApplication application;
135
136   tet_infoline("Testing RenderTaskList::CreateTask()");
137
138   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
139   DALI_TEST_CHECK(1u == taskList.GetTaskCount());
140
141   taskList.CreateTask();
142   DALI_TEST_CHECK(2u == taskList.GetTaskCount());
143   END_TEST;
144 }
145
146 int UtcDaliRenderTaskListRemoveTask(void)
147 {
148   TestApplication application;
149
150   tet_infoline("Testing RenderTaskList::RemoveTask()");
151
152   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
153   DALI_TEST_CHECK(1u == taskList.GetTaskCount());
154
155   RenderTask newTask = taskList.CreateTask();
156   DALI_TEST_CHECK(2u == taskList.GetTaskCount());
157
158   taskList.RemoveTask(newTask);
159   DALI_TEST_CHECK(1u == taskList.GetTaskCount());
160   END_TEST;
161 }
162
163 int UtcDaliRenderTaskListRemoveTaskWithExclusiveActor(void)
164 {
165   TestApplication application;
166
167   tet_infoline("Testing RenderTaskList::RemoveTask() which has an exclusive actor set");
168
169   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
170   DALI_TEST_CHECK(1u == taskList.GetTaskCount());
171
172   RenderTask newTask = taskList.CreateTask();
173   DALI_TEST_CHECK(2u == taskList.GetTaskCount());
174
175   auto actor = CreateRenderableActor();
176   newTask.SetSourceActor(actor);
177   newTask.SetExclusive(true);
178   DALI_TEST_EQUALS(actor, newTask.GetSourceActor(), TEST_LOCATION);
179   DALI_TEST_EQUALS(true, newTask.IsExclusive(), TEST_LOCATION);
180   taskList.RemoveTask(newTask);
181
182   DALI_TEST_CHECK(1u == taskList.GetTaskCount());
183   END_TEST;
184 }
185
186 int UtcDaliRenderTaskListGetTaskCount(void)
187 {
188   TestApplication application;
189
190   tet_infoline("Testing RenderTaskList::GetTaskCount()");
191
192   RenderTaskList taskList = application.GetScene().GetRenderTaskList();
193   DALI_TEST_CHECK(1u == taskList.GetTaskCount());
194
195   taskList.RemoveTask(taskList.GetTask(0u));
196   DALI_TEST_CHECK(0u == taskList.GetTaskCount());
197   END_TEST;
198 }
199
200 int UtcDaliRenderTaskListGetTask(void)
201 {
202   TestApplication application;
203
204   tet_infoline("Testing RenderTaskList::GetTask()");
205
206   RenderTaskList taskList    = application.GetScene().GetRenderTaskList();
207   RenderTask     defaultTask = taskList.GetTask(0u);
208   DALI_TEST_CHECK(1u == taskList.GetTaskCount());
209   DALI_TEST_CHECK(defaultTask);
210   DALI_TEST_CHECK(defaultTask == taskList.GetTask(0u));
211
212   RenderTask newTask = taskList.CreateTask();
213   DALI_TEST_CHECK(2u == taskList.GetTaskCount());
214
215   RenderTask temp  = taskList.GetTask(0u);
216   RenderTask temp2 = taskList.GetTask(1u);
217
218   DALI_TEST_CHECK(newTask);
219   DALI_TEST_CHECK(defaultTask != newTask);
220   DALI_TEST_CHECK(taskList.GetTask(0u) == defaultTask);
221   DALI_TEST_CHECK(taskList.GetTask(1u) == newTask);
222   DALI_TEST_CHECK(taskList.GetTask(1u) != defaultTask);
223
224   taskList.RemoveTask(taskList.GetTask(0u));
225   DALI_TEST_CHECK(1u == taskList.GetTaskCount());
226   DALI_TEST_CHECK(taskList.GetTask(0u) != defaultTask);
227   DALI_TEST_CHECK(taskList.GetTask(0u) == newTask);
228   END_TEST;
229 }
230
231 int UtcDaliRenderTaskListCreateTaskNegative(void)
232 {
233   TestApplication      application;
234   Dali::RenderTaskList instance;
235   try
236   {
237     instance.CreateTask();
238     DALI_TEST_CHECK(false); // Should not get here
239   }
240   catch(...)
241   {
242     DALI_TEST_CHECK(true); // We expect an assert
243   }
244   END_TEST;
245 }
246
247 int UtcDaliRenderTaskListRemoveTaskNegative(void)
248 {
249   TestApplication      application;
250   Dali::RenderTaskList instance;
251   try
252   {
253     Dali::RenderTask arg1(application.GetScene().GetRenderTaskList().GetTask(0u));
254     instance.RemoveTask(arg1);
255     DALI_TEST_CHECK(false); // Should not get here
256   }
257   catch(...)
258   {
259     DALI_TEST_CHECK(true); // We expect an assert
260   }
261   END_TEST;
262 }
263
264 int UtcDaliRenderTaskListGetTaskCountNegative(void)
265 {
266   TestApplication      application;
267   Dali::RenderTaskList instance;
268   try
269   {
270     instance.GetTaskCount();
271     DALI_TEST_CHECK(false); // Should not get here
272   }
273   catch(...)
274   {
275     DALI_TEST_CHECK(true); // We expect an assert
276   }
277   END_TEST;
278 }
279
280 int UtcDaliRenderTaskListGetTaskNegative(void)
281 {
282   TestApplication      application;
283   Dali::RenderTaskList instance;
284   try
285   {
286     unsigned int arg1(0u);
287     instance.GetTask(arg1);
288     DALI_TEST_CHECK(false); // Should not get here
289   }
290   catch(...)
291   {
292     DALI_TEST_CHECK(true); // We expect an assert
293   }
294   END_TEST;
295 }