Teuchos Package Browser (Single Doxygen Collection) Version of the Day
OldTestForException_UnitTests.cpp
Go to the documentation of this file.
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 //
00005 //                    Teuchos: Common Tools Package
00006 //                 Copyright (2004) Sandia Corporation
00007 //
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 //
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00039 //
00040 // ***********************************************************************
00041 // @HEADER
00042 */
00043 
00044 
00045 // Make deprecated warnings go away for this test.  Comment this define out to
00046 // see the deprecated warnings!
00047 #define TEUCHOS_DEPRECATED
00048 
00049 
00050 #include "Teuchos_UnitTestHarness.hpp"
00051 #include "Teuchos_TestForException.hpp"
00052 
00053 
00054 namespace {
00055 
00056 
00057 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPTION, noThrowExcept )
00058 {
00059   const int i = 5;
00060   TEST_NOTHROW(
00061     TEST_FOR_EXCEPTION(i != 5, std::logic_error, "Blah blah blah")
00062     );
00063 }
00064 
00065 
00066 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPTION, throwExcept )
00067 {
00068   const int i = 5;
00069   TEST_THROW(
00070     TEST_FOR_EXCEPTION(i == 5, std::logic_error, "Blah blah blah"),
00071     std::logic_error
00072     );
00073 }
00074 
00075 
00076 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPTION_CLASS_FUNC, noThrowExcept )
00077 {
00078   const int i = 5;
00079   std::string tfecfFuncName("someMethod");
00080   TEST_NOTHROW(
00081     TEST_FOR_EXCEPTION_CLASS_FUNC(i != 5, std::logic_error, "Blah blah blah")
00082     );
00083 }
00084 
00085 
00086 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPTION_CLASS_FUNC, throwExcept )
00087 {
00088   const int i = 5;
00089   std::string tfecfFuncName("someMethod");
00090   TEST_THROW(
00091     TEST_FOR_EXCEPTION_CLASS_FUNC(i == 5, std::logic_error, "Blah blah blah"),
00092     std::logic_error);
00093 }
00094 
00095 
00096 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPTION_PURE_MSG, noThrowExcept )
00097 {
00098   const int i = 5;
00099   TEST_NOTHROW(
00100     TEST_FOR_EXCEPTION_PURE_MSG(i != 5, std::logic_error, "Blah blah blah")
00101     );
00102 }
00103 
00104 
00105 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPTION_PURE_MSG, throwExcept )
00106 {
00107   const int i = 5;
00108   TEST_THROW(
00109     TEST_FOR_EXCEPTION_PURE_MSG(i == 5, std::logic_error, "Blah blah blah"),
00110     std::logic_error);
00111 }
00112 
00113 
00114 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPT, noThrowExcept )
00115 {
00116   const int i = 5;
00117   TEST_NOTHROW(
00118     TEST_FOR_EXCEPT(i != 5)
00119     );
00120 }
00121 
00122 
00123 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPT, throwExcept )
00124 {
00125   const int i = 5;
00126   TEST_THROW(
00127     TEST_FOR_EXCEPT(i == 5),
00128     std::logic_error);
00129 }
00130 
00131 
00132 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPT_MSG, noThrowExcept )
00133 {
00134   const int i = 5;
00135   TEST_NOTHROW(
00136     TEST_FOR_EXCEPT_MSG(i != 5, "Blah blah blah")
00137     );
00138 }
00139 
00140 
00141 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPT_MSG, throwExcept )
00142 {
00143   const int i = 5;
00144   TEST_THROW(
00145     TEST_FOR_EXCEPT_MSG(i == 5, "Blah blah blah"),
00146     std::logic_error);
00147 }
00148 
00149 
00150 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPTION_PRINT, noThrowExcept )
00151 {
00152   const int i = 5;
00153   TEST_NOTHROW(
00154     TEST_FOR_EXCEPTION_PRINT(i != 5, std::logic_error, "Blah blah blah", &out)
00155     );
00156 }
00157 
00158 
00159 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPTION_PRINT, throwExcept )
00160 {
00161   const int i = 5;
00162   std::ostringstream oss;
00163   TEST_THROW(
00164     TEST_FOR_EXCEPTION_PRINT(i == 5, std::logic_error, "Blah blah blah", &oss),
00165     std::logic_error);
00166   TEST_INEQUALITY(oss.str().find("Throwing an std::exception of type"), std::string::npos);
00167   TEST_INEQUALITY(oss.str().find("logic_error"), std::string::npos);
00168   TEST_INEQUALITY(oss.str().find("OldTestForException_UnitTests.cpp"), std::string::npos);
00169   TEST_INEQUALITY(oss.str().find("Throw number ="), std::string::npos);
00170   TEST_INEQUALITY(oss.str().find("Throw test that evaluated to true"), std::string::npos);
00171   TEST_INEQUALITY(oss.str().find("i == 5"), std::string::npos);
00172   TEST_INEQUALITY(oss.str().find("Blah blah blah"), std::string::npos);
00173   // NOTE: The above test asserts that the exception message is being built
00174   // somewhat correctly!
00175 }
00176 
00177 
00178 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPT_PRINT, noThrowExcept )
00179 {
00180   const int i = 5;
00181   TEST_NOTHROW(
00182     TEST_FOR_EXCEPT_PRINT(i != 5, &out)
00183     );
00184 }
00185 
00186 
00187 TEUCHOS_UNIT_TEST( TEST_FOR_EXCEPT_PRINT, throwExcept )
00188 {
00189   const int i = 5;
00190   std::ostringstream oss;
00191   TEST_THROW(
00192     TEST_FOR_EXCEPT_PRINT(i == 5, &oss),
00193     std::logic_error);
00194   TEST_INEQUALITY(oss.str().find("OldTestForException_UnitTests.cpp"), std::string::npos);
00195   TEST_INEQUALITY(oss.str().find("i == 5"), std::string::npos);
00196 }
00197 
00198 
00199 TEUCHOS_UNIT_TEST( TEUCHOS_TRACE, basic )
00200 {
00201   std::logic_error localExcept("Blah blah blah");
00202   TEST_THROW(
00203     TEUCHOS_TRACE(localExcept),
00204     std::runtime_error);
00205 }
00206 
00207 
00208 } // namespace
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines