mirror of https://github.com/OpenMW/openmw.git
initial conversion to cxxopts for mwiniimporter
clang-format clang-format again add cxxopts to cmake and 3 oses use version and not tag for cxxopts add the include dir for windows maybe add the include dir for windows maybe: part 2 give _DIR a try and point to cmake dir try prefix path add FindCXXOPTS.cmake slim down findcxxopts remove boost stuff from mwiiniimporter cmake; set include path in windows one too many S add support for fetching formatting validated that we need MaybeQuotedPath naive attempt to use vcpkg remove findCXXOPTS.cmake naive attempt to use vcpkg more cleanup; make use of cxxopts::cxxopts remove offending bad line try to integration the cxxopts install via vcpkg add vcpkg.cmake toolchain file use the right path? go the fetch route for windows fetch cxxopts workaround make use of CONFIG and also put in TODO add code coverage fix clang-format fix clang-format again add some tooling for tests const params and use order of operations allow to be run from anywhere appease the jvoisin u8 all the things make sure we can run on all systems; but require that it run in the same directory as the binary we wish to test give CLI11 a try get things building on windows too give this a try... clean-format fix1 clean-format fix2 clang-format fix3 do not check if file already exists; overwrite existing try to abstract out _wsystem and std::system appease the clang-format gods purge cli11 bring back testsini_importer_tests
parent
76842c3ba1
commit
2a98519451
@ -0,0 +1,26 @@
|
||||
file(GLOB INIIMPORTER_TESTS_SRC_FILES
|
||||
main.cpp
|
||||
)
|
||||
|
||||
source_group(apps\\openmw-iniimporter-tests FILES ${INIIMPORTER_TESTS_SRC_FILES})
|
||||
|
||||
openmw_add_executable(openmw-iniimporter-tests ${INIIMPORTER_TESTS_SRC_FILES})
|
||||
|
||||
target_include_directories(openmw-iniimporter-tests SYSTEM PRIVATE ${GTEST_INCLUDE_DIRS})
|
||||
target_include_directories(openmw-iniimporter-tests SYSTEM PRIVATE ${GMOCK_INCLUDE_DIRS})
|
||||
|
||||
target_link_libraries(openmw-iniimporter-tests PRIVATE
|
||||
GTest::GTest
|
||||
GMock::GMock
|
||||
)
|
||||
|
||||
if (BUILD_WITH_CODE_COVERAGE)
|
||||
target_compile_options(openmw-iniimporter-tests PRIVATE --coverage)
|
||||
target_link_libraries(openmw-iniimporter-tests PRIVATE gcov)
|
||||
endif()
|
||||
|
||||
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC)
|
||||
target_precompile_headers(openmw-iniimporter-tests PRIVATE
|
||||
<gtest/gtest.h>
|
||||
)
|
||||
endif()
|
@ -0,0 +1,113 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <gtest/gtest.h>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <mach-o/dyld.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
std::filesystem::path getExecutablePath()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
WCHAR buffer[MAX_PATH];
|
||||
GetModuleFileNameW(NULL, buffer, MAX_PATH);
|
||||
std::wstring exe_path(buffer);
|
||||
return std::filesystem::path(exe_path).parent_path();
|
||||
#elif defined(__APPLE__)
|
||||
char buffer[PATH_MAX];
|
||||
uint32_t bufsize = sizeof(buffer);
|
||||
_NSGetExecutablePath(buffer, &bufsize);
|
||||
return std::filesystem::path(buffer).parent_path();
|
||||
#else
|
||||
char buffer[PATH_MAX];
|
||||
ssize_t len = ::readlink("/proc/self/exe", buffer, sizeof(buffer) - 1);
|
||||
if (len == -1)
|
||||
{
|
||||
throw std::runtime_error("Could not retrieve executable path");
|
||||
}
|
||||
buffer[len] = '\0';
|
||||
std::string exe_path(buffer);
|
||||
return std::filesystem::path(exe_path).parent_path();
|
||||
#endif
|
||||
}
|
||||
|
||||
int runBinary(
|
||||
const std::filesystem::path& binaryPath, const std::filesystem::path& iniPath, const std::filesystem::path& cfgPath)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
std::wstring wBinaryPath = binaryPath.native();
|
||||
std::wstring wIniPath = iniPath.native();
|
||||
std::wstring wCfgPath = cfgPath.native();
|
||||
std::wstringstream cmd;
|
||||
cmd << wBinaryPath << L" -i " << wIniPath << L" -c " << wCfgPath;
|
||||
return _wsystem(cmd.str().c_str());
|
||||
#else
|
||||
std::stringstream cmd;
|
||||
cmd << binaryPath << " -i " << iniPath << " -c " << cfgPath;
|
||||
return std::system(cmd.str().c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
struct TestParam
|
||||
{
|
||||
std::string name;
|
||||
std::string fileName;
|
||||
};
|
||||
|
||||
const std::vector<TestParam> testParams = { { "ascii", "ascii" }, { "unicode", "(╯°□°)╯︵ ┻━┻" }, { "emoji", "💩" } };
|
||||
|
||||
class IniImporterTest : public ::testing::TestWithParam<TestParam>
|
||||
{
|
||||
};
|
||||
|
||||
TEST_P(IniImporterTest, TestIniImport)
|
||||
{
|
||||
auto const& param = IniImporterTest::GetParam();
|
||||
|
||||
// Create temporary file
|
||||
std::string iniData = R"([Archives]
|
||||
Archive 0=game1.bsa
|
||||
Archive 1=game2.bsa
|
||||
)";
|
||||
std::filesystem::path tempIniFile = std::filesystem::temp_directory_path() / (param.fileName + ".ini");
|
||||
std::ofstream tempFile(tempIniFile);
|
||||
tempFile << iniData;
|
||||
tempFile.close();
|
||||
std::filesystem::path tempCfgFile = std::filesystem::temp_directory_path() / (param.fileName + ".cfg");
|
||||
std::filesystem::path binaryPath = getExecutablePath() / "openmw-iniimporter";
|
||||
|
||||
int ret = runBinary(binaryPath, tempIniFile, tempCfgFile);
|
||||
ASSERT_EQ(ret, 0);
|
||||
|
||||
// Verify the cfg file was created and has the expected contents
|
||||
std::ifstream ifs(tempCfgFile);
|
||||
ASSERT_TRUE(ifs.good());
|
||||
|
||||
std::string cfgData = R"(fallback-archive=Morrowind.bsa
|
||||
fallback-archive=game1.bsa
|
||||
fallback-archive=game2.bsa
|
||||
)";
|
||||
|
||||
std::stringstream actual;
|
||||
actual << ifs.rdbuf();
|
||||
|
||||
ASSERT_EQ(cfgData, actual.str());
|
||||
|
||||
// Clean up temporary file
|
||||
std::filesystem::remove(tempCfgFile);
|
||||
std::filesystem::remove(tempIniFile);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(IniImporterTests, IniImporterTest, ::testing::ValuesIn(testParams));
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
Loading…
Reference in New Issue