Multiplayer_AutoComponent_NetworkInput.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. # Test Case Title : Check that network input can be created, received by the authority, and processed
  7. # fmt: off
  8. class Tests():
  9. enter_game_mode = ("Entered game mode", "Failed to enter game mode")
  10. exit_game_mode = ("Exited game mode", "Couldn't exit game mode")
  11. find_network_player = ("Found network player", "Couldn't find network player")
  12. found_lines = ("Expected log lines were found", "Expected log lines were not found")
  13. found_unexpected_lines = ("Unexpected log lines were not found", "Unexpected log lines were found")
  14. # fmt: on
  15. def Multiplayer_AutoComponent_NetworkInput():
  16. r"""
  17. Summary:
  18. Runs a test to make sure that network input can be sent from the autonomous player, received by the authority, and processed
  19. Level Description:
  20. - Dynamic
  21. 1. Although the level is empty, when the server and editor connect the server will spawn and replicate the player network prefab.
  22. a. The player network prefab has a NetworkTestPlayerComponent.AutoComponent and a script canvas attached which will listen for the CreateInput and ProcessInput events.
  23. Print logs occur upon triggering the CreateInput and ProcessInput events along with their values; we are testing to make sure the expected events are values are recieved.
  24. - Static
  25. 1. This is an empty level. All the logic occurs on the Player.network.spawnable (see the above Dynamic description)
  26. Expected Outcome:
  27. We should see editor logs stating that network input has been created and processed.
  28. However, if the script receives unexpected values for the Process event we will see print logs for bad data as well.
  29. :return:
  30. """
  31. import azlmbr.legacy.general as general
  32. from editor_python_test_tools.utils import Report
  33. from editor_python_test_tools.utils import Tracer
  34. from editor_python_test_tools.utils import TestHelper as helper
  35. level_name = "AutoComponent_NetworkInput"
  36. helper.init_idle()
  37. general.set_cvar_integer('editorsv_port', 33452)
  38. # 1) Open Level
  39. helper.open_level("Multiplayer", level_name)
  40. with Tracer() as section_tracer:
  41. # 2) Enter game mode
  42. helper.multiplayer_enter_game_mode(Tests.enter_game_mode)
  43. # 3) Make sure the network player was spawned
  44. player_id = general.find_game_entity("Player")
  45. Report.critical_result(Tests.find_network_player, player_id.IsValid())
  46. # 4) Check the editor logs for expected and unexpected log output
  47. EXPECTEDLINE_WAIT_TIME_SECONDS = 1.0
  48. helper.succeed_if_log_line_found('Script', "AutoComponent_NetworkInput CreateInput called!", section_tracer.prints, EXPECTEDLINE_WAIT_TIME_SECONDS)
  49. helper.succeed_if_log_line_found('Script', "AutoComponent_NetworkInput ProcessInput called!", section_tracer.prints, EXPECTEDLINE_WAIT_TIME_SECONDS)
  50. helper.succeed_if_log_line_found('EditorServer', 'Script: AutoComponent_NetworkInput ProcessInput called!', section_tracer.prints, EXPECTEDLINE_WAIT_TIME_SECONDS)
  51. WAIT_TIME_CLIENT_RECEIVED_INCORRECT_INPUT = 1.0
  52. helper.fail_if_log_line_found("Script", "AutoComponent_NetworkInput received bad fwdback!", section_tracer.prints, WAIT_TIME_CLIENT_RECEIVED_INCORRECT_INPUT)
  53. helper.fail_if_log_line_found("Script", "AutoComponent_NetworkInput received bad leftright!", section_tracer.prints, WAIT_TIME_CLIENT_RECEIVED_INCORRECT_INPUT)
  54. # Exit game mode
  55. helper.exit_game_mode(Tests.exit_game_mode)
  56. if __name__ == "__main__":
  57. from editor_python_test_tools.utils import Report
  58. Report.start_test(Multiplayer_AutoComponent_NetworkInput)