Merge branch 'tm_https_test'

This commit is contained in:
tamasmeszaros 2020-03-06 15:20:21 +01:00
commit 779f0cd915
8 changed files with 52 additions and 48 deletions

View File

@ -328,13 +328,21 @@ find_package(TBB REQUIRED)
# add_definitions(-DTBB_USE_CAPTURED_EXCEPTION=0) # add_definitions(-DTBB_USE_CAPTURED_EXCEPTION=0)
find_package(CURL REQUIRED) find_package(CURL REQUIRED)
include_directories(${CURL_INCLUDE_DIRS})
add_library(libcurl INTERFACE)
target_link_libraries(libcurl INTERFACE CURL::libcurl)
if (NOT WIN32)
# Required by libcurl
find_package(ZLIB REQUIRED)
target_link_libraries(libcurl INTERFACE ZLIB::ZLIB)
endif()
if (SLIC3R_STATIC) if (SLIC3R_STATIC)
if (NOT APPLE) if (NOT APPLE)
# libcurl is always linked dynamically to the system libcurl on OSX. # libcurl is always linked dynamically to the system libcurl on OSX.
# On other systems, libcurl is linked statically if SLIC3R_STATIC is set. # On other systems, libcurl is linked statically if SLIC3R_STATIC is set.
add_definitions(-DCURL_STATICLIB) target_compile_definitions(libcurl INTERFACE CURL_STATICLIB)
endif() endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Linux") if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
# As of now, our build system produces a statically linked libcurl, # As of now, our build system produces a statically linked libcurl,
@ -342,7 +350,8 @@ if (SLIC3R_STATIC)
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}") message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
message("OpenSSL libraries: ${OPENSSL_LIBRARIES}") message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
include_directories(${OPENSSL_INCLUDE_DIR}) target_include_directories(libcurl INTERFACE ${OPENSSL_INCLUDE_DIR})
target_link_libraries(libcurl INTERFACE ${OPENSSL_LIBRARIES})
endif() endif()
endif() endif()

View File

@ -104,33 +104,7 @@ endif ()
# Add the Slic3r GUI library, libcurl, OpenGL and GLU libraries. # Add the Slic3r GUI library, libcurl, OpenGL and GLU libraries.
if (SLIC3R_GUI) if (SLIC3R_GUI)
# target_link_libraries(PrusaSlicer ws2_32 uxtheme setupapi libslic3r_gui ${wxWidgets_LIBRARIES}) # target_link_libraries(PrusaSlicer ws2_32 uxtheme setupapi libslic3r_gui ${wxWidgets_LIBRARIES})
target_link_libraries(PrusaSlicer libslic3r_gui ${wxWidgets_LIBRARIES}) target_link_libraries(PrusaSlicer libslic3r_gui)
# Configure libcurl and its dependencies OpenSSL & zlib
find_package(CURL REQUIRED)
if (NOT WIN32)
# Required by libcurl
find_package(ZLIB REQUIRED)
endif()
target_include_directories(PrusaSlicer PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(PrusaSlicer ${CURL_LIBRARIES} ${ZLIB_LIBRARIES})
if (SLIC3R_STATIC)
if (NOT APPLE)
# libcurl is always linked dynamically to the system libcurl on OSX.
# On other systems, libcurl is linked statically if SLIC3R_STATIC is set.
target_compile_definitions(PrusaSlicer PRIVATE CURL_STATICLIB)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
# As of now, our build system produces a statically linked libcurl,
# which links the OpenSSL library dynamically.
find_package(OpenSSL REQUIRED)
message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
target_include_directories(PrusaSlicer PRIVATE ${OPENSSL_INCLUDE_DIR})
target_link_libraries(PrusaSlicer ${OPENSSL_LIBRARIES})
endif()
endif()
if (MSVC) if (MSVC)
# Generate debug symbols even in release mode. # Generate debug symbols even in release mode.
target_link_options(PrusaSlicer PUBLIC "$<$<CONFIG:RELEASE>:/DEBUG>") target_link_options(PrusaSlicer PUBLIC "$<$<CONFIG:RELEASE>:/DEBUG>")

View File

@ -191,7 +191,7 @@ add_library(libslic3r_gui STATIC ${SLIC3R_GUI_SOURCES})
encoding_check(libslic3r_gui) encoding_check(libslic3r_gui)
target_link_libraries(libslic3r_gui libslic3r avrdude cereal imgui GLEW::GLEW OpenGL::GL OpenGL::GLU hidapi) target_link_libraries(libslic3r_gui libslic3r avrdude cereal imgui GLEW::GLEW OpenGL::GL OpenGL::GLU hidapi libcurl ${wxWidgets_LIBRARIES})
if(APPLE) if(APPLE)
target_link_libraries(libslic3r_gui ${DISKARBITRATION_LIBRARY}) target_link_libraries(libslic3r_gui ${DISKARBITRATION_LIBRARY})

View File

@ -29,7 +29,7 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
add_subdirectory(libnest2d) add_subdirectory(libnest2d)
add_subdirectory(libslic3r) add_subdirectory(libslic3r)
add_subdirectory(timeutils) add_subdirectory(slic3rutils)
add_subdirectory(fff_print) add_subdirectory(fff_print)
add_subdirectory(sla_print) add_subdirectory(sla_print)
add_subdirectory(cpp17 EXCLUDE_FROM_ALL) # does not have to be built all the time add_subdirectory(cpp17 EXCLUDE_FROM_ALL) # does not have to be built all the time

View File

@ -13,6 +13,7 @@ add_executable(${_TEST_NAME}_tests
test_stl.cpp test_stl.cpp
test_meshsimplify.cpp test_meshsimplify.cpp
test_meshboolean.cpp test_meshboolean.cpp
test_timeutils.cpp
) )
if (TARGET OpenVDB::openvdb) if (TARGET OpenVDB::openvdb)

View File

@ -1,4 +1,4 @@
#include <catch_main.hpp> #include <catch2/catch.hpp>
#include "libslic3r/Time.hpp" #include "libslic3r/Time.hpp"
@ -6,45 +6,44 @@
#include <iomanip> #include <iomanip>
#include <locale> #include <locale>
namespace { using namespace Slic3r;
void test_time_fmt(Slic3r::Utils::TimeFormat fmt) { static void test_time_fmt(Slic3r::Utils::TimeFormat fmt) {
using namespace Slic3r::Utils; using namespace Slic3r::Utils;
time_t t = get_current_time_utc(); time_t t = get_current_time_utc();
std::string tstr = time2str(t, TimeZone::local, fmt); std::string tstr = time2str(t, TimeZone::local, fmt);
time_t parsedtime = str2time(tstr, TimeZone::local, fmt); time_t parsedtime = str2time(tstr, TimeZone::local, fmt);
REQUIRE(t == parsedtime); REQUIRE(t == parsedtime);
tstr = time2str(t, TimeZone::utc, fmt); tstr = time2str(t, TimeZone::utc, fmt);
parsedtime = str2time(tstr, TimeZone::utc, fmt); parsedtime = str2time(tstr, TimeZone::utc, fmt);
REQUIRE(t == parsedtime); REQUIRE(t == parsedtime);
parsedtime = str2time("not valid string", TimeZone::local, fmt); parsedtime = str2time("not valid string", TimeZone::local, fmt);
REQUIRE(parsedtime == time_t(-1)); REQUIRE(parsedtime == time_t(-1));
parsedtime = str2time("not valid string", TimeZone::utc, fmt); parsedtime = str2time("not valid string", TimeZone::utc, fmt);
REQUIRE(parsedtime == time_t(-1)); REQUIRE(parsedtime == time_t(-1));
} }
}
TEST_CASE("ISO8601Z", "[Timeutils]") { TEST_CASE("ISO8601Z", "[Timeutils]") {
test_time_fmt(Slic3r::Utils::TimeFormat::iso8601Z); test_time_fmt(Slic3r::Utils::TimeFormat::iso8601Z);
std::string mydate = "20190710T085000Z"; std::string mydate = "20190710T085000Z";
time_t t = Slic3r::Utils::parse_iso_utc_timestamp(mydate); time_t t = Slic3r::Utils::parse_iso_utc_timestamp(mydate);
std::string date = Slic3r::Utils::iso_utc_timestamp(t); std::string date = Slic3r::Utils::iso_utc_timestamp(t);
REQUIRE(date == mydate); REQUIRE(date == mydate);
} }
TEST_CASE("Slic3r_UTC_Time_Format", "[Timeutils]") { TEST_CASE("Slic3r_UTC_Time_Format", "[Timeutils]") {
using namespace Slic3r::Utils; using namespace Slic3r::Utils;
test_time_fmt(TimeFormat::gcode); test_time_fmt(TimeFormat::gcode);
std::string mydate = "2019-07-10 at 08:50:00 UTC"; std::string mydate = "2019-07-10 at 08:50:00 UTC";
time_t t = Slic3r::Utils::str2time(mydate, TimeZone::utc, TimeFormat::gcode); time_t t = Slic3r::Utils::str2time(mydate, TimeZone::utc, TimeFormat::gcode);
std::string date = Slic3r::Utils::utc_timestamp(t); std::string date = Slic3r::Utils::utc_timestamp(t);
REQUIRE(date == mydate); REQUIRE(date == mydate);
} }

View File

@ -1,11 +1,10 @@
get_filename_component(_TEST_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) get_filename_component(_TEST_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
add_executable(${_TEST_NAME}_tests add_executable(${_TEST_NAME}_tests
${_TEST_NAME}_tests_main.cpp ${_TEST_NAME}_tests_main.cpp
${PROJECT_SOURCE_DIR}/src/libslic3r/Time.cpp
${PROJECT_SOURCE_DIR}/src/libslic3r/Time.hpp
) )
target_link_libraries(${_TEST_NAME}_tests test_common)
target_link_libraries(${_TEST_NAME}_tests test_common libslic3r_gui)
set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests") set_property(TARGET ${_TEST_NAME}_tests PROPERTY FOLDER "tests")
# catch_discover_tests(${_TEST_NAME}_tests TEST_PREFIX "${_TEST_NAME}: ") # catch_discover_tests(${_TEST_NAME}_tests TEST_PREFIX "${_TEST_NAME}: ")
add_test(${_TEST_NAME}_tests ${_TEST_NAME}_tests ${CATCH_EXTRA_ARGS}) add_test(${_TEST_NAME}_tests ${_TEST_NAME}_tests "${CATCH_EXTRA_ARGS} exclude:[NotWorking]")

View File

@ -0,0 +1,22 @@
#include <catch_main.hpp>
#include "slic3r/Utils/Http.hpp"
TEST_CASE("Http", "[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);
}