TestUtils.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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/std/any.h>
  11. namespace UnitTest
  12. {
  13. template<typename T>
  14. void ExpectEqAny(const T& expected, const AZStd::any& anyValue, const char* description = nullptr)
  15. {
  16. if (anyValue.empty())
  17. {
  18. EXPECT_TRUE(false) << (description?description:"Value") << " is empty";
  19. }
  20. else if (!anyValue.is<T>())
  21. {
  22. EXPECT_TRUE(false) << (description?description:"Value") << " is not of the expected type. Expected " << azrtti_typeid<T>().template ToString<AZStd::string>().data() << " but was " << anyValue.get_type_info().m_id.ToString<AZStd::string>().data();
  23. }
  24. else
  25. {
  26. T value = AZStd::any_cast<T>(anyValue);
  27. EXPECT_EQ(expected, value) << (description?description:"");
  28. }
  29. }
  30. template<typename T>
  31. void ExpectEqAny(const AZStd::any& anyValue, const T& expected, const char* description = nullptr)
  32. {
  33. return ExpectEqAny(expected, anyValue, description);
  34. }
  35. }