From 08e63aee125cf06882fe879ba94467006cb906a8 Mon Sep 17 00:00:00 2001 From: Frank Dellaert Date: Sun, 5 Feb 2023 23:06:06 -0800 Subject: [PATCH] Replace boost lexical casts in CppUnitLite --- CppUnitLite/CMakeLists.txt | 1 - CppUnitLite/Test.cpp | 10 +++++----- CppUnitLite/Test.h | 22 +++++++++++----------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/CppUnitLite/CMakeLists.txt b/CppUnitLite/CMakeLists.txt index ab884ec1d..cbffa79d1 100644 --- a/CppUnitLite/CMakeLists.txt +++ b/CppUnitLite/CMakeLists.txt @@ -6,7 +6,6 @@ file(GLOB cppunitlite_src "*.cpp") add_library(CppUnitLite STATIC ${cppunitlite_src} ${cppunitlite_headers}) list(APPEND GTSAM_EXPORTED_TARGETS CppUnitLite) set(GTSAM_EXPORTED_TARGETS "${GTSAM_EXPORTED_TARGETS}" PARENT_SCOPE) -target_link_libraries(CppUnitLite PUBLIC Boost::boost) # boost/lexical_cast.h gtsam_assign_source_folders("${cppunitlite_headers};${cppunitlite_src}") # MSVC project structure diff --git a/CppUnitLite/Test.cpp b/CppUnitLite/Test.cpp index 78995a219..23bc61417 100644 --- a/CppUnitLite/Test.cpp +++ b/CppUnitLite/Test.cpp @@ -15,7 +15,7 @@ #include "TestResult.h" #include "Failure.h" -#include +#include Test::Test (const std::string& testName) : name_ (testName), next_(0), lineNumber_(-1), safeCheck_(true) @@ -47,10 +47,10 @@ bool Test::check(long expected, long actual, TestResult& result, const std::stri result.addFailure ( Failure ( name_, - boost::lexical_cast (__FILE__), + std::string(__FILE__), __LINE__, - boost::lexical_cast (expected), - boost::lexical_cast (actual))); + std::to_string(expected), + std::to_string(actual))); return false; @@ -64,7 +64,7 @@ bool Test::check(const std::string& expected, const std::string& actual, TestRes result.addFailure ( Failure ( name_, - boost::lexical_cast (__FILE__), + std::string(__FILE__), __LINE__, expected, actual)); diff --git a/CppUnitLite/Test.h b/CppUnitLite/Test.h index a898c83ef..3646a832b 100644 --- a/CppUnitLite/Test.h +++ b/CppUnitLite/Test.h @@ -23,7 +23,7 @@ #include -#include +#include class TestResult; @@ -112,17 +112,17 @@ protected: #define THROWS_EXCEPTION(condition)\ { try { condition; \ - result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Didn't throw: ") + boost::lexical_cast(#condition))); \ + result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Didn't throw: ") + std::string(#condition))); \ return; } \ catch (...) {} } #define CHECK_EXCEPTION(condition, exception_name)\ { try { condition; \ - result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Didn't throw: ") + boost::lexical_cast(#condition))); \ + result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Didn't throw: ") + std::string(#condition))); \ return; } \ catch (exception_name&) {} \ catch (...) { \ - result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Wrong exception: ") + boost::lexical_cast(#condition) + boost::lexical_cast(", expected: ") + boost::lexical_cast(#exception_name))); \ + result_.addFailure (Failure (name_, __FILE__,__LINE__, std::string("Wrong exception: ") + std::string(#condition) + std::string(", expected: ") + std::string(#exception_name))); \ return; } } #define EQUALITY(expected,actual)\ @@ -130,21 +130,21 @@ protected: result_.addFailure(Failure(name_, __FILE__, __LINE__, #expected, #actual)); } #define CHECK_EQUAL(expected,actual)\ -{ if ((expected) == (actual)) return; result_.addFailure(Failure(name_, __FILE__, __LINE__, boost::lexical_cast(expected), boost::lexical_cast(actual))); } +{ if ((expected) == (actual)) return; result_.addFailure(Failure(name_, __FILE__, __LINE__, std::to_string(expected), std::to_string(actual))); } #define LONGS_EQUAL(expected,actual)\ { long actualTemp = actual; \ long expectedTemp = expected; \ if ((expectedTemp) != (actualTemp)) \ -{ result_.addFailure (Failure (name_, __FILE__, __LINE__, boost::lexical_cast(expectedTemp), \ -boost::lexical_cast(actualTemp))); return; } } +{ result_.addFailure (Failure (name_, __FILE__, __LINE__, std::to_string(expectedTemp), \ +std::to_string(actualTemp))); return; } } #define DOUBLES_EQUAL(expected,actual,threshold)\ { double actualTemp = actual; \ double expectedTemp = expected; \ if (!std::isfinite(actualTemp) || !std::isfinite(expectedTemp) || fabs ((expectedTemp)-(actualTemp)) > threshold) \ { result_.addFailure (Failure (name_, __FILE__, __LINE__, \ -boost::lexical_cast((double)expectedTemp), boost::lexical_cast((double)actualTemp))); return; } } +std::to_string(expectedTemp), std::to_string(actualTemp))); return; } } /* EXPECTs: tests will continue running after a failure */ @@ -156,15 +156,15 @@ boost::lexical_cast((double)expectedTemp), boost::lexical_cast(expectedTemp), \ -boost::lexical_cast(actualTemp))); } } +{ result_.addFailure (Failure (name_, __FILE__, __LINE__, std::to_string(expectedTemp), \ +std::to_string(actualTemp))); } } #define EXPECT_DOUBLES_EQUAL(expected,actual,threshold)\ { double actualTemp = actual; \ double expectedTemp = expected; \ if (!std::isfinite(actualTemp) || !std::isfinite(expectedTemp) || fabs ((expectedTemp)-(actualTemp)) > threshold) \ { result_.addFailure (Failure (name_, __FILE__, __LINE__, \ -boost::lexical_cast((double)expectedTemp), boost::lexical_cast((double)actualTemp))); } } +std::to_string(expectedTemp), std::to_string(actualTemp))); } } #define FAIL(text) \