RemoteToolsTest.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <AzTest/AzTest.h>
  9. #include <AzCore/Console/LoggerSystemComponent.h>
  10. #include <AzCore/Interface/Interface.h>
  11. #include <AzCore/Name/NameDictionary.h>
  12. #include <AzCore/Serialization/SerializeContext.h>
  13. #include <AzCore/Time/TimeSystem.h>
  14. #include <AzCore/UnitTest/MockComponentApplication.h>
  15. #include <AzCore/UnitTest/TestTypes.h>
  16. #include <AzCore/UnitTest/UnitTest.h>
  17. #include <AzFramework/Network/IRemoteTools.h>
  18. #include <AzFramework/Script/ScriptDebugMsgReflection.h>
  19. #include <AzNetworking/Framework/NetworkingSystemComponent.h>
  20. #include <RemoteToolsSystemComponent.h>
  21. namespace UnitTest
  22. {
  23. using namespace RemoteTools;
  24. static constexpr AZ::Crc32 TestToolsKey("TestRemoteTools");
  25. class RemoteToolsTests : public LeakDetectionFixture
  26. {
  27. public:
  28. void SetUp() override
  29. {
  30. LeakDetectionFixture::SetUp();
  31. AZ::NameDictionary::Create();
  32. m_timeSystem = AZStd::make_unique<AZ::TimeSystem>();
  33. m_networkingSystemComponent = AZStd::make_unique<AzNetworking::NetworkingSystemComponent>();
  34. m_remoteToolsSystemComponent = AZStd::make_unique<RemoteToolsSystemComponent>();
  35. m_serializeContext = AZStd::make_unique<AZ::SerializeContext>();
  36. m_remoteTools = m_remoteToolsSystemComponent.get();
  37. m_applicationMock = AZStd::make_unique<testing::NiceMock<UnitTest::MockComponentApplication>>();
  38. ON_CALL(*m_applicationMock, GetSerializeContext())
  39. .WillByDefault(
  40. [this]()
  41. {
  42. return m_serializeContext.get();
  43. });
  44. AzFramework::ReflectScriptDebugClasses(m_serializeContext.get());
  45. }
  46. void TearDown() override
  47. {
  48. m_applicationMock.reset();
  49. m_remoteTools = nullptr;
  50. m_serializeContext.reset();
  51. m_remoteToolsSystemComponent.reset();
  52. m_networkingSystemComponent.reset();
  53. m_timeSystem.reset();
  54. AZ::NameDictionary::Destroy();
  55. LeakDetectionFixture::SetUp();
  56. }
  57. AZStd::unique_ptr<AZ::TimeSystem> m_timeSystem;
  58. AZStd::unique_ptr<AzNetworking::NetworkingSystemComponent> m_networkingSystemComponent;
  59. AZStd::unique_ptr<RemoteToolsSystemComponent> m_remoteToolsSystemComponent;
  60. AZStd::unique_ptr<AZ::SerializeContext> m_serializeContext;
  61. AzFramework::IRemoteTools* m_remoteTools = nullptr;
  62. AZStd::unique_ptr<testing::NiceMock<UnitTest::MockComponentApplication>> m_applicationMock;
  63. };
  64. TEST_F(RemoteToolsTests, TEST_RemoteToolsEmptyRegistry)
  65. {
  66. EXPECT_NE(m_remoteTools, nullptr);
  67. EXPECT_EQ(m_remoteTools->GetReceivedMessages(TestToolsKey), nullptr);
  68. AzFramework::RemoteToolsEndpointContainer endpointContainer;
  69. m_remoteTools->EnumTargetInfos(TestToolsKey, endpointContainer);
  70. EXPECT_TRUE(endpointContainer.empty());
  71. AzFramework::RemoteToolsEndpointInfo endpointInfo;
  72. endpointInfo = m_remoteTools->GetDesiredEndpoint(TestToolsKey);
  73. EXPECT_FALSE(endpointInfo.IsValid());
  74. endpointInfo = m_remoteTools->GetEndpointInfo(TestToolsKey, 0);
  75. EXPECT_FALSE(endpointInfo.IsValid());
  76. EXPECT_FALSE(m_remoteTools->IsEndpointOnline(TestToolsKey, 0));
  77. }
  78. TEST_F(RemoteToolsTests, TEST_RemoteToolsHost)
  79. {
  80. EXPECT_NE(m_remoteTools, nullptr);
  81. m_remoteTools->RegisterToolingServiceHost(TestToolsKey, AZ::Name("Test"), 6999);
  82. EXPECT_EQ(m_remoteTools->GetReceivedMessages(TestToolsKey), nullptr);
  83. AzFramework::RemoteToolsEndpointContainer endpointContainer;
  84. m_remoteTools->EnumTargetInfos(TestToolsKey, endpointContainer);
  85. EXPECT_EQ(endpointContainer.size(), 1);
  86. m_remoteTools->SetDesiredEndpoint(TestToolsKey, TestToolsKey);
  87. AzFramework::RemoteToolsEndpointInfo endpointInfo;
  88. endpointInfo = m_remoteTools->GetDesiredEndpoint(TestToolsKey);
  89. EXPECT_TRUE(endpointInfo.IsValid());
  90. EXPECT_TRUE(endpointInfo.IsSelf());
  91. EXPECT_FALSE(m_remoteTools->IsEndpointOnline(TestToolsKey, TestToolsKey));
  92. {
  93. AzFramework::ScriptDebugBreakpointRequest msg(1, "test", 2);
  94. msg.SetSenderTargetId(TestToolsKey);
  95. m_remoteTools->SendRemoteToolsMessage(endpointInfo, msg);
  96. }
  97. const AzFramework::ReceivedRemoteToolsMessages* receiveMsgs = m_remoteTools->GetReceivedMessages(TestToolsKey);
  98. EXPECT_NE(receiveMsgs, nullptr);
  99. EXPECT_EQ(receiveMsgs->size(), 1);
  100. auto msg = azrtti_cast<AzFramework::ScriptDebugBreakpointRequest*>(receiveMsgs->at(0));
  101. EXPECT_TRUE(msg != nullptr);
  102. EXPECT_EQ(msg->m_request, 1);
  103. EXPECT_STREQ(msg->m_context.c_str(), "test");
  104. EXPECT_EQ(msg->m_line, 2);
  105. m_remoteTools->ClearReceivedMessages(TestToolsKey);
  106. }
  107. }
  108. AZ_UNIT_TEST_HOOK(DEFAULT_UNIT_TEST_ENV);