AWSGameLiftJoinSessionActivityTest.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
  3. * its licensors.
  4. *
  5. * For complete copyright and license terms please see the LICENSE at the root of this
  6. * distribution (the "License"). All use of this software is governed by the License,
  7. * or, if provided, by the license below or the license accompanying this file. Do not
  8. * remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. *
  11. */
  12. #include <AWSGameLiftClientFixture.h>
  13. #include <Activity/AWSGameLiftJoinSessionActivity.h>
  14. using namespace AWSGameLift;
  15. using AWSGameLiftJoinSessionActivityTest = AWSGameLiftClientFixture;
  16. TEST_F(AWSGameLiftJoinSessionActivityTest, BuildAWSGameLiftCreatePlayerSessionRequest_Call_GetExpectedResult)
  17. {
  18. AWSGameLiftJoinSessionRequest request;
  19. request.m_playerData = "dummyPlayerData";
  20. request.m_playerId = "dummyPlayerId";
  21. request.m_sessionId = "dummySessionId";
  22. auto awsRequest = JoinSessionActivity::BuildAWSGameLiftCreatePlayerSessionRequest(request);
  23. EXPECT_TRUE(strcmp(awsRequest.GetPlayerData().c_str(), request.m_playerData.c_str()) == 0);
  24. EXPECT_TRUE(strcmp(awsRequest.GetPlayerId().c_str(), request.m_playerId.c_str()) == 0);
  25. EXPECT_TRUE(strcmp(awsRequest.GetGameSessionId().c_str(), request.m_sessionId.c_str()) == 0);
  26. }
  27. TEST_F(AWSGameLiftJoinSessionActivityTest, BuildSessionConnectionConfig_Call_GetExpectedResult)
  28. {
  29. Aws::GameLift::Model::PlayerSession playerSession;
  30. playerSession.SetIpAddress("dummyIpAddress");
  31. playerSession.SetPlayerSessionId("dummyPlayerSessionId");
  32. playerSession.SetPort(123);
  33. Aws::GameLift::Model::CreatePlayerSessionResult createPlayerSessionResult;
  34. createPlayerSessionResult.SetPlayerSession(playerSession);
  35. Aws::GameLift::Model::CreatePlayerSessionOutcome createPlayerSessionOutcome(createPlayerSessionResult);
  36. auto connectionConfig = JoinSessionActivity::BuildSessionConnectionConfig(createPlayerSessionOutcome);
  37. EXPECT_TRUE(strcmp(connectionConfig.m_ipAddress.c_str(), playerSession.GetIpAddress().c_str()) == 0);
  38. EXPECT_TRUE(strcmp(connectionConfig.m_playerSessionId.c_str(), playerSession.GetPlayerSessionId().c_str()) == 0);
  39. EXPECT_TRUE(connectionConfig.m_port == playerSession.GetPort());
  40. }
  41. TEST_F(AWSGameLiftJoinSessionActivityTest, ValidateJoinSessionRequest_CallWithBaseType_GetFalseResult)
  42. {
  43. AZ_TEST_START_TRACE_SUPPRESSION;
  44. auto result = JoinSessionActivity::ValidateJoinSessionRequest(AzFramework::JoinSessionRequest());
  45. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  46. EXPECT_FALSE(result);
  47. }
  48. TEST_F(AWSGameLiftJoinSessionActivityTest, ValidateJoinSessionRequest_CallWithEmptyPlayerId_GetFalseResult)
  49. {
  50. AWSGameLiftJoinSessionRequest request;
  51. request.m_sessionId = "dummySessionId";
  52. AZ_TEST_START_TRACE_SUPPRESSION;
  53. auto result = JoinSessionActivity::ValidateJoinSessionRequest(request);
  54. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  55. EXPECT_FALSE(result);
  56. }
  57. TEST_F(AWSGameLiftJoinSessionActivityTest, ValidateJoinSessionRequest_CallWithEmptySessionId_GetFalseResult)
  58. {
  59. AWSGameLiftJoinSessionRequest request;
  60. request.m_playerId = "dummyPlayerId";
  61. AZ_TEST_START_TRACE_SUPPRESSION;
  62. auto result = JoinSessionActivity::ValidateJoinSessionRequest(request);
  63. AZ_TEST_STOP_TRACE_SUPPRESSION(1); // capture 1 error message
  64. EXPECT_FALSE(result);
  65. }
  66. TEST_F(AWSGameLiftJoinSessionActivityTest, ValidateJoinSessionRequest_CallWithPlayerAndSessionId_GetTrueResult)
  67. {
  68. AWSGameLiftJoinSessionRequest request;
  69. request.m_playerId = "dummyPlayerId";
  70. request.m_sessionId = "dummySessionId";
  71. auto result = JoinSessionActivity::ValidateJoinSessionRequest(request);
  72. EXPECT_TRUE(result);
  73. }