1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-01 16:32:31 +01:00
openrw/tests/test_FileIndex.cpp

74 lines
2.1 KiB
C++
Raw Normal View History

#include <boost/test/unit_test.hpp>
#include <platform/FileHandle.hpp>
#include <platform/FileIndex.hpp>
#include "test_Globals.hpp"
BOOST_AUTO_TEST_SUITE(FileIndexTests)
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));
}
}
BOOST_AUTO_TEST_CASE(test_indexTree, DATA_TEST_PREDICATE) {
2016-09-09 22:13:22 +02:00
FileIndex index;
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);
2019-01-03 12:59:57 +01:00
std::filesystem::path expected{Global::getGamePath()};
2016-09-09 22:13:22 +02:00
expected /= "data/CULLZONE.DAT";
2018-08-17 03:31:29 +02:00
BOOST_CHECK(expected.compare(expected) == 0);
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);
2019-01-03 12:59:57 +01:00
std::filesystem::path expected{Global::getGamePath()};
2016-09-09 22:13:22 +02:00
expected /= "data/maps/comnbtm/comNbtm.ipl";
2018-08-17 03:31:29 +02:00
BOOST_CHECK(expected.compare(truepath) == 0);
2016-09-09 22:13:22 +02:00
}
}
BOOST_AUTO_TEST_CASE(test_openFile, DATA_TEST_PREDICATE) {
2016-09-09 22:13:22 +02:00
FileIndex index;
index.indexTree(Global::getGamePath() + "/data");
auto handle = index.openFile("cullzone.dat");
BOOST_CHECK(handle.data != nullptr);
}
BOOST_AUTO_TEST_CASE(test_indexArchive, DATA_TEST_PREDICATE) {
2016-09-09 22:13:22 +02:00
FileIndex index;
index.indexTree(Global::getGamePath());
{
auto handle = index.openFile("landstal.dff");
BOOST_CHECK(handle.data == nullptr);
}
2016-09-09 22:13:22 +02:00
index.indexArchive("models/gta3.img");
2016-09-09 22:13:22 +02:00
{
auto handle = index.openFile("landstal.dff");
BOOST_CHECK(handle.data != nullptr);
}
}
BOOST_AUTO_TEST_SUITE_END()