MockBehaviorUtils.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzTest/AzTest.h>
  10. #include <AzCore/RTTI/ReflectContext.h>
  11. #include <AzCore/RTTI/ReflectionManager.h>
  12. #include <AzCore/Script/ScriptContextAttributes.h>
  13. namespace UnitTest
  14. {
  15. void RemoveAttributePair(AZ::AttributeArray& attributes, AZ::AttributeId attributeId)
  16. {
  17. using namespace AZ::Script;
  18. auto attributePair = AZStd::find_if(attributes.begin(), attributes.end(), [attributeId](const AZ::AttributePair& pair)
  19. {
  20. return pair.first == attributeId;
  21. });
  22. if (attributePair != attributes.end())
  23. {
  24. // clean up the old attribute value
  25. if (attributePair->second)
  26. {
  27. delete attributePair->second;
  28. }
  29. attributes.erase(attributePair);
  30. }
  31. }
  32. void ScopeForUnitTest(AZ::AttributeArray& attributes)
  33. {
  34. RemoveAttributePair(attributes, AZ::Script::Attributes::Scope);
  35. attributes.push_back(AZStd::make_pair(
  36. AZ::Script::Attributes::Scope,
  37. aznew AZ::AttributeData<AZ::Script::Attributes::ScopeFlags>(AZ::Script::Attributes::ScopeFlags::Common)));
  38. }
  39. void ApplyStorageForUnitTest(AZ::AttributeArray& attributes)
  40. {
  41. RemoveAttributePair(attributes, AZ::Script::Attributes::Storage);
  42. attributes.push_back(AZStd::make_pair(
  43. AZ::Script::Attributes::Storage,
  44. aznew AZ::AttributeData<AZ::Script::Attributes::StorageType>(AZ::Script::Attributes::StorageType::Value)));
  45. }
  46. }