AWSGameLiftJoinSessionActivityTest.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 <Multiplayer/Session/ISessionHandlingRequests.h>
  9. #include <AWSGameLiftClientFixture.h>
  10. #include <Activity/AWSGameLiftJoinSessionActivity.h>
  11. using namespace AWSGameLift;
  12. using AWSGameLiftJoinSessionActivityTest = AWSGameLiftClientFixture;
  13. TEST_F(AWSGameLiftJoinSessionActivityTest, BuildAWSGameLiftCreatePlayerSessionRequest_Call_GetExpectedResult)
  14. {
  15. AWSGameLiftJoinSessionRequest request;
  16. request.m_playerData = "dummyPlayerData";
  17. request.m_playerId = "dummyPlayerId";
  18. request.m_sessionId = "dummySessionId";
  19. auto awsRequest = JoinSessionActivity::BuildAWSGameLiftCreatePlayerSessionRequest(request);
  20. EXPECT_TRUE(strcmp(awsRequest.GetPlayerData().c_str(), request.m_playerData.c_str()) == 0);
  21. EXPECT_TRUE(strcmp(awsRequest.GetPlayerId().c_str(), request.m_playerId.c_str()) == 0);
  22. EXPECT_TRUE(strcmp(awsRequest.GetGameSessionId().c_str(), request.m_sessionId.c_str()) == 0);
  23. }
  24. TEST_F(AWSGameLiftJoinSessionActivityTest, BuildSessionConnectionConfig_Call_GetIpAddressAsDestinationResult)
  25. {
  26. Aws::GameLift::Model::PlayerSession playerSession;
  27. playerSession.SetIpAddress("dummyIpAddress");
  28. playerSession.SetPlayerSessionId("dummyPlayerSessionId");
  29. playerSession.SetPort(123);
  30. Aws::GameLift::Model::CreatePlayerSessionResult createPlayerSessionResult;
  31. createPlayerSessionResult.SetPlayerSession(playerSession);
  32. Aws::GameLift::Model::CreatePlayerSessionOutcome createPlayerSessionOutcome(createPlayerSessionResult);
  33. auto connectionConfig = JoinSessionActivity::BuildSessionConnectionConfig(createPlayerSessionOutcome);
  34. EXPECT_TRUE(strcmp(connectionConfig.m_dnsName.c_str(), "") == 0);
  35. EXPECT_TRUE(strcmp(connectionConfig.m_ipAddress.c_str(), playerSession.GetIpAddress().c_str()) == 0);
  36. EXPECT_TRUE(strcmp(connectionConfig.m_playerSessionId.c_str(), playerSession.GetPlayerSessionId().c_str()) == 0);
  37. EXPECT_TRUE(connectionConfig.m_port == playerSession.GetPort());
  38. }
  39. TEST_F(AWSGameLiftJoinSessionActivityTest, BuildSessionConnectionConfig_Call_GetDNSAsDestinationResult)
  40. {
  41. Aws::GameLift::Model::PlayerSession playerSession;
  42. playerSession.SetDnsName("gameliftunittest.amazongamelift.com");
  43. playerSession.SetIpAddress("dummyIpAddress");
  44. playerSession.SetPlayerSessionId("dummyPlayerSessionId");
  45. playerSession.SetPort(123);
  46. Aws::GameLift::Model::CreatePlayerSessionResult createPlayerSessionResult;
  47. createPlayerSessionResult.SetPlayerSession(playerSession);
  48. Aws::GameLift::Model::CreatePlayerSessionOutcome createPlayerSessionOutcome(createPlayerSessionResult);
  49. auto connectionConfig = JoinSessionActivity::BuildSessionConnectionConfig(createPlayerSessionOutcome);
  50. EXPECT_TRUE(strcmp(connectionConfig.m_dnsName.c_str(), playerSession.GetDnsName().c_str()) == 0);
  51. EXPECT_TRUE(strcmp(connectionConfig.m_ipAddress.c_str(), "") == 0);
  52. EXPECT_TRUE(strcmp(connectionConfig.m_playerSessionId.c_str(), playerSession.GetPlayerSessionId().c_str()) == 0);
  53. EXPECT_TRUE(connectionConfig.m_port == playerSession.GetPort());
  54. }
  55. TEST_F(AWSGameLiftJoinSessionActivityTest, ValidateJoinSessionRequest_CallWithBaseType_GetFalseResult)
  56. {
  57. AZ_TEST_START_TRACE_SUPPRESSION;
  58. auto result = JoinSessionActivity::ValidateJoinSessionRequest(Multiplayer::JoinSessionRequest());
  59. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  60. EXPECT_FALSE(result);
  61. }
  62. TEST_F(AWSGameLiftJoinSessionActivityTest, ValidateJoinSessionRequest_CallWithEmptyPlayerId_GetFalseResult)
  63. {
  64. AWSGameLiftJoinSessionRequest request;
  65. request.m_sessionId = "dummySessionId";
  66. AZ_TEST_START_TRACE_SUPPRESSION;
  67. auto result = JoinSessionActivity::ValidateJoinSessionRequest(request);
  68. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  69. EXPECT_FALSE(result);
  70. }
  71. TEST_F(AWSGameLiftJoinSessionActivityTest, ValidateJoinSessionRequest_CallWithEmptySessionId_GetFalseResult)
  72. {
  73. AWSGameLiftJoinSessionRequest request;
  74. request.m_playerId = "dummyPlayerId";
  75. AZ_TEST_START_TRACE_SUPPRESSION;
  76. auto result = JoinSessionActivity::ValidateJoinSessionRequest(request);
  77. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  78. EXPECT_FALSE(result);
  79. }
  80. TEST_F(AWSGameLiftJoinSessionActivityTest, ValidateJoinSessionRequest_CallWithPlayerAndSessionId_GetTrueResult)
  81. {
  82. AWSGameLiftJoinSessionRequest request;
  83. request.m_playerId = "dummyPlayerId";
  84. request.m_sessionId = "dummySessionId";
  85. auto result = JoinSessionActivity::ValidateJoinSessionRequest(request);
  86. EXPECT_TRUE(result);
  87. }