mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-23 06:01:14 -05:00
* fix(test): keep embedded Python alive across slic3rutils cases * fix: clang-tidy
93 lines
2.7 KiB
C++
93 lines
2.7 KiB
C++
#include <catch2/catch_all.hpp>
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
|
#include <catch2/reporters/catch_reporter_event_listener.hpp>
|
|
#include <catch2/reporters/catch_reporter_registrars.hpp>
|
|
|
|
#include <slic3r/plugin/PluginManager.hpp>
|
|
#include <slic3r/plugin/PythonInterpreter.hpp>
|
|
|
|
#include "catch2/interfaces/catch_interfaces_reporter.hpp"
|
|
#include "slic3r/Utils/Http.hpp"
|
|
|
|
namespace {
|
|
|
|
// Finalizes the embedded interpreter once, after the last test case, and never between cases.
|
|
// CPython cannot be reinitialized after Py_Finalize (a second init aborts inside _datetime), and
|
|
// the app likewise finalizes it only at exit, so the per-test fixtures tear down only the
|
|
// PluginManager. Running at the end of the run, rather than from a static destructor, also keeps
|
|
// shutdown()'s logging ahead of boost::log's teardown.
|
|
class PythonInterpreterRunEnd final : public Catch::EventListenerBase
|
|
{
|
|
public:
|
|
using Catch::EventListenerBase::EventListenerBase;
|
|
|
|
void testRunEnded(const Catch::TestRunStats&) override
|
|
{
|
|
if (!Slic3r::PythonInterpreter::instance().is_initialized())
|
|
return;
|
|
Slic3r::PluginManager::instance().shutdown();
|
|
Slic3r::PythonInterpreter::instance().shutdown();
|
|
}
|
|
};
|
|
|
|
} // namespace
|
|
|
|
CATCH_REGISTER_LISTENER(PythonInterpreterRunEnd)
|
|
|
|
TEST_CASE("Check SSL certificates paths", "[Http][NotWorking]") {
|
|
|
|
Slic3r::Http g = Slic3r::Http::get("https://github.com/");
|
|
|
|
unsigned status = 0;
|
|
g.on_error([&status](std::string, std::string, unsigned http_status) {
|
|
status = http_status;
|
|
});
|
|
|
|
g.on_complete([&status](std::string /* body */, unsigned http_status){
|
|
status = http_status;
|
|
});
|
|
|
|
g.perform_sync();
|
|
|
|
REQUIRE(status == 200);
|
|
}
|
|
|
|
TEST_CASE("Http digest authentication", "[Http][NotWorking]") {
|
|
Slic3r::Http g = Slic3r::Http::get("https://httpbingo.org/digest-auth/auth/guest/guest");
|
|
|
|
g.auth_digest("guest", "guest");
|
|
|
|
unsigned status = 0;
|
|
g.on_error([&status](std::string, std::string, unsigned http_status) {
|
|
status = http_status;
|
|
});
|
|
|
|
g.on_complete([&status](std::string /* body */, unsigned http_status){
|
|
status = http_status;
|
|
});
|
|
|
|
g.perform_sync();
|
|
|
|
REQUIRE(status == 200);
|
|
}
|
|
|
|
TEST_CASE("Http basic authentication", "[Http][NotWorking]") {
|
|
Slic3r::Http g = Slic3r::Http::get("https://httpbingo.org/basic-auth/guest/guest");
|
|
|
|
g.auth_basic("guest", "guest");
|
|
|
|
unsigned status = 0;
|
|
g.on_error([&status](std::string, std::string, unsigned http_status) {
|
|
status = http_status;
|
|
});
|
|
|
|
g.on_complete([&status](std::string /* body */, unsigned http_status){
|
|
status = http_status;
|
|
});
|
|
|
|
g.perform_sync();
|
|
|
|
REQUIRE(status == 200);
|
|
}
|