3
0

JsonTestUtils.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include <Common/JsonTestUtils.h>
  9. #include <AzFramework/StringFunc/StringFunc.h>
  10. #include <gtest/gtest.h>
  11. namespace UnitTest
  12. {
  13. bool JsonTestResult::ContainsOutcome(AZ::JsonSerializationResult::Outcomes outcome)
  14. {
  15. for (auto& reportList : m_reports)
  16. {
  17. for (auto& report : reportList.second)
  18. {
  19. if (report.resultCode.GetOutcome() == outcome)
  20. {
  21. return true;
  22. }
  23. }
  24. }
  25. return false;
  26. }
  27. bool JsonTestResult::ContainsMessage(AZStd::string_view jsonFieldPath, AZStd::string_view messageSubstring)
  28. {
  29. auto pathIter = m_reports.find(jsonFieldPath);
  30. if (pathIter == m_reports.end())
  31. {
  32. return false;
  33. }
  34. for (auto& report : pathIter->second)
  35. {
  36. if (AzFramework::StringFunc::Find(report.message, messageSubstring) != AZStd::string::npos)
  37. {
  38. return true;
  39. }
  40. }
  41. return false;
  42. }
  43. void ExpectSimilarJson(AZStd::string_view a, AZStd::string_view b)
  44. {
  45. AZStd::string aStripped = a;
  46. AZStd::string bStripped = b;
  47. AzFramework::StringFunc::Strip(aStripped, " \t\r\n");
  48. AzFramework::StringFunc::Strip(bStripped, " \t\r\n");
  49. EXPECT_STRCASEEQ(aStripped.c_str(), bStripped.c_str());
  50. }
  51. }