AWSGameLiftClientMocks.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 <AzCore/Interface/Interface.h>
  10. #include <Multiplayer/Session/ISessionRequests.h>
  11. #include <Multiplayer/Session/ISessionHandlingRequests.h>
  12. #include <Multiplayer/Session/IMatchmakingRequests.h>
  13. #include <Multiplayer/Session/MatchmakingNotifications.h>
  14. #include <AzTest/AzTest.h>
  15. #include <aws/core/auth/AWSCredentialsProvider.h>
  16. #include <aws/core/utils/Outcome.h>
  17. #include <aws/gamelift/GameLiftClient.h>
  18. #include <aws/gamelift/GameLiftErrors.h>
  19. #include <aws/gamelift/model/AcceptMatchRequest.h>
  20. #include <aws/gamelift/model/AcceptMatchResult.h>
  21. #include <aws/gamelift/model/CreateGameSessionRequest.h>
  22. #include <aws/gamelift/model/CreateGameSessionResult.h>
  23. #include <aws/gamelift/model/CreatePlayerSessionRequest.h>
  24. #include <aws/gamelift/model/CreatePlayerSessionResult.h>
  25. #include <aws/gamelift/model/DescribeMatchmakingRequest.h>
  26. #include <aws/gamelift/model/DescribeMatchmakingResult.h>
  27. #include <aws/gamelift/model/SearchGameSessionsRequest.h>
  28. #include <aws/gamelift/model/SearchGameSessionsResult.h>
  29. #include <aws/gamelift/model/StartGameSessionPlacementRequest.h>
  30. #include <aws/gamelift/model/StartGameSessionPlacementResult.h>
  31. #include <aws/gamelift/model/StartMatchmakingRequest.h>
  32. #include <aws/gamelift/model/StartMatchmakingResult.h>
  33. #include <aws/gamelift/model/StopMatchmakingRequest.h>
  34. #include <aws/gamelift/model/StopMatchmakingResult.h>
  35. using namespace Aws::GameLift;
  36. class GameLiftClientMock
  37. : public GameLiftClient
  38. {
  39. public:
  40. GameLiftClientMock()
  41. : GameLiftClient(Aws::Auth::AWSCredentials())
  42. {
  43. }
  44. MOCK_CONST_METHOD1(AcceptMatch, Model::AcceptMatchOutcome(const Model::AcceptMatchRequest&));
  45. MOCK_CONST_METHOD1(CreateGameSession, Model::CreateGameSessionOutcome(const Model::CreateGameSessionRequest&));
  46. MOCK_CONST_METHOD1(CreatePlayerSession, Model::CreatePlayerSessionOutcome(const Model::CreatePlayerSessionRequest&));
  47. MOCK_CONST_METHOD1(DescribeMatchmaking, Model::DescribeMatchmakingOutcome(const Model::DescribeMatchmakingRequest&));
  48. MOCK_CONST_METHOD1(SearchGameSessions, Model::SearchGameSessionsOutcome(const Model::SearchGameSessionsRequest&));
  49. MOCK_CONST_METHOD1(StartGameSessionPlacement, Model::StartGameSessionPlacementOutcome(const Model::StartGameSessionPlacementRequest&));
  50. MOCK_CONST_METHOD1(StartMatchmaking, Model::StartMatchmakingOutcome(const Model::StartMatchmakingRequest&));
  51. MOCK_CONST_METHOD1(StopMatchmaking, Model::StopMatchmakingOutcome(const Model::StopMatchmakingRequest&));
  52. };
  53. class MatchmakingAsyncRequestNotificationsHandlerMock
  54. : public Multiplayer::MatchmakingAsyncRequestNotificationBus::Handler
  55. {
  56. public:
  57. MatchmakingAsyncRequestNotificationsHandlerMock()
  58. {
  59. Multiplayer::MatchmakingAsyncRequestNotificationBus::Handler::BusConnect();
  60. }
  61. ~MatchmakingAsyncRequestNotificationsHandlerMock()
  62. {
  63. Multiplayer::MatchmakingAsyncRequestNotificationBus::Handler::BusDisconnect();
  64. }
  65. MOCK_METHOD0(OnAcceptMatchAsyncComplete, void());
  66. MOCK_METHOD1(OnStartMatchmakingAsyncComplete, void(const AZStd::string&));
  67. MOCK_METHOD0(OnStopMatchmakingAsyncComplete, void());
  68. };
  69. class MatchmakingNotificationsHandlerMock
  70. : public Multiplayer::MatchmakingNotificationBus::Handler
  71. {
  72. public:
  73. MatchmakingNotificationsHandlerMock()
  74. {
  75. Multiplayer::MatchmakingNotificationBus::Handler::BusConnect();
  76. }
  77. ~MatchmakingNotificationsHandlerMock()
  78. {
  79. Multiplayer::MatchmakingNotificationBus::Handler::BusDisconnect();
  80. }
  81. void OnMatchAcceptance() override
  82. {
  83. ++m_numMatchAcceptance;
  84. }
  85. void OnMatchComplete() override
  86. {
  87. ++m_numMatchComplete;
  88. }
  89. void OnMatchError() override
  90. {
  91. ++m_numMatchError;
  92. }
  93. void OnMatchFailure() override
  94. {
  95. ++m_numMatchFailure;
  96. }
  97. int m_numMatchAcceptance = 0;
  98. int m_numMatchComplete = 0;
  99. int m_numMatchError = 0;
  100. int m_numMatchFailure = 0;
  101. };
  102. class SessionAsyncRequestNotificationsHandlerMock
  103. : public Multiplayer::SessionAsyncRequestNotificationBus::Handler
  104. {
  105. public:
  106. SessionAsyncRequestNotificationsHandlerMock()
  107. {
  108. Multiplayer::SessionAsyncRequestNotificationBus::Handler::BusConnect();
  109. }
  110. ~SessionAsyncRequestNotificationsHandlerMock()
  111. {
  112. Multiplayer::SessionAsyncRequestNotificationBus::Handler::BusDisconnect();
  113. }
  114. MOCK_METHOD1(OnCreateSessionAsyncComplete, void(const AZStd::string&));
  115. MOCK_METHOD1(OnSearchSessionsAsyncComplete, void(const Multiplayer::SearchSessionsResponse&));
  116. MOCK_METHOD1(OnJoinSessionAsyncComplete, void(bool));
  117. MOCK_METHOD0(OnLeaveSessionAsyncComplete, void());
  118. };
  119. class SessionHandlingClientRequestsMock
  120. : public Multiplayer::ISessionHandlingClientRequests
  121. {
  122. public:
  123. SessionHandlingClientRequestsMock()
  124. {
  125. AZ::Interface<Multiplayer::ISessionHandlingClientRequests>::Register(this);
  126. }
  127. virtual ~SessionHandlingClientRequestsMock()
  128. {
  129. AZ::Interface<Multiplayer::ISessionHandlingClientRequests>::Unregister(this);
  130. }
  131. MOCK_METHOD1(RequestPlayerJoinSession, bool(const Multiplayer::SessionConnectionConfig&));
  132. MOCK_METHOD0(RequestPlayerLeaveSession, void());
  133. };