From d12885d0422708ff7a8af2c463243a00b6ce04f7 Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Fri, 23 Nov 2018 20:15:20 -0600 Subject: [PATCH] use boost::locale instead of corecvt. --- src/test/libslic3r/test_log.cpp | 58 +++++++++++++++++++++++++++++++++ xs/src/libslic3r/Log.cpp | 14 +++++--- xs/src/libslic3r/Log.hpp | 4 --- 3 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/test/libslic3r/test_log.cpp b/src/test/libslic3r/test_log.cpp index bfe26eb36..f502f96f2 100644 --- a/src/test/libslic3r/test_log.cpp +++ b/src/test/libslic3r/test_log.cpp @@ -62,6 +62,64 @@ SCENARIO( "_Log output with std::string methods" ) { } } } +SCENARIO( "_Log output with std::wstring methods" ) { + GIVEN("A log stream and a _Log object") { + std::stringstream log; + std::unique_ptr<_Log> cut { _Log::make_log(log) }; + cut->set_level(log_t::DEBUG); + cut->set_inclusive(true); + WHEN("fatal_error is called with topic \"Topic\" and text \"This\"") { + log.clear(); + cut->fatal_error("Topic", L"This"); + THEN("Output string is Topic FERR: This\\n") { + REQUIRE(log.str() == "Topic FERR: This\n"); + } + } + WHEN("error is called with topic \"Topic\" and text \"This\"") { + log.clear(); + cut->error("Topic", L"This"); + THEN("Output string is Topic ERR: This\\n") { + REQUIRE(log.str() == "Topic ERR: This\n"); + } + } + WHEN("info is called with topic \"Topic\" and text \"This\"") { + log.clear(); + cut->info("Topic", L"This"); + THEN("Output string is Topic INFO: This\\n") { + REQUIRE(log.str() == "Topic INFO: This\n"); + } + } + WHEN("warn is called with topic \"Topic\" and text \"This\"") { + log.clear(); + cut->warn("Topic", L"This"); + THEN("Output string is Topic WARN: This\\n") { + REQUIRE(log.str() == "Topic WARN: This\n"); + } + } + WHEN("info is called with topic \"Topic\" and text \"This\"") { + log.clear(); + cut->info("Topic", L"This"); + THEN("Output string is Topic INFO: This\\n") { + REQUIRE(log.str() == "Topic INFO: This\n"); + } + } + WHEN("debug is called with topic \"Topic\" and text \"This\"") { + log.clear(); + cut->debug("Topic", L"This"); + THEN("Output string is Topic DEBUG: This\\n") { + REQUIRE(log.str() == "Topic DEBUG: This\n"); + } + } + WHEN("msg is called with text \"This\"") { + log.clear(); + cut->raw(L"This"); + THEN("Output string is This\\n") { + REQUIRE(log.str() == "This\n"); + } + } + } +} + SCENARIO( "_Log output with << methods" ) { GIVEN("A log stream and a _Log object") { std::stringstream log; diff --git a/xs/src/libslic3r/Log.cpp b/xs/src/libslic3r/Log.cpp index da2d2af42..b6be76aa5 100644 --- a/xs/src/libslic3r/Log.cpp +++ b/xs/src/libslic3r/Log.cpp @@ -4,6 +4,10 @@ #include #include +// Boost +#include +#include + #include "Log.hpp" /// Local class to suppress output @@ -39,11 +43,11 @@ bool _Log::_has_topic(const std::string& topic) { return this->_topics.find(topic) != this->_topics.end() || this->_topics.size() == 0; } -void _Log::fatal_error(const std::string& topic, const std::wstring& message) { this->fatal_error(topic, this->converter.to_bytes(message)); } -void _Log::error(const std::string& topic, const std::wstring& message) { this->error(topic, this->converter.to_bytes(message)); } -void _Log::warn(const std::string& topic, const std::wstring& message) { this->warn(topic, this->converter.to_bytes(message)); } -void _Log::info(const std::string& topic, const std::wstring& message) { this->info(topic, this->converter.to_bytes(message)); } -void _Log::debug(const std::string& topic, const std::wstring& message) { this->debug(topic, this->converter.to_bytes(message)); } +void _Log::fatal_error(const std::string& topic, const std::wstring& message) { this->fatal_error(topic, boost::locale::conv::utf_to_utf(message)); } +void _Log::error(const std::string& topic, const std::wstring& message) { this->error(topic, boost::locale::conv::utf_to_utf(message)); } +void _Log::warn(const std::string& topic, const std::wstring& message) { this->warn(topic, boost::locale::conv::utf_to_utf(message)); } +void _Log::info(const std::string& topic, const std::wstring& message) { this->info(topic, boost::locale::conv::utf_to_utf(message)); } +void _Log::debug(const std::string& topic, const std::wstring& message) { this->debug(topic, boost::locale::conv::utf_to_utf(message)); } void _Log::fatal_error(const std::string& topic, const std::string& message) { this->fatal_error(topic) << message << std::endl; diff --git a/xs/src/libslic3r/Log.hpp b/xs/src/libslic3r/Log.hpp index 48e309297..123c24f7a 100644 --- a/xs/src/libslic3r/Log.hpp +++ b/xs/src/libslic3r/Log.hpp @@ -6,9 +6,7 @@ #include #include #include -#include #include -#include // good until c++17 namespace Slic3r { @@ -76,8 +74,6 @@ private: std::set _log_level { }; std::set _topics { }; - std::wstring_convert> converter; - bool _has_log_level(log_t lvl); bool _has_topic(const std::string& topic);