implement appended zip loader for executable
This commit is contained in:
@@ -10,11 +10,22 @@ FilterPlatformPaths(SOURCES)
|
||||
if (NOT ENABLE_CURL)
|
||||
list(FILTER SOURCES EXCLUDE REGEX "WebResourceLoader")
|
||||
endif()
|
||||
|
||||
if (APPLE)
|
||||
list(FILTER SOURCES EXCLUDE REGEX "ExeAppendedZipLoader")
|
||||
endif()
|
||||
|
||||
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" FILES ${SOURCES})
|
||||
file(GLOB_RECURSE RESOURCES "${ROOT_FOLDER}/resources/*.rc" "${ROOT_FOLDER}/resources/*.h")
|
||||
list(APPEND SOURCES ${RESOURCES})
|
||||
add_executable(OpenVulkano_Tests ${SOURCES})
|
||||
|
||||
# append zip file at the end of executable file
|
||||
if (WIN32 OR (LINUX AND NOT APPLE))
|
||||
set(ZIP_FILE ${ROOT_FOLDER}/resources/arch.zip)
|
||||
add_custom_command(TARGET OpenVulkano_Tests POST_BUILD COMMAND ${CMAKE_COMMAND} -E cat ${ZIP_FILE} >> $<TARGET_FILE:OpenVulkano_Tests>)
|
||||
endif()
|
||||
|
||||
target_include_directories(OpenVulkano_Tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
target_include_directories(OpenVulkano_Tests PRIVATE openVulkanoCpp)
|
||||
|
||||
52
tests/Host/ExeAppendedZipLoaderTests.cpp
Normal file
52
tests/Host/ExeAppendedZipLoaderTests.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Host/Windows/ExeAppendedZipLoaderWindows.hpp"
|
||||
#else
|
||||
#include "Host/Linux/ExeAppendedZipLoaderLinux.hpp"
|
||||
#endif
|
||||
|
||||
#include "Base/Logger.hpp"
|
||||
#include <Windows.h>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
using namespace OpenVulkano;
|
||||
|
||||
TEST_CASE("Load zip from exe")
|
||||
{
|
||||
Logger::SetupLogger("", "tests.log");
|
||||
#ifdef _WIN32
|
||||
ExeAppendedZipLoaderWindows loader;
|
||||
#else
|
||||
ExeAppendedZipLoaderLinux loader;
|
||||
#endif
|
||||
Array<char> zipData = loader.GetResource(loader.GetCurrentExecutablePath());
|
||||
REQUIRE(!zipData.Empty());
|
||||
|
||||
auto files = loader.GetZipArchiveFiles(loader.GetCurrentExecutablePath());
|
||||
REQUIRE(files.size() == 2);
|
||||
|
||||
int i = 0;
|
||||
for (const auto& [fileDesc, fileData] : files)
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
REQUIRE(fileDesc.path == "madvoxel_icon.ico");
|
||||
}
|
||||
else if (i == 1)
|
||||
{
|
||||
REQUIRE(fileDesc.path == "text.txt");
|
||||
std::string s(fileData.Data(), fileData.Size());
|
||||
REQUIRE(s == "Hello world!");
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user