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 0d45357..c118011 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 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.
  *
  */
 
-#include <stdlib.h>
-#include <dali/public-api/dali-core.h>
-#include <dali/integration-api/core.h>
 #include <dali-test-suite-utils.h>
+#include <dali/integration-api/core.h>
+#include <dali/integration-api/processor-interface.h>
+#include <dali/public-api/dali-core.h>
+#include <stdlib.h>
 
 using namespace Dali;
 
-
 class TestProcessor : public Integration::Processor
 {
 public:
@@ -31,7 +31,7 @@ public:
   {
   }
 
-  virtual void Process()
+  virtual void Process(bool postProcessor)
   {
     processRun = true;
   }
@@ -39,30 +39,224 @@ 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;
 
-  TestProcessor testProcessor;
+  TestProcessor      testProcessor;
   Integration::Core& core = application.GetCore();
-  core.RegisterProcessor( testProcessor );
+  core.RegisterProcessor(testProcessor);
 
   tet_infoline("Test that the processor has not been executed yet:");
-  DALI_TEST_CHECK( testProcessor.processRun == false );
+  DALI_TEST_CHECK(testProcessor.processRun == false);
 
   application.SendNotification();
 
   tet_infoline("Test that the processor has been executed:");
-  DALI_TEST_CHECK( testProcessor.processRun );
+  DALI_TEST_CHECK(testProcessor.processRun);
 
   // Clear down for next part of test
   testProcessor.processRun = false;
 
-  core.UnregisterProcessor( testProcessor );
+  core.UnregisterProcessor(testProcessor);
   application.SendNotification();
   tet_infoline("Test that the processor has not been executed again:");
-  DALI_TEST_CHECK( testProcessor.processRun == false );
+  DALI_TEST_CHECK(testProcessor.processRun == false);
+
+  END_TEST;
+}
+
+int UtcDaliCoreProcessorMultipleP(void)
+{
+  TestApplication application;
+
+  TestProcessor testProcessor1;
+  TestProcessor testProcessor2;
+  TestProcessor testProcessor3;
+
+  Integration::Core& core = application.GetCore();
+  core.RegisterProcessor(testProcessor1);
+
+  tet_infoline("Test that the processor has not been executed yet:");
+  DALI_TEST_CHECK(testProcessor1.processRun == false);
+
+  application.SendNotification();
+
+  tet_infoline("Test that the processor has been executed:");
+  DALI_TEST_CHECK(testProcessor1.processRun);
+
+  // Clear down for next part of test
+  testProcessor1.processRun = false;
+
+  core.RegisterProcessor(testProcessor2);
+  core.RegisterProcessor(testProcessor3);
+
+  tet_infoline("Test that the processors have not been executed yet:");
+  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
+  testProcessor2.processRun = false;
+
+  core.UnregisterProcessor(testProcessor2);
+  application.SendNotification();
+  tet_infoline("Test that the unregistered processor has not been executed again but others have");
+  DALI_TEST_CHECK(testProcessor1.processRun);
+  DALI_TEST_CHECK(testProcessor2.processRun == false);
+  DALI_TEST_CHECK(testProcessor3.processRun);
+
+  END_TEST;
+}
+
+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;
 }