1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

Merge pull request #572 from danhedron/test_update/IPL

Remove data dependency from LoaderIPL tests
This commit is contained in:
Daniel Evans 2018-08-08 00:34:27 +01:00 committed by GitHub
commit be2816c398
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 84 additions and 15 deletions

View File

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

View File

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

View File

@ -1,21 +1,83 @@
#include <boost/test/unit_test.hpp>
#include <loaders/LoaderIPL.hpp>
#include <data/InstanceData.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
BOOST_AUTO_TEST_CASE(test_load_zones) {
LoaderIPL loader;
const auto& gdpath = Global::get().getGamePath();
BOOST_REQUIRE(loader.load(gdpath + "/data/gta3.zon"));
BOOST_REQUIRE(loader.zones.size() > 2);
auto& zone1 = loader.zones[0];
BOOST_CHECK_EQUAL(zone1.name, "ROADBR1");
inst
101, ModelA, 10.0, 12.0, 5.0, 1, 1, 1, 0, 0, 1, 0
112, ModelB, 10.0, 12.0, 5.0, 1, 1, 1, 0, 0, 1, 0
112, ModelB, 11.0, 12.0, 5.0, 1, 1, 1, 0, 0, 0, 1
end
)";
}
#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()