Revert "[Tizen] Appendix log for ttrace + Print keycode and timestamp"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Processors.cpp
index 9f797fb..c118011 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2020 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.
@@ -31,7 +31,7 @@ public:
   {
   }
 
-  virtual void Process()
+  virtual void Process(bool postProcessor)
   {
     processRun = true;
   }
@@ -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;
@@ -114,4 +140,123 @@ int UtcDaliCoreProcessorMultipleP(void)
   DALI_TEST_CHECK(testProcessor3.processRun);
 
   END_TEST;
-}
\ No newline at end of file
+}
+
+int UtcDaliCorePostProcessorP(void)
+{
+  TestApplication application;
+
+  TestProcessor      testProcessor;
+  Integration::Core& core = application.GetCore();
+  core.RegisterProcessor(testProcessor, true);
+
+  tet_infoline("Test that the processor has not been executed yet:");
+  DALI_TEST_CHECK(testProcessor.processRun == false);
+
+  application.SendNotification();
+
+  tet_infoline("Test that the processor has been executed:");
+  DALI_TEST_CHECK(testProcessor.processRun);
+
+  // Clear down for next part of test
+  testProcessor.processRun = false;
+
+  core.UnregisterProcessor(testProcessor);
+  application.SendNotification();
+  tet_infoline("Test that the processor is still executed:");
+  DALI_TEST_CHECK(testProcessor.processRun);
+
+  // Clear down for next part of test
+  testProcessor.processRun = false;
+
+  core.UnregisterProcessor(testProcessor, true);
+  application.SendNotification();
+  tet_infoline("Test that the processor has not been executed again:");
+  DALI_TEST_CHECK(testProcessor.processRun == false);
+
+  END_TEST;
+}
+
+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;
+}