mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-10 20:13:24 -08:00
[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:
parent
2187e47a60
commit
7b8558c695
8 changed files with 34 additions and 167 deletions
|
|
@ -371,6 +371,9 @@ cockatrice_add_test(
|
||||||
LIBS
|
LIBS
|
||||||
libcockatrice_network_server_remote
|
libcockatrice_network_server_remote
|
||||||
libcockatrice_rng
|
libcockatrice_rng
|
||||||
|
testsupport_server
|
||||||
|
INCLUDE_DIRS
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
LABELS
|
LABELS
|
||||||
server
|
server
|
||||||
)
|
)
|
||||||
|
|
@ -396,6 +399,9 @@ cockatrice_add_test(
|
||||||
LIBS
|
LIBS
|
||||||
libcockatrice_network_server_remote
|
libcockatrice_network_server_remote
|
||||||
libcockatrice_rng
|
libcockatrice_rng
|
||||||
|
testsupport_server
|
||||||
|
INCLUDE_DIRS
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
LABELS
|
LABELS
|
||||||
server
|
server
|
||||||
)
|
)
|
||||||
|
|
@ -431,6 +437,9 @@ cockatrice_add_test(
|
||||||
LIBS
|
LIBS
|
||||||
libcockatrice_network_server_remote
|
libcockatrice_network_server_remote
|
||||||
libcockatrice_rng
|
libcockatrice_rng
|
||||||
|
testsupport_server
|
||||||
|
INCLUDE_DIRS
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
LABELS
|
LABELS
|
||||||
server
|
server
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,9 @@ cockatrice_add_test(
|
||||||
LIBS
|
LIBS
|
||||||
libcockatrice_network_server_remote
|
libcockatrice_network_server_remote
|
||||||
libcockatrice_rng
|
libcockatrice_rng
|
||||||
|
testsupport_server
|
||||||
|
INCLUDE_DIRS
|
||||||
|
${CMAKE_SOURCE_DIR}/tests
|
||||||
LABELS
|
LABELS
|
||||||
server
|
server
|
||||||
)
|
)
|
||||||
|
|
@ -18,6 +21,9 @@ cockatrice_add_test(
|
||||||
LIBS
|
LIBS
|
||||||
libcockatrice_network_server_remote
|
libcockatrice_network_server_remote
|
||||||
libcockatrice_rng
|
libcockatrice_rng
|
||||||
|
testsupport_server
|
||||||
|
INCLUDE_DIRS
|
||||||
|
${CMAKE_SOURCE_DIR}/tests
|
||||||
LABELS
|
LABELS
|
||||||
server
|
server
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
#include "server_abstractuserinterface.h"
|
#include "server_abstractuserinterface.h"
|
||||||
#include "server_response_containers.h"
|
#include "server_response_containers.h"
|
||||||
#include "server_room.h"
|
#include "server_room.h"
|
||||||
#include "server_test_helpers.h"
|
#include "support/server_test_fixture.h"
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <libcockatrice/protocol/pb/game_event_container.pb.h>
|
#include <libcockatrice/protocol/pb/game_event_container.pb.h>
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
#include "libcockatrice/protocol/pb/serverinfo_zone.pb.h"
|
#include "libcockatrice/protocol/pb/serverinfo_zone.pb.h"
|
||||||
#include "server_response_containers.h"
|
#include "server_response_containers.h"
|
||||||
#include "server_room.h"
|
#include "server_room.h"
|
||||||
#include "server_test_helpers.h"
|
#include "support/server_test_fixture.h"
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
|
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
#include "server.h"
|
|
||||||
#include "server_database_interface.h"
|
|
||||||
|
|
||||||
class MockDatabaseInterface : public Server_DatabaseInterface
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AuthenticationResult checkUserPassword(Server_ProtocolHandler *,
|
|
||||||
const QString &,
|
|
||||||
const QString &,
|
|
||||||
const QString &,
|
|
||||||
QString &,
|
|
||||||
int &,
|
|
||||||
bool) override
|
|
||||||
{
|
|
||||||
return NotLoggedIn;
|
|
||||||
}
|
|
||||||
ServerInfo_User getUserData(const QString &, bool) override
|
|
||||||
{
|
|
||||||
return ServerInfo_User();
|
|
||||||
}
|
|
||||||
int getNextGameId() override
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
int getNextReplayId() override
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
int getActiveUserCount(QString) override
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class FakeServer : public Server
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FakeServer()
|
|
||||||
{
|
|
||||||
setDatabaseInterface(new MockDatabaseInterface());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
@ -3,10 +3,10 @@
|
||||||
#include "game/server_card.h"
|
#include "game/server_card.h"
|
||||||
#include "game/server_cardzone.h"
|
#include "game/server_cardzone.h"
|
||||||
#include "game/server_game.h"
|
#include "game/server_game.h"
|
||||||
#include "movecard_tests/server_test_helpers.h"
|
|
||||||
#include "server_abstractuserinterface.h"
|
#include "server_abstractuserinterface.h"
|
||||||
#include "server_response_containers.h"
|
#include "server_response_containers.h"
|
||||||
#include "server_room.h"
|
#include "server_room.h"
|
||||||
|
#include "support/server_test_fixture.h"
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,8 @@
|
||||||
|
|
||||||
#include "libcockatrice/protocol/pb/response.pb.h"
|
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||||
#include "libcockatrice/protocol/pb/server_message.pb.h"
|
#include "libcockatrice/protocol/pb/server_message.pb.h"
|
||||||
#include "server.h"
|
|
||||||
#include "server_database_interface.h"
|
|
||||||
#include "server_protocolhandler.h"
|
#include "server_protocolhandler.h"
|
||||||
|
#include "support/server_test_fixture.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
@ -22,52 +21,6 @@ RNG_Abstract *rng = nullptr; // referenced by the server_remote library
|
||||||
namespace
|
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
|
class TestHandler : public Server_ProtocolHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -103,12 +56,21 @@ protected:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class ForcedPasswordChangeTest : public ::testing::Test
|
class ForcedPasswordChangeTest : public ServerTestFixture
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
FakeServer server;
|
|
||||||
TestHandler handler{&server, server.getDatabaseInterface()};
|
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()
|
void login()
|
||||||
{
|
{
|
||||||
CommandContainer cont;
|
CommandContainer cont;
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,9 @@
|
||||||
|
|
||||||
#include "libcockatrice/protocol/pb/response.pb.h"
|
#include "libcockatrice/protocol/pb/response.pb.h"
|
||||||
#include "libcockatrice/protocol/pb/server_message.pb.h"
|
#include "libcockatrice/protocol/pb/server_message.pb.h"
|
||||||
#include "server.h"
|
|
||||||
#include "server_database_interface.h"
|
|
||||||
#include "server_protocolhandler.h"
|
#include "server_protocolhandler.h"
|
||||||
#include "server_room.h"
|
#include "server_room.h"
|
||||||
|
#include "support/server_test_fixture.h"
|
||||||
|
|
||||||
#include <QList>
|
#include <QList>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
@ -33,73 +32,6 @@ RNG_Abstract *rng = nullptr; // referenced by the server_remote library
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
class MockDatabaseInterface : public Server_DatabaseInterface
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
struct LogEntry
|
|
||||||
{
|
|
||||||
QString senderName;
|
|
||||||
QString message;
|
|
||||||
LogMessage_TargetType targetType;
|
|
||||||
int targetId;
|
|
||||||
QString targetName;
|
|
||||||
QString channel;
|
|
||||||
};
|
|
||||||
QList<LogEntry> logEntries;
|
|
||||||
|
|
||||||
void logMessage(const int /* senderId */,
|
|
||||||
const QString &senderName,
|
|
||||||
const QString & /* senderIp */,
|
|
||||||
const QString &message,
|
|
||||||
LogMessage_TargetType targetType,
|
|
||||||
const int targetId,
|
|
||||||
const QString &targetName,
|
|
||||||
const QString &channel = QString()) override
|
|
||||||
{
|
|
||||||
logEntries.append({senderName, message, targetType, targetId, targetName, channel});
|
|
||||||
}
|
|
||||||
|
|
||||||
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:
|
|
||||||
explicit FakeServer(Server_DatabaseInterface *db) : Server()
|
|
||||||
{
|
|
||||||
setDatabaseInterface(db);
|
|
||||||
}
|
|
||||||
void insertRoom(Server_Room *newRoom)
|
|
||||||
{
|
|
||||||
addRoom(newRoom);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class TestRoomHandler : public Server_ProtocolHandler
|
class TestRoomHandler : public Server_ProtocolHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -149,8 +81,8 @@ protected:
|
||||||
class RoomChannelTest : public ::testing::Test
|
class RoomChannelTest : public ::testing::Test
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
MockDatabaseInterface db;
|
FakeServer server;
|
||||||
FakeServer server{&db};
|
InMemoryServer_DatabaseInterface &db{*server.database()};
|
||||||
QList<ServerInfo_RoomChannel> catalog;
|
QList<ServerInfo_RoomChannel> catalog;
|
||||||
Server_Room *room = nullptr;
|
Server_Room *room = nullptr;
|
||||||
TestRoomHandler mod{&server, &db};
|
TestRoomHandler mod{&server, &db};
|
||||||
|
|
@ -360,7 +292,7 @@ TEST_F(RoomChannelTest, UserBelowRequiredLevelCannotSendToChannel)
|
||||||
EXPECT_TRUE(channelSayEvents(mod).isEmpty());
|
EXPECT_TRUE(channelSayEvents(mod).isEmpty());
|
||||||
EXPECT_TRUE(channelSayEvents(user).isEmpty());
|
EXPECT_TRUE(channelSayEvents(user).isEmpty());
|
||||||
bool loggedAsChannel = false;
|
bool loggedAsChannel = false;
|
||||||
for (const MockDatabaseInterface::LogEntry &entry : db.logEntries) {
|
for (const InMemoryServer_DatabaseInterface::LogEntry &entry : db.logEntries) {
|
||||||
loggedAsChannel |= entry.targetType == Server_DatabaseInterface::MessageTargetRoomChannel;
|
loggedAsChannel |= entry.targetType == Server_DatabaseInterface::MessageTargetRoomChannel;
|
||||||
}
|
}
|
||||||
EXPECT_FALSE(loggedAsChannel);
|
EXPECT_FALSE(loggedAsChannel);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue