4#include <gtest/gtest.h>
5#include <gtest/gtest-skip-exception.h>
7#include "system/shared_ptr.h"
8#include "system/decimal.h"
9#include "system/array.h"
10#include "system/collections/list.h"
11#include "system/collections/dictionary.h"
12#include "system/collections/sorted_dictionary.h"
13#include "system/collections/sorted_list.h"
14#include "system/collections/stack.h"
15#include "system/collections/queue.h"
16#include "system/collections/bitarray.h"
17#include "system/collections/specialized/string_collection.h"
18#include "system/collections/hashset.h"
19#include "system/object_ext.h"
20#include "system/value_tuple.h"
22#include "system/test_tools/test_tools.h"
23#include "system/test_tools/compare.h"
30namespace TestPredicates
42template <
typename T1,
typename T2>
43testing::AssertionResult
AreEqual(
const char* lhs_expr,
const char* rhs_expr, T1&& lhs, T2&& rhs);
52template<
typename T1,
typename T2>
53using AreFPandArithmetic = std::integral_constant<bool, (std::is_floating_point<T1>::value && std::is_arithmetic<T2>::value) || (std::is_arithmetic<T1>::value && std::is_floating_point<T2>::value) >;
59template<
typename T1,
typename T2>
60using AnyOfDecimal = std::integral_constant<bool, std::is_same<T1, System::Decimal>::value || std::is_same<T2, System::Decimal>::value>;
66template<
typename T1,
typename T2,
typename Enable =
void>
69template<
typename T1,
typename T2>
70struct LargestFPType<T1, T2, typename std::enable_if<std::is_floating_point<T1>::value && !std::is_floating_point<T2>::value>::type>
76template<
typename T1,
typename T2>
77struct LargestFPType<T1, T2, typename std::enable_if<std::is_floating_point<T2>::value && !std::is_floating_point<T1>::value>::type>
83template<
typename T1,
typename T2>
84struct LargestFPType<T1, T2, typename std::enable_if<std::is_floating_point<T1>::value && std::is_floating_point<T2>::value>::type>
87 using type =
typename std::conditional<
sizeof(T1) >=
sizeof(T2), T1, T2>::type;
94template<
typename T,
typename Enable =
void>
100 , decltype((void)(
PrintTo(std::declval<T&>(), std::declval<std::ostream*>())))
101> : std::true_type {};
106template<
typename T,
typename Enable =
void>
112 , decltype((void)(std::declval<T>().data()))
113> : std::true_type {};
119> : std::false_type {};
124using IsArray = std::is_same<T, System::Array<typename T::ValueType>>;
129using IsList = std::is_same<T, System::Collections::Generic::List<typename T::ValueType>>;
135template<
typename T1,
typename T2>
141template<
typename T,
typename Enable =
void>
147 , decltype((void)(std::declval<typename T::ValueType>()))
148> : std::is_base_of<System::Collections::Generic::IEnumerable<typename T::ValueType>, T> {};
154template <
typename T1,
typename T2>
162template<
typename T,
typename Enable =
void>
168 , decltype(std::declval<typename T::iterator>(), std::declval<typename T::const_iterator>(), void(0))
169> : std::true_type {};
176std::enable_if_t<!TypeTraits::IsEnumerable<T>::value, std::string>
180std::enable_if_t<TypeTraits::IsEnumerable<T>::value, std::string>
193typename std::enable_if<System::Details::HasToString<T>::value, std::string>::type
198 return value->ToString().ToUtf8String();
210typename std::enable_if<System::Details::HasToString<T>::value, std::string>::type
213 if (
auto ptr =
value.lock())
215 return ptr->ToString().ToUtf8String();
227typename std::enable_if<!TypeTraits::has_print_to_method<T>::value && System::Details::HasToString<T>::value, std::string>::type
231 return const_cast<T&
>(
value).ToString().ToUtf8String();
244 ::std::stringstream ss;
268template<
typename T1,
typename T2>
272 std::ostringstream os;
283template<
typename T1,
typename T2>
287 std::ostringstream os;
298typename std::enable_if<TypeTraits::IsCppContainer<T>::value && !std::is_base_of<Object, T>::value, std::string>::type
302 std::ostringstream ostr;
303 const size_t kMaxCount = 32;
307 for (
auto it = container.begin();
308 it != container.end(); ++it, ++count) {
311 if (count == kMaxCount) {
337 return ::testing::PrintToString(
value);
344std::enable_if_t<!TypeTraits::IsEnumerable<T>::value, std::string>
361 std::ostringstream ostr;
362 const size_t kMaxCount = 32;
366 while (enumerator->MoveNext())
370 if (count == kMaxCount)
378 ostr << enumerator->get_Current();
387std::enable_if_t<TypeTraits::IsEnumerable<T>::value, std::string>
390 std::ostringstream ostr;
391 const size_t kMaxCount = 32;
396 auto enumerator =
const_cast<T&
>(
value).GetEnumerator();
397 while (enumerator->MoveNext())
402 if (count == kMaxCount) {
426template<
typename T1,
typename T2>
427testing::AssertionResult
EqFailure(
const char* lhs_expr,
const char* rhs_expr
431 return testing::internal::EqFailure(lhs_expr,
445template<
typename T1,
typename T2>
446testing::AssertionResult
NotEqFailure(
const char* lhs_expr,
const char* rhs_expr
450 return testing::AssertionFailure()
451 <<
"Expected: (" << lhs_expr <<
") != (" << rhs_expr
463template<
typename T1,
typename T2>
464testing::AssertionResult
SameFailure(
const char* lhs_expr,
const char* rhs_expr
468 return testing::AssertionFailure()
469 <<
"Expected: (" << lhs_expr <<
") same (" << rhs_expr
481template<
typename T1,
typename T2>
482testing::AssertionResult
NotSameFailure(
const char* lhs_expr,
const char* rhs_expr
486 return testing::AssertionFailure()
487 <<
"Expected: (" << lhs_expr <<
") isn't same (" << rhs_expr
492namespace SharedPtrAsserts
501template<
typename T1,
typename T2>
506 return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
514template<
typename T1,
typename T2>
519 return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(),
520 [](
const typename T1::value_type &l,
const typename T2::value_type &r)
522 return System::Object::Equals(l, r);
533template<
typename T1,
typename T2>
538 return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(),
539 [](
const typename T1::value_type &l,
const typename T2::value_type &r)
541 return System::Object::Equals(l, r);
551template<
typename T1,
typename T2>
556 return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
565typename std::enable_if<!System::IsSmartPtr<typename T::value_type>::value
580 return lhs.size() == rhs.size() && std::all_of(lhs.begin(), lhs.end(),
581 [&rhs](
const typename T::value_type
value)
583 auto it = rhs.find(value.first);
584 return it != rhs.end() && System::Object::Equals(value.second, it->second);
598template<
typename T1,
typename T2>
599typename std::enable_if<TypeTraits::BothArrayOrList<typename T1::Pointee_, typename T2::Pointee_>::value
600, testing::AssertionResult>::type
602 ,
const T1& lhs,
const T2& rhs,
long long s)
606 return testing::AssertionSuccess();
608 return EqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
621template<
typename T1,
typename T2>
622typename std::enable_if<
627 testing::AssertionResult
629 ,
const T1& lhs,
const T2& rhs,
long long s)
631 auto lhEnumerable = ExplicitCast<System::Collections::Generic::IEnumerable<typename T1::Pointee_::ValueType>>(lhs);
632 auto rhEnumerable = ExplicitCast<System::Collections::Generic::IEnumerable<typename T2::Pointee_::ValueType>>(rhs);
633 auto lhEnum = lhEnumerable->GetEnumerator();
634 auto rhEnum = rhEnumerable->GetEnumerator();
636 while (lhEnum->MoveNext())
638 if (!rhEnum->MoveNext())
641 return EqFailure(lhs_expr, rhs_expr, lhs, rhs);
648 return elementResult;
652 if (!rhEnum->MoveNext())
655 return testing::AssertionSuccess();
659 return EqFailure(lhs_expr, rhs_expr, lhs, rhs);
671template<
typename K,
typename V>
678 return testing::AssertionSuccess();
680 return EqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
690template<
typename K,
typename V>
697 return testing::AssertionSuccess();
699 return EqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
709template<
typename T1,
typename T2>
716 return testing::AssertionSuccess();
718 return EqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
728template<
typename T1,
typename T2>
735 return testing::AssertionSuccess();
737 return EqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
747template<
typename T1,
typename T2>
754 return testing::AssertionSuccess();
756 return EqFailure(lhs_expr, rhs_expr, *lhs, *rhs);
766template<
typename K,
typename V>
773 return testing::AssertionSuccess();
775 return EqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
785template<
typename K,
typename V>
792 return testing::AssertionSuccess();
794 return EqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
804template<
typename K,
typename V>
811 return testing::AssertionSuccess();
813 return EqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
823template<
typename K,
typename V>
830 return testing::AssertionSuccess();
832 return EqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
840inline testing::AssertionResult
NotNullAreEqual(
const char* lhs_expr,
const char* rhs_expr
846 return testing::AssertionSuccess();
861inline testing::AssertionResult
NotNullAreEqual(
const char* lhs_expr,
const char* rhs_expr
867 return testing::AssertionSuccess();
869 return EqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
882 if (lhs->get_Count() != rhs->get_Count())
887 if (lhs->get_Count() == 0)
892 auto lhs_en = lhs->GetEnumerator();
893 auto rhs_en = rhs->GetEnumerator();
895 while (lhs_en->MoveNext() && rhs_en->MoveNext())
897 auto lhs_it = lhs_en->get_Current();
898 auto rhs_it = rhs_en->get_Current();
899 if (lhs_it != rhs_it)
921 return testing::AssertionSuccess();
924 return EqFailure(lhs_expr, rhs_expr, *lhs, *rhs);
940 return testing::AssertionSuccess();
943 return EqFailure(lhs_expr, rhs_expr, *lhs, *rhs);
953template<
typename T1,
typename T2>
955 ,
const T1& lhs,
const T2& rhs, int32_t)
957 if (lhs->Equals(rhs))
959 return ::testing::AssertionSuccess();
962 return EqFailure(lhs_expr, rhs_expr, *lhs, *rhs);
975 if (lhs->Equals(rhs))
977 return ::testing::AssertionSuccess();
980 const auto lt = lhs->GetTypeCode();
981 const auto rt = rhs->GetTypeCode();
986 return ::testing::AssertionSuccess();
991 return ::testing::AssertionSuccess();
996 return ::testing::AssertionSuccess();
1001 return ::testing::AssertionSuccess();
1003 return EqFailure(lhs_expr, rhs_expr, *lhs, *rhs);
1018 return AreBoxedValuesEqual(lhs_expr, rhs_expr, AsCast<BoxedValueBase>(lhs), AsCast<BoxedValueBase>(rhs));
1031template<
typename T1,
typename T2>
1047template<
typename T1,
typename T2>
1048testing::AssertionResult
AreEqual(
const char* lhs_expr,
const char* rhs_expr
1049 ,
const T1& lhs,
const T2& rhs)
1053 return testing::AssertionSuccess();
1060 return testing::internal::EqFailure(lhs_expr, rhs_expr,
1065 return testing::internal::EqFailure(lhs_expr, rhs_expr,
1086template<
typename T1,
typename T2>
1087typename std::enable_if<TypeTraits::BothArrayOrList<typename T1::Pointee_, typename T2::Pointee_>::value
1088, testing::AssertionResult>::type
1090 ,
const T1& lhs,
const T2& rhs,
long long s)
1094 return testing::AssertionSuccess();
1096 return NotEqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
1109template<
typename T1,
typename T2>
1110typename std::enable_if<
1115 testing::AssertionResult
1117 ,
const T1& lhs,
const T2& rhs,
long long s)
1124 return testing::AssertionSuccess();
1137template<
typename K,
typename V>
1144 return testing::AssertionSuccess();
1146 return NotEqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
1156template<
typename K,
typename V>
1163 return testing::AssertionSuccess();
1165 return NotEqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
1175template<
typename T1,
typename T2>
1182 return testing::AssertionSuccess();
1184 return NotEqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
1194template<
typename T1,
typename T2>
1201 return testing::AssertionSuccess();
1203 return NotEqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
1213template<
typename T1,
typename T2>
1220 return testing::AssertionSuccess();
1222 return NotEqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
1232template<
typename K,
typename V>
1239 return testing::AssertionSuccess();
1241 return NotEqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
1251template<
typename K,
typename V>
1258 return testing::AssertionSuccess();
1260 return NotEqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
1270template<
typename K,
typename V>
1277 return testing::AssertionSuccess();
1279 return NotEqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
1289template<
typename K,
typename V>
1296 return testing::AssertionSuccess();
1298 return NotEqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
1312 return testing::AssertionSuccess();
1333 return testing::AssertionSuccess();
1335 return NotEqFailure(lhs_expr, rhs_expr, lhs->data(), rhs->data());
1351 return testing::AssertionSuccess();
1364template<
typename T1,
typename T2>
1366 ,
const T1& lhs,
const T2& rhs, int32_t)
1368 if (!lhs->Equals(rhs))
1370 return ::testing::AssertionSuccess();
1383template<
typename T1,
typename T2>
1399template<
typename T1,
typename T2>
1400testing::AssertionResult
AreNotEqual(
const char* lhs_expr,
const char* rhs_expr
1401 ,
const T1& lhs,
const T2& rhs)
1407 return testing::AssertionSuccess();
1413 return NotEqFailure(lhs_expr, rhs_expr,
"nullptr",
"nullptr");
1426namespace TupleAsserts {
1429template <std::size_t
Index = 0,
typename... AArgs,
typename... BArgs>
1430typename std::enable_if<
Index ==
sizeof...(AArgs),
bool>::type
AreEqual(
const std::tuple<AArgs...>& a,
1431 const std::tuple<BArgs...>& b)
1437template <std::size_t
Index = 0,
typename... AArgs,
typename... BArgs>
1438typename std::enable_if<
Index !=
sizeof...(AArgs),
bool>::type
AreEqual(
const std::tuple<AArgs...>& a,
1439 const std::tuple<BArgs...>& b)
1446 return AreEqual<Index + 1>(a, b);
1472template<
typename T1,
typename T2>
1473typename std::enable_if<std::numeric_limits<T1>::has_quiet_NaN && std::numeric_limits<T2>::has_quiet_NaN,
bool>::type
1474 AreFPNaN(T1 lhs, T2 rhs) {
return (std::isnan(lhs) && std::isnan(rhs)); }
1482template<
typename T1,
typename T2>
1483typename std::enable_if<!std::numeric_limits<T1>::has_quiet_NaN || !std::numeric_limits<T2>::has_quiet_NaN,
bool>::type
1497template <
typename T1,
typename T2>
1498typename std::enable_if<TypeTraits::AreFPandArithmetic<T1, T2>::value
1499 , testing::AssertionResult>::type
1506 ? testing::AssertionSuccess()
1508 ? testing::internal::CmpHelperFloatingPointEQ<typename TypeTraits::LargestFPType<T1, T2>::type>(lhs_expr, rhs_expr,
1522template <
typename T1,
typename T2>
1523typename std::enable_if<TypeTraits::AnyOfDecimal<T1, T2>::value
1524 , testing::AssertionResult>::type
1530 return testing::internal::
1531 EqHelper::Compare<System::Decimal, System::Decimal>
1532 (lhs_expr, rhs_expr, lhs, rhs);
1543template <
typename T>
1545 , testing::AssertionResult>::type
1551 if (lhs.Equals(rhs)) {
1552 return testing::AssertionSuccess();
1566template <
typename T>
1568 , testing::AssertionResult>::type
1575 if (lhs.Equals(rhs)) {
1576 return testing::AssertionSuccess();
1590template <
typename T>
1592 , testing::AssertionResult>::type
1599 return testing::AssertionSuccess();
1613template <
typename T>
1615 , testing::AssertionResult>::type
1621 return AreEqual(lhs_expr, rhs_expr, ObjectExt::Box<T>(lhs), rhs);
1632template <
typename T>
1634 , testing::AssertionResult>::type
1640 return AreEqual(lhs_expr, rhs_expr, lhs, ObjectExt::Box<T>(rhs));
1650inline testing::AssertionResult
AreEqualImpl(
const char* lhs_expr,
const char* rhs_expr
1651 ,
const char16_t* lhs
1666inline testing::AssertionResult
AreEqualImpl(
const char* lhs_expr,
const char* rhs_expr
1668 ,
const char16_t* rhs
1682template <
typename T>
1683testing::AssertionResult
AreEqualImpl(
const char* lhs_expr,
const char* rhs_expr
1690 return testing::AssertionSuccess();
1693 return testing::internal::EqFailure(lhs_expr, rhs_expr,
1706template <
typename T>
1707testing::AssertionResult
AreEqualImpl(
const char* lhs_expr,
const char* rhs_expr
1714 return testing::AssertionSuccess();
1717 return testing::internal::EqFailure(lhs_expr, rhs_expr,
1732template<
typename T1,
typename T2>
1737 !std::is_base_of<System::IO::Stream, typename T1::Pointee_>::value ||
1738 !std::is_base_of<System::IO::Stream, typename T2::Pointee_>::value
1740 testing::AssertionResult
1760template<
typename T1,
typename T2>
1764 std::is_base_of<System::IO::Stream, typename T1::Pointee_>::value &&
1765 std::is_base_of<System::IO::Stream, typename T2::Pointee_>::value,
1766 testing::AssertionResult
1775 return testing::AssertionSuccess();
1782 return testing::internal::EqFailure(lhs_expr, rhs_expr,
1787 return testing::internal::EqFailure(lhs_expr, rhs_expr,
1795 lhs->set_Position(0);
1796 rhs->set_Position(0);
1800 b1 = lhs->ReadByte();
1801 b2 = rhs->ReadByte();
1805 return testing::internal::EqFailure(lhs_expr, rhs_expr,
1811 }
while (b1 != -1 && b2 != -1);
1813 return testing::AssertionSuccess();
1826template <
typename T1,
typename T2>
1827typename std::enable_if<!std::is_null_pointer<T1>::value && !
IsNullable<T1>::value, testing::AssertionResult>::type
1846template <
typename T1,
typename T2>
1847typename std::enable_if<!std::is_null_pointer<T2>::value && !
IsNullable<T2>::value, testing::AssertionResult>::type
1867template <
typename... T1,
typename... T2>
1871 if (Details::TupleAsserts::AreEqual<0>(lhs.
tuple(), rhs.
tuple()))
1873 return testing::AssertionSuccess();
1890template<
typename T1,
typename T2>
1891testing::AssertionResult
AreEqualImpl(
const char* lhs_expr,
const char* rhs_expr, T1 lhs, T2 rhs,
int)
1893 return ::testing::internal::EqHelper::Compare(lhs_expr, rhs_expr, lhs, rhs);
1904template<
typename T1,
typename T2>
1905testing::AssertionResult
AreEqual(
const char* lhs_expr,
const char* rhs_expr, T1&& lhs, T2&& rhs)
1907 return AreEqualImpl(lhs_expr, rhs_expr, lhs, rhs, 1LL);
1910template <
typename T1,
typename T2,
typename Cmp>
1911testing::AssertionResult
AreEqualCmp(
const char* lhs_expr,
const char* rhs_expr,
const char* cmp_expr,
1912 const T1& lhs,
const T2& rhs,
const Cmp& comparer)
1916 return testing::AssertionSuccess();
1928 auto lenum = lhs->GetEnumerator();
1929 auto renum = rhs->GetEnumerator();
1931 for (
bool lnext = lenum->MoveNext(), rnext = renum->MoveNext(); lnext || rnext; lnext = lenum->MoveNext(), rnext = renum->MoveNext())
1933 if (!lnext || !rnext)
1935 return testing::AssertionFailure();
1938 if (comparer->Compare(lenum->get_Current(), renum->get_Current()) != 0)
1945 return testing::AssertionSuccess();
1957template<
typename T1,
typename T2>
1958testing::AssertionResult
AreNotEqual(
const char* lhs_expr,
const char* rhs_expr, T1&& lhs, T2&& rhs);
1970template <
typename T1,
typename T2>
1971typename std::enable_if<TypeTraits::AnyOfDecimal<T1, T2>::value
1972 , testing::AssertionResult>::type
1980 return testing::AssertionSuccess();
2001template <
typename T>
2002typename std::enable_if<std::is_same<T, System::String>::value
2003 , testing::AssertionResult>::type
2011 if (lhs.IsNull() || rhs.IsNull())
2013 if (lhs.IsNull() && rhs.IsNull())
2015 return testing::AssertionSuccess();
2017 return testing::internal::EqFailure(lhs_expr, rhs_expr,
2023 if (lhs.Equals(rhs))
2025 return testing::AssertionSuccess();
2042template <
typename T>
2043typename std::enable_if<std::is_same<T, System::String>::value
2044 , testing::AssertionResult>::type
2052 if (lhs.IsNull() || rhs.IsNull())
2054 if (lhs.IsNull() && rhs.IsNull())
2058 return testing::AssertionSuccess();
2061 if (!lhs.Equals(rhs))
2063 return testing::AssertionSuccess();
2078template <
typename T>
2080 , testing::AssertionResult>::type
2086 if (! lhs.Equals(rhs)) {
2087 return testing::AssertionSuccess();
2101template <
typename T>
2103 , testing::AssertionResult>::type
2109 if (!lhs.Equals(rhs)) {
2110 return testing::AssertionSuccess();
2124template <
typename T>
2126 , testing::AssertionResult>::type
2133 return testing::AssertionSuccess();
2147template <
typename T>
2148typename std::enable_if<IsBoxable<T>::value
2149 , testing::AssertionResult>::type
2155 return AreNotEqual(lhs_expr, rhs_expr, lhs, System::ObjectExt::Unbox<T>(rhs));
2166template <
typename T>
2167typename std::enable_if<IsBoxable<T>::value
2168 , testing::AssertionResult>::type
2174 return AreNotEqual(lhs_expr, rhs_expr, System::ObjectExt::Unbox<T>(lhs), rhs);
2184template <
typename T>
2192 return testing::AssertionSuccess();
2205template <
typename T>
2213 return testing::AssertionSuccess();
2228template<
typename T1,
typename T2>
2230 , testing::AssertionResult>::type
2246template<
typename T1,
typename T2>
2247testing::AssertionResult
AreNotEqualImpl(
const char* lhs_expr,
const char* rhs_expr, T1 lhs, T2 rhs,
int)
2249 return ::testing::internal::CmpHelperNE(lhs_expr, rhs_expr, lhs , rhs);
2259template<
typename T1,
typename T2>
2260testing::AssertionResult
AreNotEqual(
const char* lhs_expr,
const char* rhs_expr, T1&& lhs, T2&& rhs)
2274template<
typename T1,
typename T2>
2275testing::AssertionResult
AreSame(
const char* lhs_expr,
const char* rhs_expr,
const T1& lhs,
const T2& rhs);
2287template<
typename T1,
typename T2>
2289 , testing::AssertionResult>::type
2300 auto rhs_addr =
reinterpret_cast<std::ptrdiff_t
>(rhs.GetObjectOrNull());
2303 auto lhs_addr =
reinterpret_cast<std::ptrdiff_t
>(lhs.GetObjectOrNull());
2310 return testing::AssertionSuccess();
2315 return testing::AssertionSuccess();
2318 auto rhs_addr =
reinterpret_cast<std::ptrdiff_t
>(rhs.GetObjectOrNull());
2319 auto lhs_addr =
reinterpret_cast<std::ptrdiff_t
>(lhs.GetObjectOrNull());
2332template<
typename T1,
typename T2>
2334 , testing::AssertionResult>::type
2341 return testing::AssertionSuccess();
2343 auto rhs_addr =
reinterpret_cast<std::ptrdiff_t
>(&rhs);
2344 auto lhs_addr =
reinterpret_cast<std::ptrdiff_t
>(&lhs);
2355template<
typename T1,
typename T2>
2356testing::AssertionResult
AreSameImpl(
const char* lhs_expr,
const char* rhs_expr,
const T1& lhs,
const T2& rhs,
int)
2360 return testing::AssertionSuccess();
2363 std::ptrdiff_t lhs_addr =
reinterpret_cast<std::ptrdiff_t
>(&lhs);
2364 std::ptrdiff_t rhs_addr =
reinterpret_cast<std::ptrdiff_t
>(&rhs);
2376template<
typename T1,
typename T2>
2377testing::AssertionResult
AreSame(
const char* lhs_expr,
const char* rhs_expr,
const T1& lhs,
const T2& rhs)
2379 return AreSameImpl(lhs_expr, rhs_expr, lhs, rhs, 1LL);
2391template<
typename T1,
typename T2>
2392testing::AssertionResult
AreNotSame(
const char* lhs_expr,
const char* rhs_expr,
const T1& lhs,
const T2& rhs);
2404template<
typename T1,
typename T2>
2406 , testing::AssertionResult>::type
2415 return testing::AssertionSuccess();
2426 return testing::AssertionSuccess();
2429 auto rhs_addr =
reinterpret_cast<std::ptrdiff_t
>(rhs.GetObjectOrNull());
2430 auto lhs_addr =
reinterpret_cast<std::ptrdiff_t
>(lhs.GetObjectOrNull());
2441template<
typename T1,
typename T2>
2442testing::AssertionResult
AreNotSameImpl(
const char* lhs_expr,
const char* rhs_expr,
const T1& lhs,
const T2& rhs,
int)
2446 return testing::AssertionSuccess();
2449 std::ptrdiff_t lhs_addr =
reinterpret_cast<std::ptrdiff_t
>(&lhs);
2450 std::ptrdiff_t rhs_addr =
reinterpret_cast<std::ptrdiff_t
>(&rhs);
2462template<
typename T1,
typename T2>
2463testing::AssertionResult
AreNotSame(
const char* lhs_expr,
const char* rhs_expr,
const T1& lhs,
const T2& rhs)
2476testing::AssertionResult
IsInstanceOf(
const char* lhs_expr,
const char* rhs_expr,
const TypeInfo& typeInfo,
const T& obj)
2478 if (obj->Is(typeInfo))
2480 return ::testing::AssertionSuccess();
2483 return testing::AssertionFailure()
2484 <<
"Expected: " << rhs_expr <<
" is " << lhs_expr
2485 <<
", actual: " << obj->GetType().ToString().ToUtf8String()
2495#define ASPOSE_ASSERT_EQ(val1, val2) \
2496 ASSERT_PRED_FORMAT2(System::TestPredicates::AreEqual, val1, val2)
2501#define ASPOSE_EXPECT_EQ(val1, val2) \
2502 EXPECT_PRED_FORMAT2(System::TestPredicates::AreEqual, val1, val2)
2507#define ASPOSE_ASSERT_EQ_CMP(val1, val2, val3) \
2508 ASSERT_PRED_FORMAT3(System::TestPredicates::AreEqualCmp, val1, val2, val3)
2513#define ASPOSE_EXPECT_EQ_CMP(val1, val2, val3) \
2514 EXPECT_PRED_FORMAT3(System::TestPredicates::AreEqualCmp, val1, val2, val3)
2519#define ASPOSE_ASSERT_NE(val1, val2) \
2520 ASSERT_PRED_FORMAT2(System::TestPredicates::AreNotEqual, val1, val2)
2525#define ASPOSE_EXPECT_NE(val1, val2) \
2526 EXPECT_PRED_FORMAT2(System::TestPredicates::AreNotEqual, val1, val2)
2531#define ASPOSE_ASSERT_SAME(val1, val2) \
2532 ASSERT_PRED_FORMAT2(System::TestPredicates::AreSame, val1, val2)
2537#define ASPOSE_EXPECT_SAME(val1, val2) \
2538 EXPECT_PRED_FORMAT2(System::TestPredicates::AreSame, val1, val2)
2543#define ASPOSE_ASSERT_NS(val1, val2) \
2544 ASSERT_PRED_FORMAT2(System::TestPredicates::AreNotSame, val1, val2)
2549#define ASPOSE_EXPECT_NS(val1, val2) \
2550 EXPECT_PRED_FORMAT2(System::TestPredicates::AreNotSame, val1, val2)
2555#define ASPOSE_ASSERT_ISINSTANCEOF(val1, val2) \
2556 ASSERT_PRED_FORMAT2(System::TestPredicates::IsInstanceOf, val1, val2)
2561#define ASPOSE_EXPECT_ISINSTANCEOF(val1, val2) \
2562 EXPECT_PRED_FORMAT2(System::TestPredicates::IsInstanceOf, val1, val2)
2566#define ASPOSE_GTEST_TEST_THROW_(statement, expected_exception, exception_ref, fail) \
2567 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
2568 if (::testing::internal::ConstCharPtr gtest_msg = "") { \
2569 bool gtest_caught_expected = false; \
2571 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
2573 catch (expected_exception const& e) { \
2574 gtest_caught_expected = true; \
2575 static_assert(std::is_base_of<std::remove_pointer<decltype(exception_ref)>::type, expected_exception>::value, "Should be base class of expected exception"); \
2576 *exception_ref = e; \
2580 "Expected: " #statement " throws an exception of type " \
2581 #expected_exception ".\n Actual: it throws a different type."; \
2582 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
2584 if (!gtest_caught_expected) { \
2586 "Expected: " #statement " throws an exception of type " \
2587 #expected_exception ".\n Actual: it throws nothing."; \
2588 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
2591 GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
2592 fail(gtest_msg.value)
2598#define ASPOSE_ASSERT_THROW(statement, expected_exception, exception_ref) \
2599 ASPOSE_GTEST_TEST_THROW_(statement, expected_exception, exception_ref, GTEST_FATAL_FAILURE_);
2602#define ASPOSE_ASSERT_THROW_EXCEPTION_TYPE_(statement, expected_exception_type, fail) \
2603 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
2604 if (::testing::internal::ConstCharPtr gtest_msg = "") { \
2605 bool gtest_caught_expected = false; \
2607 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
2609 catch (const System::Exception& e) { \
2610 gtest_caught_expected = true; \
2611 if(e.Get()->GetType() != expected_exception_type)\
2614 "Actual: " #statement " throws a different type."; \
2615 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
2620 "Actual: " #statement " throws a unexpected exception type."; \
2621 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
2623 if (!gtest_caught_expected) { \
2625 "Actual: " #statement " throws nothing."; \
2626 goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
2629 GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
2630 fail(gtest_msg.value)
2640#define ASPOSE_ASSERT_THROW_EXCEPTION_TYPE(statement, exceptionType) \
2641 ASPOSE_ASSERT_THROW_EXCEPTION_TYPE_(statement, exceptionType, GTEST_FATAL_FAILURE_)
2646#define ASSERT_PASS() \
2648 throw ::testing::SkipException();
Array of bits which can be addressed by index. Objects of this class should only be allocated using S...
Definition: bitarray.h:97
Forward declaration of Dictionary class.
Definition: dictionary.h:96
Forward declaration of HashSet class.
Definition: hashset.h:82
Interface of collection of elements. Objects of this class should only be allocated using System::Mak...
Definition: icollection.h:20
Interface of read-only collection of elements. Objects of this class should only be allocated using S...
Definition: iread_only_collection.h:19
Pair of key and value. This type should be allocated on stack and passed to functions by value or by ...
Definition: keyvalue_pair.h:20
Queue class forward declaration.
Definition: queue.h:88
Sorted dictionary type forward declaration.
Definition: sorted_dictionary.h:52
Sorted list wrapping FlatMap structure. Objects of this class should only be allocated using System::...
Definition: sorted_list.h:334
Stack class forward declaration.
Definition: stack.h:87
Represents a decimal number. This type should be allocated on stack and passed to functions by value ...
Definition: decimal.h:107
Represents an index into a collection. The index can be from the start or from the end....
Definition: index.h:16
Forward declaration.
Definition: nullable.h:75
T get_Value() const
Returns a copy of the value represented by the current object.
Definition: nullable.h:144
bool IsNull() const
Determines if the current object represents a null-value.
Definition: nullable.h:180
static bool IsBoxedValue(const SmartPtr< Object > &obj)
Checks if object is a boxed value.
Base class that enables using methods available for System.Object class in C#. All non-trivial classe...
Definition: object.h:51
Pointer class to wrap types being allocated on heap. Use it to manage memory for classes inheriting O...
Definition: smart_ptr.h:180
String class used across the library. Is a substitute for C# System.String when translating code....
Definition: string.h:126
std::string ToUtf8String() const
Converts string to std::string. Uses UTF-8 encoding.
Represents a particular type and provides information about it.
Definition: type_info.h:109
String ToString() const
Returns a string containing the name of the type represented by the current object.
Class that represents a ValueTuple data structure.
Definition: value_tuple.h:22
tuple_t & tuple()
Definition: value_tuple.h:142
Subclass of System::SmartPtr which sets itself to weak mode at construction. Please note that this cl...
Definition: weak_ptr.h:18
std::enable_if< TypeTraits::BothArrayOrList< typenameT1::Pointee_, typenameT2::Pointee_ >::value, testing::AssertionResult >::type NotNullAreEqualImpl(const char *lhs_expr, const char *rhs_expr, const T1 &lhs, const T2 &rhs, long long s)
Equal-compares arrays or lists.
Definition: test_predicates.h:601
testing::AssertionResult NotNullAreEqual(const char *lhs_expr, const char *rhs_expr, const SharedPtr< System::Collections::Generic::Dictionary< K, V > > &lhs, const SharedPtr< System::Collections::Generic::Dictionary< K, V > > &rhs)
Equal-compares dictionaries of value types.
Definition: test_predicates.h:672
testing::AssertionResult AreBoxedValuesEqual(const char *lhs_expr, const char *rhs_expr, const SharedPtr< BoxedValueBase > &lhs, const SharedPtr< BoxedValueBase > &rhs)
Equal-compares two Boxed types.
Definition: test_predicates.h:971
testing::AssertionResult NotNullAreNotEqual(const char *lhs_expr, const char *rhs_expr, const SharedPtr< System::Collections::Generic::Dictionary< K, V > > &lhs, const SharedPtr< System::Collections::Generic::Dictionary< K, V > > &rhs)
Not-equal-compares dictionaries of value types.
Definition: test_predicates.h:1138
std::enable_if< System::IsSmartPtr< typenameT1::value_type >::value &&System::IsSmartPtr< typenameT2::value_type >::value, bool >::type AreEqualData(const T1 &lhs, const T2 &rhs)
Equal-compares two containers using System::Object::Equals on elements. Works for SmartPtr elements.
Definition: test_predicates.h:536
testing::AssertionResult AreNotEqual(const char *lhs_expr, const char *rhs_expr, const T1 &lhs, const T2 &rhs)
Not-equal-compares arguments for AreNotEqual assertion translation.
Definition: test_predicates.h:1400
std::enable_if<!System::IsSmartPtr< typenameT1::value_type >::value &&!System::IsSmartPtr< typenameT2::value_type >::value, bool >::type AreEqualContainer(const T1 &lhs, const T2 &rhs)
Equal-compares two containers using operator == on elements. Works for non-SmartPtr elements.
Definition: test_predicates.h:504
bool NotNullAreEqualHelper(const SharedPtr< System::Collections::Generic::ICollection< T > > &lhs, const SharedPtr< System::Collections::Generic::ICollection< T > > &rhs)
Equal-compares abstract collections.
Definition: test_predicates.h:877
std::enable_if< TypeTraits::BothArrayOrList< typenameT1::Pointee_, typenameT2::Pointee_ >::value, testing::AssertionResult >::type NotNullAreNotEqualImpl(const char *lhs_expr, const char *rhs_expr, const T1 &lhs, const T2 &rhs, long long s)
Not-equal-compares arrays or lists.
Definition: test_predicates.h:1089
bool AreEqualMapOfObjects(const T &lhs, const T &rhs)
Equal-compares two maps using System::Object::Equals on elements.
Definition: test_predicates.h:578
testing::AssertionResult AreEqual(const char *lhs_expr, const char *rhs_expr, const T1 &lhs, const T2 &rhs)
Equal-compares arguments for AreEqual assertion translation.
Definition: test_predicates.h:1048
std::enable_if< Index==sizeof...(AArgs), bool >::type AreEqual(const std::tuple< AArgs... > &a, const std::tuple< BArgs... > &b)
Definition: test_predicates.h:1430
std::enable_if< System::Details::HasToString< T >::value, std::string >::type PrintToStringImpl(const SharedPtr< T > &value, long long s)
Prints System::Object subclass to string using ToString() method.
Definition: test_predicates.h:194
std::enable_if_t<!TypeTraits::IsEnumerable< T >::value, std::string > PrintToString(const T &)
Prints object to string by selecting proper serializer function.
Definition: test_predicates.h:345
testing::AssertionResult NotSameFailure(const char *lhs_expr, const char *rhs_expr, T1 &lhs, T2 &rhs)
Formats 'not same' assertion failure for output.
Definition: test_predicates.h:482
testing::AssertionResult EqFailure(const char *lhs_expr, const char *rhs_expr, T1 &lhs, T2 &rhs)
Formats == assertion failure for output.
Definition: test_predicates.h:427
testing::AssertionResult SameFailure(const char *lhs_expr, const char *rhs_expr, T1 &lhs, T2 &rhs)
Formats 'same' assertion failure for output.
Definition: test_predicates.h:464
testing::AssertionResult NotEqFailure(const char *lhs_expr, const char *rhs_expr, T1 &lhs, T2 &rhs)
Formats != assertion failure for output.
Definition: test_predicates.h:446
std::is_same< T, System::Array< typename T::ValueType > > IsArray
Checks if type is a System::Array specialization. If so, value member is set to true,...
Definition: test_predicates.h:124
std::integral_constant< bool,(IsArray< T1 >::value||IsList< T1 >::value) &&(IsArray< T2 >::value||IsList< T2 >::value)> BothArrayOrList
Checks if both type arguments are arrays or lists. If so, value member is set to true,...
Definition: test_predicates.h:136
std::integral_constant< bool, std::is_same< T1, System::Decimal >::value||std::is_same< T2, System::Decimal >::value > AnyOfDecimal
Checks that at least one of type arguments is System::Decimal. If so, sets value member to true,...
Definition: test_predicates.h:60
std::is_same< T, System::Collections::Generic::List< typename T::ValueType > > IsList
Checks if type is a System::Collections::Generic::List specialization. If so, value member is set to ...
Definition: test_predicates.h:129
std::integral_constant< bool, IsEnumerable< T1 >::value &&IsEnumerable< T2 >::value > BothEnumerable
Checks if both type arguments are IEnumerable. If so, value member is set to true,...
Definition: test_predicates.h:155
std::integral_constant< bool,(std::is_floating_point< T1 >::value &&std::is_arithmetic< T2 >::value)||(std::is_arithmetic< T1 >::value &&std::is_floating_point< T2 >::value) > AreFPandArithmetic
Checks that T1 is arithmetic and T2 is floating point, or vice versa. If so, sets value member to tru...
Definition: test_predicates.h:53
std::enable_if< TypeTraits::AnyOfDecimal< T1, T2 >::value, testing::AssertionResult >::type AreNotEqualImpl(const char *lhs_expr, const char *rhs_expr, const T1 &lhs, const T2 &rhs, long long s)
Not-equal-compares values one or both of them being Decimal.
Definition: test_predicates.h:1973
std::enable_if< TypeTraits::AreFPandArithmetic< T1, T2 >::value, testing::AssertionResult >::type AreEqualImpl(const char *lhs_expr, const char *rhs_expr, const T1 lhs, const T2 rhs, long long s)
Equal-compares floating point with arithmetic types.
Definition: test_predicates.h:1500
testing::AssertionResult AreNotSame(const char *lhs_expr, const char *rhs_expr, const T1 &lhs, const T2 &rhs)
Are-not-same-compares arguments for AreSame assertion translation.
Definition: test_predicates.h:2463
testing::AssertionResult AreEqual(const char *lhs_expr, const char *rhs_expr, T1 &&lhs, T2 &&rhs)
Equal-compares arguments for AreEqual assertion translation.
Definition: test_predicates.h:1905
testing::AssertionResult AreEqualCmp(const char *lhs_expr, const char *rhs_expr, const char *cmp_expr, const T1 &lhs, const T2 &rhs, const Cmp &comparer)
Definition: test_predicates.h:1911
std::enable_if< IsSmartPtr< T1 >::value &&IsSmartPtr< T2 >::value, testing::AssertionResult >::type AreNotSameImpl(const char *lhs_expr, const char *rhs_expr, const T1 &lhs, const T2 &rhs, long long s)
Are-not-same-compares smart pointers.
Definition: test_predicates.h:2407
testing::AssertionResult IsInstanceOf(const char *lhs_expr, const char *rhs_expr, const TypeInfo &typeInfo, const T &obj)
Is-instance-of-compares arguments for IsInstanceOf assertion translation.
Definition: test_predicates.h:2476
testing::AssertionResult AreSame(const char *lhs_expr, const char *rhs_expr, const T1 &lhs, const T2 &rhs)
Are-same-compares arguments for AreSame assertion translation.
Definition: test_predicates.h:2377
std::enable_if< IsSmartPtr< T1 >::value &&IsSmartPtr< T2 >::value, testing::AssertionResult >::type AreSameImpl(const char *lhs_expr, const char *rhs_expr, const T1 &lhs, const T2 &rhs, long long s)
Are-same-compares smart pointers.
Definition: test_predicates.h:2290
testing::AssertionResult AreNotEqual(const char *lhs_expr, const char *rhs_expr, T1 &&lhs, T2 &&rhs)
Not-equal-compares arguments for AreEqual assertion translation.
Definition: test_predicates.h:2260
std::enable_if< std::numeric_limits< T1 >::has_quiet_NaN &&std::numeric_limits< T2 >::has_quiet_NaN, bool >::type AreFPNaN(T1 lhs, T2 rhs)
Checks that two floating point values are both NaNs. Handles situation when non-signalling NaN is sup...
Definition: test_predicates.h:1474
Definition: db_command.h:9
void PrintTo(DateTime value, std::ostream *stream)
Prints value to ostream. Mostly used for debug.
@ Int16
An integral type representing signed 16-bit integers with values between -32768 and 32767.
@ Single
A floating point type representing values ranging from approximately 1.5 x 10 -45 to 3....
@ Decimal
A simple type representing values ranging from 1.0 x 10 -28 to approximately 7.9 x 10 28 with 28-29 s...
@ Int32
An integral type representing signed 32-bit integers with values between -2147483648 and 2147483647.
@ Double
A floating point type representing values ranging from approximately 5.0 x 10 -324 to 1....
std::enable_if_t< Details::CastType< Source, Result >::Static, Result > AsCast(const Source &value)
Casts the source type to the result type using 'as' operator cast. Used when simple constructor-like ...
Definition: object_ext.h:1219
static constexpr int ToInt32(bool value)
Converts the specified boolean value to an equivalent 32-bit signed integer.
Definition: convert.h:562
static Decimal ToDecimal(bool value)
Converts the specified boolean value to an equivalent decimal number.
Definition: convert.h:1022
static constexpr double ToDouble(bool value)
Converts the specified boolean value to an equivalent double-precision floating-point number.
Definition: convert.h:956
static constexpr float ToSingle(bool value)
Converts the specified boolean value to an equivalent single-precision floating-point number.
Definition: convert.h:890
Template predicate that checks if boxing of the specified type is supported.
Definition: boxable_traits.h:16
A template predicate that determines if the specified type is a Exception class or its descendant.
Definition: object.h:394
A template predicate that determines if its template argument T in Nullable or its subclass.
Definition: nullable.h:23
Trait class to check if a type is a specialization of SmartPtr class.
Definition: smart_ptr.h:1489
Template magic to check if a type is a sequence of string characters.
Definition: string.h:72
static bool AreEqual(const SharedPtr< Array< T > > &arrA, const SharedPtr< Array< U > > &arrB)
Compares arrays of non-pointers.
Definition: compare.h:83
static double & GetDefaultFloatingPointTolerance()
namespace Details
Definition: test_predicates.h:1453
~FloatingPointTolerance()
Definition: test_predicates.h:1459
FloatingPointTolerance(double tolerance)
Definition: test_predicates.h:1454
Checks if specific type is STL-style container. To do so, checks for iterator and const_iterator memb...
Definition: test_predicates.h:163
Checks if type has System::Collections::Generic::IEnumerable specialization as basetype....
Definition: test_predicates.h:142
Provides alias for longest floating point type provided. Ignores non-floating point types.
Definition: test_predicates.h:67
Checks if a type has data() method. If it does, inherits std::true_type, otherwise inherits std::fals...
Definition: test_predicates.h:107
Checks for overload of PrintTo function that accepts given type as first argument....
Definition: test_predicates.h:95
Checks whether Equals method exists in specified type. If so, inherits std::true_type,...
Definition: detail.h:137
Checks whether operator == exists in specified type. If so, inherits std::true_type,...
Definition: detail.h:122