Robot Devastation
MockNetworkManager.hpp
1 // Authors: see AUTHORS.md at project root.
2 // CopyPolicy: released under the terms of the LGPLv2.1, see LICENSE at project root.
3 // URL: https://github.com/asrob-uc3m/robotDevastation
4 
5 #ifndef __RD_MOCK_NETWORK_MANAGER_HPP__
6 #define __RD_MOCK_NETWORK_MANAGER_HPP__
7 
8 #include <string>
9 #include <vector>
10 #include <map>
11 
12 #include "NetworkManager.hpp"
13 #include "NetworkEventListener.hpp"
14 #include "Player.hpp"
15 
16 namespace rd{
17 
36 {
37  public:
38  //-- Creation and configuration
39  //--------------------------------------------------------------------------------------------
45  static bool RegisterManager();
46 
47  virtual ~MockNetworkManager();
48 
50  static const std::string id;
51 
52  //------------------------------ Manager Startup & Halting ----------------------------------------------------//
53  virtual bool start();
54  virtual bool stop();
55 
57  virtual bool configure(const std::string & parameter, const Player & value);
58 
59  //-- Server API
60  //--------------------------------------------------------------------------------------------
61  virtual bool sendPlayerHit(const Player & player, int damage);
62  virtual bool login();
63  virtual bool logout();
64  virtual bool keepAlive();
65 
66  //-- Mock object API
67  //--------------------------------------------------------------------------------------------
68  bool isLoggedIn() const;
69  bool isStopped() const;
70 
71  bool setPlayerData(const std::vector<Player> & game_players);
72  std::vector<Player> getPlayerData() const;
73  bool sendPlayerData();
74  bool setLoggedIn(bool logged_in);
75 
76  private:
84 
86  MockNetworkManager & operator=(const MockNetworkManager &);
87 
90 
91 
92  //-- Required stuff
93  bool logged_in;
94  bool stopped;
95  Player player;
96  std::vector<Player> game_players;
97  std::map <int, Player> players_dic;
98 
99 };
100 }
101 
102 #endif //-- __RD_MOCK_NETWORK_MANAGER_HPP__
rd::MockNetworkManager::id
static const std::string id
String that identifies this manager.
Definition: MockNetworkManager.hpp:50
rd::MockNetworkManager::MockNetworkManager
MockNetworkManager()
Constructor.
Definition: MockNetworkManager.cpp:208
rd::MockNetworkManager::configure
virtual bool configure(const std::string &parameter, const Player &value)
Configures a parameter with a value.
Definition: MockNetworkManager.cpp:46
rd::MockNetworkManager::login
virtual bool login()
Log the user into the network.
Definition: MockNetworkManager.cpp:88
rd::MockNetworkManager
Allow for low-level access of members in tests / manipulating internal data.
Definition: MockNetworkManager.hpp:35
rd::MockNetworkManager::start
virtual bool start()
Start the network manager.
Definition: MockNetworkManager.cpp:31
rd::MockNetworkManager::keepAlive
virtual bool keepAlive()
Keeps the user connected to the server (requires to be called periodically)
Definition: MockNetworkManager.cpp:143
rd::Player
Class that represents a player of this game, with a 'unique' id, name, health, team id and score.
Definition: Player.hpp:21
rd
The main, catch-all namespace for Robot Devastation.
Definition: groups.dox:4
rd::MockNetworkManager::stop
virtual bool stop()
Stop the network manager.
Definition: MockNetworkManager.cpp:40
rd::MockNetworkManager::sendPlayerHit
virtual bool sendPlayerHit(const Player &player, int damage)
Communicate to the network that a player has been hit by the user.
Definition: MockNetworkManager.cpp:57
rd::MockNetworkManager::uniqueInstance
static MockNetworkManager * uniqueInstance
Reference to this manager (unique instance)
Definition: MockNetworkManager.hpp:89
rd::MockNetworkManager::isStopped
bool isStopped() const
Returns true if manager is stopped (obviously)
Definition: MockNetworkManager.cpp:153
rd::MockNetworkManager::RegisterManager
static bool RegisterManager()
Register this manager in the NetworkManager registry so that can be used.
Definition: MockNetworkManager.cpp:16
rd::NetworkManager
Manages the communications between the user and the RobotDevastation network.
Definition: NetworkManager.hpp:37
rd::MockNetworkManager::logout
virtual bool logout()
Log the user out of the network.
Definition: MockNetworkManager.cpp:115