2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
26 class TestProcessor : public Integration::Processor
34 virtual void Process(bool postProcessor)
42 class NewTestProcessor : public TestProcessor
45 NewTestProcessor(Integration::Core& core)
50 virtual void Process(bool postProcessor)
53 if(unregisterProcessor)
55 core.UnregisterProcessor(*unregisterProcessor, postProcessor);
59 void SetProcessorToUnregister(Integration::Processor* processor)
61 unregisterProcessor = processor;
64 Integration::Processor* unregisterProcessor{nullptr};
65 Integration::Core& core;
68 int UtcDaliCoreProcessorP(void)
70 TestApplication application;
72 TestProcessor testProcessor;
73 Integration::Core& core = application.GetCore();
74 core.RegisterProcessor(testProcessor);
76 tet_infoline("Test that the processor has not been executed yet:");
77 DALI_TEST_CHECK(testProcessor.processRun == false);
79 application.SendNotification();
81 tet_infoline("Test that the processor has been executed:");
82 DALI_TEST_CHECK(testProcessor.processRun);
84 // Clear down for next part of test
85 testProcessor.processRun = false;
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);
95 int UtcDaliCoreProcessorMultipleP(void)
97 TestApplication application;
99 TestProcessor testProcessor1;
100 TestProcessor testProcessor2;
101 TestProcessor testProcessor3;
103 Integration::Core& core = application.GetCore();
104 core.RegisterProcessor(testProcessor1);
106 tet_infoline("Test that the processor has not been executed yet:");
107 DALI_TEST_CHECK(testProcessor1.processRun == false);
109 application.SendNotification();
111 tet_infoline("Test that the processor has been executed:");
112 DALI_TEST_CHECK(testProcessor1.processRun);
114 // Clear down for next part of test
115 testProcessor1.processRun = false;
117 core.RegisterProcessor(testProcessor2);
118 core.RegisterProcessor(testProcessor3);
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);
125 application.SendNotification();
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);
132 // Clear down for next part of test
133 testProcessor2.processRun = false;
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);
145 int UtcDaliCorePostProcessorP(void)
147 TestApplication application;
149 TestProcessor testProcessor;
150 Integration::Core& core = application.GetCore();
151 core.RegisterProcessor(testProcessor, true);
153 tet_infoline("Test that the processor has not been executed yet:");
154 DALI_TEST_CHECK(testProcessor.processRun == false);
156 application.SendNotification();
158 tet_infoline("Test that the processor has been executed:");
159 DALI_TEST_CHECK(testProcessor.processRun);
161 // Clear down for next part of test
162 testProcessor.processRun = false;
164 core.UnregisterProcessor(testProcessor);
165 application.SendNotification();
166 tet_infoline("Test that the processor is still executed:");
167 DALI_TEST_CHECK(testProcessor.processRun);
169 // Clear down for next part of test
170 testProcessor.processRun = false;
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);
180 int UtcDaliCoreProcessorUnregisterDuringCallback01(void)
182 // Test pre-processor
183 TestApplication application;
184 Integration::Core& core = application.GetCore();
186 NewTestProcessor testProcessor1(core);
187 TestProcessor testProcessor2;
188 TestProcessor testProcessor3;
190 core.RegisterProcessor(testProcessor1);
191 core.RegisterProcessor(testProcessor2);
192 core.RegisterProcessor(testProcessor3);
194 DALI_TEST_CHECK(testProcessor1.processRun == false);
195 DALI_TEST_CHECK(testProcessor2.processRun == false);
196 DALI_TEST_CHECK(testProcessor3.processRun == false);
198 application.SendNotification();
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);
205 // Clear down for next part of test
206 testProcessor1.processRun = false;
207 testProcessor2.processRun = false;
208 testProcessor3.processRun = false;
210 testProcessor1.SetProcessorToUnregister(&testProcessor3);
212 tet_infoline("Test that the processor unregistered during the callback has not been executed");
213 application.SendNotification();
215 DALI_TEST_CHECK(testProcessor1.processRun);
216 DALI_TEST_CHECK(testProcessor2.processRun);
217 DALI_TEST_CHECK(!testProcessor3.processRun);
222 int UtcDaliCoreProcessorUnregisterDuringCallback02(void)
224 // Test post-processor
225 TestApplication application;
226 Integration::Core& core = application.GetCore();
228 NewTestProcessor testProcessor1(core);
229 TestProcessor testProcessor2;
230 TestProcessor testProcessor3;
232 core.RegisterProcessor(testProcessor1, true);
233 core.RegisterProcessor(testProcessor2, true);
234 core.RegisterProcessor(testProcessor3, true);
236 DALI_TEST_CHECK(testProcessor1.processRun == false);
237 DALI_TEST_CHECK(testProcessor2.processRun == false);
238 DALI_TEST_CHECK(testProcessor3.processRun == false);
240 application.SendNotification();
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);
247 // Clear down for next part of test
248 testProcessor1.processRun = false;
249 testProcessor2.processRun = false;
250 testProcessor3.processRun = false;
252 testProcessor1.SetProcessorToUnregister(&testProcessor3);
254 tet_infoline("Test that the processor unregistered during the callback has not been executed");
255 application.SendNotification();
257 DALI_TEST_CHECK(testProcessor1.processRun);
258 DALI_TEST_CHECK(testProcessor2.processRun);
259 DALI_TEST_CHECK(!testProcessor3.processRun);