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

Add stream interface to LoaderIPL and use it in test

This commit is contained in:
Daniel Evans 2018-08-06 23:37:37 +01:00
parent 413df08ea9
commit 0af9b23fe1
3 changed files with 14 additions and 7 deletions

View File

@ -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;
} }

View File

@ -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;

View File

@ -4,21 +4,21 @@
struct WithLoaderIPL { struct WithLoaderIPL {
LoaderIPL loader; LoaderIPL loader;
std::ifstream test_data_stream {Global::get().getGamePath() + "/data/gta3.zon"};
}; };
BOOST_FIXTURE_TEST_SUITE(LoaderIPLTests, WithLoaderIPL) BOOST_FIXTURE_TEST_SUITE(LoaderIPLTests, WithLoaderIPL)
#if RW_TEST_WITH_DATA #if RW_TEST_WITH_DATA
BOOST_AUTO_TEST_CASE(zone_count_is_correct) { BOOST_AUTO_TEST_CASE(zone_count_is_correct) {
const auto& gdpath = Global::get().getGamePath(); BOOST_REQUIRE(loader.load(test_data_stream));
BOOST_REQUIRE(loader.load(gdpath + "/data/gta3.zon"));
BOOST_TEST(loader.zones.size() == 42); BOOST_TEST(loader.zones.size() == 42);
} }
BOOST_AUTO_TEST_CASE(zone_data_is_correct) { BOOST_AUTO_TEST_CASE(zone_data_is_correct) {
const auto& gdpath = Global::get().getGamePath(); BOOST_REQUIRE(loader.load(test_data_stream));
BOOST_REQUIRE(loader.load(gdpath + "/data/gta3.zon"));
auto& zone1 = loader.zones[1]; auto& zone1 = loader.zones[1];
BOOST_TEST(zone1.name == "PORT_W"); BOOST_TEST(zone1.name == "PORT_W");