|
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 "Array_UnitTest_helpers.hpp" 00046 #include "TestClasses.hpp" 00047 #include "Teuchos_ArrayRCP.hpp" 00048 #include "Teuchos_RCP.hpp" 00049 #include "Teuchos_implicit_cast.hpp" 00050 #include "Teuchos_as.hpp" 00051 #include "Teuchos_getRawPtr.hpp" 00052 00053 namespace { 00054 00055 using ArrayUnitTestHelpers::n; 00056 using ArrayUnitTestHelpers::generateArray; 00057 00058 typedef Teuchos_Ordinal Ordinal; 00059 using Teuchos::getRawPtr; 00060 using Teuchos::as; 00061 using Teuchos::null; 00062 using Teuchos::rcp; 00063 using Teuchos::RCP; 00064 using Teuchos::ArrayRCP; 00065 using Teuchos::Array; 00066 using Teuchos::arcp; 00067 using Teuchos::arcpCloneNode; 00068 using Teuchos::arcp_reinterpret_cast; 00069 using Teuchos::arcp_reinterpret_cast_nonpod; 00070 using Teuchos::ArrayView; 00071 using Teuchos::getConst; 00072 using Teuchos::DuplicateOwningRCPError; 00073 using Teuchos::NullReferenceError; 00074 using Teuchos::DanglingReferenceError; 00075 using Teuchos::RangeError; 00076 using Teuchos::RCP_STRONG; 00077 using Teuchos::RCP_WEAK; 00078 using Teuchos::RCP_STRENGTH_INVALID; 00079 using Teuchos::implicit_ptr_cast; 00080 using Teuchos::getRawPtr; 00081 00082 00083 // 00084 // Non templated unit tests 00085 // 00086 00087 00088 TEUCHOS_UNIT_TEST( ArrayRCP, memberPointer ) 00089 { 00090 ArrayRCP<A> a_arcp = arcp<A>(1); 00091 TEST_EQUALITY_CONST( a_arcp->A_f(), A_f_return ); 00092 } 00093 00094 00095 TEUCHOS_UNIT_TEST( ArrayRCP, getConst_null ) 00096 { 00097 const ArrayRCP<A> a1_arcp; 00098 const ArrayRCP<const A> a2_arcp = a1_arcp.getConst(); 00099 TEST_ASSERT(is_null(a2_arcp)); 00100 } 00101 00102 00103 TEUCHOS_UNIT_TEST( ArrayRCP, operator_parenth_ArrayView_null ) 00104 { 00105 const ArrayRCP<A> a_arcp; 00106 const ArrayView<A> av = a_arcp(); 00107 TEST_ASSERT(is_null(av)); 00108 } 00109 00110 00111 TEUCHOS_UNIT_TEST( ArrayRCP, operator_parenth_ArrayView_const_null ) 00112 { 00113 const ArrayRCP<const A> a_arcp; 00114 const ArrayView<const A> av = a_arcp(); 00115 TEST_ASSERT(is_null(av)); 00116 } 00117 00118 00119 TEUCHOS_UNIT_TEST( ArrayRCP, null_zero_ArrayView_operator ) 00120 { 00121 const ArrayRCP<const A> a_arcp; 00122 const ArrayView<const A> av = a_arcp(0, 0); 00123 TEST_ASSERT(is_null(av)); 00124 } 00125 00126 00127 TEUCHOS_UNIT_TEST( ArrayRCP, null_zero_ArrayView_view_func ) 00128 { 00129 const ArrayRCP<const A> a_arcp; 00130 const ArrayView<const A> av = a_arcp.view(0, 0); 00131 TEST_ASSERT(is_null(av)); 00132 } 00133 00134 00135 TEUCHOS_UNIT_TEST( ArrayRCP, null_zero_ArrayView_persistingView ) 00136 { 00137 const ArrayRCP<const A> a_arcp; 00138 const ArrayRCP<const A> a_arcp2 = a_arcp.persistingView(0, 0); 00139 TEST_ASSERT(is_null(a_arcp2)); 00140 } 00141 00142 00143 TEUCHOS_UNIT_TEST( ArrayRCP, implicit_ArrayRCP_const ) 00144 { 00145 const ArrayRCP<A> a_arcp; 00146 const ArrayRCP<const A> ac_arcp = a_arcp; 00147 TEST_ASSERT(is_null(ac_arcp)); 00148 } 00149 00150 00151 TEUCHOS_UNIT_TEST( ArrayRCP, ArrayRCP_void_throws ) 00152 { 00153 TEST_THROW( const ArrayRCP< void> v_arcp, std::logic_error ); 00154 TEST_THROW( const ArrayRCP<const void> cv_arcp, std::logic_error ); 00155 } 00156 00157 00158 TEUCHOS_UNIT_TEST( ArrayRCP, release ) 00159 { 00160 ArrayRCP<A> a_arcp = arcp<A>(1); 00161 delete [] a_arcp.release(); 00162 } 00163 00164 00165 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_null ) 00166 { 00167 ArrayRCP<A> a_arcp = arcp<A>(0, 0, -1, false); 00168 TEST_ASSERT(is_null(a_arcp)); 00169 } 00170 00171 00172 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_dealloc_null ) 00173 { 00174 ArrayRCP<A> a_arcp = arcp<A, Teuchos::DeallocNull<A> >(0, 0, -1, 00175 Teuchos::DeallocNull<A>(), false); 00176 TEST_ASSERT(is_null(a_arcp)); 00177 } 00178 00179 00180 TEUCHOS_UNIT_TEST( ArrayRCP, convert_from_vector_null ) 00181 { 00182 const RCP<std::vector<int> > v_rcp; 00183 const ArrayRCP<int> a_arcp = arcp(v_rcp); 00184 TEST_ASSERT(is_null(a_arcp)); 00185 } 00186 00187 00188 TEUCHOS_UNIT_TEST( ArrayRCP, convert_from_const_vector_null ) 00189 { 00190 const RCP<const std::vector<int> > v_rcp; 00191 const ArrayRCP<const int> a_arcp = arcp(v_rcp); 00192 TEST_ASSERT(is_null(a_arcp)); 00193 } 00194 00195 00196 TEUCHOS_UNIT_TEST( ArrayRCP, convert_from_vector_unsized ) 00197 { 00198 const RCP<std::vector<int> > v_rcp = rcp(new std::vector<int>); 00199 const ArrayRCP<int> a_arcp = arcp(v_rcp); 00200 TEST_ASSERT(is_null(a_arcp)); 00201 } 00202 00203 00204 TEUCHOS_UNIT_TEST( ArrayRCP, convert_from_const_vector_unsized ) 00205 { 00206 const RCP<const std::vector<int> > v_rcp = rcp(new std::vector<int>); 00207 const ArrayRCP<const int> a_arcp = arcp(v_rcp); 00208 TEST_ASSERT(is_null(a_arcp)); 00209 } 00210 00211 00212 TEUCHOS_UNIT_TEST( ArrayRCP, arcpWithEmbeddedObj ) 00213 { 00214 const ArrayRCP<const int> a_arcp = 00215 Teuchos::arcpWithEmbeddedObj<int>(new int[1], 0, 1, as<int>(1), true); 00216 const int embeddedObj = Teuchos::getEmbeddedObj<int,int>(a_arcp); 00217 TEST_EQUALITY_CONST( embeddedObj, as<int>(1) ); 00218 } 00219 00220 00221 TEUCHOS_UNIT_TEST( ArrayRCP, nonnull ) 00222 { 00223 ECHO(ArrayRCP<int> a_arcp = arcp<int>(10)); 00224 TEST_EQUALITY_CONST(is_null(a_arcp), false); 00225 TEST_EQUALITY_CONST(nonnull(a_arcp), true); 00226 ECHO(a_arcp = null); 00227 TEST_EQUALITY_CONST(is_null(a_arcp), true); 00228 TEST_EQUALITY_CONST(nonnull(a_arcp), false); 00229 } 00230 00231 00232 TEUCHOS_UNIT_TEST( ArrayRCP, weak_strong ) 00233 { 00234 00235 ECHO(ArrayRCP<int> arcp1 = arcp<int>(10)); 00236 TEST_EQUALITY_CONST( arcp1.strength(), RCP_STRONG ); 00237 00238 ECHO(ArrayRCP<int> arcp2 = arcp1.create_weak()); 00239 00240 TEST_EQUALITY_CONST( arcp2.strength(), RCP_WEAK ); 00241 TEST_EQUALITY_CONST( arcp1.strong_count(), 1 ); 00242 TEST_EQUALITY_CONST( arcp1.weak_count(), 1 ); 00243 TEST_EQUALITY_CONST( arcp2.strong_count(), 1 ); 00244 TEST_EQUALITY_CONST( arcp2.weak_count(), 1 ); 00245 00246 ECHO(ArrayRCP<int> arcp3 = arcp2.create_strong()); 00247 00248 TEST_EQUALITY_CONST( arcp3.strength(), RCP_STRONG ); 00249 TEST_EQUALITY_CONST( arcp1.strong_count(), 2 ); 00250 TEST_EQUALITY_CONST( arcp1.weak_count(), 1 ); 00251 TEST_EQUALITY_CONST( arcp2.strong_count(), 2 ); 00252 TEST_EQUALITY_CONST( arcp2.weak_count(), 1 ); 00253 00254 // This will make the underlying object A gets deleted! 00255 ECHO(arcp1 = null); 00256 ECHO(arcp3 = null); 00257 00258 ECHO(arcp2 = null); // Should make the underlying node go away 00259 00260 } 00261 00262 00263 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_null ) 00264 { 00265 ECHO(ArrayRCP<char> arcp_char = null); 00266 ECHO(ArrayRCP<int> arcp_int = arcp_reinterpret_cast<int>(arcp_char)); 00267 TEST_EQUALITY_CONST(arcp_int, null); 00268 } 00269 00270 00271 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_char_to_int ) 00272 { 00273 00274 const int sizeOfInt = sizeof(int); 00275 const int sizeOfChar = sizeof(char); 00276 const int num_ints = n; 00277 const int num_chars = (num_ints*sizeOfInt)/sizeOfChar; 00278 out << "num_ints = " << num_ints << "\n"; 00279 out << "num_chars = " << num_chars << "\n"; 00280 00281 ECHO(ArrayRCP<char> arcp_char = arcp<char>(num_chars)); 00282 ECHO(ArrayRCP<int> arcp_int = arcp_reinterpret_cast<int>(arcp_char)); 00283 TEST_EQUALITY(arcp_int.size(), num_ints); 00284 TEST_EQUALITY(implicit_ptr_cast<void>(&arcp_int[0]), 00285 implicit_ptr_cast<void>(&arcp_char[0])); 00286 TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1), 00287 implicit_ptr_cast<void>((&arcp_char[num_chars-1])+1)); 00288 00289 ECHO(arcp_char+=sizeOfInt); 00290 ECHO(arcp_int = arcp_reinterpret_cast<int>(arcp_char)); 00291 TEST_EQUALITY(arcp_int.size(), num_ints); 00292 TEST_EQUALITY_CONST( arcp_int.lowerOffset(), -1); 00293 TEST_EQUALITY( arcp_int.upperOffset(), num_ints-2); 00294 TEST_EQUALITY( implicit_ptr_cast<void>(&arcp_int[-1]), 00295 implicit_ptr_cast<void>(&arcp_char[-sizeOfInt]) 00296 ); 00297 TEST_EQUALITY( implicit_ptr_cast<void>((&arcp_int[num_ints-2])+1), 00298 implicit_ptr_cast<void>((&arcp_char[num_chars-1-sizeOfInt])+1)); 00299 00300 } 00301 00302 00303 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_int_to_char ) 00304 { 00305 00306 const int sizeOfInt = sizeof(int); 00307 const int sizeOfChar = sizeof(char); 00308 const int num_ints = n; 00309 const int num_chars = (num_ints*sizeOfInt)/sizeOfChar; 00310 out << "num_ints = " << num_ints << "\n"; 00311 out << "num_chars = " << num_chars << "\n"; 00312 00313 ECHO(ArrayRCP<int> arcp_int = arcp<int>(num_ints)); 00314 ECHO(ArrayRCP<char> arcp_char = arcp_reinterpret_cast<char>(arcp_int)); 00315 TEST_EQUALITY(arcp_char.size(), num_chars); 00316 TEST_EQUALITY(implicit_ptr_cast<void>(&arcp_int[0]), 00317 implicit_ptr_cast<void>(&arcp_char[0])); 00318 TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1), 00319 implicit_ptr_cast<void>((&arcp_char[num_chars-1])+1)); 00320 TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1), 00321 implicit_ptr_cast<void>((&arcp_char[num_chars-1])+1)); 00322 00323 ECHO(++arcp_int); 00324 ECHO(arcp_char = arcp_reinterpret_cast<char>(arcp_int)); 00325 TEST_EQUALITY(as<int>(arcp_char.lowerOffset()), as<int>(-sizeOfInt)); 00326 TEST_EQUALITY(as<int>(arcp_char.upperOffset()), as<int>(num_chars-1-sizeOfInt)); 00327 TEST_EQUALITY(implicit_ptr_cast<void>(&arcp_int[-1]), 00328 implicit_ptr_cast<void>(&arcp_char[-sizeOfInt])); 00329 TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-2])+1), 00330 implicit_ptr_cast<void>((&arcp_char[num_chars-1-sizeOfInt])+1)); 00331 00332 } 00333 00334 00335 TEUCHOS_UNIT_TEST( ArrayRCP, evil_reinterpret_cast ) 00336 { 00337 ECHO(ArrayRCP<ArrayRCP<int> > arcp1 = arcp<ArrayRCP<int> >(n)); 00338 ECHO(ArrayRCP<ArrayRCP<const int> > arcp2 = 00339 arcp_reinterpret_cast<ArrayRCP<const int> >(arcp1)); 00340 TEST_EQUALITY(arcp2.size(), arcp1.size()); 00341 TEST_EQUALITY(implicit_ptr_cast<const void>(&arcp1[0]), 00342 implicit_ptr_cast<const void>(&arcp2[0])); 00343 ECHO(ArrayRCP<const ArrayRCP<const int> > arcp3 = arcp2); 00344 TEST_EQUALITY(arcp3.size(), arcp1.size()); 00345 TEST_EQUALITY(implicit_ptr_cast<const void>(&arcp1[0]), 00346 implicit_ptr_cast<const void>(&arcp3[0])); 00347 out << "arcp3 = " << arcp3 << "\n"; 00348 } 00349 00350 00351 // 00352 // Test arcpCloneNode(...) 00353 // 00354 00355 00356 TEUCHOS_UNIT_TEST( ArrayRCP, arcpCloneNode_null ) 00357 { 00358 ECHO(ArrayRCP<ArrayRCP<int> > arcp1 = null); 00359 ECHO(ArrayRCP<ArrayRCP<int> > arcp2 = arcpCloneNode(arcp1)); 00360 TEST_EQUALITY(arcp2, null); 00361 } 00362 00363 00364 TEUCHOS_UNIT_TEST( ArrayRCP, arcpCloneNode_basic ) 00365 { 00366 00367 ECHO(ArrayRCP<int> arcp1 = arcp<int>(n)); 00368 00369 ECHO(ArrayRCP<int> arcp2 = arcpCloneNode(arcp1)); 00370 TEST_ASSERT(nonnull(arcp2)); 00371 TEST_EQUALITY(arcp1.strong_count(), 2); 00372 TEST_EQUALITY(arcp2.strong_count(), 1); 00373 00374 ECHO(ArrayRCP<int> arcp3 = arcp2); 00375 TEST_EQUALITY(arcp1.strong_count(), 2); 00376 TEST_EQUALITY(arcp2.strong_count(), 2); 00377 TEST_EQUALITY(arcp3.strong_count(), 2); 00378 00379 ECHO(ArrayRCP<int> arcp4 = arcp1); 00380 TEST_EQUALITY(arcp1.strong_count(), 3); 00381 TEST_EQUALITY(arcp2.strong_count(), 2); 00382 TEST_EQUALITY(arcp3.strong_count(), 2); 00383 00384 ECHO(arcp4 = null); 00385 TEST_EQUALITY(arcp1.strong_count(), 2); 00386 TEST_EQUALITY(arcp2.strong_count(), 2); 00387 TEST_EQUALITY(arcp3.strong_count(), 2); 00388 TEST_EQUALITY(arcp4.strong_count(), 0); 00389 00390 ECHO(arcp1 = null); 00391 TEST_EQUALITY(arcp1.strong_count(), 0); 00392 TEST_EQUALITY(arcp2.strong_count(), 2); 00393 TEST_EQUALITY(arcp3.strong_count(), 2); 00394 TEST_EQUALITY(arcp4.strong_count(), 0); 00395 00396 ECHO(arcp2 = null); 00397 TEST_EQUALITY(arcp2.strong_count(), 0); 00398 TEST_EQUALITY(arcp3.strong_count(), 1); 00399 00400 ECHO(arcp3 = null); 00401 TEST_EQUALITY(arcp3.strong_count(), 0); 00402 00403 } 00404 00405 00406 // 00407 // Test arcp_reinterpret_cast_nonpod(...) 00408 // 00409 00410 00411 class MockObject { 00412 int member_; 00413 public: 00414 00415 MockObject(int member_in = -1) : member_(member_in) { ++(numConstructorsCalled()); } 00416 MockObject(const MockObject &mo) : member_(mo.member_) { ++(numCopyConstructorsCalled()); } 00417 ~MockObject() { ++(numDestructorsCalled()); } 00418 int member() const { return member_; } 00419 00420 static int & numConstructorsCalled() 00421 { static int s_numConstructorsCalled = 0; return s_numConstructorsCalled; } 00422 static int & numCopyConstructorsCalled() 00423 { static int s_numCopyConstructorsCalled = 0; return s_numCopyConstructorsCalled; } 00424 static int & numDestructorsCalled() 00425 { static int s_numDestructorsCalled = 0; return s_numDestructorsCalled; } 00426 static void reset() { numConstructorsCalled() = numCopyConstructorsCalled() = numDestructorsCalled() = 0; } 00427 00428 }; 00429 00430 00431 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_nonpod_default_construct ) 00432 { 00433 00434 const int sizeOfMockObject = sizeof(MockObject); 00435 const int sizeOfChar = sizeof(char); 00436 const int num_objs = n; 00437 const int num_chars = (num_objs*sizeOfMockObject)/sizeOfChar; 00438 out << "num_objs = " << num_objs << "\n"; 00439 out << "num_chars = " << num_chars << "\n"; 00440 00441 ECHO(ArrayRCP<char> arcp_chars = arcp<char>(num_chars)); 00442 00443 ECHO(MockObject::reset()); 00444 TEST_EQUALITY(MockObject::numConstructorsCalled(), 0); 00445 TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), 0); 00446 TEST_EQUALITY(MockObject::numDestructorsCalled(), 0); 00447 ECHO(ArrayRCP<MockObject> arcp_objs = 00448 arcp_reinterpret_cast_nonpod<MockObject>(arcp_chars)); 00449 TEST_EQUALITY(arcp_objs.size(), num_objs); 00450 TEST_EQUALITY(MockObject::numConstructorsCalled(), 1); 00451 TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs); 00452 TEST_EQUALITY(MockObject::numDestructorsCalled(), 1); 00453 { 00454 int sum = 0; for (int i=0; i < num_objs; ++i) sum += arcp_objs[i].member(); 00455 TEST_EQUALITY(sum, -num_objs); 00456 } 00457 00458 ECHO(ArrayRCP<MockObject> arcp_objs2 = arcp_objs); 00459 TEST_EQUALITY(arcp_objs.size(), num_objs); 00460 TEST_EQUALITY(MockObject::numConstructorsCalled(), 1); 00461 TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs); 00462 TEST_EQUALITY(MockObject::numDestructorsCalled(), 1); 00463 { 00464 int sum = 0; for (int i=0; i < num_objs; ++i) sum += arcp_objs[i].member(); 00465 TEST_EQUALITY(sum, -num_objs); 00466 } 00467 00468 ECHO(arcp_objs = null); 00469 TEST_EQUALITY(MockObject::numConstructorsCalled(), 1); 00470 TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs); 00471 TEST_EQUALITY(MockObject::numDestructorsCalled(), 1); 00472 00473 ECHO(arcp_objs2 = null); 00474 TEST_EQUALITY(MockObject::numConstructorsCalled(), 1); 00475 TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs); 00476 TEST_EQUALITY(MockObject::numDestructorsCalled(), num_objs + 1); 00477 00478 } 00479 00480 00481 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_nonpod_copy_construct ) 00482 { 00483 00484 const int sizeOfMockObject = sizeof(MockObject); 00485 const int sizeOfChar = sizeof(char); 00486 const int num_objs = n; 00487 const int num_chars = (num_objs*sizeOfMockObject)/sizeOfChar; 00488 out << "num_objs = " << num_objs << "\n"; 00489 out << "num_chars = " << num_chars << "\n"; 00490 00491 ECHO(ArrayRCP<char> arcp_chars = arcp<char>(num_chars)); 00492 00493 ECHO(MockObject::reset()); 00494 TEST_EQUALITY(MockObject::numConstructorsCalled(), 0); 00495 TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), 0); 00496 TEST_EQUALITY(MockObject::numDestructorsCalled(), 0); 00497 ECHO(const MockObject mockObj(1)); 00498 TEST_EQUALITY(MockObject::numConstructorsCalled(), 1); 00499 TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), 0); 00500 TEST_EQUALITY(MockObject::numDestructorsCalled(), 0); 00501 00502 ECHO(MockObject::reset()); 00503 TEST_EQUALITY(MockObject::numConstructorsCalled(), 0); 00504 TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), 0); 00505 TEST_EQUALITY(MockObject::numDestructorsCalled(), 0); 00506 ECHO(ArrayRCP<MockObject> arcp_objs = 00507 arcp_reinterpret_cast_nonpod(arcp_chars, mockObj)); 00508 TEST_EQUALITY(arcp_objs.size(), num_objs); 00509 TEST_EQUALITY(MockObject::numConstructorsCalled(), 0); 00510 TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs); 00511 TEST_EQUALITY(MockObject::numDestructorsCalled(), 0); 00512 { 00513 int sum = 0; for (int i=0; i < num_objs; ++i) sum += arcp_objs[i].member(); 00514 TEST_EQUALITY(sum, num_objs); 00515 } 00516 00517 ECHO(ArrayRCP<MockObject> arcp_objs2 = arcp_objs); 00518 TEST_EQUALITY(arcp_objs.size(), num_objs); 00519 TEST_EQUALITY(MockObject::numConstructorsCalled(), 0); 00520 TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs); 00521 TEST_EQUALITY(MockObject::numDestructorsCalled(), 0); 00522 { 00523 int sum = 0; for (int i=0; i < num_objs; ++i) sum += arcp_objs[i].member(); 00524 TEST_EQUALITY(sum, num_objs); 00525 } 00526 00527 ECHO(arcp_objs = null); 00528 TEST_EQUALITY(MockObject::numConstructorsCalled(), 0); 00529 TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs); 00530 TEST_EQUALITY(MockObject::numDestructorsCalled(), 0); 00531 00532 ECHO(arcp_objs2 = null); 00533 TEST_EQUALITY(MockObject::numConstructorsCalled(), 0); 00534 TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs); 00535 TEST_EQUALITY(MockObject::numDestructorsCalled(), num_objs); 00536 00537 } 00538 00539 00540 // 00541 // Test catching of duplicate owning ArrayRCP objects 00542 // 00543 00544 00545 TEUCHOS_UNIT_TEST( ArrayRCP, duplicate_arcp_owning ) 00546 { 00547 SET_RCPNODE_TRACING(); 00548 ECHO(A *a_ptr = new A[n]); 00549 ECHO(ArrayRCP<A> a_arcp1 = arcp(a_ptr, 0, n)); // Okay 00550 #if defined(TEUCHOS_DEBUG) 00551 // With node tracing turned on, the implementation knows that an RCPNode 00552 // already exists pointing to this same underlying array and will therefore 00553 // throw. 00554 TEST_THROW(ArrayRCP<A> a_arcp2 = arcp(a_ptr, 0, n), DuplicateOwningRCPError); 00555 #else 00556 // Will not determine they are point to the same object! 00557 ECHO(ArrayRCP<A> a_arcp2 = arcp(a_ptr, 0, n)); 00558 TEST_EQUALITY(a_arcp2.getRawPtr(), a_ptr); 00559 ECHO(a_arcp2.release()); // Better or we will get a segfault! 00560 #endif 00561 } 00562 00563 00564 TEUCHOS_UNIT_TEST( ArrayRCP, dangling_nonowning ) 00565 { 00566 SET_RCPNODE_TRACING(); 00567 ECHO(A *a_ptr = new A[n]); 00568 ECHO(ArrayRCP<A> a_arcp1 = arcp(a_ptr, 0, n)); // Okay 00569 ECHO(ArrayRCP<A> a_arcp2 = arcp(a_ptr, 0, n, false)); // Okay 00570 a_arcp1 = null; 00571 #if defined(TEUCHOS_DEBUG) 00572 // With node tracing turned on, the implementation knows that the original 00573 // array is deleted and this is a dangling reference! 00574 TEST_THROW(a_arcp2.getRawPtr(), DanglingReferenceError); 00575 #else 00576 // With node tracing turned off, the implemetation does not know the 00577 // original array is deleted and therefore it will return a now invalid 00578 // pointer. 00579 TEST_NOTHROW(a_arcp2.getRawPtr()); 00580 #endif 00581 } 00582 00583 00584 class WeirdDealloc { 00585 int size_; 00586 RCP<std::ostream > out_; 00587 public: 00588 WeirdDealloc(int size, const RCP<std::ostream> &out) : size_(size), out_(out) {} 00589 void free(void *ptr) const 00590 { 00591 int * const int_ptr = reinterpret_cast<int*>(ptr); 00592 { 00593 // Create an ArrayView that points to the same memory that is being 00594 // deallocated by the owning ArrayRCP. Here, if RCPNode tracing is 00595 // enabled, this will thrown and there is really no way around it. 00596 ArrayView<const int> tmpav(int_ptr, size_, Teuchos::RCP_DISABLE_NODE_LOOKUP); 00597 assert(tmpav[0] == int_ptr[0]); 00598 *out_ << tmpav << std::endl; 00599 // Create a copy of the ArrayView and make sure that it does not do 00600 // node tracing either. 00601 ArrayView<const int> tmpav2(tmpav); 00602 assert(tmpav2[0] == int_ptr[0]); 00603 *out_ << tmpav2 << std::endl; 00604 // Assign the ArrayView and make sure that it does not do node tracing 00605 // either. 00606 ArrayView<const int> tmpav3; 00607 tmpav3 = tmpav; 00608 assert(tmpav3[0] == int_ptr[0]); 00609 *out_ << tmpav2 << std::endl; 00610 } 00611 delete [] int_ptr; 00612 } 00613 }; 00614 00615 00616 TEUCHOS_UNIT_TEST( ArrayRCP, weirdDealloc ) 00617 { 00618 using Teuchos::rcpFromRef; 00619 const int size = 4; 00620 const bool ownsMem = true; 00621 int *int_ptr = new int[size]; 00622 std::fill_n(int_ptr, size, 0); 00623 ArrayRCP<int> a = arcp<int>( int_ptr , 0, size, 00624 WeirdDealloc(size, rcpFromRef(out)), ownsMem ); 00625 a = Teuchos::null; 00626 } 00627 00628 00629 // 00630 // Templated unit tests 00631 // 00632 00633 00634 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, construct_n, T ) 00635 { 00636 std::vector<T> a(n, as<T>(1)); 00637 ArrayRCP<T> a_arcp(n, as<T>(1)); 00638 TEST_COMPARE_ARRAYS(a, a_arcp); 00639 } 00640 00641 00642 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, assignSelf, T ) 00643 { 00644 ArrayRCP<T> a_arcp; 00645 a_arcp = a_arcp; 00646 } 00647 00648 00649 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, assign_n_val, T ) 00650 { 00651 const T val = as<T>(1); 00652 std::vector<T> a; 00653 a.assign(n, val); 00654 ArrayRCP<T> a_arcp; 00655 a_arcp.assign(as<Ordinal>(n), val); 00656 TEST_COMPARE_ARRAYS(a, a_arcp); 00657 } 00658 00659 00660 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, assign_begin_end, T ) 00661 { 00662 const T val = as<T>(1); 00663 std::vector<T> a; 00664 a.assign(n, val); 00665 ArrayRCP<T> a_arcp; 00666 a_arcp.assign(a.begin(), a.end()); 00667 TEST_COMPARE_ARRAYS(a, a_arcp); 00668 } 00669 00670 00671 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, print_iterators, T ) 00672 { 00673 typedef typename ArrayRCP<T>::const_iterator const_iterator; 00674 ECHO(ArrayRCP<T> a_arcp = arcp<T>(n)); 00675 ECHO(const_iterator itr = a_arcp.begin()); 00676 out << "itr = " << itr << "\n"; 00677 TEST_EQUALITY(itr, a_arcp.begin()); 00678 ECHO(itr += n); 00679 out << "itr = " << itr << "\n"; 00680 TEST_EQUALITY(itr, a_arcp.end()); 00681 } 00682 00683 00684 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, deepCopy, T ) 00685 { 00686 const T val = as<T>(1); 00687 std::vector<T> a; 00688 a.assign(n, val); 00689 ArrayRCP<T> a_arcp = arcp<T>(n); 00690 ArrayRCP<T> a_arcp_cpy = a_arcp; 00691 a_arcp.deepCopy(Teuchos::arrayViewFromVector(a)); 00692 TEST_COMPARE_ARRAYS(a, a_arcp); 00693 TEST_EQUALITY(a_arcp.getRawPtr(), a_arcp_cpy.getRawPtr()); 00694 } 00695 00696 00697 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, resize, T ) 00698 { 00699 const T val1 = as<T>(1); 00700 const T val2 = as<T>(2); 00701 00702 std::vector<T> a; 00703 ArrayRCP<T> a_arcp; 00704 00705 out << "\nChecking resize(n, val1) ...\n"; 00706 a.resize(n, val1); 00707 a_arcp.resize(n, val1); 00708 TEST_COMPARE_ARRAYS(a, a_arcp); 00709 00710 out << "\nChecking resize(2*n, val2) ...\n"; 00711 a.resize(2*n, val2); 00712 a_arcp.resize(2*n, val2); 00713 TEST_COMPARE_ARRAYS(a, a_arcp); 00714 00715 out << "\nChecking resize(n/2) ...\n"; 00716 a.resize(n/2); 00717 a_arcp.resize(n/2); 00718 TEST_COMPARE_ARRAYS(a, a_arcp); 00719 00720 out << "\nChecking resize(0) ...\n"; 00721 a.resize(0); 00722 a_arcp.resize(0); 00723 TEST_COMPARE_ARRAYS(a, a_arcp); 00724 00725 #ifdef TEUCHOS_DEBUG 00726 a_arcp = arcp<T>(n); 00727 ++a_arcp; 00728 TEST_THROW(a_arcp.resize(1), std::out_of_range); 00729 #endif 00730 } 00731 00732 00733 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, clear, T ) 00734 { 00735 ArrayRCP<T> a_arcp = arcp<T>(n); 00736 TEST_EQUALITY( a_arcp.size(), n ); 00737 a_arcp.clear(); 00738 TEST_EQUALITY( a_arcp.size(), 0 ); 00739 } 00740 00741 00742 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, nullIterator, T ) 00743 { 00744 typedef ArrayRCP<T> iter_t; 00745 ArrayRCP<T> arcp1 = Teuchos::NullIteratorTraits<iter_t>::getNull(); 00746 TEST_EQUALITY_CONST(arcp1, Teuchos::null); 00747 } 00748 00749 00750 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, implicitConversions, T ) 00751 { 00752 00753 ECHO(ArrayRCP<T> arcp1 = arcp<T>(n)); 00754 ECHO(ArrayRCP<const T> arcp2 = arcp1); 00755 TEST_ASSERT(arcp1.shares_resource(arcp2)); 00756 00757 } 00758 00759 00760 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, weakDelete, T ) 00761 { 00762 00763 ECHO(ArrayRCP<T> arcp_strong = arcp<T>(n)); 00764 00765 TEST_EQUALITY_CONST( arcp_strong.strength(), RCP_STRONG ); 00766 TEST_EQUALITY_CONST( arcp_strong.is_null(), false ); 00767 TEST_EQUALITY_CONST( arcp_strong.strong_count(), 1 ); 00768 TEST_EQUALITY_CONST( arcp_strong.weak_count(), 0 ); 00769 TEST_EQUALITY_CONST( arcp_strong.total_count(), 1 ); 00770 00771 ECHO(ArrayRCP<T> arcp_weak1 = arcp_strong.create_weak()); 00772 00773 TEST_EQUALITY_CONST( arcp_weak1.strength(), RCP_WEAK ); 00774 TEST_EQUALITY_CONST( arcp_weak1.is_null(), false ); 00775 TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 1 ); 00776 TEST_EQUALITY_CONST( arcp_weak1.weak_count(), 1 ); 00777 TEST_EQUALITY_CONST( arcp_weak1.total_count(), 2 ); 00778 00779 TEST_EQUALITY_CONST( arcp_strong.strong_count(), 1 ); 00780 TEST_EQUALITY_CONST( arcp_strong.is_null(), false ); 00781 TEST_EQUALITY_CONST( arcp_strong.weak_count(), 1 ); 00782 TEST_EQUALITY_CONST( arcp_strong.total_count(), 2 ); 00783 00784 TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_strong), true ); 00785 00786 TEST_EQUALITY( arcp_weak1.get(), arcp_weak1.getRawPtr() ); 00787 TEST_EQUALITY( arcp_weak1.get(), arcp_strong.get() ); 00788 TEST_EQUALITY( arcp_weak1.getRawPtr(), arcp_strong.getRawPtr() ); 00789 00790 ECHO(ArrayRCP<T> arcp_weak2 = arcp_weak1); 00791 00792 TEST_EQUALITY_CONST( arcp_weak2.strength(), RCP_WEAK ); 00793 TEST_EQUALITY_CONST( arcp_weak2.is_null(), false ); 00794 TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 1 ); 00795 TEST_EQUALITY_CONST( arcp_weak2.weak_count(), 2 ); 00796 TEST_EQUALITY_CONST( arcp_weak2.total_count(), 3 ); 00797 00798 TEST_EQUALITY_CONST( arcp_strong.strong_count(), 1 ); 00799 TEST_EQUALITY_CONST( arcp_strong.is_null(), false ); 00800 TEST_EQUALITY_CONST( arcp_strong.weak_count(), 2 ); 00801 TEST_EQUALITY_CONST( arcp_strong.total_count(), 3 ); 00802 00803 TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_strong), true ); 00804 TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_weak2), true ); 00805 TEST_EQUALITY_CONST( arcp_weak2.shares_resource(arcp_strong), true ); 00806 00807 TEST_EQUALITY( arcp_weak2.get(), arcp_strong.get() ); 00808 TEST_EQUALITY( arcp_weak2.getRawPtr(), arcp_strong.getRawPtr() ); 00809 00810 ECHO(arcp_strong = null); // This deletes the underlying object of type T! 00811 00812 TEST_EQUALITY_CONST( arcp_strong.strength(), RCP_STRENGTH_INVALID ); 00813 TEST_EQUALITY_CONST( arcp_strong.is_null(), true ); 00814 TEST_EQUALITY_CONST( arcp_strong.strong_count(), 0 ); 00815 TEST_EQUALITY_CONST( arcp_strong.strong_count(), 0 ); 00816 TEST_EQUALITY_CONST( arcp_strong.weak_count(), 0 ); 00817 TEST_EQUALITY_CONST( arcp_strong.total_count(), 0 ); 00818 TEST_EQUALITY_CONST( arcp_strong.is_valid_ptr(), true ); 00819 00820 TEST_EQUALITY_CONST( arcp_strong.shares_resource(arcp_weak1), false ); 00821 TEST_EQUALITY_CONST( arcp_strong.shares_resource(arcp_weak2), false ); 00822 00823 TEST_EQUALITY_CONST( arcp_weak1.has_ownership(), true ); 00824 TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 0 ); 00825 TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 0 ); 00826 TEST_EQUALITY_CONST( arcp_weak1.weak_count(), 2 ); 00827 TEST_EQUALITY_CONST( arcp_weak1.total_count(), 2 ); 00828 TEST_EQUALITY_CONST( arcp_weak1.is_valid_ptr(), false ); 00829 00830 TEST_EQUALITY_CONST( arcp_weak2.has_ownership(), true ); 00831 TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 0 ); 00832 TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 0 ); 00833 TEST_EQUALITY_CONST( arcp_weak2.weak_count(), 2 ); 00834 TEST_EQUALITY_CONST( arcp_weak2.total_count(), 2 ); 00835 TEST_EQUALITY_CONST( arcp_weak2.is_valid_ptr(), false ); 00836 00837 TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_weak2), true ); 00838 00839 ECHO(arcp_weak1.assert_not_null()); // Does not throw! 00840 ECHO(arcp_weak2.assert_not_null()); // Does not throw! 00841 00842 TEST_THROW( arcp_weak1.assert_valid_ptr(), DanglingReferenceError ); 00843 #ifdef TEUCHOS_DEBUG 00844 TEST_THROW( arcp_weak1.operator->(), DanglingReferenceError ); 00845 TEST_THROW( *arcp_weak1, DanglingReferenceError ); 00846 TEST_THROW( arcp_weak1.create_weak(), DanglingReferenceError ); 00847 TEST_THROW( arcp_weak1.get(), DanglingReferenceError ); 00848 TEST_THROW( arcp_weak1.getRawPtr(), DanglingReferenceError ); 00849 TEST_THROW( arcp_weak1[0], DanglingReferenceError ); 00850 TEST_THROW( ++arcp_weak1, DanglingReferenceError ); 00851 TEST_THROW( arcp_weak1++, DanglingReferenceError ); 00852 TEST_THROW( --arcp_weak1, DanglingReferenceError ); 00853 TEST_THROW( arcp_weak1--, DanglingReferenceError ); 00854 TEST_THROW( arcp_weak1+=1, DanglingReferenceError ); 00855 TEST_THROW( arcp_weak1-=1, DanglingReferenceError ); 00856 TEST_THROW( arcp_weak1+1, DanglingReferenceError ); 00857 TEST_THROW( arcp_weak1-1, DanglingReferenceError ); 00858 TEST_THROW( arcp_weak1.getConst(), DanglingReferenceError ); 00859 TEST_THROW( arcp_weak1.persistingView(0,n), DanglingReferenceError ); 00860 TEST_THROW( arcp_weak1.lowerOffset(), DanglingReferenceError ); 00861 TEST_THROW( arcp_weak1.upperOffset(), DanglingReferenceError ); 00862 TEST_THROW( arcp_weak1.size(), DanglingReferenceError ); 00863 TEST_THROW( arcp_weak1.begin(), DanglingReferenceError ); 00864 TEST_THROW( arcp_weak1.end(), DanglingReferenceError ); 00865 TEST_THROW( arcp_weak1.view(0,n), DanglingReferenceError ); 00866 TEST_THROW( arcp_weak1(0,n), DanglingReferenceError ); 00867 TEST_THROW( arcp_weak1(), DanglingReferenceError ); 00868 TEST_THROW( {ArrayView<T> av = arcp_weak1();}, DanglingReferenceError ); 00869 TEST_THROW( {ArrayRCP<const T> ap = getConst(arcp_weak1);}, 00870 DanglingReferenceError ); 00871 TEST_THROW( arcp_weak1.release(), DanglingReferenceError ); 00872 #endif // TEUCHOS_DEBUG 00873 00874 ECHO(arcp_weak1 = null); // Just deicrements weak count! 00875 00876 TEST_EQUALITY_CONST( arcp_weak1.strength(), RCP_STRENGTH_INVALID ); 00877 TEST_EQUALITY_CONST( arcp_weak1.is_null(), true ); 00878 TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 0 ); 00879 TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 0 ); 00880 TEST_EQUALITY_CONST( arcp_weak1.weak_count(), 0 ); 00881 TEST_EQUALITY_CONST( arcp_weak1.total_count(), 0 ); 00882 TEST_EQUALITY_CONST( arcp_weak1.is_valid_ptr(), true ); 00883 00884 TEST_EQUALITY_CONST( arcp_weak2.has_ownership(), true ); 00885 TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 0 ); 00886 TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 0 ); 00887 TEST_EQUALITY_CONST( arcp_weak2.weak_count(), 1 ); 00888 TEST_EQUALITY_CONST( arcp_weak2.total_count(), 1 ); 00889 TEST_EQUALITY_CONST( arcp_weak2.is_valid_ptr(), false ); 00890 00891 TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_weak2), false ); 00892 00893 TEST_THROW( arcp_weak2.assert_valid_ptr(), DanglingReferenceError ); 00894 #ifdef TEUCHOS_DEBUG 00895 // ToDo: Fill in 00896 #endif // TEUCHOS_DEBUG 00897 00898 } 00899 00900 00901 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, danglingArrayView, T ) 00902 { 00903 ArrayView<T> av; 00904 { 00905 ArrayRCP<T> arcp1 = arcp<T>(n); 00906 av = arcp1(); 00907 } 00908 #ifdef TEUCHOS_DEBUG 00909 TEST_THROW( av.size(), DanglingReferenceError ); 00910 TEST_THROW( av.toString(), DanglingReferenceError ); 00911 TEST_THROW( av.getRawPtr(), DanglingReferenceError ); 00912 TEST_THROW( av[0], DanglingReferenceError ); 00913 TEST_THROW( av.front(), DanglingReferenceError ); 00914 TEST_THROW( av.back(), DanglingReferenceError ); 00915 TEST_THROW( av.view(0, n), DanglingReferenceError ); 00916 TEST_THROW( av(0, n), DanglingReferenceError ); 00917 TEST_THROW( av(), DanglingReferenceError ); 00918 TEST_THROW( av.getConst(), DanglingReferenceError ); 00919 TEST_THROW( av.begin(), DanglingReferenceError ); 00920 TEST_THROW( av.end(), DanglingReferenceError ); 00921 #endif 00922 } 00923 00924 00925 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, getRawPtr, T ) 00926 { 00927 ArrayRCP<const T> cptr; 00928 ArrayRCP<T> ptr; 00929 TEST_EQUALITY_CONST( getRawPtr(cptr), (const T*)NULL ); 00930 TEST_EQUALITY_CONST( getRawPtr(ptr), (T*)NULL ); 00931 cptr = arcp<T>(n); 00932 ptr = arcp<T>(n); 00933 TEST_EQUALITY( getRawPtr(cptr), &cptr[0]); 00934 TEST_EQUALITY( getRawPtr(ptr), &ptr[0] ); 00935 } 00936 00937 00938 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( CPtr, getRawPtr, T ) 00939 { 00940 const T *cptr = NULL; 00941 T *ptr = NULL; 00942 TEST_EQUALITY_CONST( getRawPtr(cptr), (const T*)NULL ); 00943 TEST_EQUALITY_CONST( getRawPtr(ptr), (T*)NULL ); 00944 cptr = new T[n]; 00945 ptr = new T[n]; 00946 TEST_EQUALITY( getRawPtr(cptr), &cptr[0]); 00947 TEST_EQUALITY( getRawPtr(ptr), &ptr[0] ); 00948 delete [] cptr; 00949 delete [] ptr; 00950 } 00951 00952 00953 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, arcp_zero, T ) 00954 { 00955 ArrayRCP<T> arcp_strong = arcp<T>(0); 00956 TEST_EQUALITY(arcp_strong.size(), as<Ordinal>(0)); 00957 } 00958 00959 00960 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, arcpFromArrayView, T ) 00961 { 00962 Array<T> a = generateArray<T>(n); 00963 ArrayView<T> av = a; 00964 ArrayRCP<T> arcp1 = Teuchos::arcpFromArrayView(av); 00965 TEST_COMPARE_ARRAYS(arcp1, av); 00966 } 00967 00968 00969 #ifdef TEUCHOS_DEBUG 00970 00971 00972 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, arcp_neg, T ) 00973 { 00974 TEST_THROW(ArrayRCP<T> arcp_strong = arcp<T>(-1), 00975 std::out_of_range); 00976 } 00977 00978 00979 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, outOfBounds, T ) 00980 { 00981 ECHO(ArrayRCP<T> arcp1 = arcp<T>(n)); 00982 TEST_THROW(arcp1(-1,n), RangeError); 00983 TEST_THROW(arcp1(0,n+1), RangeError); 00984 TEST_THROW(arcp1(0,-1), RangeError); 00985 TEST_THROW(arcp1.view(-1,n), RangeError); 00986 TEST_THROW(arcp1.view(0,n+1), RangeError); 00987 TEST_THROW(arcp1.view(0,-1), RangeError); 00988 TEST_THROW(arcp1.persistingView(-1,n), RangeError); 00989 TEST_THROW(arcp1.persistingView(0,n+1), RangeError); 00990 TEST_THROW(arcp1.persistingView(0,-1), RangeError); 00991 } 00992 00993 00994 #endif // TEUCHOS_DEBUG 00995 00996 00997 // 00998 // Template Instantiations 00999 // 01000 01001 01002 #ifdef TEUCHOS_DEBUG 01003 01004 # define DEBUG_UNIT_TEST_GROUP( T ) \ 01005 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, arcp_neg, T ) \ 01006 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, outOfBounds, T ) \ 01007 01008 #else 01009 01010 # define DEBUG_UNIT_TEST_GROUP( T ) 01011 01012 #endif 01013 01014 01015 #define UNIT_TEST_GROUP( T ) \ 01016 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, construct_n, T ) \ 01017 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, assignSelf, T ) \ 01018 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, assign_n_val, T ) \ 01019 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, assign_begin_end, T ) \ 01020 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, print_iterators, T ) \ 01021 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, deepCopy, T ) \ 01022 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, resize, T ) \ 01023 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, clear, T ) \ 01024 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, nullIterator, T ) \ 01025 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, implicitConversions, T ) \ 01026 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, weakDelete, T ) \ 01027 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, danglingArrayView, T ) \ 01028 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, getRawPtr, T) \ 01029 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( CPtr, getRawPtr, T) \ 01030 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, arcp_zero, T ) \ 01031 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, arcpFromArrayView, T ) \ 01032 DEBUG_UNIT_TEST_GROUP(T) 01033 01034 01035 UNIT_TEST_GROUP(int) 01036 UNIT_TEST_GROUP(double) 01037 UNIT_TEST_GROUP(float) 01038 01039 01040 } // namespace
1.7.6.1