mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 02:12:45 +01:00
Add stream interface to LoaderIPL and use it in test
This commit is contained in:
parent
413df08ea9
commit
0af9b23fe1
@ -13,17 +13,20 @@
|
||||
|
||||
#include "data/InstanceData.hpp"
|
||||
#include "data/ZoneData.hpp"
|
||||
#include "LoaderIPL.hpp"
|
||||
|
||||
|
||||
#include <rw/casts.hpp>
|
||||
|
||||
enum SectionTypes { INST, PICK, CULL, ZONE, NONE };
|
||||
|
||||
/// Load the IPL data into memory
|
||||
bool LoaderIPL::load(const std::string& filename) {
|
||||
std::ifstream str(filename);
|
||||
|
||||
if (!str.is_open()) return false;
|
||||
return load(str);
|
||||
}
|
||||
|
||||
bool LoaderIPL::load(std::istream &str) {
|
||||
SectionTypes section = NONE;
|
||||
while (!str.eof()) {
|
||||
std::string line;
|
||||
@ -134,3 +137,4 @@ bool LoaderIPL::load(const std::string& filename) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -15,9 +15,12 @@ struct InstanceData;
|
||||
*/
|
||||
class LoaderIPL {
|
||||
public:
|
||||
/// Load the IPL data into memory
|
||||
/// Load the IPL data from 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
|
||||
std::vector<std::shared_ptr<InstanceData>> m_instances;
|
||||
|
||||
|
@ -4,21 +4,21 @@
|
||||
|
||||
struct WithLoaderIPL {
|
||||
LoaderIPL loader;
|
||||
|
||||
std::ifstream test_data_stream {Global::get().getGamePath() + "/data/gta3.zon"};
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(LoaderIPLTests, WithLoaderIPL)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(zone_count_is_correct) {
|
||||
const auto& gdpath = Global::get().getGamePath();
|
||||
BOOST_REQUIRE(loader.load(gdpath + "/data/gta3.zon"));
|
||||
BOOST_REQUIRE(loader.load(test_data_stream));
|
||||
|
||||
BOOST_TEST(loader.zones.size() == 42);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(zone_data_is_correct) {
|
||||
const auto& gdpath = Global::get().getGamePath();
|
||||
BOOST_REQUIRE(loader.load(gdpath + "/data/gta3.zon"));
|
||||
BOOST_REQUIRE(loader.load(test_data_stream));
|
||||
|
||||
auto& zone1 = loader.zones[1];
|
||||
BOOST_TEST(zone1.name == "PORT_W");
|
||||
|
Loading…
Reference in New Issue
Block a user