mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-23 06:01:14 -05:00
tests/CATCH2.md says to run the suites with `--order rand --warn NoAssertions`. On main that fails in fff_print (8 test cases), libslic3r (15), sla_print (1) and slic3rutils (4), even when each case runs alone. ctest never passed the flag, so nothing stopped new ones. Most of these tests have SECTIONs that only set up state, with the assertions after them, or generated cases that return early for combinations that don't apply. Catch2 counts assertions per section, so each of those reads as an empty test. Where only a value or a short setup changes, use GENERATE or a table and generate only the combinations that apply. Elsewhere, end each section with a call to a local check. ctest now passes `--warn NoAssertions`, so CI fails a case or section that asserts nothing, and tests/AGENTS.md says so. ctest also passes the CATCH_EXTRA_ARGS cache variable, which nothing read before, split like a command line, so setting it now takes effect. Three tests only wrote a debug mesh or diagram and asserted nothing. They now check that the Voronoi diagram of the six points is complete, that hollowing with hfRemoveInsideTriangles removes at least half of the roughly 400 mm² of the two spheres that lies deeper than the wall, and that the half cone is closed. The legacy 3MF scenario checked for a volume map on every plate of a file that has none, so it now also saves and loads a project with a plate, and its name says so.
116 lines
3.5 KiB
C++
116 lines
3.5 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
|
|
#include <utility>
|
|
#include <memory>
|
|
#include <vector>
|
|
#include <functional>
|
|
|
|
#include "slic3r/Utils/bambu_networking.hpp"
|
|
#include "slic3r/Utils/MoonrakerPrinterAgent.hpp"
|
|
#include "slic3r/Utils/NetworkAgent.hpp"
|
|
|
|
using namespace Slic3r;
|
|
|
|
namespace {
|
|
|
|
class DiscoverySource : public MoonrakerPrinterAgent
|
|
{
|
|
public:
|
|
DiscoverySource() : MoonrakerPrinterAgent("") {}
|
|
|
|
OnMsgArrivedFn discovery_callback;
|
|
|
|
int set_on_ssdp_msg_fn(OnMsgArrivedFn fn) override
|
|
{
|
|
discovery_callback = std::move(fn);
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("Queued discovery cannot cross printer agent sessions", "[NetworkDiscovery]")
|
|
{
|
|
auto source = std::make_shared<DiscoverySource>();
|
|
NetworkAgent network(nullptr, source);
|
|
std::vector<std::function<void()>> pending;
|
|
std::vector<std::string> delivered;
|
|
network.set_queue_on_main_fn([&](std::function<void()> fn) { pending.push_back(std::move(fn)); });
|
|
network.set_on_ssdp_msg_fn([&](std::string payload) { delivered.push_back(std::move(payload)); });
|
|
|
|
auto outgoing_callback = source->discovery_callback;
|
|
outgoing_callback("unsaved-device");
|
|
outgoing_callback("saved-moonraker-device");
|
|
REQUIRE(delivered.empty());
|
|
REQUIRE(pending.size() == 2);
|
|
|
|
const auto check_session_change = [&](bool expect_active) {
|
|
for (auto& fn : pending)
|
|
fn();
|
|
pending.clear();
|
|
REQUIRE(delivered.empty());
|
|
|
|
outgoing_callback("late-outgoing-device");
|
|
REQUIRE(pending.empty());
|
|
REQUIRE(delivered.empty());
|
|
|
|
if (expect_active) {
|
|
auto active = std::dynamic_pointer_cast<DiscoverySource>(network.get_printer_agent());
|
|
REQUIRE(active);
|
|
REQUIRE(active->discovery_callback);
|
|
active->discovery_callback("active-device");
|
|
REQUIRE(delivered.empty());
|
|
REQUIRE(pending.size() == 1);
|
|
pending.front()();
|
|
REQUIRE(delivered == std::vector<std::string>{"active-device"});
|
|
}
|
|
};
|
|
|
|
SECTION("Switch to another agent")
|
|
{
|
|
network.set_printer_agent(std::make_shared<DiscoverySource>());
|
|
check_session_change(true);
|
|
}
|
|
SECTION("Clear the live agent")
|
|
{
|
|
network.set_printer_agent(nullptr);
|
|
check_session_change(false);
|
|
}
|
|
SECTION("Switch away and back to the cached agent")
|
|
{
|
|
network.set_printer_agent(std::make_shared<DiscoverySource>());
|
|
network.set_printer_agent(source);
|
|
check_session_change(true);
|
|
}
|
|
SECTION("Unregister discovery")
|
|
{
|
|
network.set_on_ssdp_msg_fn(nullptr);
|
|
check_session_change(false);
|
|
}
|
|
SECTION("Replace the discovery listener")
|
|
{
|
|
network.set_on_ssdp_msg_fn([&](std::string payload) { delivered.push_back(std::move(payload)); });
|
|
check_session_change(true);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Discovery callbacks expire when networking is destroyed", "[NetworkDiscovery]")
|
|
{
|
|
auto source = std::make_shared<DiscoverySource>();
|
|
std::vector<std::function<void()>> pending;
|
|
unsigned delivered = 0;
|
|
{
|
|
NetworkAgent network(nullptr, source);
|
|
network.set_queue_on_main_fn([&](std::function<void()> fn) { pending.push_back(std::move(fn)); });
|
|
network.set_on_ssdp_msg_fn([&](std::string) { ++delivered; });
|
|
source->discovery_callback("queued-device");
|
|
}
|
|
|
|
REQUIRE(pending.size() == 1);
|
|
pending.front()();
|
|
pending.clear();
|
|
source->discovery_callback("late-device");
|
|
REQUIRE(pending.empty());
|
|
REQUIRE(delivered == 0);
|
|
}
|