summaryrefslogtreecommitdiff
path: root/indra/test
diff options
context:
space:
mode:
authorMaxim Nikolenko <maximnproductengine@lindenlab.com>2024-10-10 17:06:08 +0300
committerGitHub <noreply@github.com>2024-10-10 17:06:08 +0300
commitd69ad11a8d0d1a3b02ff75fdec7e2b230a526abc (patch)
treede6035b1b6379d6ef79260e3ce8c9e5cfb75767d /indra/test
parent3091985d31e1ccf9aba159dec4f2d5ea31723ce0 (diff)
parentd5218c05219a6bddb63d752a9df3b5d6fe1e3cf7 (diff)
Merge branch 'develop' into maxim/lua-nearby-avatars
Diffstat (limited to 'indra/test')
-rw-r--r--indra/test/lltut.h47
1 files changed, 18 insertions, 29 deletions
diff --git a/indra/test/lltut.h b/indra/test/lltut.h
index fbf60444be..986bdd0619 100644
--- a/indra/test/lltut.h
+++ b/indra/test/lltut.h
@@ -30,8 +30,10 @@
#define LL_LLTUT_H
#include "is_approx_equal_fraction.h" // instead of llmath.h
+#include "stringize.h"
#include <cstring>
#include <string>
+#include <string_view>
#include <vector>
class LLDate;
@@ -89,49 +91,38 @@ namespace tut
// The functions BELOW this point actually consume tut.hpp functionality.
namespace tut
{
- inline void ensure_approximately_equals(const char* msg, F64 actual, F64 expected, U32 frac_bits)
+ template <typename F> // replace with C++20 floating-point concept
+ inline void ensure_approximately_equals(std::string_view msg, F actual, F expected, U32 frac_bits)
{
if(!is_approx_equal_fraction(actual, expected, frac_bits))
{
- std::stringstream ss;
- ss << (msg?msg:"") << (msg?": ":"") << "not equal actual: " << actual << " expected: " << expected;
- throw tut::failure(ss.str().c_str());
+ throw tut::failure(stringize(msg, (msg.empty()?"":": "), "not equal actual: ",
+ actual, " expected: ", expected));
}
}
- inline void ensure_approximately_equals(const char* msg, F32 actual, F32 expected, U32 frac_bits)
+ template <typename F> // replace with C++20 floating-point concept
+ inline void ensure_approximately_equals(F actual, F expected, U32 frac_bits)
{
- if(!is_approx_equal_fraction(actual, expected, frac_bits))
- {
- std::stringstream ss;
- ss << (msg?msg:"") << (msg?": ":"") << "not equal actual: " << actual << " expected: " << expected;
- throw tut::failure(ss.str().c_str());
- }
- }
-
- inline void ensure_approximately_equals(F32 actual, F32 expected, U32 frac_bits)
- {
- ensure_approximately_equals(NULL, actual, expected, frac_bits);
+ ensure_approximately_equals("", actual, expected, frac_bits);
}
- inline void ensure_approximately_equals_range(const char *msg, F32 actual, F32 expected, F32 delta)
+ template <typename F> // replace with C++20 floating-point concept
+ inline void ensure_approximately_equals_range(std::string_view msg, F actual, F expected, F delta)
{
if (fabs(actual-expected)>delta)
{
- std::stringstream ss;
- ss << (msg?msg:"") << (msg?": ":"") << "not equal actual: " << actual << " expected: " << expected << " tolerance: " << delta;
- throw tut::failure(ss.str().c_str());
+ throw tut::failure(stringize(msg, (msg.empty()?"":": "), "not equal actual: ",
+ actual, " expected: ", expected, " tolerance: ", delta));
}
}
- inline void ensure_memory_matches(const char* msg,const void* actual, U32 actual_len, const void* expected,U32 expected_len)
+ inline void ensure_memory_matches(std::string_view msg,const void* actual, U32 actual_len, const void* expected,U32 expected_len)
{
if((expected_len != actual_len) ||
(std::memcmp(actual, expected, actual_len) != 0))
{
- std::stringstream ss;
- ss << (msg?msg:"") << (msg?": ":"") << "not equal";
- throw tut::failure(ss.str().c_str());
+ throw tut::failure(stringize(msg, (msg.empty()?"":": "), "not equal"));
}
}
@@ -141,20 +132,18 @@ namespace tut
}
template <class T,class Q>
- void ensure_not_equals(const char* msg,const Q& actual,const T& expected)
+ void ensure_not_equals(std::string_view msg,const Q& actual,const T& expected)
{
if( expected == actual )
{
- std::stringstream ss;
- ss << (msg?msg:"") << (msg?": ":"") << "both equal " << expected;
- throw tut::failure(ss.str().c_str());
+ throw tut::failure(stringize(msg, (msg.empty()?"":": "), "both equal ", expected));
}
}
template <class T,class Q>
void ensure_not_equals(const Q& actual,const T& expected)
{
- ensure_not_equals(NULL, actual, expected);
+ ensure_not_equals("", actual, expected);
}
}