Revert "[Tizen] Appendix log for ttrace + Print keycode and timestamp"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Processors.cpp
1 /*
2  * Copyright (c) 2022 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/integration-api/core.h>
20 #include <dali/integration-api/processor-interface.h>
21 #include <dali/public-api/dali-core.h>
22 #include <stdlib.h>
23
24 using namespace Dali;
25
26 class TestProcessor : public Integration::Processor
27 {
28 public:
29   TestProcessor()
30   : processRun(false)
31   {
32   }
33
34   virtual void Process(bool postProcessor)
35   {
36     processRun = true;
37   }
38
39   bool processRun;
40 };
41
42 class NewTestProcessor : public TestProcessor
43 {
44 public:
45   NewTestProcessor(Integration::Core& core)
46   : core(core)
47   {
48   }
49
50   virtual void Process(bool postProcessor)
51   {
52     processRun = true;
53     if(unregisterProcessor)
54     {
55       core.UnregisterProcessor(*unregisterProcessor, postProcessor);
56     }
57   }
58
59   void SetProcessorToUnregister(Integration::Processor* processor)
60   {
61     unregisterProcessor = processor;
62   }
63
64   Integration::Processor* unregisterProcessor{nullptr};
65   Integration::Core&      core;
66 };
67
68 int UtcDaliCoreProcessorP(void)
69 {
70   TestApplication application;
71
72   TestProcessor      testProcessor;
73   Integration::Core& core = application.GetCore();
74   core.RegisterProcessor(testProcessor);
75
76   tet_infoline("Test that the processor has not been executed yet:");
77   DALI_TEST_CHECK(testProcessor.processRun == false);
78
79   application.SendNotification();
80
81   tet_infoline("Test that the processor has been executed:");
82   DALI_TEST_CHECK(testProcessor.processRun);
83
84   // Clear down for next part of test
85   testProcessor.processRun = false;
86
87   core.UnregisterProcessor(testProcessor);
88   application.SendNotification();
89   tet_infoline("Test that the processor has not been executed again:");
90   DALI_TEST_CHECK(testProcessor.processRun == false);
91
92   END_TEST;
93 }
94
95 int UtcDaliCoreProcessorMultipleP(void)
96 {
97   TestApplication application;
98
99   TestProcessor testProcessor1;
100   TestProcessor testProcessor2;
101   TestProcessor testProcessor3;
102
103   Integration::Core& core = application.GetCore();
104   core.RegisterProcessor(testProcessor1);
105
106   tet_infoline("Test that the processor has not been executed yet:");
107   DALI_TEST_CHECK(testProcessor1.processRun == false);
108
109   application.SendNotification();
110
111   tet_infoline("Test that the processor has been executed:");
112   DALI_TEST_CHECK(testProcessor1.processRun);
113
114   // Clear down for next part of test
115   testProcessor1.processRun = false;
116
117   core.RegisterProcessor(testProcessor2);
118   core.RegisterProcessor(testProcessor3);
119
120   tet_infoline("Test that the processors have not been executed yet:");
121   DALI_TEST_CHECK(testProcessor1.processRun == false);
122   DALI_TEST_CHECK(testProcessor2.processRun == false);
123   DALI_TEST_CHECK(testProcessor3.processRun == false);
124
125   application.SendNotification();
126
127   tet_infoline("Test that the processors have been executed:");
128   DALI_TEST_CHECK(testProcessor1.processRun);
129   DALI_TEST_CHECK(testProcessor2.processRun);
130   DALI_TEST_CHECK(testProcessor3.processRun);
131
132   // Clear down for next part of test
133   testProcessor2.processRun = false;
134
135   core.UnregisterProcessor(testProcessor2);
136   application.SendNotification();
137   tet_infoline("Test that the unregistered processor has not been executed again but others have");
138   DALI_TEST_CHECK(testProcessor1.processRun);
139   DALI_TEST_CHECK(testProcessor2.processRun == false);
140   DALI_TEST_CHECK(testProcessor3.processRun);
141
142   END_TEST;
143 }
144
145 int UtcDaliCorePostProcessorP(void)
146 {
147   TestApplication application;
148
149   TestProcessor      testProcessor;
150   Integration::Core& core = application.GetCore();
151   core.RegisterProcessor(testProcessor, true);
152
153   tet_infoline("Test that the processor has not been executed yet:");
154   DALI_TEST_CHECK(testProcessor.processRun == false);
155
156   application.SendNotification();
157
158   tet_infoline("Test that the processor has been executed:");
159   DALI_TEST_CHECK(testProcessor.processRun);
160
161   // Clear down for next part of test
162   testProcessor.processRun = false;
163
164   core.UnregisterProcessor(testProcessor);
165   application.SendNotification();
166   tet_infoline("Test that the processor is still executed:");
167   DALI_TEST_CHECK(testProcessor.processRun);
168
169   // Clear down for next part of test
170   testProcessor.processRun = false;
171
172   core.UnregisterProcessor(testProcessor, true);
173   application.SendNotification();
174   tet_infoline("Test that the processor has not been executed again:");
175   DALI_TEST_CHECK(testProcessor.processRun == false);
176
177   END_TEST;
178 }
179
180 int UtcDaliCoreProcessorUnregisterDuringCallback01(void)
181 {
182   // Test pre-processor
183   TestApplication    application;
184   Integration::Core& core = application.GetCore();
185
186   NewTestProcessor testProcessor1(core);
187   TestProcessor    testProcessor2;
188   TestProcessor    testProcessor3;
189
190   core.RegisterProcessor(testProcessor1);
191   core.RegisterProcessor(testProcessor2);
192   core.RegisterProcessor(testProcessor3);
193
194   DALI_TEST_CHECK(testProcessor1.processRun == false);
195   DALI_TEST_CHECK(testProcessor2.processRun == false);
196   DALI_TEST_CHECK(testProcessor3.processRun == false);
197
198   application.SendNotification();
199
200   tet_infoline("Test that the processors have been executed:");
201   DALI_TEST_CHECK(testProcessor1.processRun);
202   DALI_TEST_CHECK(testProcessor2.processRun);
203   DALI_TEST_CHECK(testProcessor3.processRun);
204
205   // Clear down for next part of test
206   testProcessor1.processRun = false;
207   testProcessor2.processRun = false;
208   testProcessor3.processRun = false;
209
210   testProcessor1.SetProcessorToUnregister(&testProcessor3);
211
212   tet_infoline("Test that the processor unregistered during the callback has not been executed");
213   application.SendNotification();
214
215   DALI_TEST_CHECK(testProcessor1.processRun);
216   DALI_TEST_CHECK(testProcessor2.processRun);
217   DALI_TEST_CHECK(!testProcessor3.processRun);
218
219   END_TEST;
220 }
221
222 int UtcDaliCoreProcessorUnregisterDuringCallback02(void)
223 {
224   // Test post-processor
225   TestApplication    application;
226   Integration::Core& core = application.GetCore();
227
228   NewTestProcessor testProcessor1(core);
229   TestProcessor    testProcessor2;
230   TestProcessor    testProcessor3;
231
232   core.RegisterProcessor(testProcessor1, true);
233   core.RegisterProcessor(testProcessor2, true);
234   core.RegisterProcessor(testProcessor3, true);
235
236   DALI_TEST_CHECK(testProcessor1.processRun == false);
237   DALI_TEST_CHECK(testProcessor2.processRun == false);
238   DALI_TEST_CHECK(testProcessor3.processRun == false);
239
240   application.SendNotification();
241
242   tet_infoline("Test that the processors have been executed:");
243   DALI_TEST_CHECK(testProcessor1.processRun);
244   DALI_TEST_CHECK(testProcessor2.processRun);
245   DALI_TEST_CHECK(testProcessor3.processRun);
246
247   // Clear down for next part of test
248   testProcessor1.processRun = false;
249   testProcessor2.processRun = false;
250   testProcessor3.processRun = false;
251
252   testProcessor1.SetProcessorToUnregister(&testProcessor3);
253
254   tet_infoline("Test that the processor unregistered during the callback has not been executed");
255   application.SendNotification();
256
257   DALI_TEST_CHECK(testProcessor1.processRun);
258   DALI_TEST_CHECK(testProcessor2.processRun);
259   DALI_TEST_CHECK(!testProcessor3.processRun);
260
261   END_TEST;
262 }