mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-03 00:59:47 +02:00
clang-format files in tests
This commit is contained in:
parent
11a9907f07
commit
3015b7f3e0
@ -2,7 +2,7 @@
|
||||
#include <boost/test/included/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
std::ostream& operator<<( std::ostream& stream, const glm::vec3& v ) {
|
||||
stream << v.x << " " << v.y << " " << v.z;
|
||||
return stream;
|
||||
std::ostream& operator<<(std::ostream& stream, const glm::vec3& v) {
|
||||
stream << v.x << " " << v.y << " " << v.z;
|
||||
return stream;
|
||||
}
|
||||
|
@ -5,50 +5,47 @@
|
||||
BOOST_AUTO_TEST_SUITE(FileIndexTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_directory_paths)
|
||||
{
|
||||
FileIndex index;
|
||||
BOOST_AUTO_TEST_CASE(test_directory_paths) {
|
||||
FileIndex index;
|
||||
|
||||
index.indexGameDirectory(Global::getGamePath());
|
||||
index.indexGameDirectory(Global::getGamePath());
|
||||
|
||||
{
|
||||
std::string upperpath { "DATA/CULLZONE.DAT" };
|
||||
auto truepath = index.findFilePath(upperpath);
|
||||
BOOST_ASSERT(! truepath.empty());
|
||||
BOOST_CHECK(upperpath != truepath);
|
||||
fs::path expected {Global::getGamePath()};
|
||||
expected /= "data/CULLZONE.DAT";
|
||||
BOOST_CHECK_EQUAL(truepath.native(), expected.native());
|
||||
}
|
||||
{
|
||||
std::string upperpath { "DATA/MAPS/COMNBTM/COMNBTM.IPL" };
|
||||
auto truepath = index.findFilePath(upperpath);
|
||||
BOOST_ASSERT(! truepath.empty());
|
||||
BOOST_CHECK(upperpath != truepath);
|
||||
fs::path expected {Global::getGamePath()};
|
||||
expected /= "data/maps/comnbtm/comNbtm.ipl";
|
||||
BOOST_CHECK_EQUAL(truepath.native(), expected.native());
|
||||
}
|
||||
{
|
||||
std::string upperpath{"DATA/CULLZONE.DAT"};
|
||||
auto truepath = index.findFilePath(upperpath);
|
||||
BOOST_ASSERT(!truepath.empty());
|
||||
BOOST_CHECK(upperpath != truepath);
|
||||
fs::path expected{Global::getGamePath()};
|
||||
expected /= "data/CULLZONE.DAT";
|
||||
BOOST_CHECK_EQUAL(truepath.native(), expected.native());
|
||||
}
|
||||
{
|
||||
std::string upperpath{"DATA/MAPS/COMNBTM/COMNBTM.IPL"};
|
||||
auto truepath = index.findFilePath(upperpath);
|
||||
BOOST_ASSERT(!truepath.empty());
|
||||
BOOST_CHECK(upperpath != truepath);
|
||||
fs::path expected{Global::getGamePath()};
|
||||
expected /= "data/maps/comnbtm/comNbtm.ipl";
|
||||
BOOST_CHECK_EQUAL(truepath.native(), expected.native());
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_file)
|
||||
{
|
||||
FileIndex index;
|
||||
BOOST_AUTO_TEST_CASE(test_file) {
|
||||
FileIndex index;
|
||||
|
||||
index.indexTree(Global::getGamePath()+"/data");
|
||||
|
||||
auto handle = index.openFile("cullzone.dat");
|
||||
BOOST_CHECK( handle != nullptr );
|
||||
index.indexTree(Global::getGamePath() + "/data");
|
||||
|
||||
auto handle = index.openFile("cullzone.dat");
|
||||
BOOST_CHECK(handle != nullptr);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_file_archive)
|
||||
{
|
||||
FileIndex index;
|
||||
|
||||
index.indexArchive(Global::getGamePath()+"/models/gta3.img");
|
||||
|
||||
auto handle = index.openFile("landstal.dff");
|
||||
BOOST_CHECK( handle != nullptr );
|
||||
BOOST_AUTO_TEST_CASE(test_file_archive) {
|
||||
FileIndex index;
|
||||
|
||||
index.indexArchive(Global::getGamePath() + "/models/gta3.img");
|
||||
|
||||
auto handle = index.openFile("landstal.dff");
|
||||
BOOST_CHECK(handle != nullptr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -5,26 +5,25 @@
|
||||
BOOST_AUTO_TEST_SUITE(GameDataTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_object_data)
|
||||
{
|
||||
GameData gd(&Global::get().log, &Global::get().work, Global::getGamePath());
|
||||
GameWorld gw(&Global::get().log, &Global::get().work, &gd);
|
||||
BOOST_AUTO_TEST_CASE(test_object_data) {
|
||||
GameData gd(&Global::get().log, &Global::get().work, Global::getGamePath());
|
||||
GameWorld gw(&Global::get().log, &Global::get().work, &gd);
|
||||
|
||||
gd.load();
|
||||
gd.load();
|
||||
|
||||
{
|
||||
auto def = gd.findObjectType<ObjectData>(1100);
|
||||
{
|
||||
auto def = gd.findObjectType<ObjectData>(1100);
|
||||
|
||||
BOOST_REQUIRE( def );
|
||||
BOOST_REQUIRE(def);
|
||||
|
||||
BOOST_ASSERT(def->class_type == ObjectInformation::_class("OBJS"));
|
||||
BOOST_ASSERT(def->class_type == ObjectInformation::_class("OBJS"));
|
||||
|
||||
BOOST_CHECK_EQUAL( def->modelName, "rd_Corner1" );
|
||||
BOOST_CHECK_EQUAL( def->textureName, "generic" );
|
||||
BOOST_CHECK_EQUAL( def->numClumps, 1 );
|
||||
BOOST_CHECK_EQUAL( def->drawDistance[0], 220 );
|
||||
BOOST_CHECK_EQUAL( def->flags, 0 );
|
||||
}
|
||||
BOOST_CHECK_EQUAL(def->modelName, "rd_Corner1");
|
||||
BOOST_CHECK_EQUAL(def->textureName, "generic");
|
||||
BOOST_CHECK_EQUAL(def->numClumps, 1);
|
||||
BOOST_CHECK_EQUAL(def->drawDistance[0], 220);
|
||||
BOOST_CHECK_EQUAL(def->flags, 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,73 +1,71 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <engine/GameData.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <objects/InstanceObject.hpp>
|
||||
#include <test_globals.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(GameWorldTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_gameobject_id)
|
||||
{
|
||||
GameWorld gw(&Global::get().log, &Global::get().work, Global::get().d);
|
||||
|
||||
auto object1 = gw.createInstance(1337, glm::vec3(100.f, 0.f, 0.f));
|
||||
auto object2 = gw.createInstance(1337, glm::vec3(100.f, 0.f, 100.f));
|
||||
BOOST_AUTO_TEST_CASE(test_gameobject_id) {
|
||||
GameWorld gw(&Global::get().log, &Global::get().work, Global::get().d);
|
||||
|
||||
BOOST_CHECK_NE( object1->getGameObjectID(), object2->getGameObjectID() );
|
||||
auto object1 = gw.createInstance(1337, glm::vec3(100.f, 0.f, 0.f));
|
||||
auto object2 = gw.createInstance(1337, glm::vec3(100.f, 0.f, 100.f));
|
||||
|
||||
BOOST_CHECK_NE(object1->getGameObjectID(), object2->getGameObjectID());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_offsetgametime)
|
||||
{
|
||||
GameWorld gw(&Global::get().log, &Global::get().work, Global::get().d);
|
||||
gw.state = new GameState();
|
||||
BOOST_AUTO_TEST_CASE(test_offsetgametime) {
|
||||
GameWorld gw(&Global::get().log, &Global::get().work, Global::get().d);
|
||||
gw.state = new GameState();
|
||||
|
||||
BOOST_CHECK_EQUAL(0, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(0, gw.getMinute());
|
||||
BOOST_CHECK_EQUAL(0, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(0, gw.getMinute());
|
||||
|
||||
gw.offsetGameTime(30);
|
||||
BOOST_CHECK_EQUAL(0, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(30, gw.getMinute());
|
||||
gw.offsetGameTime(30);
|
||||
BOOST_CHECK_EQUAL(0, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(30, gw.getMinute());
|
||||
|
||||
gw.offsetGameTime(30);
|
||||
BOOST_CHECK_EQUAL(1, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(0, gw.getMinute());
|
||||
gw.offsetGameTime(30);
|
||||
BOOST_CHECK_EQUAL(1, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(0, gw.getMinute());
|
||||
|
||||
gw.offsetGameTime(-30);
|
||||
BOOST_CHECK_EQUAL(0, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(30, gw.getMinute());
|
||||
gw.offsetGameTime(-30);
|
||||
BOOST_CHECK_EQUAL(0, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(30, gw.getMinute());
|
||||
|
||||
gw.offsetGameTime(-60);
|
||||
BOOST_CHECK_EQUAL(23, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(30, gw.getMinute());
|
||||
gw.offsetGameTime(-60);
|
||||
BOOST_CHECK_EQUAL(23, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(30, gw.getMinute());
|
||||
|
||||
gw.offsetGameTime(30);
|
||||
BOOST_CHECK_EQUAL(0, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(0, gw.getMinute());
|
||||
gw.offsetGameTime(30);
|
||||
BOOST_CHECK_EQUAL(0, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(0, gw.getMinute());
|
||||
|
||||
gw.offsetGameTime(24*60);
|
||||
BOOST_CHECK_EQUAL(0, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(0, gw.getMinute());
|
||||
gw.offsetGameTime(24 * 60);
|
||||
BOOST_CHECK_EQUAL(0, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(0, gw.getMinute());
|
||||
|
||||
gw.offsetGameTime(8*60 + 25);
|
||||
BOOST_CHECK_EQUAL(8, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(25, gw.getMinute());
|
||||
gw.offsetGameTime(8 * 60 + 25);
|
||||
BOOST_CHECK_EQUAL(8, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(25, gw.getMinute());
|
||||
|
||||
gw.offsetGameTime(-30);
|
||||
BOOST_CHECK_EQUAL(7, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(55, gw.getMinute());
|
||||
gw.offsetGameTime(-30);
|
||||
BOOST_CHECK_EQUAL(7, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(55, gw.getMinute());
|
||||
|
||||
gw.offsetGameTime(-24*60);
|
||||
BOOST_CHECK_EQUAL(7, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(55, gw.getMinute());
|
||||
gw.offsetGameTime(-24 * 60);
|
||||
BOOST_CHECK_EQUAL(7, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(55, gw.getMinute());
|
||||
|
||||
gw.offsetGameTime(0);
|
||||
BOOST_CHECK_EQUAL(7, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(55, gw.getMinute());
|
||||
gw.offsetGameTime(0);
|
||||
BOOST_CHECK_EQUAL(7, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(55, gw.getMinute());
|
||||
|
||||
gw.offsetGameTime(30*24*60 + 90);
|
||||
BOOST_CHECK_EQUAL(9, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(25, gw.getMinute());
|
||||
gw.offsetGameTime(30 * 24 * 60 + 90);
|
||||
BOOST_CHECK_EQUAL(9, gw.getHour());
|
||||
BOOST_CHECK_EQUAL(25, gw.getMinute());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -2,37 +2,36 @@
|
||||
#include <core/Logger.hpp>
|
||||
#include <test_globals.hpp>
|
||||
|
||||
class CallbackReceiver : public Logger::MessageReciever
|
||||
{
|
||||
class CallbackReceiver : public Logger::MessageReciever {
|
||||
public:
|
||||
std::function<void(const Logger::LogMessage&)> func;
|
||||
|
||||
CallbackReceiver(std::function<void(const Logger::LogMessage&)> func)
|
||||
: func(func) { }
|
||||
|
||||
virtual void messageRecieved(const Logger::LogMessage& message)
|
||||
{
|
||||
func(message);
|
||||
}
|
||||
std::function<void(const Logger::LogMessage&)> func;
|
||||
|
||||
CallbackReceiver(std::function<void(const Logger::LogMessage&)> func)
|
||||
: func(func) {
|
||||
}
|
||||
|
||||
virtual void messageRecieved(const Logger::LogMessage& message) {
|
||||
func(message);
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(LoggerTests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_reciever)
|
||||
{
|
||||
Logger log;
|
||||
|
||||
Logger::LogMessage lastMessage("", Logger::Error, "");
|
||||
|
||||
CallbackReceiver reciever([&](const Logger::LogMessage& m) { lastMessage = m; });
|
||||
|
||||
log.addReciever(&reciever);
|
||||
|
||||
log.info("Tests", "Test");
|
||||
|
||||
BOOST_CHECK_EQUAL( lastMessage.component, "Tests" );
|
||||
BOOST_CHECK_EQUAL( lastMessage.severity, Logger::Info );
|
||||
BOOST_CHECK_EQUAL( lastMessage.message, "Test" );
|
||||
BOOST_AUTO_TEST_CASE(test_reciever) {
|
||||
Logger log;
|
||||
|
||||
Logger::LogMessage lastMessage("", Logger::Error, "");
|
||||
|
||||
CallbackReceiver reciever(
|
||||
[&](const Logger::LogMessage& m) { lastMessage = m; });
|
||||
|
||||
log.addReciever(&reciever);
|
||||
|
||||
log.info("Tests", "Test");
|
||||
|
||||
BOOST_CHECK_EQUAL(lastMessage.component, "Tests");
|
||||
BOOST_CHECK_EQUAL(lastMessage.severity, Logger::Info);
|
||||
BOOST_CHECK_EQUAL(lastMessage.message, "Test");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
@ -6,19 +6,18 @@ typedef ResourceHandle<int>::Ref IntRef;
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(ResourceTests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_ResourceHandle)
|
||||
{
|
||||
int resource = 42;
|
||||
IntRef ref { new ResourceHandle<int>("") };
|
||||
|
||||
BOOST_CHECK_EQUAL( ref->resource, nullptr );
|
||||
BOOST_CHECK_EQUAL( ref->state, RW::Loading );
|
||||
|
||||
ref->state = RW::Loaded;
|
||||
ref->resource = &resource;
|
||||
|
||||
BOOST_CHECK_EQUAL( ref->resource, &resource );
|
||||
BOOST_CHECK_EQUAL( ref->state, RW::Loaded );
|
||||
BOOST_AUTO_TEST_CASE(test_ResourceHandle) {
|
||||
int resource = 42;
|
||||
IntRef ref{new ResourceHandle<int>("")};
|
||||
|
||||
BOOST_CHECK_EQUAL(ref->resource, nullptr);
|
||||
BOOST_CHECK_EQUAL(ref->state, RW::Loading);
|
||||
|
||||
ref->state = RW::Loaded;
|
||||
ref->resource = &resource;
|
||||
|
||||
BOOST_CHECK_EQUAL(ref->resource, &resource);
|
||||
BOOST_CHECK_EQUAL(ref->state, RW::Loaded);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
@ -4,7 +4,7 @@
|
||||
#include <script/ScriptMachine.hpp>
|
||||
#include <test_globals.hpp>
|
||||
|
||||
#if 0 // Disabled until we make a start on saving the game
|
||||
#if 0 // Disabled until we make a start on saving the game
|
||||
BOOST_AUTO_TEST_SUITE(SaveGameTests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_write_state)
|
||||
|
@ -1,15 +1,13 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <test_globals.hpp>
|
||||
#include <render/VisualFX.hpp>
|
||||
#include <test_globals.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(VisualFXTests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_light_data)
|
||||
{
|
||||
VisualFX fx(VisualFX::Light);
|
||||
|
||||
BOOST_CHECK_EQUAL(fx.getType(), VisualFX::Light);
|
||||
BOOST_AUTO_TEST_CASE(test_light_data) {
|
||||
VisualFX fx(VisualFX::Light);
|
||||
|
||||
BOOST_CHECK_EQUAL(fx.getType(), VisualFX::Light);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
@ -1,54 +1,54 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <engine/Animator.hpp>
|
||||
#include <data/Skeleton.hpp>
|
||||
#include <data/Model.hpp>
|
||||
#include <data/Skeleton.hpp>
|
||||
#include <engine/Animator.hpp>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(AnimationTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_matrix)
|
||||
{
|
||||
{
|
||||
Skeleton skeleton;
|
||||
Animation animation;
|
||||
|
||||
/** Models are currently needed to relate animation bones <=> model frame #s. */
|
||||
Global::get().e->data->loadDFF("player.dff");
|
||||
ModelRef& test_model = Global::get().e->data->models["player"];
|
||||
|
||||
Animator animator(test_model->resource, &skeleton);
|
||||
BOOST_AUTO_TEST_CASE(test_matrix) {
|
||||
{
|
||||
Skeleton skeleton;
|
||||
Animation animation;
|
||||
|
||||
animation.duration = 1.f;
|
||||
animation.bones["player"] = new AnimationBone{
|
||||
"player",
|
||||
0, 0, 1.0f,
|
||||
AnimationBone::RT0,
|
||||
{
|
||||
{
|
||||
glm::quat(), glm::vec3(0.f, 0.f, 0.f), glm::vec3(), 0.f, 0
|
||||
},
|
||||
{
|
||||
glm::quat(), glm::vec3(0.f, 1.f, 0.f), glm::vec3(), 1.0f, 1
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
animator.playAnimation(0, &animation, 1.f, false);
|
||||
|
||||
animator.tick(0.0f);
|
||||
|
||||
BOOST_CHECK( skeleton.getData(0).a.translation == glm::vec3(0.f, 0.f, 0.f) );
|
||||
BOOST_CHECK( skeleton.getData(0).b.translation == glm::vec3(0.f, 0.f, 0.f) );
|
||||
|
||||
animator.tick(1.0f);
|
||||
|
||||
BOOST_CHECK( skeleton.getData(0).a.translation == glm::vec3(0.f, 1.f, 0.f) );
|
||||
BOOST_CHECK( skeleton.getData(0).b.translation == glm::vec3(0.f, 0.f, 0.f) );
|
||||
}
|
||||
/** Models are currently needed to relate animation bones <=> model
|
||||
* frame #s. */
|
||||
Global::get().e->data->loadDFF("player.dff");
|
||||
ModelRef& test_model = Global::get().e->data->models["player"];
|
||||
|
||||
Animator animator(test_model->resource, &skeleton);
|
||||
|
||||
animation.duration = 1.f;
|
||||
animation.bones["player"] = new AnimationBone{
|
||||
"player",
|
||||
0,
|
||||
0,
|
||||
1.0f,
|
||||
AnimationBone::RT0,
|
||||
{
|
||||
{glm::quat(), glm::vec3(0.f, 0.f, 0.f), glm::vec3(), 0.f, 0},
|
||||
{glm::quat(), glm::vec3(0.f, 1.f, 0.f), glm::vec3(), 1.0f, 1},
|
||||
}};
|
||||
|
||||
animator.playAnimation(0, &animation, 1.f, false);
|
||||
|
||||
animator.tick(0.0f);
|
||||
|
||||
BOOST_CHECK(skeleton.getData(0).a.translation ==
|
||||
glm::vec3(0.f, 0.f, 0.f));
|
||||
BOOST_CHECK(skeleton.getData(0).b.translation ==
|
||||
glm::vec3(0.f, 0.f, 0.f));
|
||||
|
||||
animator.tick(1.0f);
|
||||
|
||||
BOOST_CHECK(skeleton.getData(0).a.translation ==
|
||||
glm::vec3(0.f, 1.f, 0.f));
|
||||
BOOST_CHECK(skeleton.getData(0).b.translation ==
|
||||
glm::vec3(0.f, 0.f, 0.f));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
@ -1,33 +1,32 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <loaders/LoaderIMG.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(ArchiveTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_open_archive)
|
||||
{
|
||||
LoaderIMG archive;
|
||||
|
||||
BOOST_REQUIRE( archive.load(Global::getGamePath() + "/models/gta3") );
|
||||
|
||||
BOOST_CHECK( archive.getAssetCount() > 0 );
|
||||
BOOST_AUTO_TEST_CASE(test_open_archive) {
|
||||
LoaderIMG archive;
|
||||
|
||||
LoaderIMGFile f, f2;
|
||||
|
||||
f = archive.getAssetInfoByIndex(0);
|
||||
|
||||
// A few assumptions..
|
||||
|
||||
BOOST_CHECK_EQUAL( f.name, "radar00.txd" );
|
||||
BOOST_CHECK_EQUAL( f.offset, 0);
|
||||
BOOST_CHECK_EQUAL( f.size, 33);
|
||||
|
||||
BOOST_CHECK( archive.findAssetInfo("radar00.txd", f2) );
|
||||
|
||||
BOOST_CHECK_EQUAL( f2.name, f.name );
|
||||
BOOST_CHECK_EQUAL( f2.offset, f.offset );
|
||||
BOOST_CHECK_EQUAL( f2.size, f.size );
|
||||
BOOST_REQUIRE(archive.load(Global::getGamePath() + "/models/gta3"));
|
||||
|
||||
BOOST_CHECK(archive.getAssetCount() > 0);
|
||||
|
||||
LoaderIMGFile f, f2;
|
||||
|
||||
f = archive.getAssetInfoByIndex(0);
|
||||
|
||||
// A few assumptions..
|
||||
|
||||
BOOST_CHECK_EQUAL(f.name, "radar00.txd");
|
||||
BOOST_CHECK_EQUAL(f.offset, 0);
|
||||
BOOST_CHECK_EQUAL(f.size, 33);
|
||||
|
||||
BOOST_CHECK(archive.findAssetInfo("radar00.txd", f2));
|
||||
|
||||
BOOST_CHECK_EQUAL(f2.name, f.name);
|
||||
BOOST_CHECK_EQUAL(f2.offset, f.offset);
|
||||
BOOST_CHECK_EQUAL(f2.size, f.size);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,63 +1,62 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <objects/VehicleObject.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(BuoyancyTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_vehicle_buoyancy)
|
||||
{
|
||||
glm::vec2 tpos(-WATER_WORLD_SIZE/2.f + 10.f);
|
||||
{
|
||||
VehicleObject* vehicle = Global::get().e->createVehicle(90u, glm::vec3(tpos, 100.f), glm::quat());
|
||||
BOOST_AUTO_TEST_CASE(test_vehicle_buoyancy) {
|
||||
glm::vec2 tpos(-WATER_WORLD_SIZE / 2.f + 10.f);
|
||||
{
|
||||
VehicleObject* vehicle = Global::get().e->createVehicle(
|
||||
90u, glm::vec3(tpos, 100.f), glm::quat());
|
||||
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
|
||||
BOOST_REQUIRE(vehicle->info != nullptr);
|
||||
BOOST_REQUIRE(vehicle->vehicle != nullptr);
|
||||
BOOST_REQUIRE(vehicle->info != nullptr);
|
||||
BOOST_REQUIRE(vehicle->vehicle != nullptr);
|
||||
|
||||
// Relies on tile 0,0 being watered...
|
||||
// Relies on tile 0,0 being watered...
|
||||
|
||||
BOOST_CHECK( ! vehicle->isInWater() );
|
||||
BOOST_CHECK(!vehicle->isInWater());
|
||||
|
||||
// Move it under the water
|
||||
vehicle->setPosition(glm::vec3(tpos, -5.f));
|
||||
// Move it under the water
|
||||
vehicle->setPosition(glm::vec3(tpos, -5.f));
|
||||
|
||||
// Allow the object to update
|
||||
vehicle->tickPhysics(0.0016f);
|
||||
// Allow the object to update
|
||||
vehicle->tickPhysics(0.0016f);
|
||||
|
||||
BOOST_CHECK( vehicle->isInWater() );
|
||||
BOOST_CHECK(vehicle->isInWater());
|
||||
|
||||
// Ensure that the in water state sticks
|
||||
vehicle->tickPhysics(0.0016f);
|
||||
// Ensure that the in water state sticks
|
||||
vehicle->tickPhysics(0.0016f);
|
||||
|
||||
BOOST_CHECK( vehicle->isInWater() );
|
||||
BOOST_CHECK(vehicle->isInWater());
|
||||
|
||||
vehicle->setPosition(glm::vec3(tpos, 5.f));
|
||||
vehicle->tickPhysics(0.0016f);
|
||||
BOOST_CHECK( ! vehicle->isInWater() );
|
||||
vehicle->setPosition(glm::vec3(tpos, 5.f));
|
||||
vehicle->tickPhysics(0.0016f);
|
||||
BOOST_CHECK(!vehicle->isInWater());
|
||||
|
||||
// TODO: fix magic numbers
|
||||
auto orgval = Global::get().e->data->realWater[0];
|
||||
Global::get().e->data->realWater[0] = NO_WATER_INDEX;
|
||||
// TODO: fix magic numbers
|
||||
auto orgval = Global::get().e->data->realWater[0];
|
||||
Global::get().e->data->realWater[0] = NO_WATER_INDEX;
|
||||
|
||||
vehicle->tickPhysics(0.0016f);
|
||||
BOOST_CHECK( ! vehicle->isInWater() );
|
||||
vehicle->tickPhysics(0.0016f);
|
||||
BOOST_CHECK(!vehicle->isInWater());
|
||||
|
||||
vehicle->setPosition(glm::vec3(tpos, -5.f));
|
||||
vehicle->setPosition(glm::vec3(tpos, -5.f));
|
||||
|
||||
vehicle->tickPhysics(0.0016f);
|
||||
BOOST_CHECK( ! vehicle->isInWater() );
|
||||
vehicle->tickPhysics(0.0016f);
|
||||
BOOST_CHECK(!vehicle->isInWater());
|
||||
|
||||
Global::get().e->data->realWater[0] = orgval;
|
||||
Global::get().e->data->realWater[0] = orgval;
|
||||
|
||||
vehicle->tickPhysics(0.0016f);
|
||||
BOOST_CHECK( ! vehicle->isInWater() );
|
||||
vehicle->tickPhysics(0.0016f);
|
||||
BOOST_CHECK(!vehicle->isInWater());
|
||||
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
}
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
@ -1,150 +1,151 @@
|
||||
#include <ai/DefaultAIController.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <engine/Animator.hpp>
|
||||
#include <objects/CharacterObject.hpp>
|
||||
#include <objects/VehicleObject.hpp>
|
||||
#include <ai/DefaultAIController.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <engine/Animator.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(CharacterTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_create)
|
||||
{
|
||||
{
|
||||
auto character = Global::get().e->createPedestrian(1, {100.f, 100.f, 50.f});
|
||||
BOOST_AUTO_TEST_CASE(test_create) {
|
||||
{
|
||||
auto character =
|
||||
Global::get().e->createPedestrian(1, {100.f, 100.f, 50.f});
|
||||
|
||||
BOOST_REQUIRE( character != nullptr );
|
||||
BOOST_REQUIRE(character != nullptr);
|
||||
|
||||
auto controller = new DefaultAIController(character);
|
||||
auto controller = new DefaultAIController(character);
|
||||
|
||||
// Check the initial activity is Idle.
|
||||
BOOST_CHECK_EQUAL(controller->getCurrentActivity(), nullptr);
|
||||
|
||||
// Check the initial activity is Idle.
|
||||
BOOST_CHECK_EQUAL( controller->getCurrentActivity(), nullptr );
|
||||
// Check that Idle activities are instantly displaced.
|
||||
controller->setNextActivity(
|
||||
new Activities::GoTo(glm::vec3{1000.f, 0.f, 0.f}));
|
||||
|
||||
// Check that Idle activities are instantly displaced.
|
||||
controller->setNextActivity( new Activities::GoTo( glm::vec3{ 1000.f, 0.f, 0.f } ) );
|
||||
BOOST_CHECK_EQUAL(controller->getCurrentActivity()->name(), "GoTo");
|
||||
BOOST_CHECK_EQUAL(controller->getNextActivity(), nullptr);
|
||||
|
||||
BOOST_CHECK_EQUAL( controller->getCurrentActivity()->name(), "GoTo" );
|
||||
BOOST_CHECK_EQUAL( controller->getNextActivity(), nullptr );
|
||||
|
||||
Global::get().e->destroyObject(character);
|
||||
delete controller;
|
||||
}
|
||||
Global::get().e->destroyObject(character);
|
||||
delete controller;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_activities)
|
||||
{
|
||||
{
|
||||
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 225.6f});
|
||||
BOOST_AUTO_TEST_CASE(test_activities) {
|
||||
{
|
||||
auto character =
|
||||
Global::get().e->createPedestrian(1, {0.f, 0.f, 225.6f});
|
||||
|
||||
BOOST_REQUIRE( character != nullptr );
|
||||
BOOST_REQUIRE(character != nullptr);
|
||||
|
||||
auto controller = new DefaultAIController(character);
|
||||
auto controller = new DefaultAIController(character);
|
||||
|
||||
controller->setNextActivity( new Activities::GoTo( glm::vec3{ 10.f, 10.f, 0.f } ) );
|
||||
controller->setNextActivity(
|
||||
new Activities::GoTo(glm::vec3{10.f, 10.f, 0.f}));
|
||||
|
||||
BOOST_CHECK_EQUAL( controller->getCurrentActivity()->name(), "GoTo" );
|
||||
BOOST_CHECK_EQUAL(controller->getCurrentActivity()->name(), "GoTo");
|
||||
|
||||
for(float t = 0.f; t < 11.5f; t+=(1.f/60.f)) {
|
||||
controller->update(1.f/60.f);
|
||||
character->tick(1.f/60.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
|
||||
}
|
||||
for (float t = 0.f; t < 11.5f; t += (1.f / 60.f)) {
|
||||
controller->update(1.f / 60.f);
|
||||
character->tick(1.f / 60.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(1.f / 60.f);
|
||||
}
|
||||
|
||||
BOOST_CHECK_LT( glm::distance(character->getPosition(), {10.f, 10.f, 0.f}), 0.1f);
|
||||
BOOST_CHECK_LT(
|
||||
glm::distance(character->getPosition(), {10.f, 10.f, 0.f}), 0.1f);
|
||||
|
||||
Global::get().e->destroyObject(character);
|
||||
delete controller;
|
||||
}
|
||||
{
|
||||
VehicleObject* vehicle = Global::get().e->createVehicle(90u, glm::vec3(10.f, 0.f, 0.f), glm::quat());
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
BOOST_REQUIRE(vehicle->model != nullptr);
|
||||
Global::get().e->destroyObject(character);
|
||||
delete controller;
|
||||
}
|
||||
{
|
||||
VehicleObject* vehicle = Global::get().e->createVehicle(
|
||||
90u, glm::vec3(10.f, 0.f, 0.f), glm::quat());
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
BOOST_REQUIRE(vehicle->model != nullptr);
|
||||
|
||||
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 0.f});
|
||||
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 0.f});
|
||||
|
||||
BOOST_REQUIRE( character != nullptr );
|
||||
BOOST_REQUIRE(character != nullptr);
|
||||
|
||||
auto controller = new DefaultAIController(character);
|
||||
auto controller = new DefaultAIController(character);
|
||||
|
||||
controller->setNextActivity( new Activities::EnterVehicle( vehicle, 0 ) );
|
||||
controller->setNextActivity(new Activities::EnterVehicle(vehicle, 0));
|
||||
|
||||
for(float t = 0.f; t < 0.5f; t+=(1.f/60.f)) {
|
||||
character->tick(1.f/60.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
|
||||
}
|
||||
for (float t = 0.f; t < 0.5f; t += (1.f / 60.f)) {
|
||||
character->tick(1.f / 60.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(1.f / 60.f);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL( nullptr, character->getCurrentVehicle() );
|
||||
BOOST_CHECK_EQUAL(nullptr, character->getCurrentVehicle());
|
||||
|
||||
for(float t = 0.f; t < 9.0f; t+=(1.f/60.f)) {
|
||||
character->tick(1.f/60.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
|
||||
}
|
||||
for (float t = 0.f; t < 9.0f; t += (1.f / 60.f)) {
|
||||
character->tick(1.f / 60.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(1.f / 60.f);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL( vehicle, character->getCurrentVehicle() );
|
||||
BOOST_CHECK_EQUAL(vehicle, character->getCurrentVehicle());
|
||||
|
||||
controller->setNextActivity( new Activities::ExitVehicle( ) );
|
||||
controller->setNextActivity(new Activities::ExitVehicle());
|
||||
|
||||
for(float t = 0.f; t < 9.0f; t+=(1.f/60.f)) {
|
||||
character->tick(1.f/60.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
|
||||
}
|
||||
for (float t = 0.f; t < 9.0f; t += (1.f / 60.f)) {
|
||||
character->tick(1.f / 60.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(1.f / 60.f);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL( nullptr, character->getCurrentVehicle() );
|
||||
BOOST_CHECK_EQUAL(nullptr, character->getCurrentVehicle());
|
||||
|
||||
character->setPosition(glm::vec3(5.f, 0.f, 0.f));
|
||||
controller->setNextActivity( new Activities::EnterVehicle( vehicle, 0 ) );
|
||||
character->setPosition(glm::vec3(5.f, 0.f, 0.f));
|
||||
controller->setNextActivity(new Activities::EnterVehicle(vehicle, 0));
|
||||
|
||||
for(float t = 0.f; t < 0.5f; t+=(1.f/60.f)) {
|
||||
character->tick(1.f/60.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
|
||||
}
|
||||
for (float t = 0.f; t < 0.5f; t += (1.f / 60.f)) {
|
||||
character->tick(1.f / 60.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(1.f / 60.f);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL( nullptr, character->getCurrentVehicle() );
|
||||
controller->skipActivity();
|
||||
BOOST_CHECK_EQUAL(nullptr, character->getCurrentVehicle());
|
||||
controller->skipActivity();
|
||||
|
||||
for(float t = 0.f; t < 5.0f; t+=(1.f/60.f)) {
|
||||
character->tick(1.f/60.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(1.f/60.f);
|
||||
}
|
||||
for (float t = 0.f; t < 5.0f; t += (1.f / 60.f)) {
|
||||
character->tick(1.f / 60.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(1.f / 60.f);
|
||||
}
|
||||
|
||||
BOOST_CHECK_EQUAL( nullptr, character->getCurrentVehicle() );
|
||||
BOOST_CHECK_EQUAL(nullptr, character->getCurrentVehicle());
|
||||
|
||||
Global::get().e->destroyObject(character);
|
||||
delete controller;
|
||||
}
|
||||
Global::get().e->destroyObject(character);
|
||||
delete controller;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_death)
|
||||
{
|
||||
{
|
||||
auto character = Global::get().e->createPedestrian(1, {100.f, 100.f, 50.f});
|
||||
BOOST_REQUIRE( character != nullptr );
|
||||
auto controller = new DefaultAIController(character);
|
||||
BOOST_AUTO_TEST_CASE(test_death) {
|
||||
{
|
||||
auto character =
|
||||
Global::get().e->createPedestrian(1, {100.f, 100.f, 50.f});
|
||||
BOOST_REQUIRE(character != nullptr);
|
||||
auto controller = new DefaultAIController(character);
|
||||
|
||||
BOOST_CHECK_EQUAL( character->getCurrentState().health, 100.f );
|
||||
BOOST_CHECK( character->isAlive() );
|
||||
BOOST_CHECK_EQUAL(character->getCurrentState().health, 100.f);
|
||||
BOOST_CHECK(character->isAlive());
|
||||
|
||||
GameObject::DamageInfo dmg;
|
||||
dmg.type = GameObject::DamageInfo::Bullet;
|
||||
dmg.hitpoints = character->getCurrentState().health + 1.f;
|
||||
GameObject::DamageInfo dmg;
|
||||
dmg.type = GameObject::DamageInfo::Bullet;
|
||||
dmg.hitpoints = character->getCurrentState().health + 1.f;
|
||||
|
||||
// Do some damage
|
||||
BOOST_CHECK(character->takeDamage(dmg));
|
||||
// Do some damage
|
||||
BOOST_CHECK(character->takeDamage(dmg));
|
||||
|
||||
BOOST_CHECK( ! character->isAlive() );
|
||||
BOOST_CHECK(!character->isAlive());
|
||||
|
||||
character->tick(0.16f);
|
||||
character->tick(0.16f);
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
character->animator->getAnimation(0),
|
||||
character->animations.ko_shot_front);
|
||||
BOOST_CHECK_EQUAL(character->animator->getAnimation(0),
|
||||
character->animations.ko_shot_front);
|
||||
|
||||
Global::get().e->destroyObject(character);
|
||||
delete controller;
|
||||
}
|
||||
Global::get().e->destroyObject(character);
|
||||
delete controller;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <data/Chase.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(ChaseTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_load_keyframes)
|
||||
{
|
||||
std::vector<ChaseKeyframe> keyframes;
|
||||
BOOST_REQUIRE(ChaseKeyframe::load(Global::getGamePath() + "/data/paths/CHASE0.DAT", keyframes));
|
||||
BOOST_REQUIRE(keyframes.size() == 5400);
|
||||
BOOST_CHECK_CLOSE(keyframes[0].position.x, 273.5422, 0.1);
|
||||
BOOST_AUTO_TEST_CASE(test_load_keyframes) {
|
||||
std::vector<ChaseKeyframe> keyframes;
|
||||
BOOST_REQUIRE(ChaseKeyframe::load(
|
||||
Global::getGamePath() + "/data/paths/CHASE0.DAT", keyframes));
|
||||
BOOST_REQUIRE(keyframes.size() == 5400);
|
||||
BOOST_CHECK_CLOSE(keyframes[0].position.x, 273.5422, 0.1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,21 +1,20 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <GameConfig.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <fstream>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(ConfigTests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_loading)
|
||||
{
|
||||
// Write out a temporary file
|
||||
std::ofstream test_config("/tmp/openrw_test.ini");
|
||||
test_config << "[game]\n"
|
||||
<< "path=/dev/test" << std::endl;
|
||||
BOOST_AUTO_TEST_CASE(test_loading) {
|
||||
// Write out a temporary file
|
||||
std::ofstream test_config("/tmp/openrw_test.ini");
|
||||
test_config << "[game]\n"
|
||||
<< "path=/dev/test" << std::endl;
|
||||
|
||||
GameConfig config("openrw_test.ini", "/tmp");
|
||||
GameConfig config("openrw_test.ini", "/tmp");
|
||||
|
||||
BOOST_CHECK(config.isValid());
|
||||
BOOST_CHECK(config.isValid());
|
||||
|
||||
BOOST_CHECK_EQUAL(config.getGameDataPath(), "/dev/test");
|
||||
BOOST_CHECK_EQUAL(config.getGameDataPath(), "/dev/test");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -6,28 +6,27 @@
|
||||
BOOST_AUTO_TEST_SUITE(CutsceneTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_load)
|
||||
{
|
||||
{
|
||||
auto d = Global::get().e->data->index.openFile("intro.dat");
|
||||
BOOST_AUTO_TEST_CASE(test_load) {
|
||||
{
|
||||
auto d = Global::get().e->data->index.openFile("intro.dat");
|
||||
|
||||
CutsceneTracks tracks;
|
||||
CutsceneTracks tracks;
|
||||
|
||||
LoaderCutsceneDAT loader;
|
||||
LoaderCutsceneDAT loader;
|
||||
|
||||
loader.load( tracks, d );
|
||||
loader.load(tracks, d);
|
||||
|
||||
BOOST_CHECK( tracks.position.find(0.f) != tracks.position.end() );
|
||||
BOOST_CHECK( tracks.position.find(64.8f) != tracks.position.end() );
|
||||
BOOST_CHECK(tracks.position.find(0.f) != tracks.position.end());
|
||||
BOOST_CHECK(tracks.position.find(64.8f) != tracks.position.end());
|
||||
|
||||
BOOST_CHECK( tracks.zoom.find(64.8f) != tracks.zoom.end() );
|
||||
BOOST_CHECK(tracks.zoom.find(64.8f) != tracks.zoom.end());
|
||||
|
||||
BOOST_CHECK( tracks.zoom.find(64.8f) != tracks.zoom.end() );
|
||||
BOOST_CHECK(tracks.zoom.find(64.8f) != tracks.zoom.end());
|
||||
|
||||
BOOST_CHECK( tracks.target.find(64.8f) != tracks.target.end() );
|
||||
BOOST_CHECK(tracks.target.find(64.8f) != tracks.target.end());
|
||||
|
||||
BOOST_CHECK( tracks.duration == 64.8f );
|
||||
}
|
||||
BOOST_CHECK(tracks.duration == 64.8f);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <data/WeaponData.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <loaders/GenericDATLoader.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
// Tests against loading various data files
|
||||
// These tests are bad but so are the interfaces so it cancels out.
|
||||
@ -9,84 +9,80 @@
|
||||
BOOST_AUTO_TEST_SUITE(DataTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_weapon_dat)
|
||||
{
|
||||
GenericDATLoader l;
|
||||
WeaponDataPtrs weaponData;
|
||||
BOOST_AUTO_TEST_CASE(test_weapon_dat) {
|
||||
GenericDATLoader l;
|
||||
WeaponDataPtrs weaponData;
|
||||
|
||||
l.loadWeapons(Global::get().getGamePath() + "/data/weapon.dat", weaponData);
|
||||
l.loadWeapons(Global::get().getGamePath() + "/data/weapon.dat", weaponData);
|
||||
|
||||
BOOST_ASSERT( weaponData.size() > 0 );
|
||||
BOOST_ASSERT(weaponData.size() > 0);
|
||||
|
||||
WeaponDataPtr data = weaponData[0];
|
||||
|
||||
BOOST_CHECK( data->fireType == WeaponData::MELEE );
|
||||
BOOST_CHECK( data->hitRange == 2.8f );
|
||||
BOOST_CHECK( data->fireRate == 750 );
|
||||
BOOST_CHECK( data->reloadMS == 300 );
|
||||
BOOST_CHECK( data->clipSize == 1000 );
|
||||
BOOST_CHECK( data->damage == 8);
|
||||
BOOST_CHECK( data->speed == -1.f);
|
||||
BOOST_CHECK( data->meleeRadius == 0.5f );
|
||||
BOOST_CHECK( data->lifeSpan == -1.0f );
|
||||
BOOST_CHECK( data->spread == -1.0f );
|
||||
BOOST_CHECK( data->fireOffset == glm::vec3(0.1f, 0.65f, 0.2f) );
|
||||
BOOST_CHECK( data->animation1 == "fightppunch" );
|
||||
BOOST_CHECK( data->animation2 == "kick_floor");
|
||||
BOOST_CHECK( data->animLoopStart == 0 );
|
||||
BOOST_CHECK( data->animLoopEnd == 99 );
|
||||
BOOST_CHECK( data->animFirePoint == 12 );
|
||||
BOOST_CHECK( data->animCrouchFirePoint == 12 );
|
||||
BOOST_CHECK( data->modelID == -1 );
|
||||
BOOST_CHECK( data->flags == 0) ;
|
||||
WeaponDataPtr data = weaponData[0];
|
||||
|
||||
BOOST_CHECK(data->fireType == WeaponData::MELEE);
|
||||
BOOST_CHECK(data->hitRange == 2.8f);
|
||||
BOOST_CHECK(data->fireRate == 750);
|
||||
BOOST_CHECK(data->reloadMS == 300);
|
||||
BOOST_CHECK(data->clipSize == 1000);
|
||||
BOOST_CHECK(data->damage == 8);
|
||||
BOOST_CHECK(data->speed == -1.f);
|
||||
BOOST_CHECK(data->meleeRadius == 0.5f);
|
||||
BOOST_CHECK(data->lifeSpan == -1.0f);
|
||||
BOOST_CHECK(data->spread == -1.0f);
|
||||
BOOST_CHECK(data->fireOffset == glm::vec3(0.1f, 0.65f, 0.2f));
|
||||
BOOST_CHECK(data->animation1 == "fightppunch");
|
||||
BOOST_CHECK(data->animation2 == "kick_floor");
|
||||
BOOST_CHECK(data->animLoopStart == 0);
|
||||
BOOST_CHECK(data->animLoopEnd == 99);
|
||||
BOOST_CHECK(data->animFirePoint == 12);
|
||||
BOOST_CHECK(data->animCrouchFirePoint == 12);
|
||||
BOOST_CHECK(data->modelID == -1);
|
||||
BOOST_CHECK(data->flags == 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_dynamic_dat_loader)
|
||||
{
|
||||
GenericDATLoader l;
|
||||
DynamicObjectDataPtrs loaded;
|
||||
BOOST_AUTO_TEST_CASE(test_dynamic_dat_loader) {
|
||||
GenericDATLoader l;
|
||||
DynamicObjectDataPtrs loaded;
|
||||
|
||||
l.loadDynamicObjects(Global::get().getGamePath() + "/data/object.dat", loaded);
|
||||
l.loadDynamicObjects(Global::get().getGamePath() + "/data/object.dat",
|
||||
loaded);
|
||||
|
||||
BOOST_ASSERT( loaded.size() > 0 );
|
||||
BOOST_ASSERT(loaded.size() > 0);
|
||||
|
||||
BOOST_ASSERT( loaded.find("wastebin") != loaded.end() );
|
||||
BOOST_ASSERT( loaded.find("lamppost1") != loaded.end() );
|
||||
BOOST_ASSERT(loaded.find("wastebin") != loaded.end());
|
||||
BOOST_ASSERT(loaded.find("lamppost1") != loaded.end());
|
||||
|
||||
DynamicObjectDataPtr lamp = loaded["lamppost1"];
|
||||
DynamicObjectDataPtr lamp = loaded["lamppost1"];
|
||||
|
||||
BOOST_CHECK_EQUAL( lamp->mass, 600.0);
|
||||
BOOST_CHECK_EQUAL( lamp->turnMass, 4000.0);
|
||||
BOOST_CHECK_CLOSE( lamp->airRes, 0.99, 1.0);
|
||||
BOOST_CHECK_CLOSE( lamp->elacticity, 0.05, 0.01);
|
||||
BOOST_CHECK_EQUAL( lamp->bouancy, 50.0);
|
||||
BOOST_CHECK_EQUAL( lamp->uprootForce, 400);
|
||||
BOOST_CHECK_EQUAL( lamp->collDamageMulti, 1.0);
|
||||
BOOST_CHECK_EQUAL( lamp->collDamageFlags, 1);
|
||||
BOOST_CHECK_EQUAL( lamp->collResponseFlags, 1);
|
||||
BOOST_CHECK_EQUAL( lamp->cameraAvoid, false);
|
||||
BOOST_CHECK_EQUAL(lamp->mass, 600.0);
|
||||
BOOST_CHECK_EQUAL(lamp->turnMass, 4000.0);
|
||||
BOOST_CHECK_CLOSE(lamp->airRes, 0.99, 1.0);
|
||||
BOOST_CHECK_CLOSE(lamp->elacticity, 0.05, 0.01);
|
||||
BOOST_CHECK_EQUAL(lamp->bouancy, 50.0);
|
||||
BOOST_CHECK_EQUAL(lamp->uprootForce, 400);
|
||||
BOOST_CHECK_EQUAL(lamp->collDamageMulti, 1.0);
|
||||
BOOST_CHECK_EQUAL(lamp->collDamageFlags, 1);
|
||||
BOOST_CHECK_EQUAL(lamp->collResponseFlags, 1);
|
||||
BOOST_CHECK_EQUAL(lamp->cameraAvoid, false);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_handling_data_loader)
|
||||
{
|
||||
GenericDATLoader l;
|
||||
VehicleInfoPtrs loaded;
|
||||
BOOST_AUTO_TEST_CASE(test_handling_data_loader) {
|
||||
GenericDATLoader l;
|
||||
VehicleInfoPtrs loaded;
|
||||
|
||||
l.loadHandling(Global::get().getGamePath() + "/data/handling.cfg", loaded);
|
||||
l.loadHandling(Global::get().getGamePath() + "/data/handling.cfg", loaded);
|
||||
|
||||
BOOST_ASSERT( loaded.size() > 0 );
|
||||
BOOST_ASSERT( loaded.find("STINGER") != loaded.end() );
|
||||
BOOST_ASSERT(loaded.size() > 0);
|
||||
BOOST_ASSERT(loaded.find("STINGER") != loaded.end());
|
||||
|
||||
VehicleInfoPtr info = loaded["STINGER"];
|
||||
VehicleHandlingInfo& handling = info->handling;
|
||||
VehicleInfoPtr info = loaded["STINGER"];
|
||||
VehicleHandlingInfo& handling = info->handling;
|
||||
|
||||
BOOST_CHECK_EQUAL( handling.mass, 1000.0 );
|
||||
BOOST_CHECK_EQUAL( handling.flags, 0xA182 );
|
||||
BOOST_CHECK_EQUAL( handling.driveType, VehicleHandlingInfo::All );
|
||||
BOOST_CHECK_EQUAL( handling.engineType, VehicleHandlingInfo::Petrol );
|
||||
BOOST_CHECK_EQUAL(handling.mass, 1000.0);
|
||||
BOOST_CHECK_EQUAL(handling.flags, 0xA182);
|
||||
BOOST_CHECK_EQUAL(handling.driveType, VehicleHandlingInfo::All);
|
||||
BOOST_CHECK_EQUAL(handling.engineType, VehicleHandlingInfo::Petrol);
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
@ -1,117 +1,123 @@
|
||||
#ifndef _TESTGLOBABLS_HPP_
|
||||
#define _TESTGLOBABLS_HPP_
|
||||
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <GameConfig.hpp>
|
||||
#include <GameWindow.hpp>
|
||||
#include <core/Logger.hpp>
|
||||
#include <engine/GameData.hpp>
|
||||
#include <engine/GameState.hpp>
|
||||
#include <core/Logger.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <GameWindow.hpp>
|
||||
#include <GameConfig.hpp>
|
||||
|
||||
std::ostream& operator<<( std::ostream& stream, glm::vec3 const& v );
|
||||
std::ostream& operator<<(std::ostream& stream, glm::vec3 const& v);
|
||||
|
||||
// Boost moved the print_log_value struct in version 1.59
|
||||
// TODO: use another testing library
|
||||
#if BOOST_VERSION >= 105900
|
||||
#define BOOST_NS_MAGIC namespace tt_detail {
|
||||
#define BOOST_NS_MAGIC_CLOSING }
|
||||
#define BOOST_NS_MAGIC namespace tt_detail {
|
||||
#define BOOST_NS_MAGIC_CLOSING }
|
||||
#else
|
||||
#define BOOST_NS_MAGIC
|
||||
#define BOOST_NS_MAGIC_CLOSING
|
||||
#define BOOST_NS_MAGIC
|
||||
#define BOOST_NS_MAGIC_CLOSING
|
||||
#endif
|
||||
|
||||
namespace boost { namespace test_tools { BOOST_NS_MAGIC
|
||||
template<>
|
||||
namespace boost {
|
||||
namespace test_tools {
|
||||
BOOST_NS_MAGIC
|
||||
template <>
|
||||
struct print_log_value<glm::vec3> {
|
||||
void operator()( std::ostream& s , glm::vec3 const& v )
|
||||
{
|
||||
s << glm::to_string(v);
|
||||
}
|
||||
void operator()(std::ostream& s, glm::vec3 const& v) {
|
||||
s << glm::to_string(v);
|
||||
}
|
||||
};
|
||||
}} BOOST_NS_MAGIC_CLOSING
|
||||
}
|
||||
}
|
||||
BOOST_NS_MAGIC_CLOSING
|
||||
|
||||
namespace boost { namespace test_tools { BOOST_NS_MAGIC
|
||||
template<>
|
||||
namespace boost {
|
||||
namespace test_tools {
|
||||
BOOST_NS_MAGIC
|
||||
template <>
|
||||
struct print_log_value<std::nullptr_t> {
|
||||
void operator()( std::ostream& s , std::nullptr_t )
|
||||
{
|
||||
s << "nullptr";
|
||||
}
|
||||
void operator()(std::ostream& s, std::nullptr_t) {
|
||||
s << "nullptr";
|
||||
}
|
||||
};
|
||||
}} BOOST_NS_MAGIC_CLOSING
|
||||
}
|
||||
}
|
||||
BOOST_NS_MAGIC_CLOSING
|
||||
|
||||
namespace boost { namespace test_tools { BOOST_NS_MAGIC
|
||||
template<>
|
||||
namespace boost {
|
||||
namespace test_tools {
|
||||
BOOST_NS_MAGIC
|
||||
template <>
|
||||
struct print_log_value<GameString> {
|
||||
void operator()( std::ostream& s , GameString const& v )
|
||||
{
|
||||
for (GameString::size_type i = 0u; i<v.size(); ++i) {
|
||||
s << (char)v[i];
|
||||
}
|
||||
}
|
||||
void operator()(std::ostream& s, GameString const& v) {
|
||||
for (GameString::size_type i = 0u; i < v.size(); ++i) {
|
||||
s << (char)v[i];
|
||||
}
|
||||
}
|
||||
};
|
||||
}} BOOST_NS_MAGIC_CLOSING
|
||||
}
|
||||
}
|
||||
BOOST_NS_MAGIC_CLOSING
|
||||
|
||||
#undef BOOST_NS_MAGIC
|
||||
#undef BOOST_NS_MAGIC_CLOSING
|
||||
|
||||
class Global
|
||||
{
|
||||
class Global {
|
||||
public:
|
||||
GameWindow window;
|
||||
GameWindow window;
|
||||
#if RW_TEST_WITH_DATA
|
||||
GameData* d;
|
||||
GameWorld* e;
|
||||
GameState* s;
|
||||
Logger log;
|
||||
WorkContext work;
|
||||
GameData* d;
|
||||
GameWorld* e;
|
||||
GameState* s;
|
||||
Logger log;
|
||||
WorkContext work;
|
||||
#endif
|
||||
|
||||
Global() {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
throw std::runtime_error("Failed to initialize SDL2!");
|
||||
Global() {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
throw std::runtime_error("Failed to initialize SDL2!");
|
||||
|
||||
window.create("Tests", 800, 600, false);
|
||||
window.hideCursor();
|
||||
window.create("Tests", 800, 600, false);
|
||||
window.hideCursor();
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
d = new GameData(&log, &work, getGamePath());
|
||||
d = new GameData(&log, &work, getGamePath());
|
||||
|
||||
d->load();
|
||||
d->load();
|
||||
|
||||
e = new GameWorld(&log, &work, d);
|
||||
s = new GameState;
|
||||
e->state = s;
|
||||
e = new GameWorld(&log, &work, d);
|
||||
s = new GameState;
|
||||
e->state = s;
|
||||
|
||||
e->dynamicsWorld->setGravity(btVector3(0.f, 0.f, 0.f));
|
||||
e->dynamicsWorld->setGravity(btVector3(0.f, 0.f, 0.f));
|
||||
|
||||
while( ! e->_work->isEmpty() ) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
while (!e->_work->isEmpty()) {
|
||||
std::this_thread::yield();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
~Global() {
|
||||
window.close();
|
||||
~Global() {
|
||||
window.close();
|
||||
#if RW_TEST_WITH_DATA
|
||||
delete e;
|
||||
delete e;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
static std::string getGamePath()
|
||||
{
|
||||
return GameConfig("openrw.ini").getGameDataPath();
|
||||
}
|
||||
static std::string getGamePath() {
|
||||
return GameConfig("openrw.ini").getGameDataPath();
|
||||
}
|
||||
#endif
|
||||
|
||||
static Global& get()
|
||||
{
|
||||
static Global g;
|
||||
return g;
|
||||
}
|
||||
static Global& get() {
|
||||
static Global g;
|
||||
return g;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -6,35 +6,33 @@
|
||||
BOOST_AUTO_TEST_SUITE(ItemTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_character_inventory)
|
||||
{
|
||||
{
|
||||
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 0.f});
|
||||
BOOST_REQUIRE( character != nullptr );
|
||||
BOOST_AUTO_TEST_CASE(test_character_inventory) {
|
||||
{
|
||||
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 0.f});
|
||||
BOOST_REQUIRE(character != nullptr);
|
||||
|
||||
auto item = Global::get().e->getInventoryItem(4);
|
||||
auto fist = Global::get().e->getInventoryItem(0);
|
||||
auto item = Global::get().e->getInventoryItem(4);
|
||||
auto fist = Global::get().e->getInventoryItem(0);
|
||||
|
||||
BOOST_REQUIRE(item != nullptr);
|
||||
BOOST_REQUIRE(fist != nullptr );
|
||||
BOOST_CHECK_NE( fist, item );
|
||||
BOOST_REQUIRE(item != nullptr);
|
||||
BOOST_REQUIRE(fist != nullptr);
|
||||
BOOST_CHECK_NE(fist, item);
|
||||
|
||||
character->addToInventory(item);
|
||||
character->addToInventory(item);
|
||||
|
||||
BOOST_CHECK_EQUAL( character->getActiveItem(), fist );
|
||||
BOOST_CHECK_EQUAL(character->getActiveItem(), fist);
|
||||
|
||||
character->setActiveItem( item->getInventorySlot() );
|
||||
character->setActiveItem(item->getInventorySlot());
|
||||
|
||||
BOOST_CHECK_EQUAL( character->getActiveItem(), item );
|
||||
BOOST_CHECK_EQUAL(character->getActiveItem(), item);
|
||||
|
||||
character->removeFromInventory( item->getInventorySlot() );
|
||||
character->removeFromInventory(item->getInventorySlot());
|
||||
|
||||
BOOST_CHECK_EQUAL( character->getActiveItem(), fist );
|
||||
BOOST_CHECK_EQUAL(character->getActiveItem(), fist);
|
||||
|
||||
Global::get().e->destroyObject(character);
|
||||
}
|
||||
Global::get().e->destroyObject(character);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
@ -7,27 +7,27 @@
|
||||
BOOST_AUTO_TEST_SUITE(LifetimeTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_cleanup)
|
||||
{
|
||||
GameObject* f = Global::get().e->createInstance(1337, glm::vec3(0.f, 0.f, 1000.f));
|
||||
auto id = f->getGameObjectID();
|
||||
auto& objects = Global::get().e->instancePool.objects;
|
||||
BOOST_AUTO_TEST_CASE(test_cleanup) {
|
||||
GameObject* f =
|
||||
Global::get().e->createInstance(1337, glm::vec3(0.f, 0.f, 1000.f));
|
||||
auto id = f->getGameObjectID();
|
||||
auto& objects = Global::get().e->instancePool.objects;
|
||||
|
||||
f->setLifetime(GameObject::TrafficLifetime);
|
||||
|
||||
{
|
||||
auto search = objects.find(id);
|
||||
BOOST_CHECK( search != objects.end() );
|
||||
}
|
||||
|
||||
ViewCamera testCamera;
|
||||
testCamera.position = glm::vec3(0.f, 0.f, 0.f);
|
||||
Global::get().e->cleanupTraffic(testCamera);
|
||||
|
||||
{
|
||||
auto search = objects.find(id);
|
||||
BOOST_CHECK( search != objects.end() );
|
||||
}
|
||||
f->setLifetime(GameObject::TrafficLifetime);
|
||||
|
||||
{
|
||||
auto search = objects.find(id);
|
||||
BOOST_CHECK(search != objects.end());
|
||||
}
|
||||
|
||||
ViewCamera testCamera;
|
||||
testCamera.position = glm::vec3(0.f, 0.f, 0.f);
|
||||
Global::get().e->cleanupTraffic(testCamera);
|
||||
|
||||
{
|
||||
auto search = objects.find(id);
|
||||
BOOST_CHECK(search != objects.end());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,69 +1,67 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <data/Model.hpp>
|
||||
#include <job/WorkContext.hpp>
|
||||
#include <loaders/BackgroundLoader.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(LoaderDFFTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_load_dff)
|
||||
{
|
||||
{
|
||||
auto d = Global::get().e->data->index.openFile("landstal.dff");
|
||||
BOOST_AUTO_TEST_CASE(test_load_dff) {
|
||||
{
|
||||
auto d = Global::get().e->data->index.openFile("landstal.dff");
|
||||
|
||||
LoaderDFF loader;
|
||||
LoaderDFF loader;
|
||||
|
||||
Model* m = loader.loadFromMemory(d);
|
||||
Model* m = loader.loadFromMemory(d);
|
||||
|
||||
BOOST_REQUIRE( m != nullptr );
|
||||
BOOST_REQUIRE(m != nullptr);
|
||||
|
||||
BOOST_REQUIRE_EQUAL( m->frames.size(), 40 );
|
||||
BOOST_REQUIRE_EQUAL(m->frames.size(), 40);
|
||||
|
||||
BOOST_REQUIRE_EQUAL( m->geometries.size(), 16 );
|
||||
BOOST_REQUIRE_EQUAL(m->geometries.size(), 16);
|
||||
|
||||
BOOST_REQUIRE_EQUAL( m->geometries[0]->subgeom.size(), 5 );
|
||||
BOOST_REQUIRE_EQUAL(m->geometries[0]->subgeom.size(), 5);
|
||||
|
||||
for(auto& g : m->geometries) {
|
||||
BOOST_CHECK_GT( g->geometryBounds.radius, 0.f );
|
||||
}
|
||||
for (auto& g : m->geometries) {
|
||||
BOOST_CHECK_GT(g->geometryBounds.radius, 0.f);
|
||||
}
|
||||
|
||||
BOOST_REQUIRE( m->atomics.size() > 0 );
|
||||
BOOST_REQUIRE(m->atomics.size() > 0);
|
||||
|
||||
for(Model::Atomic& a : m->atomics) {
|
||||
BOOST_CHECK( a.frame < m->frames.size() );
|
||||
BOOST_CHECK( a.geometry < m->geometries.size() );
|
||||
}
|
||||
|
||||
delete m;
|
||||
}
|
||||
for (Model::Atomic& a : m->atomics) {
|
||||
BOOST_CHECK(a.frame < m->frames.size());
|
||||
BOOST_CHECK(a.geometry < m->geometries.size());
|
||||
}
|
||||
|
||||
delete m;
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_loader_job)
|
||||
{
|
||||
{
|
||||
WorkContext ctx;
|
||||
BOOST_AUTO_TEST_CASE(test_loader_job) {
|
||||
{
|
||||
WorkContext ctx;
|
||||
|
||||
ResourceHandle<Model>::Ref modelRef { new ResourceHandle<Model>("landstal.dff") };
|
||||
|
||||
auto index = &Global::get().e->data->index;
|
||||
auto job = new BackgroundLoaderJob<Model, LoaderDFF>{ &ctx, index, "landstal.dff", modelRef };
|
||||
ResourceHandle<Model>::Ref modelRef{
|
||||
new ResourceHandle<Model>("landstal.dff")};
|
||||
|
||||
ctx.queueJob(job);
|
||||
auto index = &Global::get().e->data->index;
|
||||
auto job = new BackgroundLoaderJob<Model, LoaderDFF>{
|
||||
&ctx, index, "landstal.dff", modelRef};
|
||||
|
||||
while( modelRef->state == RW::Loading ) {
|
||||
ctx.update();
|
||||
std::this_thread::yield();
|
||||
}
|
||||
ctx.queueJob(job);
|
||||
|
||||
BOOST_REQUIRE( modelRef->resource != nullptr );
|
||||
while (modelRef->state == RW::Loading) {
|
||||
ctx.update();
|
||||
std::this_thread::yield();
|
||||
}
|
||||
|
||||
BOOST_CHECK( modelRef->resource->frames.size() > 0 );
|
||||
|
||||
delete modelRef->resource;
|
||||
}
|
||||
BOOST_REQUIRE(modelRef->resource != nullptr);
|
||||
|
||||
BOOST_CHECK(modelRef->resource->frames.size() > 0);
|
||||
|
||||
delete modelRef->resource;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,97 +1,93 @@
|
||||
#include <MenuSystem.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <MenuSystem.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(MenuUnitTests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(menu_test_click)
|
||||
{
|
||||
bool clickered = false;
|
||||
Menu test(0);
|
||||
test.addEntry(Menu::lambda("Test", [&]{ clickered = true; }));
|
||||
|
||||
BOOST_CHECK(! clickered );
|
||||
|
||||
// Click underneath the menu item.
|
||||
test.click(0.f, -1.f);
|
||||
|
||||
BOOST_CHECK(! clickered );
|
||||
|
||||
float h = test.entries.at(0)->getHeight();
|
||||
|
||||
test.click(0.f, h + 1.f);
|
||||
|
||||
BOOST_CHECK(! clickered );
|
||||
|
||||
test.click(0.f, h / 2.f);
|
||||
|
||||
BOOST_CHECK( clickered );
|
||||
BOOST_AUTO_TEST_CASE(menu_test_click) {
|
||||
bool clickered = false;
|
||||
Menu test(0);
|
||||
test.addEntry(Menu::lambda("Test", [&] { clickered = true; }));
|
||||
|
||||
BOOST_CHECK(!clickered);
|
||||
|
||||
// Click underneath the menu item.
|
||||
test.click(0.f, -1.f);
|
||||
|
||||
BOOST_CHECK(!clickered);
|
||||
|
||||
float h = test.entries.at(0)->getHeight();
|
||||
|
||||
test.click(0.f, h + 1.f);
|
||||
|
||||
BOOST_CHECK(!clickered);
|
||||
|
||||
test.click(0.f, h / 2.f);
|
||||
|
||||
BOOST_CHECK(clickered);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(menu_test_click_offset)
|
||||
{
|
||||
bool clickered = false;
|
||||
Menu test(0);
|
||||
test.offset = glm::vec2(200.f, 200.f);
|
||||
test.addEntry(Menu::lambda("Test", [&]{ clickered = true; }));
|
||||
|
||||
BOOST_CHECK(! clickered );
|
||||
|
||||
// Click underneath the menu item.
|
||||
test.click(201.f, -1.f);
|
||||
|
||||
BOOST_CHECK(! clickered );
|
||||
|
||||
float h = test.entries.at(0)->getHeight();
|
||||
|
||||
test.click(201.f, 200.f + h + 1.f);
|
||||
|
||||
BOOST_CHECK(! clickered );
|
||||
|
||||
test.click(201.f, 200.f + h / 2.f);
|
||||
|
||||
BOOST_CHECK( clickered );
|
||||
BOOST_AUTO_TEST_CASE(menu_test_click_offset) {
|
||||
bool clickered = false;
|
||||
Menu test(0);
|
||||
test.offset = glm::vec2(200.f, 200.f);
|
||||
test.addEntry(Menu::lambda("Test", [&] { clickered = true; }));
|
||||
|
||||
BOOST_CHECK(!clickered);
|
||||
|
||||
// Click underneath the menu item.
|
||||
test.click(201.f, -1.f);
|
||||
|
||||
BOOST_CHECK(!clickered);
|
||||
|
||||
float h = test.entries.at(0)->getHeight();
|
||||
|
||||
test.click(201.f, 200.f + h + 1.f);
|
||||
|
||||
BOOST_CHECK(!clickered);
|
||||
|
||||
test.click(201.f, 200.f + h / 2.f);
|
||||
|
||||
BOOST_CHECK(clickered);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(menu_test_active_index)
|
||||
{
|
||||
int clickindex = -1;
|
||||
Menu test(0);
|
||||
test.addEntry(Menu::lambda("Test1", [&]{ clickindex = 0; }));
|
||||
test.addEntry(Menu::lambda("Test2", [&]{ clickindex = 1; }));
|
||||
|
||||
test.activate();
|
||||
|
||||
BOOST_CHECK( clickindex == -1 );
|
||||
|
||||
test.move( 1);
|
||||
test.activate();
|
||||
|
||||
BOOST_CHECK( clickindex == 0 );
|
||||
|
||||
test.move( 1);
|
||||
test.activate();
|
||||
|
||||
BOOST_CHECK( clickindex == 1 );
|
||||
|
||||
test.move(-1);
|
||||
test.activate();
|
||||
|
||||
BOOST_CHECK( clickindex == 0 );
|
||||
BOOST_AUTO_TEST_CASE(menu_test_active_index) {
|
||||
int clickindex = -1;
|
||||
Menu test(0);
|
||||
test.addEntry(Menu::lambda("Test1", [&] { clickindex = 0; }));
|
||||
test.addEntry(Menu::lambda("Test2", [&] { clickindex = 1; }));
|
||||
|
||||
test.activate();
|
||||
|
||||
BOOST_CHECK(clickindex == -1);
|
||||
|
||||
test.move(1);
|
||||
test.activate();
|
||||
|
||||
BOOST_CHECK(clickindex == 0);
|
||||
|
||||
test.move(1);
|
||||
test.activate();
|
||||
|
||||
BOOST_CHECK(clickindex == 1);
|
||||
|
||||
test.move(-1);
|
||||
test.activate();
|
||||
|
||||
BOOST_CHECK(clickindex == 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(menu_test_hover_index)
|
||||
{
|
||||
int clickindex = -1;
|
||||
Menu test(0);
|
||||
test.addEntry(Menu::lambda("Test1", [&]{ clickindex = 0; }));
|
||||
test.addEntry(Menu::lambda("Test2", [&]{ clickindex = 1; }));
|
||||
|
||||
test.hover(0.f, test.entries[0]->getHeight() - 0.1f);
|
||||
BOOST_CHECK( test.activeEntry == 0 );
|
||||
|
||||
test.hover(0.f, test.entries[0]->getHeight() + 0.1f);
|
||||
BOOST_CHECK( test.activeEntry == 1 );
|
||||
BOOST_AUTO_TEST_CASE(menu_test_hover_index) {
|
||||
int clickindex = -1;
|
||||
Menu test(0);
|
||||
test.addEntry(Menu::lambda("Test1", [&] { clickindex = 0; }));
|
||||
test.addEntry(Menu::lambda("Test2", [&] { clickindex = 1; }));
|
||||
|
||||
test.hover(0.f, test.entries[0]->getHeight() - 0.1f);
|
||||
BOOST_CHECK(test.activeEntry == 0);
|
||||
|
||||
test.hover(0.f, test.entries[0]->getHeight() + 0.1f);
|
||||
BOOST_CHECK(test.activeEntry == 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -1,11 +1,11 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <objects/InstanceObject.hpp>
|
||||
#include <engine/GameWorld.hpp>
|
||||
#include <objects/InstanceObject.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(ObjectUnitTests)
|
||||
|
||||
#if 0 // Tests disabled as object damage logic is unclear
|
||||
#if 0 // Tests disabled as object damage logic is unclear
|
||||
|
||||
BOOST_AUTO_TEST_CASE(instance_test_damage)
|
||||
{
|
||||
|
@ -5,55 +5,52 @@
|
||||
BOOST_AUTO_TEST_SUITE(ObjectDataTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_object_data)
|
||||
{
|
||||
{
|
||||
LoaderIDE l;
|
||||
BOOST_AUTO_TEST_CASE(test_object_data) {
|
||||
{
|
||||
LoaderIDE l;
|
||||
|
||||
l.load(Global::get().getGamePath() + "/data/maps/generic.ide");
|
||||
l.load(Global::get().getGamePath() + "/data/maps/generic.ide");
|
||||
|
||||
BOOST_ASSERT( l.objects.find(1100) != l.objects.end() );
|
||||
BOOST_ASSERT(l.objects.find(1100) != l.objects.end());
|
||||
|
||||
auto obj = l.objects[1100];
|
||||
auto obj = l.objects[1100];
|
||||
|
||||
auto def = std::dynamic_pointer_cast<ObjectData>(obj);
|
||||
auto def = std::dynamic_pointer_cast<ObjectData>(obj);
|
||||
|
||||
BOOST_ASSERT(def->class_type == ObjectInformation::_class("OBJS"));
|
||||
BOOST_ASSERT(def->class_type == ObjectInformation::_class("OBJS"));
|
||||
|
||||
BOOST_CHECK_EQUAL( def->modelName, "rd_Corner1" );
|
||||
BOOST_CHECK_EQUAL( def->textureName, "generic" );
|
||||
BOOST_CHECK_EQUAL( def->numClumps, 1 );
|
||||
BOOST_CHECK_EQUAL( def->drawDistance[0], 220 );
|
||||
BOOST_CHECK_EQUAL( def->flags, 0 );
|
||||
}
|
||||
{
|
||||
LoaderIDE l;
|
||||
BOOST_CHECK_EQUAL(def->modelName, "rd_Corner1");
|
||||
BOOST_CHECK_EQUAL(def->textureName, "generic");
|
||||
BOOST_CHECK_EQUAL(def->numClumps, 1);
|
||||
BOOST_CHECK_EQUAL(def->drawDistance[0], 220);
|
||||
BOOST_CHECK_EQUAL(def->flags, 0);
|
||||
}
|
||||
{
|
||||
LoaderIDE l;
|
||||
|
||||
l.load(Global::get().getGamePath() + "/data/default.ide");
|
||||
l.load(Global::get().getGamePath() + "/data/default.ide");
|
||||
|
||||
BOOST_ASSERT( l.objects.find(90) != l.objects.end() );
|
||||
BOOST_ASSERT(l.objects.find(90) != l.objects.end());
|
||||
|
||||
auto obj = l.objects[90];
|
||||
auto obj = l.objects[90];
|
||||
|
||||
auto def = std::dynamic_pointer_cast<VehicleData>(obj);
|
||||
auto def = std::dynamic_pointer_cast<VehicleData>(obj);
|
||||
|
||||
BOOST_ASSERT(def->class_type == ObjectInformation::_class("CARS"));
|
||||
BOOST_ASSERT(def->class_type == ObjectInformation::_class("CARS"));
|
||||
|
||||
BOOST_CHECK_EQUAL( def->modelName, "landstal");
|
||||
BOOST_CHECK_EQUAL( def->textureName, "landstal" );
|
||||
BOOST_CHECK_EQUAL( def->type, VehicleData::CAR );
|
||||
BOOST_CHECK_EQUAL( def->handlingID, "LANDSTAL" );
|
||||
BOOST_CHECK_EQUAL( def->gameName, "LANDSTK" );
|
||||
BOOST_CHECK_EQUAL( def->classType, VehicleData::RICHFAMILY );
|
||||
BOOST_CHECK_EQUAL( def->frequency, 10 );
|
||||
BOOST_CHECK_EQUAL( def->wheelModelID, 164 );
|
||||
BOOST_CHECK_CLOSE( def->wheelScale, 0.8f, 0.01f);
|
||||
}
|
||||
BOOST_CHECK_EQUAL(def->modelName, "landstal");
|
||||
BOOST_CHECK_EQUAL(def->textureName, "landstal");
|
||||
BOOST_CHECK_EQUAL(def->type, VehicleData::CAR);
|
||||
BOOST_CHECK_EQUAL(def->handlingID, "LANDSTAL");
|
||||
BOOST_CHECK_EQUAL(def->gameName, "LANDSTK");
|
||||
BOOST_CHECK_EQUAL(def->classType, VehicleData::RICHFAMILY);
|
||||
BOOST_CHECK_EQUAL(def->frequency, 10);
|
||||
BOOST_CHECK_EQUAL(def->wheelModelID, 164);
|
||||
BOOST_CHECK_CLOSE(def->wheelScale, 0.8f, 0.01f);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_gamedata_data)
|
||||
{
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_gamedata_data) {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,97 +1,97 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <objects/PickupObject.hpp>
|
||||
#include <objects/ItemPickup.hpp>
|
||||
#include <items/InventoryItem.hpp>
|
||||
#include <data/WeaponData.hpp>
|
||||
#include <items/InventoryItem.hpp>
|
||||
#include <objects/CharacterObject.hpp>
|
||||
#include <objects/ItemPickup.hpp>
|
||||
#include <objects/PickupObject.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
class TestPickup : public PickupObject
|
||||
{
|
||||
class TestPickup : public PickupObject {
|
||||
public:
|
||||
bool picked_up = false;
|
||||
bool picked_up = false;
|
||||
|
||||
TestPickup(GameWorld* engine, const glm::vec3& position)
|
||||
: PickupObject(engine, position, 0, OnStreet)
|
||||
{}
|
||||
TestPickup(GameWorld* engine, const glm::vec3& position)
|
||||
: PickupObject(engine, position, 0, OnStreet) {
|
||||
}
|
||||
|
||||
bool onCharacterTouch(CharacterObject *character) {
|
||||
picked_up = true;
|
||||
return true;
|
||||
}
|
||||
bool onCharacterTouch(CharacterObject* character) {
|
||||
picked_up = true;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(PickupTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_pickup_interaction)
|
||||
{
|
||||
{
|
||||
auto character = Global::get().e->createPedestrian(1, { 30.1f, 0.f, 0.f });
|
||||
BOOST_REQUIRE( character != nullptr );
|
||||
BOOST_AUTO_TEST_CASE(test_pickup_interaction) {
|
||||
{
|
||||
auto character =
|
||||
Global::get().e->createPedestrian(1, {30.1f, 0.f, 0.f});
|
||||
BOOST_REQUIRE(character != nullptr);
|
||||
|
||||
TestPickup* p = new TestPickup(Global::get().e, { 30.f, 0.f, 0.f } );
|
||||
TestPickup* p = new TestPickup(Global::get().e, {30.f, 0.f, 0.f});
|
||||
|
||||
//Global::get().e->insertObject(p);
|
||||
// Global::get().e->insertObject(p);
|
||||
|
||||
BOOST_CHECK( ! p->picked_up );
|
||||
BOOST_CHECK(!p->picked_up);
|
||||
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f);
|
||||
p->tick(0.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f);
|
||||
p->tick(0.f);
|
||||
|
||||
BOOST_CHECK( p->picked_up );
|
||||
BOOST_CHECK(p->picked_up);
|
||||
|
||||
p->picked_up = false;
|
||||
p->picked_up = false;
|
||||
|
||||
BOOST_CHECK( ! p->picked_up );
|
||||
BOOST_CHECK(!p->picked_up);
|
||||
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f);
|
||||
p->tick(0.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f);
|
||||
p->tick(0.f);
|
||||
|
||||
BOOST_CHECK( ! p->picked_up );
|
||||
BOOST_CHECK(!p->picked_up);
|
||||
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f);
|
||||
p->tick(60.5f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f);
|
||||
p->tick(60.5f);
|
||||
|
||||
BOOST_CHECK( p->picked_up );
|
||||
BOOST_CHECK(p->picked_up);
|
||||
|
||||
|
||||
Global::get().e->destroyObject(p);
|
||||
Global::get().e->destroyObject(character);
|
||||
}
|
||||
Global::get().e->destroyObject(p);
|
||||
Global::get().e->destroyObject(character);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_item_pickup)
|
||||
{
|
||||
{
|
||||
auto character = Global::get().e->createPedestrian(1, { 30.1f, 0.f, 0.f });
|
||||
BOOST_REQUIRE( character != nullptr );
|
||||
BOOST_AUTO_TEST_CASE(test_item_pickup) {
|
||||
{
|
||||
auto character =
|
||||
Global::get().e->createPedestrian(1, {30.1f, 0.f, 0.f});
|
||||
BOOST_REQUIRE(character != nullptr);
|
||||
|
||||
auto item = Global::get().e->getInventoryItem(3);
|
||||
BOOST_REQUIRE(item != nullptr);
|
||||
auto item = Global::get().e->getInventoryItem(3);
|
||||
BOOST_REQUIRE(item != nullptr);
|
||||
|
||||
ItemPickup* p = new ItemPickup(Global::get().e, { 30.f, 0.f, 0.f }, PickupObject::OnStreet, item);
|
||||
ItemPickup* p = new ItemPickup(Global::get().e, {30.f, 0.f, 0.f},
|
||||
PickupObject::OnStreet, item);
|
||||
|
||||
Global::get().e->allObjects.push_back(p);
|
||||
Global::get().e->allObjects.push_back(p);
|
||||
|
||||
// Check the characters inventory is empty.
|
||||
for (int i = 0; i < maxInventorySlots; ++i) {
|
||||
BOOST_CHECK( character->getCurrentState().weapons[i].weaponId == 0 );
|
||||
}
|
||||
// Check the characters inventory is empty.
|
||||
for (int i = 0; i < maxInventorySlots; ++i) {
|
||||
BOOST_CHECK(character->getCurrentState().weapons[i].weaponId == 0);
|
||||
}
|
||||
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f);
|
||||
p->tick(0.f);
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f);
|
||||
p->tick(0.f);
|
||||
|
||||
auto& inventory = character->getCurrentState().weapons;
|
||||
BOOST_CHECK( std::any_of( std::begin(inventory), std::end(inventory),
|
||||
[&](const CharacterWeaponSlot& i)
|
||||
{ return i.weaponId == item->getInventorySlot(); }) );
|
||||
auto& inventory = character->getCurrentState().weapons;
|
||||
BOOST_CHECK(std::any_of(std::begin(inventory), std::end(inventory),
|
||||
[&](const CharacterWeaponSlot& i) {
|
||||
return i.weaponId ==
|
||||
item->getInventorySlot();
|
||||
}));
|
||||
|
||||
Global::get().e->destroyObject(p);
|
||||
Global::get().e->destroyObject(character);
|
||||
}
|
||||
Global::get().e->destroyObject(p);
|
||||
Global::get().e->destroyObject(character);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
@ -1,28 +1,27 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <render/GameRenderer.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(RendererTests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(frustum_test_visible)
|
||||
{
|
||||
{
|
||||
ViewFrustum f(0.1f, 100.f, glm::half_pi<float>(), 1.f);
|
||||
BOOST_AUTO_TEST_CASE(frustum_test_visible) {
|
||||
{
|
||||
ViewFrustum f(0.1f, 100.f, glm::half_pi<float>(), 1.f);
|
||||
|
||||
f.update(f.projection());
|
||||
f.update(f.projection());
|
||||
|
||||
BOOST_CHECK( f.intersects({10.f, 0.f,-10.f}, 1.f ) );
|
||||
BOOST_CHECK(!f.intersects({ 0.f, 0.f, 10.f}, 1.f ) );
|
||||
BOOST_CHECK(f.intersects({10.f, 0.f, -10.f}, 1.f));
|
||||
BOOST_CHECK(!f.intersects({0.f, 0.f, 10.f}, 1.f));
|
||||
|
||||
BOOST_CHECK(!f.intersects({0.f, 10.f, 0.f}, 1.f ) );
|
||||
BOOST_CHECK(!f.intersects({0.f,-10.f, 0.f}, 1.f ) );
|
||||
BOOST_CHECK(!f.intersects({0.f, 10.f, 0.f}, 1.f));
|
||||
BOOST_CHECK(!f.intersects({0.f, -10.f, 0.f}, 1.f));
|
||||
|
||||
BOOST_CHECK(!f.intersects({ 10.f, 0.f, 0.f}, 1.f ) );
|
||||
BOOST_CHECK(!f.intersects({-10.f, 0.f, 0.f}, 1.f ) );
|
||||
BOOST_CHECK(!f.intersects({10.f, 0.f, 0.f}, 1.f));
|
||||
BOOST_CHECK(!f.intersects({-10.f, 0.f, 0.f}, 1.f));
|
||||
|
||||
BOOST_CHECK( f.intersects({ 10.f, 0.f,-10.f}, 1.f ) );
|
||||
BOOST_CHECK( f.intersects({-10.f, 0.f,-10.f}, 1.f ) );
|
||||
}
|
||||
BOOST_CHECK(f.intersects({10.f, 0.f, -10.f}, 1.f));
|
||||
BOOST_CHECK(f.intersects({-10.f, 0.f, -10.f}, 1.f));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -1,32 +1,31 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <loaders/RWBinaryStream.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(RWBStreamTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(iterate_stream_test)
|
||||
{
|
||||
{
|
||||
auto d = Global::get().e->data->index.openFile("landstal.dff");
|
||||
|
||||
RWBStream stream(d->data, d->length);
|
||||
|
||||
RWBStream::ChunkID id = stream.getNextChunk();
|
||||
BOOST_AUTO_TEST_CASE(iterate_stream_test) {
|
||||
{
|
||||
auto d = Global::get().e->data->index.openFile("landstal.dff");
|
||||
|
||||
BOOST_REQUIRE_EQUAL( id, 0x0010 );
|
||||
RWBStream stream(d->data, d->length);
|
||||
|
||||
auto inner = stream.getInnerStream();
|
||||
RWBStream::ChunkID id = stream.getNextChunk();
|
||||
|
||||
auto inner1 = inner.getNextChunk();
|
||||
BOOST_REQUIRE_EQUAL(id, 0x0010);
|
||||
|
||||
BOOST_REQUIRE_EQUAL( inner1, 0x0001 );
|
||||
auto inner = stream.getInnerStream();
|
||||
|
||||
auto innerCursor = inner.getCursor();
|
||||
auto inner1 = inner.getNextChunk();
|
||||
|
||||
// This is a value inside in the Clump's struct header section.
|
||||
BOOST_CHECK_EQUAL( *(std::uint32_t*)innerCursor, 0x10 );
|
||||
}
|
||||
BOOST_REQUIRE_EQUAL(inner1, 0x0001);
|
||||
|
||||
auto innerCursor = inner.getCursor();
|
||||
|
||||
// This is a value inside in the Clump's struct header section.
|
||||
BOOST_CHECK_EQUAL(*(std::uint32_t*)innerCursor, 0x10);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,29 +1,23 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <script/ScriptMachine.hpp>
|
||||
#include <script/SCMFile.hpp>
|
||||
#include <script/ScriptMachine.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
SCMByte data[] = {
|
||||
0x02,0x00,0x01,0x08,0x00,0x00,0x00,0x00,
|
||||
0x02,0x00,0x01,0x18,0x00,0x00,0x00,0x00,
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x02,0x00,0x01,0x28,0x00,0x00,0x00,0x00,
|
||||
0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00
|
||||
};
|
||||
|
||||
SCMByte data[] = {0x02, 0x00, 0x01, 0x08, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
|
||||
0x01, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x01, 0x28, 0x00, 0x00,
|
||||
0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(ScriptMachineTests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scmfile_test) {
|
||||
SCMFile f;
|
||||
f.loadFile(data, sizeof(data));
|
||||
|
||||
BOOST_AUTO_TEST_CASE(scmfile_test)
|
||||
{
|
||||
SCMFile f;
|
||||
f.loadFile(data, sizeof(data));
|
||||
|
||||
BOOST_CHECK_EQUAL( f.getModelSection(), 0x10 );
|
||||
BOOST_CHECK_EQUAL( f.getMissionSection(), 0x20 );
|
||||
BOOST_CHECK_EQUAL( f.getCodeSection(), 0x28 );
|
||||
BOOST_CHECK_EQUAL(f.getModelSection(), 0x10);
|
||||
BOOST_CHECK_EQUAL(f.getMissionSection(), 0x20);
|
||||
BOOST_CHECK_EQUAL(f.getCodeSection(), 0x28);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -4,61 +4,60 @@
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(SkeletonTests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_methods)
|
||||
{
|
||||
Skeleton::FrameTransform t1 { glm::vec3(0.f, 0.f, 0.f), glm::quat(0.f, 0.f, 0.f, 0.f) };
|
||||
Skeleton::FrameTransform t2 { glm::vec3(1.f, 0.f, 0.f), glm::quat(0.f, 0.f, 1.f, 0.f) };
|
||||
|
||||
Skeleton skeleton;
|
||||
|
||||
skeleton.setAllData({
|
||||
{0, { t1, t2, true }}
|
||||
});
|
||||
|
||||
BOOST_CHECK(skeleton.getData(0).a.translation == t1.translation);
|
||||
BOOST_CHECK(skeleton.getData(0).a.rotation == t1.rotation);
|
||||
|
||||
BOOST_CHECK(skeleton.getData(0).b.translation == t2.translation);
|
||||
BOOST_CHECK(skeleton.getData(0).b.rotation == t2.rotation);
|
||||
|
||||
BOOST_CHECK(skeleton.getData(0).enabled);
|
||||
|
||||
skeleton.setData(0, {t2, t1, false});
|
||||
|
||||
BOOST_CHECK(skeleton.getData(0).a.translation == t2.translation);
|
||||
BOOST_CHECK(skeleton.getData(0).a.rotation == t2.rotation);
|
||||
|
||||
BOOST_CHECK(skeleton.getData(0).b.translation == t1.translation);
|
||||
BOOST_CHECK(skeleton.getData(0).b.rotation == t1.rotation);
|
||||
|
||||
BOOST_CHECK(! skeleton.getData(0).enabled);
|
||||
BOOST_AUTO_TEST_CASE(test_methods) {
|
||||
Skeleton::FrameTransform t1{glm::vec3(0.f, 0.f, 0.f),
|
||||
glm::quat(0.f, 0.f, 0.f, 0.f)};
|
||||
Skeleton::FrameTransform t2{glm::vec3(1.f, 0.f, 0.f),
|
||||
glm::quat(0.f, 0.f, 1.f, 0.f)};
|
||||
|
||||
Skeleton skeleton;
|
||||
|
||||
skeleton.setAllData({{0, {t1, t2, true}}});
|
||||
|
||||
BOOST_CHECK(skeleton.getData(0).a.translation == t1.translation);
|
||||
BOOST_CHECK(skeleton.getData(0).a.rotation == t1.rotation);
|
||||
|
||||
BOOST_CHECK(skeleton.getData(0).b.translation == t2.translation);
|
||||
BOOST_CHECK(skeleton.getData(0).b.rotation == t2.rotation);
|
||||
|
||||
BOOST_CHECK(skeleton.getData(0).enabled);
|
||||
|
||||
skeleton.setData(0, {t2, t1, false});
|
||||
|
||||
BOOST_CHECK(skeleton.getData(0).a.translation == t2.translation);
|
||||
BOOST_CHECK(skeleton.getData(0).a.rotation == t2.rotation);
|
||||
|
||||
BOOST_CHECK(skeleton.getData(0).b.translation == t1.translation);
|
||||
BOOST_CHECK(skeleton.getData(0).b.rotation == t1.rotation);
|
||||
|
||||
BOOST_CHECK(!skeleton.getData(0).enabled);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_interpolate)
|
||||
{
|
||||
Skeleton::FrameTransform t1 { glm::vec3(0.f, 0.f, 0.f), glm::quat(0.f, 0.f, 0.f, 0.f) };
|
||||
Skeleton::FrameTransform t2 { glm::vec3(1.f, 0.f, 0.f), glm::quat(0.f, 0.f, 1.f, 0.f) };
|
||||
|
||||
Skeleton skeleton;
|
||||
|
||||
skeleton.setAllData({
|
||||
{0, { t2, t1, true }}
|
||||
});
|
||||
|
||||
/** Without calling Skeleton::interpolate(alpha) the result is identity */
|
||||
|
||||
BOOST_CHECK(skeleton.getInterpolated(0).translation == Skeleton::IdentityTransform.translation);
|
||||
BOOST_CHECK(skeleton.getInterpolated(0).rotation == Skeleton::IdentityTransform.rotation);
|
||||
|
||||
skeleton.interpolate(0.f);
|
||||
|
||||
BOOST_CHECK(skeleton.getInterpolated(0).translation == t1.translation);
|
||||
BOOST_CHECK(skeleton.getInterpolated(0).rotation == t1.rotation);
|
||||
|
||||
skeleton.interpolate(1.f);
|
||||
|
||||
BOOST_CHECK(skeleton.getInterpolated(0).translation == t2.translation);
|
||||
BOOST_CHECK(skeleton.getInterpolated(0).rotation == t2.rotation);
|
||||
BOOST_AUTO_TEST_CASE(test_interpolate) {
|
||||
Skeleton::FrameTransform t1{glm::vec3(0.f, 0.f, 0.f),
|
||||
glm::quat(0.f, 0.f, 0.f, 0.f)};
|
||||
Skeleton::FrameTransform t2{glm::vec3(1.f, 0.f, 0.f),
|
||||
glm::quat(0.f, 0.f, 1.f, 0.f)};
|
||||
|
||||
Skeleton skeleton;
|
||||
|
||||
skeleton.setAllData({{0, {t2, t1, true}}});
|
||||
|
||||
/** Without calling Skeleton::interpolate(alpha) the result is identity */
|
||||
|
||||
BOOST_CHECK(skeleton.getInterpolated(0).translation ==
|
||||
Skeleton::IdentityTransform.translation);
|
||||
BOOST_CHECK(skeleton.getInterpolated(0).rotation ==
|
||||
Skeleton::IdentityTransform.rotation);
|
||||
|
||||
skeleton.interpolate(0.f);
|
||||
|
||||
BOOST_CHECK(skeleton.getInterpolated(0).translation == t1.translation);
|
||||
BOOST_CHECK(skeleton.getInterpolated(0).rotation == t1.rotation);
|
||||
|
||||
skeleton.interpolate(1.f);
|
||||
|
||||
BOOST_CHECK(skeleton.getInterpolated(0).translation == t2.translation);
|
||||
BOOST_CHECK(skeleton.getInterpolated(0).rotation == t2.rotation);
|
||||
}
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <State.hpp>
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <State.hpp>
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(StateUnitTests)
|
||||
|
||||
|
@ -1,173 +1,136 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <data/GameTexts.hpp>
|
||||
#include <loaders/LoaderGXT.hpp>
|
||||
#include <engine/ScreenText.hpp>
|
||||
#include <loaders/LoaderGXT.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
#define T(x) GameStringUtil::fromString(x)
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TextTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(load_test)
|
||||
{
|
||||
{
|
||||
auto d = Global::get().e->data->index.openFilePath("text/english.gxt");
|
||||
BOOST_AUTO_TEST_CASE(load_test) {
|
||||
{
|
||||
auto d = Global::get().e->data->index.openFilePath("text/english.gxt");
|
||||
|
||||
GameTexts texts;
|
||||
GameTexts texts;
|
||||
|
||||
LoaderGXT loader;
|
||||
LoaderGXT loader;
|
||||
|
||||
loader.load( texts, d );
|
||||
loader.load(texts, d);
|
||||
|
||||
BOOST_CHECK_EQUAL( texts.text("1008"), T("BUSTED") );
|
||||
}
|
||||
BOOST_CHECK_EQUAL(texts.text("1008"), T("BUSTED"));
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(big_test)
|
||||
{
|
||||
// Check that makeBig creates a text in the right place
|
||||
{
|
||||
auto big = ScreenTextEntry::makeBig(
|
||||
"TEST_1",
|
||||
T("Test String"),
|
||||
1,
|
||||
5000);
|
||||
BOOST_AUTO_TEST_CASE(big_test) {
|
||||
// Check that makeBig creates a text in the right place
|
||||
{
|
||||
auto big =
|
||||
ScreenTextEntry::makeBig("TEST_1", T("Test String"), 1, 5000);
|
||||
|
||||
BOOST_CHECK_EQUAL("TEST_1", big.id);
|
||||
BOOST_CHECK_EQUAL(T("Test String"), big.text);
|
||||
BOOST_CHECK_EQUAL(5000, big.durationMS);
|
||||
BOOST_CHECK_EQUAL(0, big.displayedMS);
|
||||
BOOST_CHECK_EQUAL(1, big.alignment);
|
||||
BOOST_CHECK_EQUAL(50, big.size);
|
||||
}
|
||||
{
|
||||
auto big = ScreenTextEntry::makeBig(
|
||||
"TEST_1",
|
||||
T("Test String"),
|
||||
2,
|
||||
5000);
|
||||
BOOST_CHECK_EQUAL("TEST_1", big.id);
|
||||
BOOST_CHECK_EQUAL(T("Test String"), big.text);
|
||||
BOOST_CHECK_EQUAL(5000, big.durationMS);
|
||||
BOOST_CHECK_EQUAL(0, big.displayedMS);
|
||||
BOOST_CHECK_EQUAL(1, big.alignment);
|
||||
BOOST_CHECK_EQUAL(50, big.size);
|
||||
}
|
||||
{
|
||||
auto big =
|
||||
ScreenTextEntry::makeBig("TEST_1", T("Test String"), 2, 5000);
|
||||
|
||||
BOOST_CHECK_EQUAL(T("Test String"), big.text);
|
||||
BOOST_CHECK_EQUAL(5000, big.durationMS);
|
||||
BOOST_CHECK_EQUAL(0, big.displayedMS);
|
||||
BOOST_CHECK_EQUAL(2, big.alignment);
|
||||
BOOST_CHECK_EQUAL(30, big.size);
|
||||
}
|
||||
BOOST_CHECK_EQUAL(T("Test String"), big.text);
|
||||
BOOST_CHECK_EQUAL(5000, big.durationMS);
|
||||
BOOST_CHECK_EQUAL(0, big.displayedMS);
|
||||
BOOST_CHECK_EQUAL(2, big.alignment);
|
||||
BOOST_CHECK_EQUAL(30, big.size);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(help_test)
|
||||
{
|
||||
auto help = ScreenTextEntry::makeHelp(
|
||||
"TEST_1",
|
||||
T("Test Help"));
|
||||
BOOST_AUTO_TEST_CASE(help_test) {
|
||||
auto help = ScreenTextEntry::makeHelp("TEST_1", T("Test Help"));
|
||||
|
||||
BOOST_CHECK_EQUAL(T("Test Help"), help.text);
|
||||
BOOST_CHECK_EQUAL(5000, help.durationMS);
|
||||
BOOST_CHECK_EQUAL(0, help.displayedMS);
|
||||
BOOST_CHECK_EQUAL(18, help.size);
|
||||
BOOST_CHECK_EQUAL(T("Test Help"), help.text);
|
||||
BOOST_CHECK_EQUAL(5000, help.durationMS);
|
||||
BOOST_CHECK_EQUAL(0, help.displayedMS);
|
||||
BOOST_CHECK_EQUAL(18, help.size);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(queue_test)
|
||||
{
|
||||
// Check that creating a test puts it on the right queue.
|
||||
BOOST_AUTO_TEST_CASE(queue_test) {
|
||||
// Check that creating a test puts it on the right queue.
|
||||
|
||||
ScreenText st;
|
||||
ScreenText st;
|
||||
|
||||
st.addText<ScreenTextType::Big>(
|
||||
ScreenTextEntry::makeBig(
|
||||
"TEST_1",
|
||||
T("Test String"),
|
||||
2,
|
||||
5000));
|
||||
st.addText<ScreenTextType::HighPriority>(
|
||||
ScreenTextEntry::makeHighPriority(
|
||||
"TEST_1",
|
||||
T("Test String"),
|
||||
5000));
|
||||
st.addText<ScreenTextType::Big>(
|
||||
ScreenTextEntry::makeBig("TEST_1", T("Test String"), 2, 5000));
|
||||
st.addText<ScreenTextType::HighPriority>(
|
||||
ScreenTextEntry::makeHighPriority("TEST_1", T("Test String"), 5000));
|
||||
|
||||
BOOST_REQUIRE(st.getText<ScreenTextType::Big>().size() == 1);
|
||||
BOOST_CHECK_EQUAL(T("Test String"), st.getText<ScreenTextType::Big>()[0].text);
|
||||
BOOST_CHECK_EQUAL(5000, st.getText<ScreenTextType::Big>()[0].durationMS);
|
||||
BOOST_CHECK_EQUAL(0, st.getText<ScreenTextType::Big>()[0].displayedMS);
|
||||
BOOST_REQUIRE(st.getText<ScreenTextType::Big>().size() == 1);
|
||||
BOOST_CHECK_EQUAL(T("Test String"),
|
||||
st.getText<ScreenTextType::Big>()[0].text);
|
||||
BOOST_CHECK_EQUAL(5000, st.getText<ScreenTextType::Big>()[0].durationMS);
|
||||
BOOST_CHECK_EQUAL(0, st.getText<ScreenTextType::Big>()[0].displayedMS);
|
||||
|
||||
BOOST_CHECK_EQUAL(1, st.getText<ScreenTextType::HighPriority>().size());
|
||||
BOOST_CHECK_EQUAL(1, st.getText<ScreenTextType::HighPriority>().size());
|
||||
|
||||
st.tick(6.f);
|
||||
st.tick(6.f);
|
||||
|
||||
BOOST_CHECK_EQUAL(0, st.getText<ScreenTextType::Big>().size());
|
||||
BOOST_CHECK_EQUAL(0, st.getText<ScreenTextType::HighPriority>().size());
|
||||
BOOST_CHECK_EQUAL(0, st.getText<ScreenTextType::Big>().size());
|
||||
BOOST_CHECK_EQUAL(0, st.getText<ScreenTextType::HighPriority>().size());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(clear_test)
|
||||
{
|
||||
ScreenText st;
|
||||
BOOST_AUTO_TEST_CASE(clear_test) {
|
||||
ScreenText st;
|
||||
|
||||
st.addText<ScreenTextType::Big>(
|
||||
ScreenTextEntry::makeBig(
|
||||
"TEST_1",
|
||||
T("Test String"),
|
||||
2,
|
||||
5000));
|
||||
st.addText<ScreenTextType::Big>(
|
||||
ScreenTextEntry::makeBig("TEST_1", T("Test String"), 2, 5000));
|
||||
|
||||
BOOST_CHECK_EQUAL(1, st.getText<ScreenTextType::Big>().size());
|
||||
BOOST_CHECK_EQUAL(1, st.getText<ScreenTextType::Big>().size());
|
||||
|
||||
st.clear<ScreenTextType::Big>();
|
||||
st.clear<ScreenTextType::Big>();
|
||||
|
||||
BOOST_CHECK_EQUAL(0, st.getText<ScreenTextType::Big>().size());
|
||||
BOOST_CHECK_EQUAL(0, st.getText<ScreenTextType::Big>().size());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(format_test)
|
||||
{
|
||||
// Test formating of string codes into strings.
|
||||
const auto codeStr1 = T("Hello ~1~ world");
|
||||
const auto codeStr2 = T("~1~Hello ~1~ world~1~");
|
||||
const auto codeStr3 = T("Hello world~1~");
|
||||
BOOST_AUTO_TEST_CASE(format_test) {
|
||||
// Test formating of string codes into strings.
|
||||
const auto codeStr1 = T("Hello ~1~ world");
|
||||
const auto codeStr2 = T("~1~Hello ~1~ world~1~");
|
||||
const auto codeStr3 = T("Hello world~1~");
|
||||
|
||||
auto f1 = ScreenText::format(codeStr1, T("r"));
|
||||
BOOST_CHECK_EQUAL(f1, T("Hello r world"));
|
||||
auto f1 = ScreenText::format(codeStr1, T("r"));
|
||||
BOOST_CHECK_EQUAL(f1, T("Hello r world"));
|
||||
|
||||
auto f2 = ScreenText::format(codeStr2, T("k"), T("h"));
|
||||
BOOST_CHECK_EQUAL(f2, T("kHello h world~1~"));
|
||||
auto f2 = ScreenText::format(codeStr2, T("k"), T("h"));
|
||||
BOOST_CHECK_EQUAL(f2, T("kHello h world~1~"));
|
||||
|
||||
auto f3 = ScreenText::format(codeStr3, T("x"));
|
||||
BOOST_CHECK_EQUAL(f3, T("Hello worldx"));
|
||||
auto f3 = ScreenText::format(codeStr3, T("x"));
|
||||
BOOST_CHECK_EQUAL(f3, T("Hello worldx"));
|
||||
|
||||
auto f4 = ScreenText::format(codeStr3, T("x"), T("k"));
|
||||
BOOST_CHECK_EQUAL(f4, T("Hello worldx"));
|
||||
auto f4 = ScreenText::format(codeStr3, T("x"), T("k"));
|
||||
BOOST_CHECK_EQUAL(f4, T("Hello worldx"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(format_remove)
|
||||
{
|
||||
// Test removing an identified string from the list
|
||||
ScreenText st;
|
||||
BOOST_AUTO_TEST_CASE(format_remove) {
|
||||
// Test removing an identified string from the list
|
||||
ScreenText st;
|
||||
|
||||
st.addText<ScreenTextType::Big>(
|
||||
ScreenTextEntry::makeBig(
|
||||
"TEST_2",
|
||||
T("Test String"),
|
||||
2,
|
||||
5000));
|
||||
st.addText<ScreenTextType::Big>(
|
||||
ScreenTextEntry::makeBig("TEST_2", T("Test String"), 2, 5000));
|
||||
|
||||
st.addText<ScreenTextType::Big>(
|
||||
ScreenTextEntry::makeBig(
|
||||
"TEST_1",
|
||||
T("Test String"),
|
||||
2,
|
||||
5000));
|
||||
st.addText<ScreenTextType::Big>(
|
||||
ScreenTextEntry::makeBig("TEST_1", T("Test String"), 2, 5000));
|
||||
|
||||
st.addText<ScreenTextType::Big>(
|
||||
ScreenTextEntry::makeBig(
|
||||
"TEST_1",
|
||||
T("Test String"),
|
||||
2,
|
||||
5000));
|
||||
st.addText<ScreenTextType::Big>(
|
||||
ScreenTextEntry::makeBig("TEST_1", T("Test String"), 2, 5000));
|
||||
|
||||
BOOST_CHECK_EQUAL(3, st.getText<ScreenTextType::Big>().size());
|
||||
BOOST_CHECK_EQUAL(3, st.getText<ScreenTextType::Big>().size());
|
||||
|
||||
st.remove<ScreenTextType::Big>("TEST_1");
|
||||
st.remove<ScreenTextType::Big>("TEST_1");
|
||||
|
||||
BOOST_CHECK_EQUAL(1, st.getText<ScreenTextType::Big>().size());
|
||||
BOOST_CHECK_EQUAL(1, st.getText<ScreenTextType::Big>().size());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,222 +1,168 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
#include <ai/TrafficDirector.hpp>
|
||||
#include <ai/AIGraph.hpp>
|
||||
#include <objects/InstanceObject.hpp>
|
||||
#include <ai/TrafficDirector.hpp>
|
||||
#include <objects/CharacterObject.hpp>
|
||||
#include <objects/InstanceObject.hpp>
|
||||
#include <render/ViewCamera.hpp>
|
||||
|
||||
bool operator!=(const AIGraphNode* lhs, const glm::vec3 &rhs) { return lhs->position != rhs; }
|
||||
std::ostream &operator<<(std::ostream &os, const AIGraphNode* yt) { os << glm::to_string(yt->position); return os; }
|
||||
bool operator!=(const AIGraphNode* lhs, const glm::vec3& rhs) {
|
||||
return lhs->position != rhs;
|
||||
}
|
||||
std::ostream& operator<<(std::ostream& os, const AIGraphNode* yt) {
|
||||
os << glm::to_string(yt->position);
|
||||
return os;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(TrafficDirectorTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_available_nodes)
|
||||
{
|
||||
AIGraph graph;
|
||||
|
||||
PathData path {
|
||||
PathData::PATH_PED,
|
||||
0, "",
|
||||
{
|
||||
{
|
||||
PathNode::EXTERNAL,
|
||||
1,
|
||||
{ 10.f, 10.f, 0.f },
|
||||
1.f, 0, 0
|
||||
},
|
||||
{
|
||||
PathNode::EXTERNAL,
|
||||
2,
|
||||
{ 10.f, 0.f, 0.f },
|
||||
1.f, 0, 0
|
||||
},
|
||||
{
|
||||
PathNode::EXTERNAL,
|
||||
3,
|
||||
{ 10.f,-10.f, 0.f },
|
||||
1.f, 0, 0
|
||||
},
|
||||
{
|
||||
PathNode::EXTERNAL,
|
||||
4,
|
||||
{ 0.f,-10.f, 0.f },
|
||||
1.f, 0, 0
|
||||
},
|
||||
{
|
||||
PathNode::EXTERNAL,
|
||||
5,
|
||||
{-10.f,-10.f, 0.f },
|
||||
1.f, 0, 0
|
||||
},
|
||||
{
|
||||
PathNode::EXTERNAL,
|
||||
6,
|
||||
{-10.f, 0.f, 0.f },
|
||||
1.f, 0, 0
|
||||
},
|
||||
{
|
||||
PathNode::EXTERNAL,
|
||||
-1,
|
||||
{-10.f, 10.f, 0.f },
|
||||
1.f, 0, 0
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
graph.createPathNodes(glm::vec3(), glm::quat(), path);
|
||||
|
||||
TrafficDirector director(&graph, Global::get().e);
|
||||
BOOST_AUTO_TEST_CASE(test_available_nodes) {
|
||||
AIGraph graph;
|
||||
|
||||
ViewCamera testCamera(glm::vec3(-5.f, -5.f, 0.f));
|
||||
|
||||
auto open = director.findAvailableNodes(AIGraphNode::Pedestrian, testCamera, 10.f);
|
||||
|
||||
std::vector<glm::vec3> expected {
|
||||
{ 0.f,-10.f, 0.f },
|
||||
{-10.f,-10.f, 0.f },
|
||||
{-10.f, 0.f, 0.f }
|
||||
};
|
||||
|
||||
BOOST_REQUIRE(expected.size() == 3);
|
||||
BOOST_ASSERT( expected.size() == open.size() );
|
||||
|
||||
for (auto& v : expected) {
|
||||
BOOST_CHECK(std::find_if(open.begin(), open.end(),
|
||||
[v](AIGraphNode* n) { return n->position == v; }) != open.end());
|
||||
}
|
||||
PathData path{PathData::PATH_PED,
|
||||
0,
|
||||
"",
|
||||
{
|
||||
{PathNode::EXTERNAL, 1, {10.f, 10.f, 0.f}, 1.f, 0, 0},
|
||||
{PathNode::EXTERNAL, 2, {10.f, 0.f, 0.f}, 1.f, 0, 0},
|
||||
{PathNode::EXTERNAL, 3, {10.f, -10.f, 0.f}, 1.f, 0, 0},
|
||||
{PathNode::EXTERNAL, 4, {0.f, -10.f, 0.f}, 1.f, 0, 0},
|
||||
{PathNode::EXTERNAL, 5, {-10.f, -10.f, 0.f}, 1.f, 0, 0},
|
||||
{PathNode::EXTERNAL, 6, {-10.f, 0.f, 0.f}, 1.f, 0, 0},
|
||||
{PathNode::EXTERNAL, -1, {-10.f, 10.f, 0.f}, 1.f, 0, 0},
|
||||
}};
|
||||
|
||||
graph.createPathNodes(glm::vec3(), glm::quat(), path);
|
||||
|
||||
TrafficDirector director(&graph, Global::get().e);
|
||||
|
||||
ViewCamera testCamera(glm::vec3(-5.f, -5.f, 0.f));
|
||||
|
||||
auto open =
|
||||
director.findAvailableNodes(AIGraphNode::Pedestrian, testCamera, 10.f);
|
||||
|
||||
std::vector<glm::vec3> expected{
|
||||
{0.f, -10.f, 0.f}, {-10.f, -10.f, 0.f}, {-10.f, 0.f, 0.f}};
|
||||
|
||||
BOOST_REQUIRE(expected.size() == 3);
|
||||
BOOST_ASSERT(expected.size() == open.size());
|
||||
|
||||
for (auto& v : expected) {
|
||||
BOOST_CHECK(std::find_if(open.begin(), open.end(), [v](AIGraphNode* n) {
|
||||
return n->position == v;
|
||||
}) != open.end());
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_node_not_blocking)
|
||||
{
|
||||
AIGraph graph;
|
||||
|
||||
PathData path {
|
||||
PathData::PATH_PED,
|
||||
0, "",
|
||||
{
|
||||
{
|
||||
PathNode::EXTERNAL,
|
||||
1,
|
||||
{ 10.f, 10.f, 0.f },
|
||||
1.f, 0, 0
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
graph.createPathNodes(glm::vec3(), glm::quat(), path);
|
||||
|
||||
TrafficDirector director(&graph, Global::get().e);
|
||||
|
||||
// Create something that isn't a pedestrian
|
||||
InstanceObject* box = Global::get().e->createInstance(1337, glm::vec3(10.f, 10.f, 0.f));
|
||||
|
||||
{
|
||||
auto open = director.findAvailableNodes(AIGraphNode::Pedestrian, glm::vec3( 5.f, 5.f, 0.f), 10.f);
|
||||
BOOST_CHECK( open.size() == 1 );
|
||||
}
|
||||
|
||||
Global::get().e->destroyObject(box);
|
||||
BOOST_AUTO_TEST_CASE(test_node_not_blocking) {
|
||||
AIGraph graph;
|
||||
|
||||
PathData path{PathData::PATH_PED,
|
||||
0,
|
||||
"",
|
||||
{
|
||||
{PathNode::EXTERNAL, 1, {10.f, 10.f, 0.f}, 1.f, 0, 0},
|
||||
}};
|
||||
|
||||
graph.createPathNodes(glm::vec3(), glm::quat(), path);
|
||||
|
||||
TrafficDirector director(&graph, Global::get().e);
|
||||
|
||||
// Create something that isn't a pedestrian
|
||||
InstanceObject* box =
|
||||
Global::get().e->createInstance(1337, glm::vec3(10.f, 10.f, 0.f));
|
||||
|
||||
{
|
||||
auto open = director.findAvailableNodes(AIGraphNode::Pedestrian,
|
||||
glm::vec3(5.f, 5.f, 0.f), 10.f);
|
||||
BOOST_CHECK(open.size() == 1);
|
||||
}
|
||||
|
||||
Global::get().e->destroyObject(box);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_node_blocking)
|
||||
{
|
||||
AIGraph graph;
|
||||
|
||||
PathData path {
|
||||
PathData::PATH_PED,
|
||||
0, "",
|
||||
{
|
||||
{
|
||||
PathNode::EXTERNAL,
|
||||
1,
|
||||
{ 10.f, 10.f, 0.f },
|
||||
1.f, 0, 0
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
graph.createPathNodes(glm::vec3(), glm::quat(), path);
|
||||
|
||||
TrafficDirector director(&graph, Global::get().e);
|
||||
|
||||
// create something that should block the spawn point
|
||||
CharacterObject* ped = Global::get().e->createPedestrian(1, glm::vec3(10.f, 10.f, 0.f));
|
||||
|
||||
{
|
||||
auto open = director.findAvailableNodes(AIGraphNode::Pedestrian, glm::vec3( 5.f, 5.f, 0.f), 10.f);
|
||||
BOOST_CHECK( open.size() == 0 );
|
||||
}
|
||||
|
||||
Global::get().e->destroyObject(ped);
|
||||
BOOST_AUTO_TEST_CASE(test_node_blocking) {
|
||||
AIGraph graph;
|
||||
|
||||
PathData path{PathData::PATH_PED,
|
||||
0,
|
||||
"",
|
||||
{
|
||||
{PathNode::EXTERNAL, 1, {10.f, 10.f, 0.f}, 1.f, 0, 0},
|
||||
}};
|
||||
|
||||
graph.createPathNodes(glm::vec3(), glm::quat(), path);
|
||||
|
||||
TrafficDirector director(&graph, Global::get().e);
|
||||
|
||||
// create something that should block the spawn point
|
||||
CharacterObject* ped =
|
||||
Global::get().e->createPedestrian(1, glm::vec3(10.f, 10.f, 0.f));
|
||||
|
||||
{
|
||||
auto open = director.findAvailableNodes(AIGraphNode::Pedestrian,
|
||||
glm::vec3(5.f, 5.f, 0.f), 10.f);
|
||||
BOOST_CHECK(open.size() == 0);
|
||||
}
|
||||
|
||||
Global::get().e->destroyObject(ped);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_node_density)
|
||||
{
|
||||
AIGraph graph;
|
||||
|
||||
PathData path {
|
||||
PathData::PATH_PED,
|
||||
0, "",
|
||||
{
|
||||
{
|
||||
PathNode::EXTERNAL,
|
||||
1,
|
||||
{ 10.f, 10.f, 0.f },
|
||||
1.f, 0, 0
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
graph.createPathNodes(glm::vec3(), glm::quat(), path);
|
||||
|
||||
TrafficDirector director(&graph, Global::get().e);
|
||||
|
||||
CharacterObject* ped = Global::get().e->createPedestrian(1, glm::vec3(5.f, 5.f, 0.f));
|
||||
|
||||
{
|
||||
director.setDensity(AIGraphNode::Pedestrian, 1.f);
|
||||
auto open = director.findAvailableNodes(AIGraphNode::Pedestrian, glm::vec3( 5.f, 5.f, 0.f), 10.f);
|
||||
BOOST_CHECK( open.size() == 0 );
|
||||
}
|
||||
|
||||
{
|
||||
director.setDensity(AIGraphNode::Pedestrian, 2.f);
|
||||
auto open = director.findAvailableNodes(AIGraphNode::Pedestrian, glm::vec3( 5.f, 5.f, 0.f), 10.f);
|
||||
BOOST_CHECK( open.size() == 1 );
|
||||
}
|
||||
|
||||
Global::get().e->destroyObject(ped);
|
||||
BOOST_AUTO_TEST_CASE(test_node_density) {
|
||||
AIGraph graph;
|
||||
|
||||
PathData path{PathData::PATH_PED,
|
||||
0,
|
||||
"",
|
||||
{
|
||||
{PathNode::EXTERNAL, 1, {10.f, 10.f, 0.f}, 1.f, 0, 0},
|
||||
}};
|
||||
|
||||
graph.createPathNodes(glm::vec3(), glm::quat(), path);
|
||||
|
||||
TrafficDirector director(&graph, Global::get().e);
|
||||
|
||||
CharacterObject* ped =
|
||||
Global::get().e->createPedestrian(1, glm::vec3(5.f, 5.f, 0.f));
|
||||
|
||||
{
|
||||
director.setDensity(AIGraphNode::Pedestrian, 1.f);
|
||||
auto open = director.findAvailableNodes(AIGraphNode::Pedestrian,
|
||||
glm::vec3(5.f, 5.f, 0.f), 10.f);
|
||||
BOOST_CHECK(open.size() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
director.setDensity(AIGraphNode::Pedestrian, 2.f);
|
||||
auto open = director.findAvailableNodes(AIGraphNode::Pedestrian,
|
||||
glm::vec3(5.f, 5.f, 0.f), 10.f);
|
||||
BOOST_CHECK(open.size() == 1);
|
||||
}
|
||||
|
||||
Global::get().e->destroyObject(ped);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_create_traffic)
|
||||
{
|
||||
AIGraph graph;
|
||||
|
||||
PathData path {
|
||||
PathData::PATH_PED,
|
||||
0, "",
|
||||
{
|
||||
{
|
||||
PathNode::EXTERNAL,
|
||||
1,
|
||||
{ 10.f, 10.f, 0.f },
|
||||
1.f, 0, 0
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
graph.createPathNodes(glm::vec3(), glm::quat(), path);
|
||||
|
||||
TrafficDirector director(&graph, Global::get().e);
|
||||
|
||||
auto created = director.populateNearby(glm::vec3(0.f, 0.f, 0.f), 20.f);
|
||||
|
||||
BOOST_CHECK( created.size() == 1 );
|
||||
|
||||
//Global::get().e->destroyObject(created[0]);
|
||||
BOOST_AUTO_TEST_CASE(test_create_traffic) {
|
||||
AIGraph graph;
|
||||
|
||||
PathData path{PathData::PATH_PED,
|
||||
0,
|
||||
"",
|
||||
{
|
||||
{PathNode::EXTERNAL, 1, {10.f, 10.f, 0.f}, 1.f, 0, 0},
|
||||
}};
|
||||
|
||||
graph.createPathNodes(glm::vec3(), glm::quat(), path);
|
||||
|
||||
TrafficDirector director(&graph, Global::get().e);
|
||||
|
||||
auto created = director.populateNearby(glm::vec3(0.f, 0.f, 0.f), 20.f);
|
||||
|
||||
BOOST_CHECK(created.size() == 1);
|
||||
|
||||
// Global::get().e->destroyObject(created[0]);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,135 +1,133 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <objects/VehicleObject.hpp>
|
||||
#include <data/Model.hpp>
|
||||
#include <data/Skeleton.hpp>
|
||||
#include <objects/VehicleObject.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(VehicleTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(test_create_vehicle)
|
||||
{
|
||||
VehicleObject* vehicle = Global::get().e->createVehicle(90u, glm::vec3(), glm::quat());
|
||||
BOOST_AUTO_TEST_CASE(test_create_vehicle) {
|
||||
VehicleObject* vehicle =
|
||||
Global::get().e->createVehicle(90u, glm::vec3(), glm::quat());
|
||||
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
|
||||
BOOST_REQUIRE(vehicle->info != nullptr);
|
||||
BOOST_REQUIRE(vehicle->vehicle != nullptr);
|
||||
BOOST_REQUIRE(vehicle->info != nullptr);
|
||||
BOOST_REQUIRE(vehicle->vehicle != nullptr);
|
||||
|
||||
// Hardcoded values for the moment
|
||||
BOOST_CHECK_EQUAL(vehicle->vehicle->type, VehicleData::CAR);
|
||||
// Hardcoded values for the moment
|
||||
BOOST_CHECK_EQUAL(vehicle->vehicle->type, VehicleData::CAR);
|
||||
|
||||
BOOST_CHECK_EQUAL(vehicle->info->wheels.size(), 4);
|
||||
BOOST_CHECK_EQUAL(vehicle->info->wheels.size(), 4);
|
||||
|
||||
BOOST_CHECK_EQUAL(vehicle->info->seats.size(), 4);
|
||||
BOOST_CHECK_EQUAL(vehicle->info->seats.size(), 4);
|
||||
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(vehicle_parts)
|
||||
{
|
||||
VehicleObject* vehicle = Global::get().e->createVehicle(90u, glm::vec3(), glm::quat());
|
||||
BOOST_AUTO_TEST_CASE(vehicle_parts) {
|
||||
VehicleObject* vehicle =
|
||||
Global::get().e->createVehicle(90u, glm::vec3(), glm::quat());
|
||||
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
BOOST_REQUIRE(vehicle->model != nullptr);
|
||||
|
||||
VehicleObject::Part* part = vehicle->getPart("bonnet_dummy");
|
||||
|
||||
BOOST_REQUIRE( part != nullptr );
|
||||
|
||||
BOOST_REQUIRE( part->normal != nullptr );
|
||||
BOOST_REQUIRE( part->damaged != nullptr );
|
||||
|
||||
BOOST_CHECK_EQUAL( part->normal->getName(), "bonnet_hi_ok");
|
||||
BOOST_CHECK_EQUAL( part->damaged->getName(), "bonnet_hi_dam");
|
||||
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
BOOST_REQUIRE(vehicle->model != nullptr);
|
||||
|
||||
VehicleObject::Part* part = vehicle->getPart("bonnet_dummy");
|
||||
|
||||
BOOST_REQUIRE(part != nullptr);
|
||||
|
||||
BOOST_REQUIRE(part->normal != nullptr);
|
||||
BOOST_REQUIRE(part->damaged != nullptr);
|
||||
|
||||
BOOST_CHECK_EQUAL(part->normal->getName(), "bonnet_hi_ok");
|
||||
BOOST_CHECK_EQUAL(part->damaged->getName(), "bonnet_hi_dam");
|
||||
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(vehicle_part_vis)
|
||||
{
|
||||
VehicleObject* vehicle = Global::get().e->createVehicle(90u, glm::vec3(), glm::quat());
|
||||
BOOST_AUTO_TEST_CASE(vehicle_part_vis) {
|
||||
VehicleObject* vehicle =
|
||||
Global::get().e->createVehicle(90u, glm::vec3(), glm::quat());
|
||||
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
BOOST_REQUIRE(vehicle->model != nullptr);
|
||||
|
||||
VehicleObject::Part* bonnetpart = vehicle->getPart("bonnet_dummy");
|
||||
auto skel = vehicle->skeleton;
|
||||
|
||||
vehicle->setPartState(bonnetpart, VehicleObject::DAM);
|
||||
|
||||
BOOST_CHECK(!skel->getData(bonnetpart->normal->getIndex()).enabled );
|
||||
BOOST_CHECK( skel->getData(bonnetpart->damaged->getIndex()).enabled );
|
||||
|
||||
vehicle->setPartState(bonnetpart, VehicleObject::OK);
|
||||
|
||||
BOOST_CHECK( skel->getData(bonnetpart->normal->getIndex()).enabled );
|
||||
BOOST_CHECK(!skel->getData(bonnetpart->damaged->getIndex()).enabled );
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
BOOST_REQUIRE(vehicle->model != nullptr);
|
||||
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
VehicleObject::Part* bonnetpart = vehicle->getPart("bonnet_dummy");
|
||||
auto skel = vehicle->skeleton;
|
||||
|
||||
vehicle->setPartState(bonnetpart, VehicleObject::DAM);
|
||||
|
||||
BOOST_CHECK(!skel->getData(bonnetpart->normal->getIndex()).enabled);
|
||||
BOOST_CHECK(skel->getData(bonnetpart->damaged->getIndex()).enabled);
|
||||
|
||||
vehicle->setPartState(bonnetpart, VehicleObject::OK);
|
||||
|
||||
BOOST_CHECK(skel->getData(bonnetpart->normal->getIndex()).enabled);
|
||||
BOOST_CHECK(!skel->getData(bonnetpart->damaged->getIndex()).enabled);
|
||||
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_door_position)
|
||||
{
|
||||
VehicleObject* vehicle = Global::get().e->createVehicle(90u, glm::vec3(10.f, 0.f, 0.f), glm::quat());
|
||||
BOOST_AUTO_TEST_CASE(test_door_position) {
|
||||
VehicleObject* vehicle = Global::get().e->createVehicle(
|
||||
90u, glm::vec3(10.f, 0.f, 0.f), glm::quat());
|
||||
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
|
||||
BOOST_REQUIRE(vehicle->info != nullptr);
|
||||
BOOST_REQUIRE(vehicle->vehicle != nullptr);
|
||||
BOOST_REQUIRE(vehicle->info != nullptr);
|
||||
BOOST_REQUIRE(vehicle->vehicle != nullptr);
|
||||
|
||||
BOOST_CHECK( vehicle->getSeatEntryPositionWorld(0).x > 5.f );
|
||||
BOOST_CHECK(vehicle->getSeatEntryPositionWorld(0).x > 5.f);
|
||||
|
||||
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_hinges)
|
||||
{
|
||||
VehicleObject* vehicle = Global::get().e->createVehicle(90u, glm::vec3(10.f, 0.f, 0.f), glm::quat());
|
||||
|
||||
BOOST_REQUIRE( vehicle != nullptr );
|
||||
BOOST_AUTO_TEST_CASE(test_hinges) {
|
||||
VehicleObject* vehicle = Global::get().e->createVehicle(
|
||||
90u, glm::vec3(10.f, 0.f, 0.f), glm::quat());
|
||||
|
||||
VehicleObject::Part* part = vehicle->getPart("door_lf_dummy");
|
||||
|
||||
BOOST_REQUIRE( part != nullptr );
|
||||
|
||||
BOOST_CHECK_EQUAL( part->constraint, nullptr );
|
||||
BOOST_CHECK_EQUAL( part->body, nullptr );
|
||||
|
||||
vehicle->setPartLocked(part, false);
|
||||
|
||||
BOOST_CHECK_NE( part->body, nullptr );
|
||||
BOOST_CHECK_NE( part->constraint, nullptr );
|
||||
|
||||
vehicle->setPartLocked(part, true);
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
|
||||
BOOST_CHECK_EQUAL( part->constraint, nullptr );
|
||||
BOOST_CHECK_EQUAL( part->body, nullptr );
|
||||
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
VehicleObject::Part* part = vehicle->getPart("door_lf_dummy");
|
||||
|
||||
BOOST_REQUIRE(part != nullptr);
|
||||
|
||||
BOOST_CHECK_EQUAL(part->constraint, nullptr);
|
||||
BOOST_CHECK_EQUAL(part->body, nullptr);
|
||||
|
||||
vehicle->setPartLocked(part, false);
|
||||
|
||||
BOOST_CHECK_NE(part->body, nullptr);
|
||||
BOOST_CHECK_NE(part->constraint, nullptr);
|
||||
|
||||
vehicle->setPartLocked(part, true);
|
||||
|
||||
BOOST_CHECK_EQUAL(part->constraint, nullptr);
|
||||
BOOST_CHECK_EQUAL(part->body, nullptr);
|
||||
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_open_part)
|
||||
{
|
||||
VehicleObject* vehicle = Global::get().e->createVehicle(90u, glm::vec3(10.f, 0.f, 0.f), glm::quat());
|
||||
|
||||
BOOST_REQUIRE( vehicle != nullptr );
|
||||
BOOST_AUTO_TEST_CASE(test_open_part) {
|
||||
VehicleObject* vehicle = Global::get().e->createVehicle(
|
||||
90u, glm::vec3(10.f, 0.f, 0.f), glm::quat());
|
||||
|
||||
VehicleObject::Part* part = vehicle->getPart("door_lf_dummy");
|
||||
|
||||
BOOST_REQUIRE( part != nullptr );
|
||||
|
||||
BOOST_CHECK_EQUAL( part->body, nullptr );
|
||||
|
||||
vehicle->setPartLocked(part, true);
|
||||
vehicle->setPartTarget(part, true, 1.f);
|
||||
|
||||
/// @todo a reasonable test
|
||||
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
BOOST_REQUIRE(vehicle != nullptr);
|
||||
|
||||
VehicleObject::Part* part = vehicle->getPart("door_lf_dummy");
|
||||
|
||||
BOOST_REQUIRE(part != nullptr);
|
||||
|
||||
BOOST_CHECK_EQUAL(part->body, nullptr);
|
||||
|
||||
vehicle->setPartLocked(part, true);
|
||||
vehicle->setPartTarget(part, true, 1.f);
|
||||
|
||||
/// @todo a reasonable test
|
||||
|
||||
Global::get().e->destroyObject(vehicle);
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
@ -1,130 +1,117 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "test_globals.hpp"
|
||||
#include <objects/CharacterObject.hpp>
|
||||
#include <data/WeaponData.hpp>
|
||||
#include <objects/CharacterObject.hpp>
|
||||
#include <objects/ProjectileObject.hpp>
|
||||
#include "test_globals.hpp"
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(WeaponTests)
|
||||
|
||||
#if RW_TEST_WITH_DATA
|
||||
BOOST_AUTO_TEST_CASE(TestWeaponScan)
|
||||
{
|
||||
{
|
||||
// Test RADIUS scan
|
||||
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 0.f});
|
||||
BOOST_REQUIRE( character != nullptr );
|
||||
BOOST_REQUIRE( character->model != nullptr);
|
||||
BOOST_REQUIRE( character->physObject != nullptr);
|
||||
BOOST_AUTO_TEST_CASE(TestWeaponScan) {
|
||||
{
|
||||
// Test RADIUS scan
|
||||
auto character = Global::get().e->createPedestrian(1, {0.f, 0.f, 0.f});
|
||||
BOOST_REQUIRE(character != nullptr);
|
||||
BOOST_REQUIRE(character->model != nullptr);
|
||||
BOOST_REQUIRE(character->physObject != nullptr);
|
||||
|
||||
WeaponScan scan( 10.f, {0.f, 0.f, 10.f}, {0.f,0.f, -10.f} );
|
||||
WeaponScan scan(10.f, {0.f, 0.f, 10.f}, {0.f, 0.f, -10.f});
|
||||
|
||||
Global::get().e->doWeaponScan( scan );
|
||||
Global::get().e->doWeaponScan(scan);
|
||||
|
||||
BOOST_CHECK( character->getCurrentState().health < 100.f );
|
||||
BOOST_CHECK(character->getCurrentState().health < 100.f);
|
||||
|
||||
Global::get().e->destroyObject(character);
|
||||
}
|
||||
Global::get().e->destroyObject(character);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TestProjectile)
|
||||
{
|
||||
{
|
||||
auto character = Global::get().e->createPedestrian(1, {25.f, 0.f, 0.f});
|
||||
BOOST_REQUIRE( character != nullptr );
|
||||
BOOST_AUTO_TEST_CASE(TestProjectile) {
|
||||
{
|
||||
auto character = Global::get().e->createPedestrian(1, {25.f, 0.f, 0.f});
|
||||
BOOST_REQUIRE(character != nullptr);
|
||||
|
||||
auto wepdata = Global::get().e->data->weaponData[5];
|
||||
auto wepdata = Global::get().e->data->weaponData[5];
|
||||
|
||||
auto projectile = new ProjectileObject(Global::get().e, {26.f, 1.f, 10.f},
|
||||
{
|
||||
ProjectileObject::Grenade,
|
||||
{0.f, 0.f, -1.f},
|
||||
2.0f,
|
||||
5.0f,
|
||||
wepdata
|
||||
});
|
||||
auto projectile = new ProjectileObject(
|
||||
Global::get().e, {26.f, 1.f, 10.f},
|
||||
{ProjectileObject::Grenade, {0.f, 0.f, -1.f}, 2.0f, 5.0f, wepdata});
|
||||
|
||||
Global::get().e->allObjects.push_back( projectile );
|
||||
Global::get().e->allObjects.push_back(projectile);
|
||||
|
||||
BOOST_CHECK( character->getCurrentState().health == 100.f );
|
||||
BOOST_CHECK(character->getCurrentState().health == 100.f);
|
||||
|
||||
for(float t = 0.f; t <= 5.f; t += 0.016f) {
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f, 0, 0);
|
||||
projectile->tick(0.016f);
|
||||
}
|
||||
for (float t = 0.f; t <= 5.f; t += 0.016f) {
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f, 0, 0);
|
||||
projectile->tick(0.016f);
|
||||
}
|
||||
|
||||
BOOST_CHECK_LT( glm::distance(character->getPosition(), projectile->getPosition()), 10.f );
|
||||
BOOST_CHECK_LT( glm::distance(character->getPosition(), projectile->getPosition()), 5.f );
|
||||
BOOST_CHECK_LT(
|
||||
glm::distance(character->getPosition(), projectile->getPosition()),
|
||||
10.f);
|
||||
BOOST_CHECK_LT(
|
||||
glm::distance(character->getPosition(), projectile->getPosition()),
|
||||
5.f);
|
||||
|
||||
// Grenade should have dentonated by this point
|
||||
BOOST_CHECK( character->getCurrentState().health < 100.f );
|
||||
// Grenade should have dentonated by this point
|
||||
BOOST_CHECK(character->getCurrentState().health < 100.f);
|
||||
|
||||
Global::get().e->destroyObjectQueued(character);
|
||||
Global::get().e->destroyQueuedObjects();
|
||||
}
|
||||
Global::get().e->destroyObjectQueued(character);
|
||||
Global::get().e->destroyQueuedObjects();
|
||||
}
|
||||
|
||||
{
|
||||
auto character = Global::get().e->createPedestrian(1, {25.f, 0.f, 0.f});
|
||||
BOOST_REQUIRE( character != nullptr );
|
||||
{
|
||||
auto character = Global::get().e->createPedestrian(1, {25.f, 0.f, 0.f});
|
||||
BOOST_REQUIRE(character != nullptr);
|
||||
|
||||
auto wepdata = Global::get().e->data->weaponData[6];
|
||||
auto wepdata = Global::get().e->data->weaponData[6];
|
||||
|
||||
auto projectile = new ProjectileObject(Global::get().e, {26.f, 1.f, 10.f},
|
||||
{
|
||||
ProjectileObject::Molotov,
|
||||
{0.f, 0.f, -1.f},
|
||||
2.0f,
|
||||
10.f,
|
||||
wepdata
|
||||
});
|
||||
auto projectile = new ProjectileObject(
|
||||
Global::get().e, {26.f, 1.f, 10.f},
|
||||
{ProjectileObject::Molotov, {0.f, 0.f, -1.f}, 2.0f, 10.f, wepdata});
|
||||
|
||||
Global::get().e->allObjects.push_back( projectile );
|
||||
Global::get().e->allObjects.push_back(projectile);
|
||||
|
||||
BOOST_CHECK( character->getCurrentState().health == 100.f );
|
||||
BOOST_CHECK(character->getCurrentState().health == 100.f);
|
||||
|
||||
for(float t = 0.f; t <= 9.0f; t += 0.016f) {
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f, 0, 0);
|
||||
projectile->tick(0.016f);
|
||||
}
|
||||
for (float t = 0.f; t <= 9.0f; t += 0.016f) {
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f, 0, 0);
|
||||
projectile->tick(0.016f);
|
||||
}
|
||||
|
||||
BOOST_CHECK( projectile->getPosition().z < 10.f );
|
||||
BOOST_CHECK( projectile->getPosition().z > 0.f );
|
||||
BOOST_CHECK(projectile->getPosition().z < 10.f);
|
||||
BOOST_CHECK(projectile->getPosition().z > 0.f);
|
||||
|
||||
BOOST_CHECK( character->getCurrentState().health < 100.f );
|
||||
BOOST_CHECK(character->getCurrentState().health < 100.f);
|
||||
|
||||
Global::get().e->destroyObjectQueued(character);
|
||||
Global::get().e->destroyQueuedObjects();
|
||||
}
|
||||
{
|
||||
auto character = Global::get().e->createPedestrian(1, {25.f, 0.f, 0.f});
|
||||
BOOST_REQUIRE( character != nullptr );
|
||||
Global::get().e->destroyObjectQueued(character);
|
||||
Global::get().e->destroyQueuedObjects();
|
||||
}
|
||||
{
|
||||
auto character = Global::get().e->createPedestrian(1, {25.f, 0.f, 0.f});
|
||||
BOOST_REQUIRE(character != nullptr);
|
||||
|
||||
auto wepdata = Global::get().e->data->weaponData[7];
|
||||
auto wepdata = Global::get().e->data->weaponData[7];
|
||||
|
||||
auto projectile = new ProjectileObject(Global::get().e, {26.f, 1.f, 10.f},
|
||||
{
|
||||
ProjectileObject::RPG,
|
||||
{0.f, 0.f, -1.f},
|
||||
2.0f,
|
||||
10.f,
|
||||
wepdata
|
||||
});
|
||||
auto projectile = new ProjectileObject(
|
||||
Global::get().e, {26.f, 1.f, 10.f},
|
||||
{ProjectileObject::RPG, {0.f, 0.f, -1.f}, 2.0f, 10.f, wepdata});
|
||||
|
||||
Global::get().e->allObjects.push_back( projectile );
|
||||
Global::get().e->allObjects.push_back(projectile);
|
||||
|
||||
BOOST_CHECK( character->getCurrentState().health == 100.f );
|
||||
BOOST_CHECK(character->getCurrentState().health == 100.f);
|
||||
|
||||
for(float t = 0.f; t <= 9.f; t += 0.016f) {
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f, 0, 0);
|
||||
projectile->tick(0.016f);
|
||||
}
|
||||
for (float t = 0.f; t <= 9.f; t += 0.016f) {
|
||||
Global::get().e->dynamicsWorld->stepSimulation(0.016f, 0, 0);
|
||||
projectile->tick(0.016f);
|
||||
}
|
||||
|
||||
BOOST_CHECK( projectile->getPosition().z < 10.f );
|
||||
BOOST_CHECK(projectile->getPosition().z < 10.f);
|
||||
|
||||
BOOST_CHECK( character->getCurrentState().health < 100.f );
|
||||
BOOST_CHECK(character->getCurrentState().health < 100.f);
|
||||
|
||||
Global::get().e->destroyObjectQueued(character);
|
||||
Global::get().e->destroyQueuedObjects();
|
||||
}
|
||||
Global::get().e->destroyObjectQueued(character);
|
||||
Global::get().e->destroyQueuedObjects();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1,48 +1,49 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <job/WorkContext.hpp>
|
||||
|
||||
class TestJob : public WorkJob
|
||||
{
|
||||
class TestJob : public WorkJob {
|
||||
public:
|
||||
bool *_worked, *_completed;
|
||||
bool *_worked, *_completed;
|
||||
|
||||
TestJob( WorkContext* context, bool *w, bool *c )
|
||||
: WorkJob(context), _worked(w), _completed(c)
|
||||
{}
|
||||
TestJob(WorkContext *context, bool *w, bool *c)
|
||||
: WorkJob(context), _worked(w), _completed(c) {
|
||||
}
|
||||
|
||||
void work() { *_worked = true; }
|
||||
void work() {
|
||||
*_worked = true;
|
||||
}
|
||||
|
||||
void complete() { *_completed = true; }
|
||||
void complete() {
|
||||
*_completed = true;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(WorkTests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(test_interface)
|
||||
{
|
||||
{
|
||||
WorkContext context;
|
||||
BOOST_AUTO_TEST_CASE(test_interface) {
|
||||
{
|
||||
WorkContext context;
|
||||
|
||||
bool worked = false, completed = false;
|
||||
bool worked = false, completed = false;
|
||||
|
||||
TestJob* job = new TestJob(&context, &worked, &completed);
|
||||
TestJob *job = new TestJob(&context, &worked, &completed);
|
||||
|
||||
BOOST_CHECK( ! worked );
|
||||
BOOST_CHECK( ! completed );
|
||||
BOOST_CHECK(!worked);
|
||||
BOOST_CHECK(!completed);
|
||||
|
||||
context.queueJob(job);
|
||||
context.queueJob(job);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
|
||||
BOOST_CHECK( worked );
|
||||
BOOST_CHECK( ! completed );
|
||||
BOOST_CHECK(worked);
|
||||
BOOST_CHECK(!completed);
|
||||
|
||||
context.update();;
|
||||
context.update();
|
||||
;
|
||||
|
||||
BOOST_CHECK( worked );
|
||||
BOOST_CHECK( completed );
|
||||
}
|
||||
BOOST_CHECK(worked);
|
||||
BOOST_CHECK(completed);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
|
@ -3,9 +3,7 @@
|
||||
|
||||
BOOST_AUTO_TEST_SUITE(WorldTests)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(world_object_destroy)
|
||||
{
|
||||
|
||||
BOOST_AUTO_TEST_CASE(world_object_destroy) {
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
Loading…
Reference in New Issue
Block a user