[Tizen] Ensure the processor unregistered during the callback is not executed 84/281184/1 accepted/tizen/unified/20220914.164048
authorHeeyong Song <heeyong.song@samsung.com>
Wed, 14 Sep 2022 05:50:53 +0000 (14:50 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Wed, 14 Sep 2022 05:54:55 +0000 (14:54 +0900)
Change-Id: I11215bc7bb6fdec892723f176ad6497bbf61f2a7

automated-tests/src/dali/utc-Dali-Processors.cpp
dali/internal/common/core-impl.cpp

index 0d1b864..c118011 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -39,6 +39,32 @@ public:
   bool processRun;
 };
 
+class NewTestProcessor : public TestProcessor
+{
+public:
+  NewTestProcessor(Integration::Core& core)
+  : core(core)
+  {
+  }
+
+  virtual void Process(bool postProcessor)
+  {
+    processRun = true;
+    if(unregisterProcessor)
+    {
+      core.UnregisterProcessor(*unregisterProcessor, postProcessor);
+    }
+  }
+
+  void SetProcessorToUnregister(Integration::Processor* processor)
+  {
+    unregisterProcessor = processor;
+  }
+
+  Integration::Processor* unregisterProcessor{nullptr};
+  Integration::Core&      core;
+};
+
 int UtcDaliCoreProcessorP(void)
 {
   TestApplication application;
@@ -149,4 +175,88 @@ int UtcDaliCorePostProcessorP(void)
   DALI_TEST_CHECK(testProcessor.processRun == false);
 
   END_TEST;
-}
\ No newline at end of file
+}
+
+int UtcDaliCoreProcessorUnregisterDuringCallback01(void)
+{
+  // Test pre-processor
+  TestApplication    application;
+  Integration::Core& core = application.GetCore();
+
+  NewTestProcessor testProcessor1(core);
+  TestProcessor    testProcessor2;
+  TestProcessor    testProcessor3;
+
+  core.RegisterProcessor(testProcessor1);
+  core.RegisterProcessor(testProcessor2);
+  core.RegisterProcessor(testProcessor3);
+
+  DALI_TEST_CHECK(testProcessor1.processRun == false);
+  DALI_TEST_CHECK(testProcessor2.processRun == false);
+  DALI_TEST_CHECK(testProcessor3.processRun == false);
+
+  application.SendNotification();
+
+  tet_infoline("Test that the processors have been executed:");
+  DALI_TEST_CHECK(testProcessor1.processRun);
+  DALI_TEST_CHECK(testProcessor2.processRun);
+  DALI_TEST_CHECK(testProcessor3.processRun);
+
+  // Clear down for next part of test
+  testProcessor1.processRun = false;
+  testProcessor2.processRun = false;
+  testProcessor3.processRun = false;
+
+  testProcessor1.SetProcessorToUnregister(&testProcessor3);
+
+  tet_infoline("Test that the processor unregistered during the callback has not been executed");
+  application.SendNotification();
+
+  DALI_TEST_CHECK(testProcessor1.processRun);
+  DALI_TEST_CHECK(testProcessor2.processRun);
+  DALI_TEST_CHECK(!testProcessor3.processRun);
+
+  END_TEST;
+}
+
+int UtcDaliCoreProcessorUnregisterDuringCallback02(void)
+{
+  // Test post-processor
+  TestApplication    application;
+  Integration::Core& core = application.GetCore();
+
+  NewTestProcessor testProcessor1(core);
+  TestProcessor    testProcessor2;
+  TestProcessor    testProcessor3;
+
+  core.RegisterProcessor(testProcessor1, true);
+  core.RegisterProcessor(testProcessor2, true);
+  core.RegisterProcessor(testProcessor3, true);
+
+  DALI_TEST_CHECK(testProcessor1.processRun == false);
+  DALI_TEST_CHECK(testProcessor2.processRun == false);
+  DALI_TEST_CHECK(testProcessor3.processRun == false);
+
+  application.SendNotification();
+
+  tet_infoline("Test that the processors have been executed:");
+  DALI_TEST_CHECK(testProcessor1.processRun);
+  DALI_TEST_CHECK(testProcessor2.processRun);
+  DALI_TEST_CHECK(testProcessor3.processRun);
+
+  // Clear down for next part of test
+  testProcessor1.processRun = false;
+  testProcessor2.processRun = false;
+  testProcessor3.processRun = false;
+
+  testProcessor1.SetProcessorToUnregister(&testProcessor3);
+
+  tet_infoline("Test that the processor unregistered during the callback has not been executed");
+  application.SendNotification();
+
+  DALI_TEST_CHECK(testProcessor1.processRun);
+  DALI_TEST_CHECK(testProcessor2.processRun);
+  DALI_TEST_CHECK(!testProcessor3.processRun);
+
+  END_TEST;
+}
index 5e02c36..dd9917b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2022 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -368,7 +368,13 @@ void Core::RunProcessors()
   {
     if(processor)
     {
-      processor->Process(false);
+      // Run processor if the processor is still in the list.
+      // It may be removed during the loop.
+      auto iter = std::find(mProcessors.Begin(), mProcessors.End(), processor);
+      if(iter != mProcessors.End())
+      {
+        processor->Process(false);
+      }
     }
   }
 }
@@ -382,7 +388,13 @@ void Core::RunPostProcessors()
   {
     if(processor)
     {
-      processor->Process(true);
+      // Run processor if the processor is still in the list.
+      // It may be removed during the loop.
+      auto iter = std::find(mPostProcessors.Begin(), mPostProcessors.End(), processor);
+      if(iter != mPostProcessors.End())
+      {
+        processor->Process(true);
+      }
     }
   }
 }