Files
DarkflameServer/tests/dGameTests/dComponentsTests/ModelComponentTests.cpp
Aaron Kimbrell 8a1d278265 fix: the zone keeps its paths after the merge, and the tests follow the merged readers
- Zone::LoadZoneIntoMemory takes the paths the zone file reader read (lost in the merge of the raw terrain loading)
- the terrain reader is main's unchanged: files from before version 32 keep their colour and texture maps as the file
  has them, and the dashboard's terrain tests expect that (bounds by the span between the first and last point too)
- the model component test counts the model block only: the item block in front of it is the ItemComponent's
- scene file tests: a file from before chunks keeps only its header, editor settings are a count of colours, and the
  tests that log have a logger
- the settings catalog lists export_terrain_to_obj

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 12:14:23 -06:00

56 lines
1.8 KiB
C++

#include "GameDependencies.h"
#include "BitStream.h"
#include "CDClientManager.h"
#include "CDComponentsRegistryTable.h"
#include "Entity.h"
#include "GameMessages.h"
#include "ModelComponent.h"
#include <gtest/gtest.h>
class ModelComponentTests : public GameDependenciesTest {
protected:
void SetUp() override {
SetUpDependencies();
CDClientManager::GetEntriesMutable<CDComponentsRegistryTable>().insert_or_assign(static_cast<uint64_t>(info.lot), 0);
}
void TearDown() override {
TearDownDependencies();
}
// The bits a model's serialization writes
static uint32_t SerializedBits(Entity& entity) {
auto* model = entity.AddComponent<ModelComponent>(-1);
RakNet::BitStream bitStream;
model->Serialize(bitStream, true);
return bitStream.GetNumberOfBitsUsed();
}
};
// Model block (1 + 1 + 32 + 96 + 128); the item block in front of it is the ItemComponent's
constexpr uint32_t ModelBlockBits = 258;
// Behavior info: flag, count, paused, and on the initial update the editing info flag
constexpr uint32_t BehaviorBits = 1 + 32 + 1 + 1;
// The client reads the behaviors only for property and inventory models (ObjectLoader2::LoadModelBehaviorsComponent)
TEST_F(ModelComponentTests, OtherModelsHaveNoBehaviorInfo) {
Entity entity(1, info);
EXPECT_EQ(SerializedBits(entity), ModelBlockBits);
}
TEST_F(ModelComponentTests, PropertyModelsHaveBehaviorInfo) {
EntityInfo propertyInfo = info;
propertyInfo.settings.Insert<bool>(u"propertyObjectID", true);
Entity entity(1, propertyInfo);
EXPECT_EQ(SerializedBits(entity), ModelBlockBits + BehaviorBits);
}
TEST_F(ModelComponentTests, InventoryModelsHaveBehaviorInfo) {
EntityInfo inventoryInfo = info;
inventoryInfo.settings.Insert<bool>(u"inInventory", true);
Entity entity(1, inventoryInfo);
EXPECT_EQ(SerializedBits(entity), ModelBlockBits + BehaviorBits);
}