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