2017-01-18 00:57:20 +01:00
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
#include <loaders/LoaderIPL.hpp>
|
2018-08-07 02:18:01 +02:00
|
|
|
#include <data/InstanceData.hpp>
|
2017-10-26 03:51:24 +02:00
|
|
|
#include "test_Globals.hpp"
|
2017-01-18 00:57:20 +01:00
|
|
|
|
2018-08-07 00:48:16 +02:00
|
|
|
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
|
2018-08-07 02:18:01 +02:00
|
|
|
|
|
|
|
inst
|
2018-08-08 00:15:20 +02:00
|
|
|
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
|
2018-08-07 02:18:01 +02:00
|
|
|
112, ModelB, 11.0, 12.0, 5.0, 1, 1, 1, 0, 0, 0, 1
|
|
|
|
end
|
2018-08-07 00:48:16 +02:00
|
|
|
)";
|
|
|
|
}
|
|
|
|
|
2018-08-08 00:15:20 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-08-07 00:02:07 +02:00
|
|
|
struct WithLoaderIPL {
|
|
|
|
LoaderIPL loader;
|
2018-08-07 00:37:37 +02:00
|
|
|
|
2018-08-07 00:48:16 +02:00
|
|
|
std::istringstream test_data_stream {kIPLTestData};
|
2018-08-07 00:02:07 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
BOOST_FIXTURE_TEST_SUITE(LoaderIPLTests, WithLoaderIPL)
|
2017-01-18 00:57:20 +01:00
|
|
|
|
2018-08-07 00:25:03 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(zone_count_is_correct) {
|
2018-08-07 00:37:37 +02:00
|
|
|
BOOST_REQUIRE(loader.load(test_data_stream));
|
2018-08-07 00:48:16 +02:00
|
|
|
BOOST_TEST(loader.zones.size() == 2);
|
2017-01-18 00:57:20 +01:00
|
|
|
}
|
|
|
|
|
2018-08-07 00:25:03 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(zone_data_is_correct) {
|
2018-08-07 00:37:37 +02:00
|
|
|
BOOST_REQUIRE(loader.load(test_data_stream));
|
2018-08-07 00:25:03 +02:00
|
|
|
|
2018-08-08 00:15:20 +02:00
|
|
|
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);
|
2018-08-07 00:25:03 +02:00
|
|
|
}
|
2017-01-18 00:57:20 +01:00
|
|
|
|
2018-08-07 02:18:01 +02:00
|
|
|
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));
|
|
|
|
|
2018-08-08 00:15:20 +02:00
|
|
|
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});
|
2019-01-18 02:07:36 +01:00
|
|
|
BOOST_TEST(loader.m_instances[1] == expectedInstance);
|
2018-08-07 02:18:01 +02:00
|
|
|
}
|
|
|
|
|
2017-01-18 00:57:20 +01:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|