Revert "[Tizen] Appendix log for ttrace + Print keycode and timestamp"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Constraint.cpp
index c215e84..e0255b2 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.
@@ -17,6 +17,7 @@
 
 #include <dali-test-suite-utils.h>
 #include <dali/public-api/dali-core.h>
+#include <mesh-builder.h>
 #include <stdlib.h>
 
 #include <iostream>
@@ -259,6 +260,7 @@ int UtcDaliConstraintNewFunctorN(void)
 
   END_TEST;
 }
+
 ///////////////////////////////////////////////////////////////////////////////
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -1559,3 +1561,135 @@ int UtcDaliConstraintGetTagNegative(void)
   }
   END_TEST;
 }
+
+namespace ComponentTest
+{
+void CheckComponentProperty(TestApplication& application, Actor& actor, Property::Index property)
+{
+  float value = actor.GetCurrentProperty<float>(property);
+
+  // Add a component 0 constraint
+  RelativeToConstraintFloat relativeConstraint(2.0f);
+  Constraint                constraint = Constraint::New<float>(actor, property, relativeConstraint);
+  constraint.AddSource(Source{actor, property});
+  DALI_TEST_CHECK(constraint);
+  constraint.SetRemoveAction(Constraint::RemoveAction::DISCARD);
+  constraint.Apply();
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(actor.GetCurrentProperty<float>(property), value * 2.0f, TEST_LOCATION);
+
+  constraint.Remove();
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(actor.GetCurrentProperty<float>(property), value, TEST_LOCATION);
+}
+} // namespace ComponentTest
+
+int UtcDaliConstraintComponentTransformPropertyConstraintP(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  actor.SetProperty(Actor::Property::POSITION, Vector3(100.0f, 100.0f, 100.0f));
+  application.GetScene().Add(actor);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), Vector3(100.0f, 100.0f, 100.0f), TEST_LOCATION);
+
+  ComponentTest::CheckComponentProperty(application, actor, Actor::Property::POSITION_X); // Component 0
+  ComponentTest::CheckComponentProperty(application, actor, Actor::Property::POSITION_Y); // Component 1
+  ComponentTest::CheckComponentProperty(application, actor, Actor::Property::POSITION_Z); // Component 2
+
+  END_TEST;
+}
+
+int UtcDaliConstraintComponentNonTransformPropertyConstraintP(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  actor.SetProperty(Actor::Property::COLOR, Vector4(0.25f, 0.25f, 0.25f, 0.25f));
+  application.GetScene().Add(actor);
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector4>(Actor::Property::COLOR), Vector4(0.25f, 0.25f, 0.25f, 0.25f), TEST_LOCATION);
+
+  ComponentTest::CheckComponentProperty(application, actor, Actor::Property::COLOR_RED);   // Component 0
+  ComponentTest::CheckComponentProperty(application, actor, Actor::Property::COLOR_GREEN); // Component 1
+  ComponentTest::CheckComponentProperty(application, actor, Actor::Property::COLOR_BLUE);  // Component 2
+  ComponentTest::CheckComponentProperty(application, actor, Actor::Property::COLOR_ALPHA); // Component 3
+
+  END_TEST;
+}
+
+
+namespace PostConstraintTest
+{
+void CheckComponentProperty(TestApplication& application, Actor& actor, Handle target)
+{
+  actor.SetProperty(Actor::Property::POSITION, Vector3::ONE);
+  DALI_TEST_EQUALS(actor.GetProperty<Vector3>(Actor::Property::POSITION), Vector3::ONE, TEST_LOCATION);
+
+  application.SendNotification();
+  application.Render();
+
+  actor.SetProperty(Actor::Property::POSITION, Vector3::ONE * 2.0f);
+
+  DALI_TEST_EQUALS(actor.GetProperty<Vector3>(Actor::Property::POSITION), Vector3::ONE * 2.0f, TEST_LOCATION);
+  DALI_TEST_EQUALS(actor.GetCurrentProperty<Vector3>(Actor::Property::POSITION), Vector3::ONE, TEST_LOCATION);
+
+  Property::Index prePropertyIndex = target.RegisterProperty("testPreProperty", Vector3::ZERO);
+  Constraint preConstraint = Constraint::New<Vector3>(target, prePropertyIndex, [](Vector3& output, const PropertyInputContainer& inputs) {
+    output = inputs[0]->GetVector3();
+  });
+  preConstraint.AddSource(Source{actor, Actor::Property::WORLD_POSITION});
+  preConstraint.Apply();
+
+  Property::Index postPropertyIndex = target.RegisterProperty("testPostProperty", Vector3::ZERO);
+  Constraint postConstraint = Constraint::New<Vector3>(target, postPropertyIndex, [](Vector3& output, const PropertyInputContainer& inputs) {
+    output = inputs[0]->GetVector3();
+  });
+  postConstraint.AddSource(Source{actor, Actor::Property::WORLD_POSITION});
+  postConstraint.ApplyPost();
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS(target.GetCurrentProperty<Vector3>(prePropertyIndex), Vector3(-239.0, -399.0, 1.0), TEST_LOCATION);
+  DALI_TEST_EQUALS(target.GetCurrentProperty<Vector3>(postPropertyIndex), Vector3(-238.0, -398.0, 2.0), TEST_LOCATION);
+
+  preConstraint.Remove();
+  postConstraint.Remove();
+}
+}
+
+int UtcDaliConstraintApplyPost(void)
+{
+  TestApplication application;
+
+  Actor actor = Actor::New();
+  application.GetScene().Add(actor);
+
+  Geometry       targetGeometry = CreateQuadGeometry();
+  Shader         targetShader   = CreateShader();
+  Renderer       targetRenderer = Renderer::New(targetGeometry, targetShader);
+  Actor          targetActor    = Actor::New();
+  RenderTaskList taskList       = application.GetScene().GetRenderTaskList();
+
+  application.GetScene().Add(targetActor);
+  PostConstraintTest::CheckComponentProperty(application, actor, targetShader);         // Shader
+  PostConstraintTest::CheckComponentProperty(application, actor, targetRenderer);       // Renderer
+  PostConstraintTest::CheckComponentProperty(application, actor, targetActor);          // Actor(Node)
+  PostConstraintTest::CheckComponentProperty(application, actor, taskList.GetTask(0u)); // RenderTask
+
+  END_TEST;
+}
\ No newline at end of file