mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 02:12:45 +01:00
Extract object data assertions to functions
This commit is contained in:
parent
81b7e5226a
commit
3b7bb14de6
@ -172,7 +172,7 @@ public:
|
||||
loddistances_[n] = d;
|
||||
}
|
||||
|
||||
float getLodDistance(int n) {
|
||||
float getLodDistance(int n) const {
|
||||
RW_CHECK(n < 3, "Lod Index out of range");
|
||||
return loddistances_[n];
|
||||
}
|
||||
|
@ -17,6 +17,36 @@ cars
|
||||
90, vehicle, texture, car, HANDLING, NAME, richfamily, 10, 7, 0, 164, 0.8
|
||||
end
|
||||
)";
|
||||
|
||||
template<size_t N>
|
||||
void ASSERT_INSTANCE_IS(BaseModelInfo& info, const char* model, const char* txd,
|
||||
const std::array<float, N>& lods, size_t flags) {
|
||||
BOOST_ASSERT(info.type() == SimpleModelInfo::kType);
|
||||
const auto& t = dynamic_cast<SimpleModelInfo&>(info);
|
||||
BOOST_CHECK_EQUAL(t.name, model);
|
||||
BOOST_CHECK_EQUAL(t.textureslot, txd);
|
||||
BOOST_CHECK_EQUAL(t.getNumAtomics(), lods.size());
|
||||
for (auto i = 0u; i < lods.size(); ++i) {
|
||||
BOOST_CHECK_EQUAL(t.getLodDistance(i), lods[i]);
|
||||
}
|
||||
BOOST_CHECK_EQUAL(t.flags, flags);
|
||||
}
|
||||
|
||||
void ASSERT_VEHICLE_IS(BaseModelInfo& info, const char* model, const char* txd,
|
||||
VehicleModelInfo::VehicleType type, const char* handling, const char* name,
|
||||
VehicleModelInfo::VehicleClass clas_, int frequency, ModelID wheel, float wheelScale) {
|
||||
BOOST_ASSERT(info.type() == VehicleModelInfo::kType);
|
||||
const auto& t = dynamic_cast<VehicleModelInfo&>(info);
|
||||
BOOST_CHECK_EQUAL(t.name, model);
|
||||
BOOST_CHECK_EQUAL(t.textureslot, txd);
|
||||
BOOST_CHECK_EQUAL(t.vehicletype_, type);
|
||||
BOOST_CHECK_EQUAL(t.handling_, handling);
|
||||
BOOST_CHECK_EQUAL(t.vehiclename_, name);
|
||||
BOOST_CHECK_EQUAL(t.vehicleclass_, clas_);
|
||||
BOOST_CHECK_EQUAL(t.frequency_, frequency);
|
||||
BOOST_CHECK_EQUAL(t.wheelmodel_, wheel);
|
||||
BOOST_CHECK_EQUAL(t.wheelscale_, wheelScale);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(ObjectDataTests, WithLoaderIDE)
|
||||
@ -26,18 +56,9 @@ BOOST_AUTO_TEST_CASE(parses_basic_instance) {
|
||||
loader.load(str, {});
|
||||
|
||||
BOOST_ASSERT(loader.objects.find(1100) != loader.objects.end());
|
||||
auto info = loader.objects[1100].get();
|
||||
|
||||
auto obj = loader.objects[1100].get();
|
||||
|
||||
auto def = dynamic_cast<SimpleModelInfo *>(obj);
|
||||
|
||||
BOOST_ASSERT(def->type() == ModelDataType::SimpleInfo);
|
||||
|
||||
BOOST_CHECK_EQUAL(def->name, "NAME");
|
||||
BOOST_CHECK_EQUAL(def->textureslot, "TXD");
|
||||
BOOST_CHECK_EQUAL(def->getNumAtomics(), 1);
|
||||
BOOST_CHECK_EQUAL(def->getLodDistance(0), 220);
|
||||
BOOST_CHECK_EQUAL(def->flags, 0);
|
||||
ASSERT_INSTANCE_IS<1>(*info, "NAME", "TXD", {220}, 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parses_vehicle) {
|
||||
@ -45,22 +66,10 @@ BOOST_AUTO_TEST_CASE(parses_vehicle) {
|
||||
loader.load(str, {});
|
||||
|
||||
BOOST_ASSERT(loader.objects.find(90) != loader.objects.end());
|
||||
|
||||
auto obj = loader.objects[90].get();
|
||||
|
||||
auto def = dynamic_cast<VehicleModelInfo*>(obj);
|
||||
|
||||
BOOST_ASSERT(def->type() == ModelDataType::VehicleInfo);
|
||||
|
||||
BOOST_CHECK_EQUAL(def->name, "vehicle");
|
||||
BOOST_CHECK_EQUAL(def->textureslot, "texture");
|
||||
BOOST_CHECK_EQUAL(def->vehicletype_, VehicleModelInfo::CAR);
|
||||
BOOST_CHECK_EQUAL(def->handling_, "HANDLING");
|
||||
BOOST_CHECK_EQUAL(def->vehiclename_, "NAME");
|
||||
BOOST_CHECK_EQUAL(def->vehicleclass_, VehicleModelInfo::RICHFAMILY);
|
||||
BOOST_CHECK_EQUAL(def->frequency_, 10);
|
||||
BOOST_CHECK_EQUAL(def->wheelmodel_, 164);
|
||||
BOOST_CHECK_CLOSE(def->wheelscale_, 0.8f, 0.01f);
|
||||
ASSERT_VEHICLE_IS(*obj, "vehicle", "texture", VehicleModelInfo::CAR, "HANDLING", "NAME",
|
||||
VehicleModelInfo::RICHFAMILY, 10, 164, 0.8f);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
Reference in New Issue
Block a user