|
Teuchos Package Browser (Single Doxygen Collection)
Version of the Day
|
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 #include "Teuchos_UnitTestHarness.hpp" 00045 #include "Teuchos_Assert.hpp" 00046 00047 00048 namespace { 00049 00050 00051 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPTION, noThrowExcept ) 00052 { 00053 const int i = 5; 00054 TEST_NOTHROW( 00055 TEUCHOS_TEST_FOR_EXCEPTION(i != 5, std::logic_error, "Blah blah blah") 00056 ); 00057 } 00058 00059 00060 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPTION, throwExcept ) 00061 { 00062 const int i = 5; 00063 TEST_THROW( 00064 TEUCHOS_TEST_FOR_EXCEPTION(i == 5, std::logic_error, "Blah blah blah"), 00065 std::logic_error 00066 ); 00067 } 00068 00069 00070 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC, noThrowExcept ) 00071 { 00072 const int i = 5; 00073 std::string tfecfFuncName("someMethod"); 00074 TEST_NOTHROW( 00075 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(i != 5, std::logic_error, "Blah blah blah") 00076 ); 00077 } 00078 00079 00080 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC, throwExcept ) 00081 { 00082 const int i = 5; 00083 std::string tfecfFuncName("someMethod"); 00084 TEST_THROW( 00085 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(i == 5, std::logic_error, "Blah blah blah"), 00086 std::logic_error); 00087 } 00088 00089 00090 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG, noThrowExcept ) 00091 { 00092 const int i = 5; 00093 TEST_NOTHROW( 00094 TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(i != 5, std::logic_error, "Blah blah blah") 00095 ); 00096 } 00097 00098 00099 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG, throwExcept ) 00100 { 00101 const int i = 5; 00102 TEST_THROW( 00103 TEUCHOS_TEST_FOR_EXCEPTION_PURE_MSG(i == 5, std::logic_error, "Blah blah blah"), 00104 std::logic_error); 00105 } 00106 00107 00108 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPT, noThrowExcept ) 00109 { 00110 const int i = 5; 00111 TEST_NOTHROW( 00112 TEUCHOS_TEST_FOR_EXCEPT(i != 5) 00113 ); 00114 } 00115 00116 00117 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPT, throwExcept ) 00118 { 00119 const int i = 5; 00120 TEST_THROW( 00121 TEUCHOS_TEST_FOR_EXCEPT(i == 5), 00122 std::logic_error); 00123 } 00124 00125 00126 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPT_MSG, noThrowExcept ) 00127 { 00128 const int i = 5; 00129 TEST_NOTHROW( 00130 TEUCHOS_TEST_FOR_EXCEPT_MSG(i != 5, "Blah blah blah") 00131 ); 00132 } 00133 00134 00135 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPT_MSG, throwExcept ) 00136 { 00137 const int i = 5; 00138 TEST_THROW( 00139 TEUCHOS_TEST_FOR_EXCEPT_MSG(i == 5, "Blah blah blah"), 00140 std::logic_error); 00141 } 00142 00143 00144 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPTION_PRINT, noThrowExcept ) 00145 { 00146 const int i = 5; 00147 TEST_NOTHROW( 00148 TEUCHOS_TEST_FOR_EXCEPTION_PRINT(i != 5, std::logic_error, "Blah blah blah", &out) 00149 ); 00150 } 00151 00152 00153 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPTION_PRINT, throwExcept ) 00154 { 00155 const int i = 5; 00156 std::ostringstream oss; 00157 TEST_THROW( 00158 TEUCHOS_TEST_FOR_EXCEPTION_PRINT(i == 5, std::logic_error, "Blah blah blah", &oss), 00159 std::logic_error); 00160 TEST_INEQUALITY(oss.str().find("Throwing an std::exception of type"), std::string::npos); 00161 TEST_INEQUALITY(oss.str().find("logic_error"), std::string::npos); 00162 TEST_INEQUALITY(oss.str().find("AssertAndThrow_UnitTests.cpp"), std::string::npos); 00163 TEST_INEQUALITY(oss.str().find("Throw number ="), std::string::npos); 00164 TEST_INEQUALITY(oss.str().find("Throw test that evaluated to true"), std::string::npos); 00165 TEST_INEQUALITY(oss.str().find("i == 5"), std::string::npos); 00166 TEST_INEQUALITY(oss.str().find("Blah blah blah"), std::string::npos); 00167 // NOTE: The above test asserts that the exception message is being built 00168 // somewhat correctly! 00169 } 00170 00171 00172 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPT_PRINT, noThrowExcept ) 00173 { 00174 const int i = 5; 00175 TEST_NOTHROW( 00176 TEUCHOS_TEST_FOR_EXCEPT_PRINT(i != 5, &out) 00177 ); 00178 } 00179 00180 00181 TEUCHOS_UNIT_TEST( TEUCHOS_TEST_FOR_EXCEPT_PRINT, throwExcept ) 00182 { 00183 const int i = 5; 00184 std::ostringstream oss; 00185 TEST_THROW( 00186 TEUCHOS_TEST_FOR_EXCEPT_PRINT(i == 5, &oss), 00187 std::logic_error); 00188 TEST_INEQUALITY(oss.str().find("AssertAndThrow_UnitTests.cpp"), std::string::npos); 00189 TEST_INEQUALITY(oss.str().find("i == 5"), std::string::npos); 00190 } 00191 00192 00193 TEUCHOS_UNIT_TEST( TEUCHOS_TRACE, basic ) 00194 { 00195 std::logic_error localExcept("Blah blah blah"); 00196 TEST_THROW( 00197 TEUCHOS_TRACE(localExcept), 00198 std::runtime_error); 00199 } 00200 00201 00202 } // namespace
1.7.6.1