Skip to content

Commit

Permalink
Remove dependency on Boost's UUID and Lexical Cast libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
Ortham committed Jan 15, 2025
1 parent 349981b commit 7442a16
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 22 deletions.
2 changes: 2 additions & 0 deletions cmake/tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ set(LIBLOOT_INTERNALS_TESTS_ALL_SOURCES
${LIBLOOT_SRC_TESTS_INTERNALS_CPP_FILES}
${LIBLOOT_SRC_TESTS_INTERNALS_H_FILES}
"${CMAKE_SOURCE_DIR}/src/tests/common_game_test_fixture.h"
"${CMAKE_SOURCE_DIR}/src/tests/test_helpers.h"
"${CMAKE_SOURCE_DIR}/src/tests/printers.h")

set(LIBLOOT_INTERFACE_TESTS_ALL_SOURCES
${LIBLOOT_SRC_TESTS_INTERFACE_CPP_FILES}
${LIBLOOT_SRC_TESTS_INTERFACE_H_FILES}
"${CMAKE_SOURCE_DIR}/src/tests/common_game_test_fixture.h"
"${CMAKE_SOURCE_DIR}/src/tests/test_helpers.h"
"${CMAKE_SOURCE_DIR}/src/tests/printers.h")


Expand Down
14 changes: 5 additions & 9 deletions src/tests/api/internals/bsa_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ along with LOOT. If not, see

#include <gtest/gtest.h>

#include <boost/lexical_cast.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <fstream>

#include "api/bsa.h"
#include "tests/test_helpers.h"

namespace loot::test {
TEST(GetAssetsInBethesdaArchive, shouldSupportV103BSAs) {
Expand Down Expand Up @@ -141,6 +140,8 @@ class GetAssetsInBethesdaArchive_BA2Version
: public ::testing::TestWithParam<char> {
protected:
GetAssetsInBethesdaArchive_BA2Version() : path(GetArchivePath()) {
std::filesystem::create_directories(path.parent_path());

const auto sourcePath =
std::filesystem::u8path("./Fallout 4/Data/Blank - Main.ba2");
std::filesystem::copy(sourcePath, path);
Expand All @@ -152,18 +153,13 @@ class GetAssetsInBethesdaArchive_BA2Version
stream.close();
}

void TearDown() override { std::filesystem::remove(path); }
void TearDown() override { std::filesystem::remove_all(path.parent_path()); }

const std::filesystem::path path;

private:
std::filesystem::path GetArchivePath() {
const auto tempFilename =
"LOOT-test-" +
boost::lexical_cast<std::string>((boost::uuids::random_generator())()) +
".ba2";

return std::filesystem::temp_directory_path() / tempFilename;
return getRootTestPath() / "test.ba2";
}
};

Expand Down
15 changes: 2 additions & 13 deletions src/tests/common_game_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,17 @@ along with LOOT. If not, see
#include <gtest/gtest.h>

#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <chrono>
#include <filesystem>
#include <fstream>
#include <map>

#include "loot/enum/game_type.h"

#include "tests/test_helpers.h"

namespace loot {
namespace test {

std::filesystem::path getRootTestPath() {
auto directoryName =
u8"LOOT-t\u00E9st-" +
boost::lexical_cast<std::string>((boost::uuids::random_generator())());

return std::filesystem::absolute(std::filesystem::temp_directory_path() /
std::filesystem::u8path(directoryName));
}

class CommonGameTestFixture : public ::testing::TestWithParam<GameType> {
protected:
CommonGameTestFixture() :
Expand Down
52 changes: 52 additions & 0 deletions src/tests/test_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* LOOT
A load order optimisation tool for Oblivion, Skyrim, Fallout 3 and
Fallout: New Vegas.
Copyright (C) 2014-2016 WrinklyNinja
This file is part of LOOT.
LOOT is free software: you can redistribute
it and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
LOOT is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with LOOT. If not, see
<https://www.gnu.org/licenses/>.
*/

#ifndef LOOT_TESTS_TEST_HELPERS
#define LOOT_TESTS_TEST_HELPERS

#include <filesystem>
#include <random>
#include <string>

namespace loot::test {
std::filesystem::path getRootTestPath() {
std::random_device randomDevice;
std::default_random_engine prng(randomDevice());
std::uniform_int_distribution dist(0x61,
0x7A); // values of a-z in ASCII/UTF-8.

// The non-ASCII character is there to ensure test coverage of non-ASCII path
// handling.
std::string directoryName = u8"libloot-t\u00E9st-";

for (int i = 0; i < 16; i += 1) {
directoryName.push_back(static_cast<char>(dist(prng)));
}

return std::filesystem::absolute(std::filesystem::temp_directory_path() /
std::filesystem::u8path(directoryName));
}
}

#endif

0 comments on commit 7442a16

Please sign in to comment.