[Tests] Migrate server tests to the shared fixture

Replace the remaining private MockDatabaseInterface/FakeServer copies in the forced-password, room-channel, movecard, and random-reveal tests with InMemoryServer_DatabaseInterface and ServerTestFixture. The room-channel test keeps its log assertions against the shared logEntries; the forced-password test seeds its moderator user and auth result through the fixture knobs. Delete movecard_tests/server_test_helpers.h.
This commit is contained in:
Lukas Brübach 2026-11-09 16:02:47 +01:00
parent 2187e47a60
commit 7b8558c695
8 changed files with 34 additions and 167 deletions

View file

@ -5,9 +5,8 @@
#include "libcockatrice/protocol/pb/response.pb.h"
#include "libcockatrice/protocol/pb/server_message.pb.h"
#include "server.h"
#include "server_database_interface.h"
#include "server_protocolhandler.h"
#include "support/server_test_fixture.h"
#include <QString>
#include <gtest/gtest.h>
@ -22,52 +21,6 @@ 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 PasswordChangeRequired;
}
ServerInfo_User getUserData(const QString &name, bool withId) override
{
ServerInfo_User user;
user.set_name(name.toStdString());
user.set_user_level(ServerInfo_User::IsUser | ServerInfo_User::IsRegistered | ServerInfo_User::IsModerator);
if (withId) {
user.set_id(1);
}
return user;
}
int getNextReplayId() override
{
return 1;
}
int getNextGameId() override
{
return 1;
}
int getActiveUserCount(QString) override
{
return 0;
}
};
class FakeServer : public Server
{
public:
FakeServer()
{
setDatabaseInterface(new MockDatabaseInterface());
}
};
class TestHandler : public Server_ProtocolHandler
{
public:
@ -103,12 +56,21 @@ protected:
}
};
class ForcedPasswordChangeTest : public ::testing::Test
class ForcedPasswordChangeTest : public ServerTestFixture
{
protected:
FakeServer server;
TestHandler handler{&server, server.getDatabaseInterface()};
void SetUp() override
{
database()->authenticationResult = PasswordChangeRequired;
ServerInfo_User mod;
mod.set_name("mod");
mod.set_id(1);
mod.set_user_level(ServerInfo_User::IsUser | ServerInfo_User::IsRegistered | ServerInfo_User::IsModerator);
database()->addUser(mod);
}
void login()
{
CommandContainer cont;