/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2020 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.
UtcDaliConstraintNewFunction::gConstraintFunctionCalled = false;
Actor actor = Actor::New();
- Stage::GetCurrent().Add( actor );
+ application.GetScene().Add( actor );
application.SendNotification();
application.Render();
END_TEST;
}
+
+// helper for next test
+void StringConstraintFunction( std::string& /* current */, const PropertyInputContainer& /* inputs */ )
+{
+}
+
+int UtcDaliConstraintNewFunctionNonConstrainableTypeN(void)
+{
+ // Ensure that we can create a constraint using a C function and that it is called.
+
+ TestApplication application;
+ UtcDaliConstraintNewFunction::gConstraintFunctionCalled = false;
+
+ Actor actor = Actor::New();
+ application.GetScene().Add( actor );
+
+ application.SendNotification();
+ application.Render();
+
+ try
+ {
+ // Add a constraint
+ Constraint constraint = Constraint::New< std::string >( actor, Actor::Property::COLOR_MODE, &StringConstraintFunction );
+ DALI_TEST_CHECK( constraint );
+ constraint.Apply();
+ tet_result(TET_FAIL);
+ }
+ catch ( Dali::DaliException& e )
+ {
+ DALI_TEST_ASSERT( e, "Property not constrainable", TEST_LOCATION );
+ }
+
+ END_TEST;
+}
+
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
bool functorCalled = false;
Actor actor = Actor::New();
- Stage::GetCurrent().Add( actor );
+ application.GetScene().Add( actor );
application.SendNotification();
application.Render();
bool sizeFunctorCalled = false;
Actor actor = Actor::New();
- Stage::GetCurrent().Add( actor );
+ application.GetScene().Add( actor );
application.SendNotification();
application.Render();
Actor actor = Actor::New();
Actor clone = Actor::New();
- Stage stage = Stage::GetCurrent();
+ Integration::Scene stage = application.GetScene();
stage.Add( actor );
stage.Add( clone );
// Reset
calledCount = 0;
- // Ensure constraint isn't called again if scene doesn't change
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( calledCount, 0, TEST_LOCATION );
+ DALI_TEST_EQUALS( calledCount, 1, TEST_LOCATION );
// Apply the clone constraint
constraintClone.Apply();
application.SendNotification();
application.Render();
- // Should only be called once for the new constraint clone ONLY
- DALI_TEST_EQUALS( calledCount, 1, TEST_LOCATION );
+ // Should be called once for the new constraint clone and once for the original constraint
+ DALI_TEST_EQUALS( calledCount, 3, TEST_LOCATION );
// Reset
calledCount = 0;
// Change the position of both actors
- actor.SetPosition( 100.0f, 100.0f );
- clone.SetPosition( 100.0f, 100.0f );
+ actor.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
+ clone.SetProperty( Actor::Property::POSITION, Vector2( 100.0f, 100.0f ));
application.SendNotification();
application.Render();
Actor actor = Actor::New();
Actor clone = Actor::New();
- Stage stage = Stage::GetCurrent();
+ Integration::Scene stage = application.GetScene();
stage.Add( actor );
stage.Add( clone );
constraint.AddSource( LocalSource( Actor::Property::ORIENTATION ) );
constraint.AddSource( LocalSource( Actor::Property::COLOR ) );
constraint.AddSource( LocalSource( Actor::Property::VISIBLE ) );
- constraint.SetRemoveAction( Constraint::Discard );
+ constraint.SetRemoveAction( Constraint::DISCARD );
constraint.SetTag( 123 );
// Clone the constraint & apply the clone
TestApplication application;
Actor actor = Actor::New();
- Stage::GetCurrent().Add( actor );
+ application.GetScene().Add( actor );
Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
Constraint copied( constraint );
}
///////////////////////////////////////////////////////////////////////////////
+int UtcDaliConstraintMoveConstructor(void)
+{
+ // Ensure copy constructor & assignment operators work
+
+ TestApplication application;
+
+ Actor actor = Actor::New();
+ application.GetScene().Add( actor );
+
+ Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
+ DALI_TEST_CHECK( constraint );
+ DALI_TEST_EQUALS( 1, constraint.GetBaseObject().ReferenceCount(), TEST_LOCATION );
+ DALI_TEST_CHECK( constraint.GetTargetObject() == actor );
+
+ Constraint moved = std::move( constraint );
+ DALI_TEST_CHECK( moved );
+ DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
+ DALI_TEST_CHECK( moved.GetTargetObject() == actor );
+ DALI_TEST_CHECK( !constraint );
+
+ END_TEST;
+}
+
+int UtcDaliConstraintMoveAssignment(void)
+{
+ // Ensure copy constructor & assignment operators work
+
+ TestApplication application;
+
+ Actor actor = Actor::New();
+ application.GetScene().Add( actor );
+
+ Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
+ DALI_TEST_CHECK( constraint );
+ DALI_TEST_EQUALS( 1, constraint.GetBaseObject().ReferenceCount(), TEST_LOCATION );
+ DALI_TEST_CHECK( constraint.GetTargetObject() == actor );
+
+ Constraint moved;
+ moved = std::move( constraint );
+ DALI_TEST_CHECK( moved );
+ DALI_TEST_EQUALS( 1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION );
+ DALI_TEST_CHECK( moved.GetTargetObject() == actor );
+ DALI_TEST_CHECK( !constraint );
+
+ END_TEST;
+}
+
///////////////////////////////////////////////////////////////////////////////
// Constraint::DownCast
///////////////////////////////////////////////////////////////////////////////
Actor actor = Actor::New();
Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
- DALI_TEST_EQUALS( constraint.GetTargetProperty(), Actor::Property::POSITION, TEST_LOCATION );
+ DALI_TEST_EQUALS( constraint.GetTargetProperty(), (Property::Index)Actor::Property::POSITION, TEST_LOCATION );
END_TEST;
}
Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &BasicFunction< Vector3 > );
DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::DEFAULT_REMOVE_ACTION, TEST_LOCATION );
- constraint.SetRemoveAction( Constraint::Discard );
- DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::Discard, TEST_LOCATION );
+ constraint.SetRemoveAction( Constraint::DISCARD );
+ DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::DISCARD, TEST_LOCATION );
- constraint.SetRemoveAction( Constraint::Bake );
- DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::Bake, TEST_LOCATION );
+ constraint.SetRemoveAction( Constraint::BAKE );
+ DALI_TEST_EQUALS( constraint.GetRemoveAction(), Constraint::BAKE, TEST_LOCATION );
END_TEST;
}
Constraint constraint;
try
{
- constraint.SetRemoveAction( Constraint::Discard );
+ constraint.SetRemoveAction( Constraint::DISCARD );
DALI_TEST_CHECK( false ); // Should not reach here!
}
catch( ... )
TestApplication application;
Actor actor = Actor::New();
- Stage::GetCurrent().Add( actor );
+ application.GetScene().Add( actor );
application.SendNotification();
application.Render();
// Should not equal position by default
Vector3 position( 10.0f, 20.0f, 30.0f );
- DALI_TEST_CHECK( actor.GetCurrentPosition() != position );
+ DALI_TEST_CHECK( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ) != position );
// Create a constraint that constrains to position
Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, SetValueFunctor< Vector3 >( position ) );
- constraint.SetRemoveAction( Constraint::Bake );
+ constraint.SetRemoveAction( Constraint::BAKE );
constraint.Apply();
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( actor.GetCurrentPosition(), position, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), position, TEST_LOCATION );
// Remove the constraint, it should still be at position
constraint.Remove();
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( actor.GetCurrentPosition(), position, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), position, TEST_LOCATION );
END_TEST;
}
TestApplication application;
Actor actor = Actor::New();
- Stage::GetCurrent().Add( actor );
+ application.GetScene().Add( actor );
application.SendNotification();
application.Render();
// Get and store current position
- Vector3 originalPosition = actor.GetCurrentPosition();
+ Vector3 originalPosition = actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION );
// Should not equal position by default
Vector3 position( 10.0f, 20.0f, 30.0f );
- DALI_TEST_CHECK( actor.GetCurrentPosition() != position );
+ DALI_TEST_CHECK( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ) != position );
// Create a constraint that constrains to position
Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, SetValueFunctor< Vector3 >( position ) );
- constraint.SetRemoveAction( Constraint::Discard );
+ constraint.SetRemoveAction( Constraint::DISCARD );
constraint.Apply();
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( actor.GetCurrentPosition(), position, TEST_LOCATION );
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), position, TEST_LOCATION );
// Remove the constraint, it should still be at position
constraint.Remove();
application.SendNotification();
application.Render();
- DALI_TEST_EQUALS( actor.GetCurrentPosition(), originalPosition, TEST_LOCATION );
- DALI_TEST_CHECK( actor.GetCurrentPosition() != position );
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ), originalPosition, TEST_LOCATION );
+ DALI_TEST_CHECK( actor.GetCurrentProperty< Vector3 >( Actor::Property::POSITION ) != position );
END_TEST;
}
bool functorCalled = false;
Actor actor = Actor::New();
- Stage::GetCurrent().Add( actor );
+ application.GetScene().Add( actor );
application.SendNotification();
application.Render();
DALI_TEST_EQUALS( functorCalled, false, TEST_LOCATION );
// Add actor to stage
- Stage::GetCurrent().Add( actor );
+ application.GetScene().Add( actor );
application.SendNotification();
application.Render();
constraint.Remove();
// Add actor to stage
- Stage::GetCurrent().Add( actor );
+ application.GetScene().Add( actor );
application.SendNotification();
application.Render();
// Create an actor and add to stage
Actor actor = Actor::New();
- Stage stage = Stage::GetCurrent();
+ Integration::Scene stage = application.GetScene();
stage.Add( actor );
// Create a constraint and apply
// Create an actor and add to stage
Actor actor = Actor::New();
- Stage stage = Stage::GetCurrent();
+ Integration::Scene stage = application.GetScene();
stage.Add( actor );
// Create a constraint and apply
application.SendNotification();
application.Render();
- // Constraint should not have been called as the input-properties (none) have not changed for the constraint
- DALI_TEST_EQUALS( count, 0, TEST_LOCATION );
+ DALI_TEST_EQUALS( count, 1, TEST_LOCATION );
// Reset
count = 0;
// Change the position property, apply again
- actor.SetPosition( 10.0f, 10.0f );
+ actor.SetProperty( Actor::Property::POSITION, Vector2( 10.0f, 10.0f ));
constraint.Apply();
application.SendNotification();
TestApplication application;
Actor actor = Actor::New();
- Stage::GetCurrent().Add( actor );
+ application.GetScene().Add( actor );
// Create a constraint, add sources
Constraint constraint = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &UtcDaliConstraintAddSource::Function );
TestApplication application;
Actor actor = Actor::New();
- Stage::GetCurrent().Add( actor );
+ application.GetScene().Add( actor );
Constraint constraint1 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function1 );
Constraint constraint2 = Constraint::New< Vector3 >( actor, Actor::Property::POSITION, &TestChaining::Function2 );
Actor actor = Actor::New();
Property::Index index = actor.RegisterProperty( "TEMP_PROPERTY_NAME", value );
- Stage::GetCurrent().Add( actor );
+ application.GetScene().Add( actor );
application.SendNotification();
application.Render();
///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+namespace
+{
+void SetHalfOpacity( Vector4& current, const PropertyInputContainer& inputs )
+{
+ current.a = 0.5f;
+}
+} // unnamed namespace
+
+int UtcDaliConstraintEnsureResetterAppliedOnSceneRemoval(void)
+{
+ // Ensure BOTH double-buffered values of our color property is reset when a constraint is applied to it.
+
+ TestApplication application;
+
+ Actor actor = Actor::New();
+ application.GetScene().Add( actor );
+
+ // Check initial value is fully opaque
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
+
+ // Create a constraint whose value is discarded when it is removed
+ Constraint constraint = Constraint::New< Vector4 >( actor, Actor::Property::COLOR, SetHalfOpacity );
+ constraint.SetRemoveAction( Constraint::RemoveAction::DISCARD );
+ constraint.Apply();
+
+ // Check value after one render, it should be constrained
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 0.5f, TEST_LOCATION );
+
+ // Render another frame, ensure the other value has also been updated
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 0.5f, TEST_LOCATION );
+
+ // Remove the actor from the stage and delete the constraint
+ actor.Unparent();
+ constraint.Remove();
+ constraint.Reset();
+
+ // Check value while off-stage, it should be fully opaque
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
+
+ // Add the actor back to the stage and check the value, it should be fully opaque again
+ application.GetScene().Add( actor );
+
+ // Check value when back on-stage, it should be fully opaque as the constraint is no longer applied to it.
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
+
+ // Render for another frame to ensure both buffers have the correct value
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliConstraintOnActorAddedAndRemoved(void)
+{
+ // Ensure adding and removing an actor from stage with a constraint still has it applied when it is re-added back to the stage
+
+ TestApplication application;
+
+ Actor actor = Actor::New();
+ application.GetScene().Add( actor );
+
+ // Check initial value is fully opaque
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
+
+ // Create a constraint whose value is discarded when it is removed
+ Constraint constraint = Constraint::New< Vector4 >( actor, Actor::Property::COLOR, SetHalfOpacity );
+ constraint.SetRemoveAction( Constraint::RemoveAction::DISCARD );
+ constraint.Apply();
+
+ // Check value after one render, it should be constrained
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 0.5f, TEST_LOCATION );
+
+ // Render another frame, ensure the other value has also been updated
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 0.5f, TEST_LOCATION );
+
+ // Remove the actor from the stage
+ actor.Unparent();
+
+ // Check value while off-stage, the constraint is no longer being applied as it's off-stage
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
+
+ // Check the other buffer, the constraint should not be applied to this either.
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 1.0f, TEST_LOCATION );
+
+ // Add the actor back to the stage and check the value, the constraint should have been re-applied
+ application.GetScene().Add( actor );
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 0.5f, TEST_LOCATION );
+
+ // Render for another frame to ensure both buffers have the correct value
+ application.SendNotification();
+ application.Render();
+ DALI_TEST_EQUALS( actor.GetCurrentProperty< Vector4 >( Actor::Property::COLOR ).a, 0.5f, TEST_LOCATION );
+
+ END_TEST;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+int UtcDaliConstraintGetTargetObjectNegative(void)
+{
+ TestApplication application;
+ Dali::Constraint instance;
+ try
+ {
+ instance.GetTargetObject();
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}
+
+int UtcDaliConstraintSetRemoveActionNegative(void)
+{
+ TestApplication application;
+ Dali::Constraint instance;
+ try
+ {
+ Dali::Constraint::RemoveAction arg1(Constraint::BAKE);
+ instance.SetRemoveAction(arg1);
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}
+
+int UtcDaliConstraintGetTargetPropertyNegative(void)
+{
+ TestApplication application;
+ Dali::Constraint instance;
+ try
+ {
+ instance.GetTargetProperty();
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}
+
+int UtcDaliConstraintApplyNegative(void)
+{
+ TestApplication application;
+ Dali::Constraint instance;
+ try
+ {
+ instance.Apply();
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}
+
+int UtcDaliConstraintCloneNegative(void)
+{
+ TestApplication application;
+ Dali::Constraint instance;
+ try
+ {
+ Dali::Handle arg1;
+ instance.Clone(arg1);
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}
+
+int UtcDaliConstraintRemoveNegative(void)
+{
+ TestApplication application;
+ Dali::Constraint instance;
+ try
+ {
+ instance.Remove();
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}
+
+int UtcDaliConstraintSetTagNegative(void)
+{
+ TestApplication application;
+ Dali::Constraint instance;
+ try
+ {
+ unsigned int arg1(0u);
+ instance.SetTag(arg1);
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}
+
+int UtcDaliConstraintGetRemoveActionNegative(void)
+{
+ TestApplication application;
+ Dali::Constraint instance;
+ try
+ {
+ instance.GetRemoveAction();
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}
+
+int UtcDaliConstraintGetTagNegative(void)
+{
+ TestApplication application;
+ Dali::Constraint instance;
+ try
+ {
+ instance.GetTag();
+ DALI_TEST_CHECK(false); // Should not get here
+ }
+ catch(...)
+ {
+ DALI_TEST_CHECK(true); // We expect an assert
+ }
+ END_TEST;
+}