mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2025-10-15 11:58:10 +00:00
Merge branch 'main' into fix/cmake-libs-2
This commit is contained in:
@@ -101,7 +101,7 @@ TEST(LUString33Test, SerializeReadTestNew) {
|
||||
std::string testString;
|
||||
for (int i = 0; i < 33; i++) testString += "a";
|
||||
bitStream.Write(LUString(testString, 33));
|
||||
LUString result(33);
|
||||
LUString result;
|
||||
ASSERT_EQ(result.size, 33);
|
||||
ASSERT_TRUE(bitStream.Read(result));
|
||||
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
|
||||
@@ -113,7 +113,7 @@ TEST(LUString33Test, SerializeReadTestNewPartial) {
|
||||
std::string testString;
|
||||
for (int i = 0; i < 15; i++) testString += "a";
|
||||
bitStream.Write(LUString(testString, 33));
|
||||
LUString result(33);
|
||||
LUString result;
|
||||
ASSERT_EQ(result.size, 33);
|
||||
ASSERT_TRUE(bitStream.Read(result));
|
||||
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
|
||||
|
@@ -101,7 +101,7 @@ TEST(LUWString33Test, SerializeReadTestNew) {
|
||||
std::u16string testString;
|
||||
for (int i = 0; i < 33; i++) testString += u'ü';
|
||||
bitStream.Write(LUWString(testString, 33));
|
||||
LUWString result(33);
|
||||
LUWString result;
|
||||
ASSERT_EQ(result.size, 33);
|
||||
ASSERT_TRUE(bitStream.Read(result));
|
||||
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
|
||||
@@ -113,7 +113,7 @@ TEST(LUWString33Test, SerializeReadTestNewPartial) {
|
||||
std::u16string testString;
|
||||
for (int i = 0; i < 15; i++) testString += u'ü';
|
||||
bitStream.Write(LUWString(testString, 33));
|
||||
LUWString result(33);
|
||||
LUWString result;
|
||||
ASSERT_EQ(result.size, 33);
|
||||
ASSERT_TRUE(bitStream.Read(result));
|
||||
ASSERT_EQ(bitStream.GetNumberOfUnreadBits(), 0);
|
||||
|
@@ -116,27 +116,30 @@ TEST(MagicEnumTest, eGameMessageTypeTest) {
|
||||
delete Game::logger;
|
||||
}
|
||||
|
||||
#define ASSERT_EARRAY_SORTED(EARRAY_VAR)\
|
||||
for (int i = 0; i < EARRAY_VAR->size(); i++) {\
|
||||
const auto entryCurr = EARRAY_VAR->at(i).first;\
|
||||
LOG_EARRAY(EARRAY_VAR, i, entryCurr);\
|
||||
const auto entryNext = EARRAY_VAR->at(++i).first;\
|
||||
LOG_EARRAY(EARRAY_VAR, i, entryNext);\
|
||||
ASSERT_TRUE(entryCurr < entryNext);\
|
||||
};\
|
||||
#define LOG_EARRAY(EARRAY_VAR, INDICE, ENTRY) LOG(#EARRAY_VAR"[%i] = %i, %s", INDICE, ENTRY, magic_enum::enum_name(ENTRY).data());
|
||||
|
||||
#define LOG_EARRAY(EARRAY_VAR, INDICE, ENTRY)\
|
||||
LOG(#EARRAY_VAR"[%i] = %i, %s", INDICE, ENTRY, magic_enum::enum_name(ENTRY).data());
|
||||
namespace {
|
||||
template <typename T>
|
||||
void AssertEnumArraySorted(const T& eArray) {
|
||||
for (int i = 0; i < eArray->size(); ++i) {
|
||||
const auto entryCurr = eArray->at(i).first;
|
||||
LOG_EARRAY(eArray, i, entryCurr);
|
||||
const auto entryNext = eArray->at(++i).first;
|
||||
LOG_EARRAY(eArray, i, entryNext);
|
||||
ASSERT_TRUE(entryCurr < entryNext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test that the magic enum arrays are pre-sorted
|
||||
TEST(MagicEnumTest, ArraysAreSorted) {
|
||||
Game::logger = new Logger("./MagicEnumTest_ArraysAreSorted.log", true, true);
|
||||
|
||||
constexpr auto wmArray = &magic_enum::enum_entries<eWorldMessageType>();
|
||||
ASSERT_EARRAY_SORTED(wmArray);
|
||||
AssertEnumArraySorted(wmArray);
|
||||
|
||||
constexpr auto gmArray = &magic_enum::enum_entries<eGameMessageType>();
|
||||
ASSERT_EARRAY_SORTED(gmArray);
|
||||
AssertEnumArraySorted(gmArray);
|
||||
|
||||
delete Game::logger;
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include "Game.h"
|
||||
#include "Logger.h"
|
||||
#include "dServer.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "EntityInfo.h"
|
||||
#include "EntityManager.h"
|
||||
#include "dConfig.h"
|
||||
@@ -33,6 +34,9 @@ protected:
|
||||
Game::server = new dServerMock();
|
||||
Game::config = new dConfig("worldconfig.ini");
|
||||
Game::entityManager = new EntityManager();
|
||||
|
||||
// Create a CDClientManager instance and load from defaults
|
||||
CDClientManager::Instance().LoadValuesFromDefaults();
|
||||
}
|
||||
|
||||
void TearDownDependencies() {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
set(DCOMPONENTS_TESTS
|
||||
"DestroyableComponentTests.cpp"
|
||||
"PetComponentTests.cpp"
|
||||
"SimplePhysicsComponentTests.cpp"
|
||||
)
|
||||
|
||||
|
43
tests/dGameTests/dComponentsTests/PetComponentTests.cpp
Normal file
43
tests/dGameTests/dComponentsTests/PetComponentTests.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "GameDependencies.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "BitStream.h"
|
||||
#include "PetComponent.h"
|
||||
#include "Entity.h"
|
||||
#include "eReplicaComponentType.h"
|
||||
#include "ePetAbilityType.h"
|
||||
#include "eStateChangeType.h"
|
||||
|
||||
class PetTest : public GameDependenciesTest {
|
||||
protected:
|
||||
Entity* baseEntity;
|
||||
PetComponent* petComponent;
|
||||
CBITSTREAM
|
||||
|
||||
void SetUp() override {
|
||||
SetUpDependencies();
|
||||
|
||||
// Set up entity and pet component
|
||||
baseEntity = new Entity(15, GameDependenciesTest::info);
|
||||
petComponent = baseEntity->AddComponent<PetComponent>(1);
|
||||
|
||||
// Initialize some values to be not default
|
||||
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
delete baseEntity;
|
||||
TearDownDependencies();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(PetTest, PlacementNewAddComponentTest) {
|
||||
// Test adding component
|
||||
ASSERT_NE(petComponent, nullptr);
|
||||
baseEntity->AddComponent<PetComponent>(1);
|
||||
ASSERT_NE(baseEntity->GetComponent<PetComponent>(), nullptr);
|
||||
|
||||
// Test getting initial status
|
||||
ASSERT_EQ(petComponent->GetParent()->GetObjectID(), 15);
|
||||
ASSERT_EQ(petComponent->GetAbility(), ePetAbilityType::Invalid);
|
||||
}
|
Reference in New Issue
Block a user