2015-02-26 04:57:28 +01:00
|
|
|
#include <boost/test/unit_test.hpp>
|
2018-07-06 22:05:43 +02:00
|
|
|
#include <platform/FileHandle.hpp>
|
2016-09-09 22:13:15 +02:00
|
|
|
#include <platform/FileIndex.hpp>
|
2017-10-26 03:51:24 +02:00
|
|
|
#include "test_Globals.hpp"
|
2015-02-26 04:57:28 +01:00
|
|
|
|
|
|
|
BOOST_AUTO_TEST_SUITE(FileIndexTests)
|
|
|
|
|
2018-06-21 23:41:10 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_normalizeName) {
|
|
|
|
std::string ref = "a/b/c";
|
|
|
|
{
|
|
|
|
std::string dirty = "a\\b\\c";
|
|
|
|
BOOST_CHECK_EQUAL(ref, FileIndex::normalizeFilePath(dirty));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::string dirty = "A/B/C";
|
|
|
|
BOOST_CHECK_EQUAL(ref, FileIndex::normalizeFilePath(dirty));
|
|
|
|
}
|
|
|
|
{
|
|
|
|
std::string dirty = "A\\B\\C";
|
|
|
|
BOOST_CHECK_EQUAL(ref, FileIndex::normalizeFilePath(dirty));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-16 22:11:55 +02:00
|
|
|
#if RW_TEST_WITH_DATA
|
2018-06-21 23:41:10 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_indexTree) {
|
2016-09-09 22:13:22 +02:00
|
|
|
FileIndex index;
|
2018-06-21 23:41:10 +02:00
|
|
|
index.indexTree(Global::getGamePath());
|
2016-09-09 22:13:22 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
std::string upperpath{"DATA/CULLZONE.DAT"};
|
|
|
|
auto truepath = index.findFilePath(upperpath);
|
|
|
|
BOOST_ASSERT(!truepath.empty());
|
|
|
|
BOOST_CHECK(upperpath != truepath);
|
2018-06-21 23:41:10 +02:00
|
|
|
rwfs::path expected{Global::getGamePath()};
|
2016-09-09 22:13:22 +02:00
|
|
|
expected /= "data/CULLZONE.DAT";
|
2017-04-24 20:13:59 +02:00
|
|
|
BOOST_CHECK_EQUAL(truepath.string(), expected.string());
|
2016-09-09 22:13:22 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
std::string upperpath{"DATA/MAPS/COMNBTM/COMNBTM.IPL"};
|
|
|
|
auto truepath = index.findFilePath(upperpath);
|
|
|
|
BOOST_ASSERT(!truepath.empty());
|
|
|
|
BOOST_CHECK(upperpath != truepath);
|
2018-06-21 23:41:10 +02:00
|
|
|
rwfs::path expected{Global::getGamePath()};
|
2016-09-09 22:13:22 +02:00
|
|
|
expected /= "data/maps/comnbtm/comNbtm.ipl";
|
2017-04-24 20:13:59 +02:00
|
|
|
BOOST_CHECK_EQUAL(truepath.string(), expected.string());
|
2016-09-09 22:13:22 +02:00
|
|
|
}
|
2016-08-28 17:23:34 +02:00
|
|
|
}
|
|
|
|
|
2018-06-21 23:41:10 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_openFile) {
|
2016-09-09 22:13:22 +02:00
|
|
|
FileIndex index;
|
|
|
|
index.indexTree(Global::getGamePath() + "/data");
|
|
|
|
|
|
|
|
auto handle = index.openFile("cullzone.dat");
|
2018-07-06 22:05:43 +02:00
|
|
|
BOOST_CHECK(handle.data != nullptr);
|
2015-02-26 04:57:28 +01:00
|
|
|
}
|
|
|
|
|
2018-06-21 23:41:10 +02:00
|
|
|
BOOST_AUTO_TEST_CASE(test_indexArchive) {
|
2016-09-09 22:13:22 +02:00
|
|
|
FileIndex index;
|
2018-06-21 23:41:10 +02:00
|
|
|
index.indexTree(Global::getGamePath());
|
|
|
|
|
|
|
|
{
|
|
|
|
auto handle = index.openFile("landstal.dff");
|
2018-07-06 22:05:43 +02:00
|
|
|
BOOST_CHECK(handle.data == nullptr);
|
2018-06-21 23:41:10 +02:00
|
|
|
}
|
2016-09-09 22:13:22 +02:00
|
|
|
|
2018-06-21 23:41:10 +02:00
|
|
|
index.indexArchive("models/gta3.img");
|
2016-09-09 22:13:22 +02:00
|
|
|
|
2018-06-21 23:41:10 +02:00
|
|
|
{
|
|
|
|
auto handle = index.openFile("landstal.dff");
|
2018-07-06 22:05:43 +02:00
|
|
|
BOOST_CHECK(handle.data != nullptr);
|
2018-06-21 23:41:10 +02:00
|
|
|
}
|
2015-02-26 04:57:28 +01:00
|
|
|
}
|
2016-06-16 22:11:55 +02:00
|
|
|
#endif
|
2015-02-26 04:57:28 +01:00
|
|
|
|
2016-04-15 02:06:10 +02:00
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|