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