2014-02-10 13:09:16 +01:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2017-01-03 15:18:06 +01:00
|
|
|
#include <data/Clump.hpp>
|
2017-10-26 03:51:24 +02:00
|
|
|
#include "test_Globals.hpp"
|
2014-02-10 13:09:16 +01:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(LoaderDFFTests)
|
|
|
|
|
2016-06-16 22:11:55 +02:00
|
|
|
#if RW_TEST_WITH_DATA
|
2016-09-09 22:13:22 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_load_dff) {
|
|
|
|
{
|
|
|
|
auto d = Global::get().e->data->index.openFile("landstal.dff");
|
2014-06-04 12:53:11 +02:00
|
|
|
|
2016-09-09 22:13:22 +02:00
|
|
|
LoaderDFF loader;
|
2014-06-04 12:53:11 +02:00
|
|
|
|
rwlib: Use ClumpPtr instead of Clump*
Should fix these memory leaks:
==22737== 14,598,040 (131,472 direct, 14,466,568 indirect) bytes in 2,739 blocks are definitely lost in loss record 3,124 of 3,126
==22737== at 0x4C2F1CA: operator new(unsigned long) (vg_replace_malloc.c:334)
==22737== by 0x90FE4B: LoaderDFF::loadFromMemory(std::shared_ptr<FileContentsInfo>) (LoaderDFF.cpp:443)
==22737== by 0x7BCC86: GameData::loadModel(unsigned short) (GameData.cpp:474)
==22737== by 0x7DF7BC: GameWorld::createInstance(unsigned short, glm::tvec3<float, (glm::precision)0> const&, glm::tquat<float, (glm::precision)0> const&) (GameWorld.cpp:144)
==22737== by 0x7DF44C: GameWorld::placeItems(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (GameWorld.cpp:120)
==22737== by 0x758D38: RWGame::newGame() (RWGame.cpp:116)
==22737== by 0x786389: LoadingState::enter() (LoadingState.cpp:9)
==22737== by 0x75DC59: void StateManager::enter<LoadingState, RWGame*, RWGame::RWGame(Logger&, int, char**)::{lambda()#1}>(RWGame*&&, RWGame::RWGame(Logger&, int, char**)::{lambda()#1}&&) (StateManager.hpp:40)
==22737== by 0x758484: RWGame::RWGame(Logger&, int, char**) (RWGame.cpp:81)
==22737== by 0x747815: main (main.cpp:13)
2017-09-13 00:47:22 +02:00
|
|
|
auto m = loader.loadFromMemory(d);
|
2014-06-04 12:53:11 +02:00
|
|
|
|
rwlib: Use ClumpPtr instead of Clump*
Should fix these memory leaks:
==22737== 14,598,040 (131,472 direct, 14,466,568 indirect) bytes in 2,739 blocks are definitely lost in loss record 3,124 of 3,126
==22737== at 0x4C2F1CA: operator new(unsigned long) (vg_replace_malloc.c:334)
==22737== by 0x90FE4B: LoaderDFF::loadFromMemory(std::shared_ptr<FileContentsInfo>) (LoaderDFF.cpp:443)
==22737== by 0x7BCC86: GameData::loadModel(unsigned short) (GameData.cpp:474)
==22737== by 0x7DF7BC: GameWorld::createInstance(unsigned short, glm::tvec3<float, (glm::precision)0> const&, glm::tquat<float, (glm::precision)0> const&) (GameWorld.cpp:144)
==22737== by 0x7DF44C: GameWorld::placeItems(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) (GameWorld.cpp:120)
==22737== by 0x758D38: RWGame::newGame() (RWGame.cpp:116)
==22737== by 0x786389: LoadingState::enter() (LoadingState.cpp:9)
==22737== by 0x75DC59: void StateManager::enter<LoadingState, RWGame*, RWGame::RWGame(Logger&, int, char**)::{lambda()#1}>(RWGame*&&, RWGame::RWGame(Logger&, int, char**)::{lambda()#1}&&) (StateManager.hpp:40)
==22737== by 0x758484: RWGame::RWGame(Logger&, int, char**) (RWGame.cpp:81)
==22737== by 0x747815: main (main.cpp:13)
2017-09-13 00:47:22 +02:00
|
|
|
BOOST_REQUIRE(m.get() != nullptr);
|
2014-06-04 12:53:11 +02:00
|
|
|
|
2017-01-04 22:08:21 +01:00
|
|
|
BOOST_REQUIRE(m->getFrame());
|
2014-08-04 23:21:01 +02:00
|
|
|
|
2017-01-04 22:08:21 +01:00
|
|
|
BOOST_REQUIRE(!m->getAtomics().empty());
|
|
|
|
const auto& atomic = m->getAtomics()[0];
|
2014-08-04 23:21:01 +02:00
|
|
|
|
2017-01-04 22:08:21 +01:00
|
|
|
BOOST_REQUIRE(atomic->getGeometry());
|
|
|
|
BOOST_REQUIRE(atomic->getFrame());
|
2016-09-09 22:13:22 +02:00
|
|
|
}
|
2014-06-04 12:53:11 +02:00
|
|
|
}
|
|
|
|
|
2016-06-16 22:11:55 +02:00
|
|
|
#endif
|
2014-02-10 13:09:16 +01:00
|
|
|
|
2017-01-05 02:26:37 +01:00
|
|
|
BOOST_AUTO_TEST_CASE(test_clump_clone) {
|
|
|
|
{
|
|
|
|
auto frame1 = std::make_shared<ModelFrame>(0);
|
|
|
|
frame1->setName("Frame1");
|
|
|
|
auto frame2 = std::make_shared<ModelFrame>(1);
|
|
|
|
frame2->setName("Frame2");
|
|
|
|
|
|
|
|
frame1->addChild(frame2);
|
|
|
|
|
|
|
|
auto geometry = std::make_shared<Geometry>();
|
|
|
|
|
|
|
|
auto atomic = std::make_shared<Atomic>();
|
|
|
|
atomic->setFrame(frame2);
|
|
|
|
atomic->setGeometry(geometry);
|
|
|
|
|
|
|
|
auto clump = std::make_shared<Clump>();
|
|
|
|
clump->addAtomic(atomic);
|
|
|
|
clump->setFrame(frame1);
|
|
|
|
|
|
|
|
// Now clone and verify that:
|
|
|
|
// The hierarchy has the same data but different objects
|
|
|
|
// The atomics have the same data but different objects
|
|
|
|
// Suspected correct behaviour:
|
|
|
|
// The geometry is the same for each atomic
|
|
|
|
|
|
|
|
auto newclump = std::shared_ptr<Clump>(clump->clone());
|
|
|
|
BOOST_REQUIRE(newclump);
|
|
|
|
|
|
|
|
BOOST_CHECK_NE(newclump, clump);
|
|
|
|
|
|
|
|
BOOST_REQUIRE(newclump->getFrame());
|
|
|
|
BOOST_CHECK_NE(newclump->getFrame(), clump->getFrame());
|
|
|
|
BOOST_CHECK_EQUAL(newclump->getFrame()->getChildren().size(), 1);
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(newclump->getAtomics().size(), 1);
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL(frame1->getName(), newclump->getFrame()->getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 13:09:16 +01:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|