mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 20:13:24 -08:00
[Tests] Add a shared in-memory server test fixture
Add tests/support/server_test_fixture as a built-but-unshipped static target: an InMemoryServer_DatabaseInterface with configurable auth, a user table, session bookkeeping, ban state, id counters, and chat-log capture, plus FakeServer and ServerTestFixture. Migrate server_game_join_test to it, removing the first private copy of the mock.
This commit is contained in:
parent
3b379618c3
commit
2187e47a60
4 changed files with 266 additions and 44 deletions
|
|
@ -7,9 +7,8 @@
|
|||
#include "game/role_info.h"
|
||||
#include "game/server_game.h"
|
||||
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||
#include "server.h"
|
||||
#include "server_database_interface.h"
|
||||
#include "server_room.h"
|
||||
#include "support/server_test_fixture.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
|
@ -23,50 +22,9 @@ RNG_Abstract *rng = nullptr; // referenced by the server_remote library
|
|||
namespace
|
||||
{
|
||||
|
||||
class MockDatabaseInterface : public Server_DatabaseInterface
|
||||
{
|
||||
public:
|
||||
AuthenticationResult checkUserPassword(Server_ProtocolHandler *,
|
||||
const QString &,
|
||||
const QString &,
|
||||
const QString &,
|
||||
QString &,
|
||||
int &,
|
||||
bool) override
|
||||
{
|
||||
return NotLoggedIn;
|
||||
}
|
||||
int getNextReplayId() override
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
int getNextGameId() override
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
int getActiveUserCount(QString) override
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
ServerInfo_User getUserData(const QString &, bool) override
|
||||
{
|
||||
return ServerInfo_User();
|
||||
}
|
||||
};
|
||||
|
||||
class FakeServer : public Server
|
||||
{
|
||||
public:
|
||||
FakeServer()
|
||||
{
|
||||
setDatabaseInterface(new MockDatabaseInterface());
|
||||
}
|
||||
};
|
||||
|
||||
class GameJoinOverrideTest : public ::testing::Test
|
||||
class GameJoinOverrideTest : public ServerTestFixture
|
||||
{
|
||||
protected:
|
||||
FakeServer server;
|
||||
Server_Room room{0, 0, "", "", "", "", false, "", {}, &server};
|
||||
ServerInfo_User creator;
|
||||
ServerInfo_User plainUser;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue