summaryrefslogtreecommitdiff
path: root/indra/llcommon/tests
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/tests')
-rw-r--r--indra/llcommon/tests/llcond_test.cpp75
-rw-r--r--indra/llcommon/tests/llrand_test.cpp2
2 files changed, 76 insertions, 1 deletions
diff --git a/indra/llcommon/tests/llcond_test.cpp b/indra/llcommon/tests/llcond_test.cpp
index f2a302ed13..7d1ac6edb9 100644
--- a/indra/llcommon/tests/llcond_test.cpp
+++ b/indra/llcommon/tests/llcond_test.cpp
@@ -19,6 +19,7 @@
// other Linden headers
#include "../test/lltut.h"
#include "llcoros.h"
+#include "lldefs.h" // llless()
/*****************************************************************************
* TUT
@@ -64,4 +65,78 @@ namespace tut
cond.set_all(2);
cond.wait_equal(3);
}
+
+ template <typename T0, typename T1>
+ struct compare
+ {
+ const char* desc;
+ T0 lhs;
+ T1 rhs;
+ bool expect;
+
+ void test() const
+ {
+ // fails
+// ensure_equals(desc, (lhs < rhs), expect);
+ ensure_equals(desc, llless(lhs, rhs), expect);
+ }
+ };
+
+ template<> template<>
+ void object::test<3>()
+ {
+ set_test_name("comparison");
+ // Try to construct signed and unsigned variables such that the
+ // compiler can't optimize away the code to compare at runtime.
+ std::istringstream input("-1 10 20 10 20");
+ int minus1, s10, s20;
+ input >> minus1 >> s10 >> s20;
+ unsigned u10, u20;
+ input >> u10 >> u20;
+ ensure_equals("minus1 wrong", minus1, -1);
+ ensure_equals("s10 wrong", s10, 10);
+ ensure_equals("s20 wrong", s20, 20);
+ ensure_equals("u10 wrong", u10, 10);
+ ensure_equals("u20 wrong", u20, 20);
+ // signed < signed should always work!
+ compare<int, int> ss[] =
+ { {"minus1 < s10", minus1, s10, true},
+ {"s10 < s10", s10, s10, false},
+ {"s20 < s10", s20, s20, false}
+ };
+ for (const auto& cmp : ss)
+ {
+ cmp.test();
+ }
+ // unsigned < unsigned should always work!
+ compare<unsigned, unsigned> uu[] =
+ { {"u10 < u20", u10, u20, true},
+ {"u20 < u20", u20, u20, false},
+ {"u20 < u10", u20, u10, false}
+ };
+ for (const auto& cmp : uu)
+ {
+ cmp.test();
+ }
+ // signed < unsigned ??
+ compare<int, unsigned> su[] =
+ { {"minus1 < u10", minus1, u10, true},
+ {"s10 < u10", s10, u10, false},
+ {"s20 < u10", s20, u10, false}
+ };
+ for (const auto& cmp : su)
+ {
+ cmp.test();
+ }
+ // unsigned < signed ??
+ compare<unsigned, int> us[] =
+ { {"u10 < minus1", u10, minus1, false},
+ {"u10 < s10", u10, s10, false},
+ {"u10 < s20", u10, s20, true}
+ };
+ for (const auto& cmp : us)
+ {
+ cmp.test();
+ }
+ }
} // namespace tut
diff --git a/indra/llcommon/tests/llrand_test.cpp b/indra/llcommon/tests/llrand_test.cpp
index a0dd4ef576..85dd53ce96 100644
--- a/indra/llcommon/tests/llrand_test.cpp
+++ b/indra/llcommon/tests/llrand_test.cpp
@@ -38,7 +38,7 @@
// testing extent < 0, negate the return value and the extent before passing
// into ensure_in_range().
template <typename NUMBER>
-void ensure_in_range(const std::string_view& name,
+void ensure_in_range(std::string_view name,
NUMBER value, NUMBER low, NUMBER high)
{
auto failmsg{ stringize(name, " >= ", low, " (", value, ')') };