mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-14 00:52:04 +00:00
Merge branch 'main' into zaa
This commit is contained in:
@@ -2,6 +2,14 @@
|
||||
|
||||
add_subdirectory(catch2)
|
||||
|
||||
# The top-level project defines _UNICODE globally, which makes Catch2's bundled
|
||||
# main emit wmain instead of main. Test executables link with the default
|
||||
# /SUBSYSTEM:CONSOLE entry point (mainCRTStartup, which calls main), so force
|
||||
# Catch2 to emit main to keep the CRT entry point happy.
|
||||
if(MSVC)
|
||||
target_compile_definitions(Catch2WithMain PRIVATE DO_NOT_USE_WMAIN)
|
||||
endif()
|
||||
|
||||
set(TEST_DATA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/data)
|
||||
file(TO_NATIVE_PATH "${TEST_DATA_DIR}" TEST_DATA_DIR)
|
||||
|
||||
@@ -18,6 +26,27 @@ if (APPLE)
|
||||
target_link_libraries(test_common INTERFACE "-liconv -framework IOKit" "-framework CoreFoundation" -lc++)
|
||||
endif()
|
||||
|
||||
# Copies runtime DLLs next to each test executable. Handles both single-config
|
||||
# generators (CMAKE_BUILD_TYPE set) and multi-config generators (Ninja
|
||||
# Multi-Config, Visual Studio) where CMAKE_BUILD_TYPE is empty and DLLs must
|
||||
# land in every per-config output directory.
|
||||
function(orcaslicer_copy_test_dlls)
|
||||
if (NOT WIN32)
|
||||
return()
|
||||
endif()
|
||||
set(_configs ${CMAKE_CONFIGURATION_TYPES})
|
||||
if (NOT _configs)
|
||||
set(_configs "${CMAKE_BUILD_TYPE}")
|
||||
endif()
|
||||
foreach(_cfg IN LISTS _configs)
|
||||
if (_cfg STREQUAL "Debug")
|
||||
orcaslicer_copy_dlls(COPY_DLLS "Debug" "d" _unused_dlls)
|
||||
else()
|
||||
orcaslicer_copy_dlls(COPY_DLLS "${_cfg}" "" _unused_dlls)
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
add_subdirectory(libnest2d)
|
||||
add_subdirectory(libslic3r)
|
||||
add_subdirectory(slic3rutils)
|
||||
|
||||
@@ -19,14 +19,6 @@ add_executable(${_TEST_NAME}_tests
|
||||
target_link_libraries(${_TEST_NAME}_tests test_common libslic3r Catch2::Catch2WithMain)
|
||||
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
||||
|
||||
if (WIN32)
|
||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
||||
orcaslicer_copy_dlls(COPY_DLLS "Debug" "d" output_dlls_Debug)
|
||||
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
|
||||
orcaslicer_copy_dlls(COPY_DLLS "RelWithDebInfo" "" output_dlls_Release)
|
||||
else()
|
||||
orcaslicer_copy_dlls(COPY_DLLS "Release" "" output_dlls_Release)
|
||||
endif()
|
||||
endif()
|
||||
orcaslicer_copy_test_dlls()
|
||||
|
||||
catch_discover_tests(${_TEST_NAME}_tests)
|
||||
|
||||
@@ -8,14 +8,6 @@ add_executable(${_TEST_NAME}_tests
|
||||
target_link_libraries(${_TEST_NAME}_tests test_common libnest2d Catch2::Catch2WithMain)
|
||||
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
||||
|
||||
if (WIN32)
|
||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
||||
orcaslicer_copy_dlls(COPY_DLLS "Debug" "d" output_dlls_Debug)
|
||||
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
|
||||
orcaslicer_copy_dlls(COPY_DLLS "RelWithDebInfo" "" output_dlls_Release)
|
||||
else()
|
||||
orcaslicer_copy_dlls(COPY_DLLS "Release" "" output_dlls_Release)
|
||||
endif()
|
||||
endif()
|
||||
orcaslicer_copy_test_dlls()
|
||||
|
||||
catch_discover_tests(${_TEST_NAME}_tests)
|
||||
|
||||
@@ -9,6 +9,7 @@ add_executable(${_TEST_NAME}_tests
|
||||
test_clipper_offset.cpp
|
||||
test_clipper_utils.cpp
|
||||
test_config.cpp
|
||||
test_preset_bundle_loading.cpp
|
||||
test_elephant_foot_compensation.cpp
|
||||
test_geometry.cpp
|
||||
test_placeholder_parser.cpp
|
||||
@@ -34,14 +35,6 @@ target_link_libraries(${_TEST_NAME}_tests test_common libslic3r Catch2::Catch2Wi
|
||||
target_include_directories(${_TEST_NAME}_tests PRIVATE ${CMAKE_SOURCE_DIR}/src)
|
||||
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
||||
|
||||
if (WIN32)
|
||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
||||
orcaslicer_copy_dlls(COPY_DLLS "Debug" "d" output_dlls_Debug)
|
||||
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
|
||||
orcaslicer_copy_dlls(COPY_DLLS "RelWithDebInfo" "" output_dlls_Release)
|
||||
else()
|
||||
orcaslicer_copy_dlls(COPY_DLLS "Release" "" output_dlls_Release)
|
||||
endif()
|
||||
endif()
|
||||
orcaslicer_copy_test_dlls()
|
||||
|
||||
catch_discover_tests(${_TEST_NAME}_tests)
|
||||
|
||||
102
tests/libslic3r/test_preset_bundle_loading.cpp
Normal file
102
tests/libslic3r/test_preset_bundle_loading.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include <catch2/catch_all.hpp>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "libslic3r/PresetBundle.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
namespace {
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
struct TempPresetDir {
|
||||
fs::path path;
|
||||
|
||||
TempPresetDir()
|
||||
{
|
||||
path = fs::temp_directory_path() / fs::unique_path("orcaslicer-preset-%%%%-%%%%-%%%%");
|
||||
fs::create_directories(path);
|
||||
}
|
||||
|
||||
~TempPresetDir()
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
fs::remove_all(path, ec);
|
||||
}
|
||||
};
|
||||
|
||||
void write_print_preset(const DynamicPrintConfig &default_config, const fs::path &file, const std::string &name, const std::string &inherits = {})
|
||||
{
|
||||
DynamicPrintConfig config(default_config);
|
||||
config.option<ConfigOptionString>("print_settings_id", true)->value = name;
|
||||
config.option<ConfigOptionString>(BBL_JSON_KEY_INHERITS, true)->value = inherits;
|
||||
|
||||
fs::create_directories(file.parent_path());
|
||||
config.save_to_json(file.string(), name, "User", "1.0.0");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Preset identity is canonicalized from load path", "[Preset][Identity]")
|
||||
{
|
||||
TempPresetDir temp_dir;
|
||||
PresetBundle bundle;
|
||||
PresetsConfigSubstitutions substitutions;
|
||||
|
||||
write_print_preset(bundle.prints.default_preset().config, temp_dir.path / PRESET_PRINT_NAME / "User.json", "User");
|
||||
write_print_preset(bundle.prints.default_preset().config, temp_dir.path / PRESET_LOCAL_DIR / "bundle-1" / PRESET_PRINT_NAME / "LocalBundle.json", "LocalBundle");
|
||||
write_print_preset(bundle.prints.default_preset().config, temp_dir.path / PRESET_SUBSCRIBED_DIR / "remote-1" / PRESET_PRINT_NAME / "Subscribed.json", "Subscribed");
|
||||
|
||||
bundle.prints.load_presets(temp_dir.path.string(), PRESET_PRINT_NAME, substitutions, ForwardCompatibilitySubstitutionRule::Disable);
|
||||
bundle.prints.load_presets((temp_dir.path / PRESET_LOCAL_DIR / "bundle-1").string(), PRESET_PRINT_NAME, substitutions, ForwardCompatibilitySubstitutionRule::Disable);
|
||||
bundle.prints.load_presets((temp_dir.path / PRESET_SUBSCRIBED_DIR / "remote-1").string(), PRESET_PRINT_NAME, substitutions, ForwardCompatibilitySubstitutionRule::Disable);
|
||||
|
||||
const Preset *root_user = bundle.prints.find_preset("User");
|
||||
REQUIRE(root_user != nullptr);
|
||||
CHECK(root_user->name == "User");
|
||||
CHECK_FALSE(root_user->is_from_bundle());
|
||||
|
||||
const Preset *local_bundle = bundle.prints.find_preset("_local/bundle-1/LocalBundle");
|
||||
REQUIRE(local_bundle != nullptr);
|
||||
CHECK(local_bundle->name == "_local/bundle-1/LocalBundle");
|
||||
CHECK(local_bundle->is_from_bundle());
|
||||
|
||||
const Preset *subscribed = bundle.prints.find_preset("_subscribed/remote-1/Subscribed");
|
||||
REQUIRE(subscribed != nullptr);
|
||||
CHECK(subscribed->name == "_subscribed/remote-1/Subscribed");
|
||||
CHECK(subscribed->is_from_bundle());
|
||||
}
|
||||
|
||||
TEST_CASE("Legacy bundle import without bundle metadata stays in the user preset directory", "[Preset][Identity]")
|
||||
{
|
||||
TempPresetDir temp_dir;
|
||||
PresetBundle bundle;
|
||||
|
||||
PresetsConfigSubstitutions substitutions;
|
||||
std::vector<std::string> result;
|
||||
int overwrite = 0;
|
||||
std::string file = (temp_dir.path / "legacy-bundle" / "Imported.json").string();
|
||||
const fs::path user_root = temp_dir.path / "user";
|
||||
|
||||
write_print_preset(bundle.prints.default_preset().config, file, "Imported");
|
||||
fs::create_directories(user_root);
|
||||
bundle.prints.update_user_presets_directory(user_root.string(), PRESET_PRINT_NAME);
|
||||
|
||||
REQUIRE(bundle.import_json_presets(
|
||||
substitutions,
|
||||
file,
|
||||
[](std::string const &) { return 1; },
|
||||
ForwardCompatibilitySubstitutionRule::Disable,
|
||||
overwrite,
|
||||
result));
|
||||
|
||||
const Preset *imported = bundle.prints.find_preset("Imported");
|
||||
REQUIRE(imported != nullptr);
|
||||
CHECK(imported->name == "Imported");
|
||||
CHECK(imported->bundle_id.empty());
|
||||
CHECK_FALSE(imported->is_from_bundle());
|
||||
// Detached user presets (no inherits) are saved in the "base" subfolder of the user preset root.
|
||||
CHECK(fs::equivalent(fs::path(imported->file).parent_path().parent_path(), user_root / PRESET_PRINT_NAME));
|
||||
}
|
||||
|
||||
@@ -7,14 +7,6 @@ add_executable(${_TEST_NAME}_tests ${_TEST_NAME}_tests_main.cpp
|
||||
target_link_libraries(${_TEST_NAME}_tests test_common libslic3r Catch2::Catch2WithMain)
|
||||
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
||||
|
||||
if (WIN32)
|
||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
||||
orcaslicer_copy_dlls(COPY_DLLS "Debug" "d" output_dlls_Debug)
|
||||
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
|
||||
orcaslicer_copy_dlls(COPY_DLLS "RelWithDebInfo" "" output_dlls_Release)
|
||||
else()
|
||||
orcaslicer_copy_dlls(COPY_DLLS "Release" "" output_dlls_Release)
|
||||
endif()
|
||||
endif()
|
||||
orcaslicer_copy_test_dlls()
|
||||
|
||||
catch_discover_tests(${_TEST_NAME}_tests)
|
||||
|
||||
@@ -10,14 +10,6 @@ endif ()
|
||||
target_link_libraries(${_TEST_NAME}_tests test_common libslic3r_gui libslic3r Catch2::Catch2WithMain)
|
||||
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
|
||||
|
||||
if (WIN32)
|
||||
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
||||
orcaslicer_copy_dlls(COPY_DLLS "Debug" "d" output_dlls_Debug)
|
||||
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
|
||||
orcaslicer_copy_dlls(COPY_DLLS "RelWithDebInfo" "" output_dlls_Release)
|
||||
else()
|
||||
orcaslicer_copy_dlls(COPY_DLLS "Release" "" output_dlls_Release)
|
||||
endif()
|
||||
endif()
|
||||
orcaslicer_copy_test_dlls()
|
||||
|
||||
catch_discover_tests(${_TEST_NAME}_tests)
|
||||
|
||||
Reference in New Issue
Block a user