1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-25 11:52:40 +01:00

Add more object tests and fix a ped info bug

The car mask ped info member was being loaded as base 10 instead of base 16
This commit is contained in:
Daniel Evans 2018-08-05 23:55:20 +01:00
parent a8b2b94b05
commit fc64c5e87e
2 changed files with 30 additions and 11 deletions

View File

@ -172,7 +172,7 @@ bool LoaderIDE::load(std::istream& str, const PedStatsList& stats) {
getline(strstream, peds->animgroup_, ','); getline(strstream, peds->animgroup_, ',');
getline(strstream, buff, ','); getline(strstream, buff, ',');
peds->carsmask_ = lexical_cast<int>(buff); peds->carsmask_ = static_cast<int>(std::strtol(buff.c_str(), nullptr, 16));
objects.emplace(peds->id(), std::move(peds)); objects.emplace(peds->id(), std::move(peds));
break; break;

View File

@ -12,6 +12,10 @@ end
cars cars
90, vehicle, texture, car, HANDLING, NAME, richfamily, 10, 7, 0, 164, 0.8 90, vehicle, texture, car, HANDLING, NAME, richfamily, 10, 7, 0, 164, 0.8
end end
peds
1, mod, txd, COP, STAT_COP, man, 7f
end
)"; )";
template<size_t N> template<size_t N>
@ -43,6 +47,19 @@ void ASSERT_VEHICLE_IS(BaseModelInfo& info, const char* model, const char* txd,
BOOST_CHECK_EQUAL(t.wheelmodel_, wheel); BOOST_CHECK_EQUAL(t.wheelmodel_, wheel);
BOOST_CHECK_EQUAL(t.wheelscale_, wheelScale); BOOST_CHECK_EQUAL(t.wheelscale_, wheelScale);
} }
void ASSERT_PED_IS(BaseModelInfo& info, const char* model, const char* txd,
PedModelInfo::PedType type, int statindex, const char* animgroup,
size_t carmask) {
BOOST_ASSERT(info.type() == PedModelInfo::kType);
const auto& t = dynamic_cast<PedModelInfo&>(info);
BOOST_CHECK_EQUAL(t.name, model);
BOOST_CHECK_EQUAL(t.textureslot, txd);
BOOST_CHECK_EQUAL(t.pedtype_, type);
BOOST_CHECK_EQUAL(t.statindex_, statindex);
BOOST_CHECK_EQUAL(t.animgroup_, animgroup);
BOOST_CHECK_EQUAL(t.carsmask_, carmask);
}
} }
struct WithLoaderIDE { struct WithLoaderIDE {
@ -53,23 +70,25 @@ struct WithLoaderIDE {
BOOST_FIXTURE_TEST_SUITE(ObjectDataTests, WithLoaderIDE) BOOST_FIXTURE_TEST_SUITE(ObjectDataTests, WithLoaderIDE)
BOOST_AUTO_TEST_CASE(parses_basic_instance) { BOOST_AUTO_TEST_CASE(objects_contains_modelID) {
loader.load(test_data_stream, {}); loader.load(test_data_stream, {});
BOOST_ASSERT(loader.objects.find(1100) != loader.objects.end()); BOOST_ASSERT(loader.objects.find(1100) != loader.objects.end());
auto info = loader.objects[1100].get();
ASSERT_INSTANCE_IS<1>(*info, "NAME", "TXD", {220}, 0);
} }
BOOST_AUTO_TEST_CASE(parses_vehicle) { BOOST_AUTO_TEST_CASE(instance_data_is_correct) {
loader.load(test_data_stream, {}); loader.load(test_data_stream, {});
ASSERT_INSTANCE_IS<1>(*loader.objects[1100], "NAME", "TXD", {220}, 0);
}
BOOST_ASSERT(loader.objects.find(90) != loader.objects.end()); BOOST_AUTO_TEST_CASE(vehicle_data_is_correct) {
auto obj = loader.objects[90].get(); loader.load(test_data_stream, {});
ASSERT_VEHICLE_IS(*loader.objects[90], "vehicle", "texture", VehicleModelInfo::CAR, "HANDLING", "NAME",
ASSERT_VEHICLE_IS(*obj, "vehicle", "texture", VehicleModelInfo::CAR, "HANDLING", "NAME",
VehicleModelInfo::RICHFAMILY, 10, 164, 0.8f); VehicleModelInfo::RICHFAMILY, 10, 164, 0.8f);
} }
BOOST_AUTO_TEST_CASE(pedestrian_data_is_correct) {
loader.load(test_data_stream, {});
ASSERT_PED_IS(*loader.objects[1], "mod", "txd", PedModelInfo::COP, -1, "man", 0x7f);
}
BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_SUITE_END()