AssetBuilderApplicationTests.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 <AssetBuilderApplication.h>
  9. #include <TraceMessageHook.h>
  10. #include <AzCore/StringFunc/StringFunc.h>
  11. #include <AzCore/UnitTest/TestTypes.h>
  12. #include <AzToolsFramework/Component/EditorComponentAPIComponent.h>
  13. #include <AzToolsFramework/Debug/TraceContext.h>
  14. #include <AzToolsFramework/Entity/EditorEntityContextComponent.h>
  15. #include <AzToolsFramework/Entity/EditorEntityModelComponent.h>
  16. #include <AzToolsFramework/Entity/EditorEntitySearchComponent.h>
  17. #include <AzToolsFramework/Slice/SliceMetadataEntityContextComponent.h>
  18. namespace AssetBuilder
  19. {
  20. using namespace UnitTest;
  21. using AssetBuilderAppTest = LeakDetectionFixture;
  22. TEST_F(AssetBuilderAppTest, AssetBuilder_EditorScriptingComponents_Exists)
  23. {
  24. AssetBuilderApplication app(nullptr, nullptr);
  25. AZ::ComponentTypeList systemComponents = app.GetRequiredSystemComponents();
  26. auto searchFor = [&systemComponents](const AZ::Uuid& typeId) -> bool
  27. {
  28. auto entry = AZStd::find(systemComponents.begin(), systemComponents.end(), typeId);
  29. return systemComponents.end() != entry;
  30. };
  31. EXPECT_TRUE(searchFor(azrtti_typeid<AzToolsFramework::SliceMetadataEntityContextComponent>()));
  32. EXPECT_TRUE(searchFor(azrtti_typeid<AzToolsFramework::Components::EditorComponentAPIComponent>()));
  33. EXPECT_TRUE(searchFor(azrtti_typeid<AzToolsFramework::Components::EditorEntitySearchComponent>()));
  34. EXPECT_TRUE(searchFor(azrtti_typeid<AzToolsFramework::Components::EditorEntityModelComponent>()));
  35. EXPECT_TRUE(searchFor(azrtti_typeid<AzToolsFramework::EditorEntityContextComponent>()));
  36. }
  37. void VerifyOutput(const AZStd::string& output)
  38. {
  39. ASSERT_FALSE(output.empty());
  40. AZStd::vector<AZStd::string> tokens;
  41. AZ::StringFunc::Tokenize(output, tokens, "\n", false, false);
  42. // There should be an even number of lines since every line has a context line printed before it
  43. ASSERT_GT(tokens.size(), 0);
  44. ASSERT_EQ(tokens.size() % 2, 0);
  45. for (int i = 0; i < tokens.size(); i += 2)
  46. {
  47. ASSERT_STREQ(tokens[0].c_str(), "C: [Source] = Test");
  48. }
  49. }
  50. struct LoggingTest
  51. : LeakDetectionFixture
  52. {
  53. void SetUp() override
  54. {
  55. m_messageHook.EnableTraceContext(true);
  56. }
  57. TraceMessageHook m_messageHook;
  58. };
  59. TEST_F(LoggingTest, TracePrintf_ContainsContextOnEachLine)
  60. {
  61. testing::internal::CaptureStdout();
  62. AZ_TraceContext("Source", "Test");
  63. AZ_TracePrintf("window", "line1\nline2\nline3");
  64. auto output = testing::internal::GetCapturedStdout();
  65. VerifyOutput(output.c_str());
  66. }
  67. TEST_F(LoggingTest, Warning_ContainsContextOnEachLine)
  68. {
  69. testing::internal::CaptureStdout();
  70. AZ_TraceContext("Source", "Test");
  71. AZ_Warning("window", false, "line1\nline2\nline3");
  72. auto output = testing::internal::GetCapturedStdout();
  73. VerifyOutput(output.c_str());
  74. }
  75. TEST_F(LoggingTest, Error_ContainsContextOnEachLine)
  76. {
  77. testing::internal::CaptureStderr();
  78. AZ_TraceContext("Source", "Test");
  79. AZ_TEST_START_TRACE_SUPPRESSION;
  80. AZ_Error("window", false, "line1\nline2\nline3");
  81. AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT;
  82. auto output = testing::internal::GetCapturedStderr();
  83. VerifyOutput(output.c_str());
  84. }
  85. TEST_F(LoggingTest, Assert_ContainsContextOnEachLine)
  86. {
  87. testing::internal::CaptureStderr();
  88. AZ_TraceContext("Source", "Test");
  89. AZ_TEST_START_TRACE_SUPPRESSION;
  90. AZ_Assert(false, "line1\nline2\nline3");
  91. AZ_TEST_STOP_TRACE_SUPPRESSION_NO_COUNT;
  92. auto output = testing::internal::GetCapturedStderr();
  93. VerifyOutput(output.c_str());
  94. }
  95. } // namespace AssetBuilder