mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-04 14:20:58 +00:00
* Ignore Clipper, libpng, mcut and Boost.Polygon Internals in clang-tidy Each only works through a wrapper or umbrella header: libslic3r/clipper.hpp or clipper_z.hpp configure Clipper before including it, png.h pulls in libpng's config headers, and Boost.Polygon's headers only compile through polygon.hpp or voronoi.hpp. * Ignore minilzo's Config Headers in clang-tidy lzoconf.h and lzodefs.h are internal to minilzo.h, which is what the code includes. * Add Missing Includes Across the Remaining Sources and Tests Covers src/slic3r/Utils, src/slic3r/plugin, src/slic3r/Config, src/libvgcode, src/dev-utils, src/OrcaSlicer.cpp and tests/, the directories left after src/slic3r/GUI and src/libslic3r. Generated with clang-tidy misc-include-cleaner. libvgcode's own headers are included by relative path as in the rest of that library, and Catch2 and pybind11 with angle brackets as elsewhere in the repo. * Make the GUI and Test Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Headers that only compile on one platform, or that nothing built includes, are left alone. * Keep Windows and nanosvg Setup Ahead of the Added Includes OrcaSlicer.cpp and several tests set _WIN32_WINNT, WIN32_LEAN_AND_MEAN or NOMINMAX before including Windows.h, and the profile validator defines NANOSVG_IMPLEMENTATION before any libslic3r header. The added includes had landed above those blocks, which broke the Windows build. * Add the GUI Includes the First Pass Missed Covers headers that only became editable once they compiled on their own, and wx symbols whose suggested header changed as the clang-tidy ignore list grew after the src/slic3r/GUI pass. * Keep the Added Test Includes Below the NOMINMAX Guard test_marchingsquares.cpp and test_texture_displacement.cpp had includes inside #ifndef NOMINMAX, which the tests inherit as defined on Windows from libslic3r, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory, as in #16068.
163 lines
5.9 KiB
C++
163 lines
5.9 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
#include <catch2/catch_all.hpp>
|
|
|
|
#include <slic3r/GUI/DeviceCore/DevManager.h>
|
|
#include <slic3r/GUI/DeviceManager.hpp>
|
|
#include <libslic3r/AppConfig.hpp>
|
|
#include "slic3r/Utils/IPrinterAgent.hpp"
|
|
#include "slic3r/Utils/CloudProvider.hpp"
|
|
#include <slic3r/Utils/NetworkAgent.hpp>
|
|
#include <slic3r/Utils/OrcaCloudServiceAgent.hpp>
|
|
#include <slic3r/Utils/OrcaPrinterAgent.hpp>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include <memory>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <utility>
|
|
|
|
using namespace Slic3r;
|
|
using json = nlohmann::json;
|
|
|
|
namespace {
|
|
|
|
class StubCloudAgent final : public OrcaCloudServiceAgent
|
|
{
|
|
public:
|
|
StubCloudAgent() : OrcaCloudServiceAgent("") {}
|
|
|
|
int get_user_print_info(unsigned int* http_code, std::string* http_body) override
|
|
{
|
|
if (http_code)
|
|
*http_code = 200;
|
|
if (http_body)
|
|
*http_body = R"({"devices":[]})";
|
|
return 0;
|
|
}
|
|
|
|
std::string get_user_name() override { return "integration-test-user"; }
|
|
};
|
|
|
|
class TestPrinterAgent final : public OrcaPrinterAgent
|
|
{
|
|
public:
|
|
explicit TestPrinterAgent(std::string id)
|
|
: OrcaPrinterAgent(""), m_info{std::move(id), "Integration Test Agent", "1.0", "test agent"}
|
|
{
|
|
}
|
|
|
|
AgentInfo get_agent_info() override { return m_info; }
|
|
|
|
private:
|
|
AgentInfo m_info;
|
|
};
|
|
|
|
struct ScopedAppConfig
|
|
{
|
|
AppConfig config;
|
|
};
|
|
|
|
std::string machine_list_response(const std::string& provider, const std::string& agent_id,
|
|
std::uint64_t generation, const std::string& name)
|
|
{
|
|
json machine;
|
|
machine["dev_id"] = "integration-device";
|
|
machine["dev_name"] = name;
|
|
machine["dev_online"] = true;
|
|
machine["task_status"] = "idle";
|
|
|
|
json response;
|
|
response["provider"] = provider;
|
|
response["agent_id"] = agent_id;
|
|
response["generation"] = generation;
|
|
response["devices"] = json::array({machine});
|
|
return response.dump();
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("Network agent stamps user-machine responses with request context", "[DeviceManager][integration]")
|
|
{
|
|
auto cloud = std::make_shared<StubCloudAgent>();
|
|
NetworkAgent network(cloud, nullptr);
|
|
network.set_printer_agent(std::make_shared<TestPrinterAgent>("integration-agent-a"));
|
|
|
|
const std::uint64_t generation_before = network.get_user_machine_list_generation();
|
|
unsigned int http_code = 0;
|
|
std::string body;
|
|
REQUIRE(network.get_user_print_info(&http_code, &body, ORCA_CLOUD_PROVIDER) == 0);
|
|
|
|
const json response = json::parse(body);
|
|
CHECK(http_code == 200);
|
|
CHECK(response["provider"] == ORCA_CLOUD_PROVIDER);
|
|
CHECK(response["agent_id"] == "integration-agent-a");
|
|
CHECK(response["generation"] == generation_before + 1);
|
|
}
|
|
|
|
TEST_CASE("Device manager ignores stale cloud machine responses", "[DeviceManager][integration]")
|
|
{
|
|
ScopedAppConfig app_config;
|
|
NetworkAgent network(nullptr, std::make_shared<TestPrinterAgent>("integration-agent"));
|
|
network.set_printer_agent(std::make_shared<TestPrinterAgent>("integration-agent"));
|
|
DeviceManager manager(&network, false, &app_config.config);
|
|
|
|
const std::uint64_t current_generation = network.get_user_machine_list_generation();
|
|
manager.parse_user_print_info(machine_list_response(ORCA_CLOUD_PROVIDER, "integration-agent",
|
|
current_generation, "Fresh name"));
|
|
|
|
auto machines = manager.get_user_machinelist();
|
|
REQUIRE(machines.size() == 1);
|
|
REQUIRE(machines.at("integration-device") != nullptr);
|
|
CHECK(machines.at("integration-device")->get_dev_name() == "Fresh name");
|
|
|
|
manager.parse_user_print_info(machine_list_response(BBL_CLOUD_PROVIDER, "integration-agent",
|
|
current_generation, "Stale provider"));
|
|
manager.parse_user_print_info(machine_list_response(ORCA_CLOUD_PROVIDER, "other-agent",
|
|
current_generation, "Stale agent"));
|
|
manager.parse_user_print_info(machine_list_response(ORCA_CLOUD_PROVIDER, "integration-agent",
|
|
current_generation + 1, "Stale generation"));
|
|
|
|
machines = manager.get_user_machinelist();
|
|
REQUIRE(machines.size() == 1);
|
|
CHECK(machines.at("integration-device")->get_dev_name() == "Fresh name");
|
|
}
|
|
|
|
TEST_CASE("Device manager filters and rehomes devices by printer-agent ownership", "[DeviceManager][integration]")
|
|
{
|
|
ScopedAppConfig app_config;
|
|
auto agent_a = std::make_shared<TestPrinterAgent>("integration-agent-a");
|
|
auto agent_b = std::make_shared<TestPrinterAgent>("integration-agent-b");
|
|
NetworkAgent network(nullptr, agent_a);
|
|
DeviceManager manager(&network, false, &app_config.config);
|
|
|
|
BBLocalMachine machine;
|
|
machine.dev_id = "integration-lan-device";
|
|
machine.dev_name = "Integration LAN device";
|
|
machine.dev_ip = "192.0.2.10";
|
|
machine.printer_type = "C11";
|
|
|
|
MachineObject* object = manager.insert_local_device(machine, "lan", "free", "", "access-code");
|
|
REQUIRE(object != nullptr);
|
|
CHECK(object->printer_agent_id == "integration-agent-a");
|
|
CHECK(manager.get_my_machine_list("integration-agent-a").count(machine.dev_id) == 1);
|
|
CHECK(manager.get_my_machine_list("integration-agent-b").empty());
|
|
|
|
network.set_printer_agent(agent_b);
|
|
CHECK(manager.get_my_machine_list("integration-agent-b").empty());
|
|
|
|
manager.on_machine_alive(R"({
|
|
"dev_name":"Rediscovered device",
|
|
"dev_id":"integration-lan-device",
|
|
"dev_ip":"192.0.2.10",
|
|
"dev_type":"C11",
|
|
"dev_signal":"strong",
|
|
"connect_type":"lan",
|
|
"bind_state":"free"
|
|
})");
|
|
|
|
CHECK(object->printer_agent_id == "integration-agent-b");
|
|
CHECK(manager.get_my_machine_list("integration-agent-a").empty());
|
|
CHECK(manager.get_my_machine_list("integration-agent-b").count(machine.dev_id) == 1);
|
|
}
|