From d88856a9942433b184b70cc6e2b305d9ae551c09 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Wed, 10 Dec 2014 11:25:20 +0100 Subject: [PATCH] Fix failing unit tests refs #8043 --- lib/base/convert.cpp | 5 ----- lib/base/convert.hpp | 5 ++++- test/base-convert.cpp | 6 ++++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/base/convert.cpp b/lib/base/convert.cpp index 12a074e52..f90be4b77 100644 --- a/lib/base/convert.cpp +++ b/lib/base/convert.cpp @@ -22,11 +22,6 @@ using namespace icinga; -bool Convert::ToBool(const String& val) -{ - return (ToLong(val) != 0); -} - String Convert::ToString(const String& val) { return val; diff --git a/lib/base/convert.hpp b/lib/base/convert.hpp index 2b152d488..f637ac8f6 100644 --- a/lib/base/convert.hpp +++ b/lib/base/convert.hpp @@ -64,7 +64,10 @@ public: return val; } - static bool ToBool(const String& val); + static inline bool ToBool(const Value& val) + { + return val.ToBool(); + } template static String ToString(const T& val) diff --git a/test/base-convert.cpp b/test/base-convert.cpp index 0eaa35db1..574e14665 100644 --- a/test/base-convert.cpp +++ b/test/base-convert.cpp @@ -60,10 +60,12 @@ BOOST_AUTO_TEST_CASE(tostring) BOOST_AUTO_TEST_CASE(tobool) { - BOOST_CHECK_THROW(Convert::ToBool("a"), boost::exception); - BOOST_CHECK(Convert::ToBool("0") == false); + BOOST_CHECK(Convert::ToBool("a") == true); + BOOST_CHECK(Convert::ToBool("0") == true); BOOST_CHECK(Convert::ToBool("1") == true); BOOST_CHECK(Convert::ToBool("2") == true); + BOOST_CHECK(Convert::ToBool(1) == true); + BOOST_CHECK(Convert::ToBool(0) == false); BOOST_CHECK(Convert::ToBool(Value(true)) == true); BOOST_CHECK(Convert::ToBool(Value(false)) == false); } -- 2.40.0