48 #define TEST_NOTHROW_WITH_MESSAGE( code ) \ 50 (out) << "Test that code {"#code";} does not throw : "; \ 52 (out) << "passes\n"; \ 54 catch (std::exception& theException) { \ 57 out << "\nException message for unexpected exception:\n\n"; \ 59 Teuchos::OSTab l_tab(out); \ 60 out << theException.what() << "\n\n"; \ 72 typedef unsigned short unsigned_short_type;
73 typedef unsigned int unsigned_int_type;
74 typedef unsigned long unsigned_long_type;
76 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 77 typedef long long long_long_type;
78 typedef unsigned long long unsigned_long_long_type;
79 #endif // HAVE_TEUCHOS_LONG_LONG_INT 88 const float minF = -std::numeric_limits<float>::max ();
89 const float minusOneF = -1;
90 const float maxF = std::numeric_limits<float>::max ();
92 const double minD = -std::numeric_limits<double>::max ();
93 const double minusOneD = -1;
94 const double maxD = std::numeric_limits<double>::max ();
98 long double valLD = 0;
189 const long double minLD = -std::numeric_limits<long double>::max ();
190 const long double minusOneLD = -1;
191 const long double maxLD = std::numeric_limits<long double>::max ();
278 const float minF = -std::numeric_limits<float>::max ();
279 const float minusOneF = -1;
280 const float maxF = std::numeric_limits<float>::max ();
282 const double minD = -std::numeric_limits<double>::max ();
283 const double minusOneD = -1;
284 const double maxD = std::numeric_limits<double>::max ();
307 const long double minLD = -std::numeric_limits<long double>::max ();
308 const long double minusOneLD = -1;
309 const long double maxLD = std::numeric_limits<long double>::max ();
313 long double valLD = 0;
319 std::ostringstream os;
332 std::ostringstream os;
341 std::ostringstream os;
351 std::ostringstream os;
364 std::ostringstream os;
367 TEST_THROW(valF = asSafe<float> (os.str ()), std::range_error);
370 std::ostringstream os;
373 TEST_THROW(valF = asSafe<float> (os.str ()), std::range_error);
380 std::ostringstream os;
389 std::ostringstream os;
398 std::ostringstream os;
411 if (
sizeof (
long double) >
sizeof (
double)) {
413 std::ostringstream os;
416 TEST_THROW(valD = asSafe<double> (os.str ()), std::range_error);
419 std::ostringstream os;
422 TEST_THROW(valD = asSafe<double> (os.str ()), std::range_error);
430 std::ostringstream os;
439 std::ostringstream os;
448 std::ostringstream os;
474 const RealType minVal = -std::numeric_limits<RealType>::max ();
475 const RealType maxVal = std::numeric_limits<RealType>::max ();
477 SignedIntType val = 0;
478 if (
sizeof (SignedIntType) <
sizeof (RealType)) {
479 TEST_THROW(val = asSafe<SignedIntType> (minVal), std::range_error);
480 TEST_THROW(val = asSafe<SignedIntType> (maxVal), std::range_error);
501 const RealType minVal = -std::numeric_limits<RealType>::max ();
502 const RealType maxVal = std::numeric_limits<RealType>::max ();
503 const UnsignedIntType maxUnsignedIntVal =
504 std::numeric_limits<UnsignedIntType>::max ();
508 UnsignedIntType val = 42;
512 val == static_cast<UnsignedIntType> (maxVal),
514 "Dear test author, please pick a different marker value. " 515 "Please report this bug to the Teuchos developers.");
518 TEST_THROW(val = asSafe<UnsignedIntType> (minVal), std::range_error);
519 const RealType minusOne = -1;
520 TEST_THROW(val = asSafe<UnsignedIntType> (minusOne), std::range_error);
523 if (maxUnsignedIntVal < maxVal) {
524 TEST_THROW(val = asSafe<UnsignedIntType> (maxVal), std::range_error);
526 std::cerr << std::endl
527 <<
"*** RealType = " << TypeNameTraits<RealType>::name ()
528 <<
", UnsignedIntType = " << TypeNameTraits<UnsignedIntType>::name ()
529 <<
", maxVal = " << maxVal
530 <<
", maxUnsignedIntVal = " << maxUnsignedIntVal
531 <<
", asSafe (maxVal) = " << asSafe<UnsignedIntType> (maxVal)
534 std::cerr <<
"(asSafe threw an exception)" << std::endl;
545 "Hey, how come val == 42? It should be something completely different. " 547 <<
"FYI, static_cast<" << TypeNameTraits<UnsignedIntType>::name ()
548 <<
"> (minVal) = " << static_cast<UnsignedIntType> (minVal)
551 <<
"static_cast<" << TypeNameTraits<UnsignedIntType>::name ()
552 <<
"> (maxVal) = " << static_cast<UnsignedIntType> (maxVal)
553 <<
". val should be equal to the latter." 555 <<
"As float: minVal = " << minVal <<
", maxVal = " << maxVal <<
".");
591 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 593 #endif // HAVE_TEUCHOS_LONG_LONG_INT 600 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 602 #endif // HAVE_TEUCHOS_LONG_LONG_INT 613 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 615 #endif // HAVE_TEUCHOS_LONG_LONG_INT 623 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 625 #endif // HAVE_TEUCHOS_LONG_LONG_INT 654 std::ostringstream os;
655 const FirstIntType origVal = 42;
656 const SecondIntType origValSecond = 42;
658 SecondIntType asVal = 0, asSafeVal = 0;
660 TEST_NOTHROW(asSafeVal = asSafe<SecondIntType> (origVal));
666 FirstIntType backVal = 0, backSafeVal = 0;
668 TEST_NOTHROW(backSafeVal = asSafe<FirstIntType> (asSafeVal));
686 sizeof (SignedIntType) !=
sizeof (UnsignedIntType),
688 "Unit test Teuchos,asSafe,negativeSignedIntToUnsignedInt requires that the " 689 "two template parameters SignedIntType and UnsignedIntType have the same " 692 std::ostringstream os;
693 const SignedIntType origVal = -1;
695 UnsignedIntType asSafeVal = 0;
699 TEST_THROW(asSafeVal = asSafe<UnsignedIntType> (origVal), std::range_error);
704 UnsignedIntType negVal =
static_cast<UnsignedIntType
> (origVal);
705 SignedIntType backSafeVal = 0;
706 TEST_THROW(backSafeVal = asSafe<SignedIntType> (negVal), std::range_error);
719 std::ostringstream os;
720 const FirstSignedIntType origVal = -42;
724 ! std::numeric_limits<FirstSignedIntType>::is_signed ||
725 ! std::numeric_limits<SecondSignedIntType>::is_signed,
727 "Unit test Teuchos,as,negativeSignedIntToSignedInt requires that the " 728 "two template parameters FirstSignedIntType and SecondSignedIntType " 729 "both be signed built-in integer types.");
733 SecondSignedIntType asVal = 0, asSafeVal = 0;
734 TEST_NOTHROW(asVal = as<SecondSignedIntType> (origVal));
735 TEST_NOTHROW(asSafeVal = asSafe<SecondSignedIntType> (origVal));
740 FirstSignedIntType backVal = 0, backSafeVal = 0;
741 TEST_NOTHROW(backVal = as<FirstSignedIntType> (origVal));
742 TEST_NOTHROW(backSafeVal = asSafe<FirstSignedIntType> (origVal));
793 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 835 #endif // HAVE_TEUCHOS_LONG_LONG_INT 847 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 849 #endif // HAVE_TEUCHOS_LONG_LONG_INT 867 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 875 #endif // HAVE_TEUCHOS_LONG_LONG_INT 886 std::ostringstream os;
887 const int maxInt = std::numeric_limits<int>::max ();
891 if (
sizeof (
int) <
sizeof (
long)) {
892 const long maxIntPlusOne =
static_cast<long> (maxInt) + static_cast<long> (1);
898 TEST_THROW(intVal = asSafe<int> (os.str ()), std::range_error);
922 std::ostringstream os;
923 const int minInt = std::numeric_limits<int>::min ();
927 if (
sizeof (
int) <
sizeof (
long)) {
928 const long minIntMinusOne =
static_cast<long> (minInt) - static_cast<long> (1);
929 os << minIntMinusOne;
934 TEST_THROW(intVal = asSafe<int> (os.str ()), std::range_error);
958 std::ostringstream os;
959 os << static_cast<IntegerType> (42);
970 std::ostringstream os;
971 os << static_cast<IntegerType> (-42);
982 std::ostringstream os;
983 os <<
"This string definitely does not contain an integer.";
985 TEST_THROW(val = asSafe<IntegerType> (os.str ()), std::invalid_argument);
993 #define UNIT_TEST_GROUP_ANY_INTEGER( AnyIntegerType ) \ 994 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( asSafe, stringToIntegerPositive, AnyIntegerType ) \ 995 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( asSafe, stringToIntegerShouldThrow, AnyIntegerType ) 997 #define UNIT_TEST_GROUP_SIGNED_INTEGER( SignedIntegerType ) \ 998 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( asSafe, stringToIntegerNegative, SignedIntegerType ) 1019 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 1026 #endif // HAVE_TEUCHOS_LONG_LONG_INT #define TEUCHOS_UNIT_TEST_TEMPLATE_2_INSTANT(TEST_GROUP, TEST_NAME, TYPE1, TYPE2)
Instantiate a templated unit test with two template parameters.
#define TEST_NOTHROW(code)
Asserr that the statement 'code' does not thrown any excpetions.
TypeTo asSafe(const TypeFrom &t)
Convert from one value type to another, with validity checks if appropriate.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Macro for throwing an exception with breakpointing to ease debugging.
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(TEST_GROUP, TEST_NAME, TYPE)
Macro for defining a templated unit test with one template parameter.
#define TEST_THROW(code, ExceptType)
Assert that the statement 'code' throws the exception 'ExceptType' (otherwise the test fails)...
#define TEUCHOS_UNIT_TEST_TEMPLATE_2_DECL(TEST_GROUP, TEST_NAME, TYPE1, TYPE2)
Macro for defining a templated unit test with two template parameters.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
#define TEST_NOTHROW_WITH_MESSAGE(code)
#define UNIT_TEST_GROUP_ANY_INTEGER(AnyIntegerType)
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
Default traits class that just returns typeid(T).name().
Definition of Teuchos::as, for conversions between types.
#define UNIT_TEST_GROUP_SIGNED_INTEGER(SignedIntegerType)