mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-18 16:32:32 +02:00
Merge pull request #572 from danhedron/test_update/IPL
Remove data dependency from LoaderIPL tests
This commit is contained in:
commit
be2816c398
@ -13,17 +13,20 @@
|
|||||||
|
|
||||||
#include "data/InstanceData.hpp"
|
#include "data/InstanceData.hpp"
|
||||||
#include "data/ZoneData.hpp"
|
#include "data/ZoneData.hpp"
|
||||||
|
#include "LoaderIPL.hpp"
|
||||||
|
|
||||||
|
|
||||||
#include <rw/casts.hpp>
|
#include <rw/casts.hpp>
|
||||||
|
|
||||||
enum SectionTypes { INST, PICK, CULL, ZONE, NONE };
|
enum SectionTypes { INST, PICK, CULL, ZONE, NONE };
|
||||||
|
|
||||||
/// Load the IPL data into memory
|
|
||||||
bool LoaderIPL::load(const std::string& filename) {
|
bool LoaderIPL::load(const std::string& filename) {
|
||||||
std::ifstream str(filename);
|
std::ifstream str(filename);
|
||||||
|
|
||||||
if (!str.is_open()) return false;
|
if (!str.is_open()) return false;
|
||||||
|
return load(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LoaderIPL::load(std::istream &str) {
|
||||||
SectionTypes section = NONE;
|
SectionTypes section = NONE;
|
||||||
while (!str.eof()) {
|
while (!str.eof()) {
|
||||||
std::string line;
|
std::string line;
|
||||||
@ -134,3 +137,4 @@ bool LoaderIPL::load(const std::string& filename) {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,9 +15,12 @@ struct InstanceData;
|
|||||||
*/
|
*/
|
||||||
class LoaderIPL {
|
class LoaderIPL {
|
||||||
public:
|
public:
|
||||||
/// Load the IPL data into memory
|
/// Load the IPL data from filename
|
||||||
bool load(const std::string& filename);
|
bool load(const std::string& filename);
|
||||||
|
|
||||||
|
/// Parse IPL data from the stream
|
||||||
|
bool load(std::istream& stream);
|
||||||
|
|
||||||
/// The list of instances from the IPL file
|
/// The list of instances from the IPL file
|
||||||
std::vector<std::shared_ptr<InstanceData>> m_instances;
|
std::vector<std::shared_ptr<InstanceData>> m_instances;
|
||||||
|
|
||||||
|
@ -1,21 +1,83 @@
|
|||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
#include <loaders/LoaderIPL.hpp>
|
#include <loaders/LoaderIPL.hpp>
|
||||||
|
#include <data/InstanceData.hpp>
|
||||||
#include "test_Globals.hpp"
|
#include "test_Globals.hpp"
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE(LoaderIPLTests)
|
namespace {
|
||||||
|
constexpr auto kIPLTestData = R"(
|
||||||
|
zone
|
||||||
|
ZONE_A, 1, -100.0, -200.00, -100.0, 100.0, 1000.0, 100.0, 1
|
||||||
|
ZONE_B, 0, 200.0, 10.0, -100.0, 100.0, 1000.0, 100.0, 2
|
||||||
|
end
|
||||||
|
|
||||||
#if RW_TEST_WITH_DATA
|
inst
|
||||||
BOOST_AUTO_TEST_CASE(test_load_zones) {
|
101, ModelA, 10.0, 12.0, 5.0, 1, 1, 1, 0, 0, 1, 0
|
||||||
LoaderIPL loader;
|
112, ModelB, 10.0, 12.0, 5.0, 1, 1, 1, 0, 0, 1, 0
|
||||||
const auto& gdpath = Global::get().getGamePath();
|
112, ModelB, 11.0, 12.0, 5.0, 1, 1, 1, 0, 0, 0, 1
|
||||||
BOOST_REQUIRE(loader.load(gdpath + "/data/gta3.zon"));
|
end
|
||||||
|
)";
|
||||||
BOOST_REQUIRE(loader.zones.size() > 2);
|
|
||||||
|
|
||||||
auto& zone1 = loader.zones[0];
|
|
||||||
BOOST_CHECK_EQUAL(zone1.name, "ROADBR1");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
bool operator==(const ZoneData& lhs, const ZoneData& rhs) {
|
||||||
|
return
|
||||||
|
lhs.name == rhs.name &&
|
||||||
|
lhs.type == rhs.type &&
|
||||||
|
lhs.min == rhs.min &&
|
||||||
|
lhs.max == rhs.max &&
|
||||||
|
lhs.island == rhs.island;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& str, const ZoneData& z) {
|
||||||
|
str << "ZoneData { " << z.name << ", "
|
||||||
|
<< z.type << ", " << z.min << ", " << z.max << ", " << z.island << " }";
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const InstanceData& lhs, const InstanceData& rhs) {
|
||||||
|
return
|
||||||
|
lhs.id == rhs.id &&
|
||||||
|
lhs.model == rhs.model &&
|
||||||
|
lhs.pos == rhs.pos &&
|
||||||
|
lhs.scale == rhs.scale &&
|
||||||
|
lhs.rot == rhs.rot;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& str, const InstanceData& i) {
|
||||||
|
str << "InstanceData { " << i.id << ", "
|
||||||
|
<< i.model << ", " << i.pos << ", " << i.scale << ", " << glm::to_string(i.rot) << " }";
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct WithLoaderIPL {
|
||||||
|
LoaderIPL loader;
|
||||||
|
|
||||||
|
std::istringstream test_data_stream {kIPLTestData};
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_SUITE(LoaderIPLTests, WithLoaderIPL)
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(zone_count_is_correct) {
|
||||||
|
BOOST_REQUIRE(loader.load(test_data_stream));
|
||||||
|
BOOST_TEST(loader.zones.size() == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(zone_data_is_correct) {
|
||||||
|
BOOST_REQUIRE(loader.load(test_data_stream));
|
||||||
|
|
||||||
|
const auto expectedZone = ZoneData("ZONE_B", 0, {200.0f, 10.0f, -100.0}, {100.0f, 1000.0f, 100.0f}, 2, 0, 0);
|
||||||
|
BOOST_TEST(loader.zones[1] == expectedZone);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(instance_count_is_correct) {
|
||||||
|
BOOST_REQUIRE(loader.load(test_data_stream));
|
||||||
|
BOOST_TEST(loader.m_instances.size() == 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(instance_data_is_correct) {
|
||||||
|
BOOST_REQUIRE(loader.load(test_data_stream));
|
||||||
|
|
||||||
|
const auto expectedInstance = InstanceData(112, "ModelB", {10.0f, 12.0f, 5.0f}, {1.f, 1.f, 1.f}, {0.0f, 0.f, 0.f, 1.0f});
|
||||||
|
BOOST_TEST(*loader.m_instances[1] == expectedInstance);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
Loading…
Reference in New Issue
Block a user