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