mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-05 23:01:17 +00:00
* Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced Generated with include-what-you-use and applied conservatively. Only OrcaSlicer's own headers, the ones under src/ and tests/, are removed or forward-declared; standard-library and third-party includes are left alone. An include is removed only when both the Release and the Debug configuration leave it unused, never from inside a conditional block, and never from a file with platform-specific blocks, which only gain includes. Files whose only use of a header sits behind a feature or debug macro (libvgcode's OpenGL ES and marker code, the ARACHNE/TESTS_EXPORT_SVGS debug output) keep their includes. clonable_ptr.hpp gains #pragma once; it had no include guard and was only safe while Config.hpp was its sole includer. * Remove Unused Project Includes From Files With Platform-Specific Code A Linux include-what-you-use run cannot see the code inside _WIN32, __APPLE__ or __linux__ blocks, so its verdict is only taken where nothing the removed header declares, directly or through what it includes, is named inside those blocks. Removals also have to hold in both the Release and Debug configuration and never touch a line inside a conditional block. * Restore the libslic3r Precompiled Header and Direct Includes Lost in the Platform Pass The platform-file pass treated pchheader.hpp as an ordinary header and emptied it, and left GUI_Preview.hpp and 14 other files relying on headers they no longer reached directly. * Restore MainFrame.hpp in ParamsDialog.cpp for the Windows-Only Reparent Call * Include Headers That Files Reached Through Ones the Cleanup Removed * Drop Includes Duplicated by the Cleanup or by Main's Own Additions * Leave PreciseSeam.cpp as Main Has It After the Precise Seam Rework
243 lines
10 KiB
C++
243 lines
10 KiB
C++
#include <boost/filesystem/operations.hpp>
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include <boost/filesystem.hpp>
|
|
#include <boost/nowide/fstream.hpp>
|
|
#include <vector>
|
|
#include "libslic3r/AppConfig.hpp"
|
|
#include <cstddef>
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include "slic3r/Utils/bambu_networking.hpp"
|
|
|
|
#include "plugin_test_utils.hpp"
|
|
|
|
using namespace Slic3r;
|
|
namespace fs = boost::filesystem;
|
|
|
|
namespace {
|
|
|
|
// Platform naming used by BBLNetworkPlugin::scan_plugin_versions().
|
|
#if defined(_MSC_VER) || defined(_WIN32)
|
|
static const char* PLUGIN_PREFIX = "bambu_networking_";
|
|
static const char* PLUGIN_EXT = ".dll";
|
|
#elif defined(__WXMAC__) || defined(__APPLE__)
|
|
static const char* PLUGIN_PREFIX = "libbambu_networking_";
|
|
static const char* PLUGIN_EXT = ".dylib";
|
|
#else
|
|
static const char* PLUGIN_PREFIX = "libbambu_networking_";
|
|
static const char* PLUGIN_EXT = ".so";
|
|
#endif
|
|
|
|
struct PluginFolderFixture
|
|
{
|
|
ScopedDataDir data{"netver"};
|
|
|
|
PluginFolderFixture()
|
|
{
|
|
fs::create_directories(data.dir / "plugins");
|
|
}
|
|
|
|
void add_plugin(const std::string& version)
|
|
{
|
|
boost::nowide::ofstream f((data.dir / "plugins" / (PLUGIN_PREFIX + version + PLUGIN_EXT)).string());
|
|
f << "stub";
|
|
}
|
|
};
|
|
|
|
int count_version(const std::vector<NetworkLibraryVersionInfo>& versions, const std::string& v)
|
|
{
|
|
int n = 0;
|
|
for (const auto& info : versions)
|
|
if (info.version == v)
|
|
++n;
|
|
return n;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("Series and managed classification", "[NetworkVersions]")
|
|
{
|
|
// The AA.BB.CC series is the stored identity of every modern build.
|
|
CHECK(network_plugin_series("02.08.01.53") == "02.08.01");
|
|
CHECK(network_plugin_series("02.08.01") == "02.08.01"); // idempotent
|
|
CHECK(network_plugin_series("02.08.01_custom") == "02.08.01");
|
|
CHECK(network_plugin_series("02.08.01.52-dev") == "02.08.01");
|
|
CHECK(network_plugin_series(BAMBU_NETWORK_AGENT_VERSION_LEGACY) == BAMBU_NETWORK_AGENT_VERSION_LEGACY);
|
|
CHECK(network_plugin_series("").empty());
|
|
|
|
// Only pure dotted-numeric builds collapse into their series entry; legacy and any
|
|
// custom-named build keep their own identity.
|
|
CHECK(is_series_managed_version("02.08.01"));
|
|
CHECK(is_series_managed_version("02.08.01.53"));
|
|
CHECK_FALSE(is_series_managed_version("02.08.01_custom"));
|
|
CHECK_FALSE(is_series_managed_version("02.08.01.52-dev"));
|
|
CHECK_FALSE(is_series_managed_version(BAMBU_NETWORK_AGENT_VERSION_LEGACY));
|
|
CHECK_FALSE(is_series_managed_version(""));
|
|
}
|
|
|
|
TEST_CASE_METHOD(PluginFolderFixture, "Managed builds fold into the series; customs are surfaced", "[NetworkVersions]")
|
|
{
|
|
add_plugin("02.08.01.55"); // managed, same series -> folded into the 02.08.01 row
|
|
add_plugin("02.09.00.10"); // managed, unknown series -> not listed
|
|
add_plugin("02.03.00.62"); // managed, older whitelisted series -> folded into 02.03.00
|
|
add_plugin("02.01.01.52"); // managed, series with no ABI in this build -> not listed
|
|
add_plugin("02.08.01_custom"); // custom, whitelisted series -> listed under it
|
|
add_plugin("02.08.01.52-dev"); // custom (dash-suffixed), whitelisted series -> listed
|
|
|
|
auto versions = get_all_available_versions();
|
|
|
|
// The specific managed build never gets its own row - the series represents it.
|
|
REQUIRE(count_version(versions, "02.08.01.55") == 0);
|
|
REQUIRE(count_version(versions, "02.08.01") == 1);
|
|
REQUIRE(count_version(versions, "02.09.00.10") == 0);
|
|
REQUIRE(count_version(versions, "02.03.00.62") == 0);
|
|
REQUIRE(count_version(versions, "02.03.00") == 1);
|
|
REQUIRE(count_version(versions, "02.01.01.52") == 0);
|
|
// Custom-named builds are distinct files kept under their own name.
|
|
REQUIRE(count_version(versions, "02.08.01_custom") == 1);
|
|
REQUIRE(count_version(versions, "02.08.01.52-dev") == 1);
|
|
|
|
// Newest series first, its customs nested under it (suffix sort: "" < ".52-dev" < "_custom"),
|
|
// then older series, legacy last.
|
|
REQUIRE(versions[0].version == "02.08.01");
|
|
REQUIRE(versions[1].version == "02.08.01.52-dev");
|
|
REQUIRE(versions[2].version == "02.08.01_custom");
|
|
REQUIRE(versions[3].version == "02.03.00");
|
|
REQUIRE(versions.back().version == BAMBU_NETWORK_AGENT_VERSION_LEGACY);
|
|
|
|
// An older whitelisted series is a flat row of its own, and never holds "(Latest)".
|
|
REQUIRE(versions[3].suffix.empty());
|
|
REQUIRE_FALSE(versions[3].is_latest);
|
|
|
|
// Customs sort/render nested under their series (non-empty suffix, base = the series).
|
|
REQUIRE(versions[1].base_version == "02.08.01");
|
|
REQUIRE_FALSE(versions[1].suffix.empty());
|
|
REQUIRE(versions[2].base_version == "02.08.01");
|
|
REQUIRE_FALSE(versions[2].suffix.empty());
|
|
|
|
// "(Latest)" is the series row, never a nested custom build.
|
|
REQUIRE(versions[0].suffix.empty());
|
|
REQUIRE(versions[0].is_latest);
|
|
REQUIRE_FALSE(versions[1].is_latest);
|
|
REQUIRE_FALSE(versions[2].is_latest);
|
|
|
|
// The stored default that drives download and update-check decisions is now the series.
|
|
REQUIRE(std::string(get_latest_network_version()) == "02.08.01");
|
|
}
|
|
|
|
TEST_CASE_METHOD(PluginFolderFixture, "Only the loaded series is marked installed", "[NetworkVersions]")
|
|
{
|
|
add_plugin("02.08.01.55");
|
|
add_plugin("02.08.01_custom");
|
|
|
|
// The loaded plug-in reports its full build (02.08.01.55); the series row is what gets marked.
|
|
{
|
|
auto versions = get_all_available_versions("02.08.01.55");
|
|
int marked = 0;
|
|
for (const auto& info : versions)
|
|
if (info.is_loaded) { ++marked; REQUIRE(info.version == "02.08.01"); }
|
|
REQUIRE(marked == 1);
|
|
}
|
|
|
|
// An older series is marked the same way, and never bleeds onto the latest row.
|
|
{
|
|
add_plugin("02.03.00.62");
|
|
auto versions = get_all_available_versions("02.03.00.62");
|
|
int marked = 0;
|
|
for (const auto& info : versions)
|
|
if (info.is_loaded) { ++marked; REQUIRE(info.version == "02.03.00"); }
|
|
REQUIRE(marked == 1);
|
|
}
|
|
|
|
// A loaded custom build matches its own row, never the bare series.
|
|
{
|
|
auto versions = get_all_available_versions("02.08.01_custom");
|
|
int marked = 0;
|
|
for (const auto& info : versions)
|
|
if (info.is_loaded) { ++marked; REQUIRE(info.version == "02.08.01_custom"); }
|
|
REQUIRE(marked == 1);
|
|
}
|
|
|
|
// Nothing loaded marks nothing, even though libraries are on disk.
|
|
for (const auto& info : get_all_available_versions(""))
|
|
REQUIRE_FALSE(info.is_loaded);
|
|
}
|
|
|
|
TEST_CASE("Only whitelisted series pass the load gate", "[NetworkVersions]")
|
|
{
|
|
// Each whitelisted series, its builds, and custom-named builds of that series.
|
|
REQUIRE(is_supported_network_version("02.08.01"));
|
|
REQUIRE(is_supported_network_version("02.08.01.52"));
|
|
REQUIRE(is_supported_network_version("02.08.01.55"));
|
|
REQUIRE(is_supported_network_version("02.08.01_custom"));
|
|
REQUIRE(is_supported_network_version("02.08.01.52-dev"));
|
|
REQUIRE(is_supported_network_version("02.03.00"));
|
|
REQUIRE(is_supported_network_version("02.03.00.62"));
|
|
REQUIRE(is_supported_network_version("02.03.00.70"));
|
|
REQUIRE(is_supported_network_version("02.03.00_custom"));
|
|
REQUIRE(is_supported_network_version(BAMBU_NETWORK_AGENT_VERSION_LEGACY));
|
|
|
|
// Series whitelisted by previous Orca releases that no generation here can call.
|
|
REQUIRE_FALSE(is_supported_network_version("02.01.01.52"));
|
|
REQUIRE_FALSE(is_supported_network_version("02.00.02.50"));
|
|
|
|
// A neighbouring series of a whitelisted one is still its own ABI.
|
|
REQUIRE_FALSE(is_supported_network_version("02.03.01.51"));
|
|
|
|
// Unknown series, legacy siblings, and malformed values.
|
|
REQUIRE_FALSE(is_supported_network_version("02.09.00.10"));
|
|
std::string legacy = BAMBU_NETWORK_AGENT_VERSION_LEGACY;
|
|
std::string legacy_sibling = legacy.substr(0, 9) + (legacy.substr(9) == "99" ? "98" : "99");
|
|
REQUIRE_FALSE(is_supported_network_version(legacy_sibling));
|
|
REQUIRE_FALSE(is_supported_network_version(""));
|
|
REQUIRE_FALSE(is_supported_network_version("02.08"));
|
|
}
|
|
|
|
TEST_CASE("Each version resolves to the ABI generation that can call it", "[NetworkVersions]")
|
|
{
|
|
// The generation is keyed on the series, so every build of a series - including the
|
|
// custom-named ones - resolves to the same one.
|
|
CHECK(network_plugin_abi("02.08.01") == NetworkAbi::Current);
|
|
CHECK(network_plugin_abi("02.08.01.55") == NetworkAbi::Current);
|
|
CHECK(network_plugin_abi("02.08.01.52-dev") == NetworkAbi::Current);
|
|
CHECK(network_plugin_abi("02.03.00") == NetworkAbi::V0203);
|
|
CHECK(network_plugin_abi("02.03.00.62") == NetworkAbi::V0203);
|
|
CHECK(network_plugin_abi("02.03.00_custom") == NetworkAbi::V0203);
|
|
CHECK(network_plugin_abi(BAMBU_NETWORK_AGENT_VERSION_LEGACY) == NetworkAbi::Legacy);
|
|
|
|
// Anything the load gate rejects must dispatch through nothing at all, rather than
|
|
// defaulting to a layout it does not share.
|
|
CHECK(network_plugin_abi("02.01.01.52") == NetworkAbi::Unsupported);
|
|
CHECK(network_plugin_abi("02.00.02.50") == NetworkAbi::Unsupported);
|
|
CHECK(network_plugin_abi("02.09.00.10") == NetworkAbi::Unsupported);
|
|
CHECK(network_plugin_abi("") == NetworkAbi::Unsupported);
|
|
|
|
// A series may only be offered once the dispatch layer implements its generation.
|
|
for (size_t i = 0; i < AVAILABLE_NETWORK_VERSIONS_COUNT; ++i)
|
|
CHECK(AVAILABLE_NETWORK_VERSIONS[i].abi != NetworkAbi::Unsupported);
|
|
}
|
|
|
|
TEST_CASE_METHOD(PluginFolderFixture, "Legacy series never adopts discovered builds", "[NetworkVersions]")
|
|
{
|
|
// A different build of the legacy series must not be surfaced: is_legacy_version()
|
|
// matches exactly, so it would be loaded with the modern struct layout.
|
|
std::string legacy = BAMBU_NETWORK_AGENT_VERSION_LEGACY;
|
|
std::string legacy_sibling = legacy.substr(0, 9) + (legacy.substr(9) == "99" ? "98" : "99");
|
|
add_plugin(legacy_sibling);
|
|
|
|
auto versions = get_all_available_versions();
|
|
|
|
REQUIRE(count_version(versions, legacy_sibling) == 0);
|
|
REQUIRE(count_version(versions, legacy) == 1);
|
|
|
|
// With nothing else on disk, the series holds "(Latest)" even though its library is
|
|
// not installed.
|
|
for (const auto& info : versions) {
|
|
if (info.version == "02.08.01") {
|
|
REQUIRE(info.is_latest);
|
|
REQUIRE_FALSE(info.is_loaded);
|
|
}
|
|
}
|
|
}
|