Teuchos Package Browser (Single Doxygen Collection) Version of the Day
ArrayRCP_test.cpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //                    Teuchos: Common Tools Package
00005 //                 Copyright (2004) Sandia Corporation
00006 //
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #include "Teuchos_ArrayRCP.hpp"
00043 #include "Teuchos_Array.hpp"
00044 #include "Teuchos_CommandLineProcessor.hpp"
00045 #include "Teuchos_GlobalMPISession.hpp"
00046 #include "Teuchos_VerboseObject.hpp"
00047 #include "Teuchos_StandardCatchMacros.hpp"
00048 #include "Teuchos_Version.hpp"
00049 #include "Teuchos_Assert.hpp"
00050 #include "Teuchos_LocalTestingHelpers.hpp"
00051 
00052 
00053 // Temporarily uncomment any or all of these macros to see compilation
00054 // failures for code that is rightfully not supposed to compile (which is a
00055 // wonderful thing)! The fact that this code does not compile show that the
00056 // design of the Teuchos::ArrayRCP class supports full support of
00057 // const projection in all of its forms when dealing with arrays of objects.
00058 //#define SHOW_COMPILE_FAILURE_1
00059 //#define SHOW_COMPILE_FAILURE_2
00060 //#define SHOW_COMPILE_FAILURE_3
00061 
00062 
00063 //
00064 // Iterator testing function
00065 //
00066 
00067 template<class T>
00068 bool test_ArrayRCP_iterators(
00069   const Teuchos::ArrayRCP<T> &ptr,
00070   Teuchos::FancyOStream &out
00071   )
00072 {
00073 
00074   using Teuchos::ArrayRCP;
00075   using Teuchos::null;
00076   using Teuchos::arcp;
00077 
00078   bool success = true;
00079 
00080   out
00081     << "\n***"
00082     << "\n*** Testing iterators and accessors for ptr = " << ptr
00083     << "\n***\n";
00084 
00085   Teuchos::OSTab tab(out);
00086 
00087   const int size = ptr.size();
00088 
00089   // Pointer ++
00090  
00091   {
00092     out << "\nChecking ++itr and < ...\n";
00093     ArrayRCP<T> itr = ptr;
00094     for( int i = 0; itr < ptr+size; ++i, ++itr )
00095       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00096   }
00097  
00098   {
00099     out << "\nChecking itr++ and <= ...\n";
00100     ArrayRCP<T> itr = ptr;
00101     for( int i = 0; itr <= ptr+size-1; ++i, itr++ )
00102       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00103   }
00104  
00105   {
00106     out << "\nChecking itr+=1 and != ...\n";
00107     ArrayRCP<T> itr = ptr;
00108     for( int i = 0; itr != ptr+size; ++i, itr+=1 )
00109       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00110   }
00111  
00112   {
00113     out << "\nChecking itr=itr+1 and == ...\n";
00114     ArrayRCP<T> itr = ptr;
00115     for( int i = 0; !( itr == ptr+size ); ++i, itr=itr+1 )
00116       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00117   }
00118 
00119   // Pointer --
00120  
00121   {
00122     out << "\nChecking --itr and >= ...\n";
00123     ArrayRCP<T> itr = ptr+size-1;
00124     for( int i = size-1; itr >= ptr; --i, --itr )
00125       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00126   }
00127  
00128   {
00129     out << "\nChecking itr-- and > ...\n";
00130     ArrayRCP<T> itr = ptr+size-1;
00131     for( int i = size-1; itr+1 > ptr; i--, itr-- )
00132       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00133   }
00134  
00135   {
00136     out << "\nChecking itr-=1 and != ...\n";
00137     ArrayRCP<T> itr = ptr+size-1;
00138     for( int i = size-1; itr+1 != ptr; i--, itr-=1 )
00139       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00140   }
00141  
00142   {
00143     out << "\nChecking itr=itr-1 and == ...\n";
00144     ArrayRCP<T> itr = ptr+size-1;
00145     for( int i = size-1; !( itr+1 == ptr ); i--, itr=itr-1 )
00146       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00147   }
00148 
00149   // Iterator - Iterator
00150  
00151   {
00152     out << "\nChecking ptr.end() - ptr.begin() == ptr.size() ...\n";
00153     TEUCHOS_ASSERT_EQUALITY( ptr.end() - ptr.begin(), ptr.size() );
00154   }
00155 
00156   // Iterator ++
00157  
00158   {
00159     out << "\nChecking iterator ++itr and < ...\n";
00160     typename ArrayRCP<T>::const_iterator itr = ptr.begin();
00161     for( int i = 0; itr < ptr.end(); ++i, ++itr )
00162       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00163   }
00164  
00165   {
00166     out << "\nChecking iterator itr++ and <= ...\n";
00167     typename ArrayRCP<T>::const_iterator itr = ptr.begin();
00168     for( int i = 0; itr <= ptr.end()-1; ++i, itr++ )
00169       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00170   }
00171  
00172   {
00173     out << "\nChecking iterator itr+=1 and != ...\n";
00174     typename ArrayRCP<T>::const_iterator itr = ptr.begin();
00175     for( int i = 0; itr != ptr.end(); ++i, itr+=1 )
00176       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00177   }
00178  
00179   {
00180     out << "\nChecking iterator itr=itr+1 and == ...\n";
00181     typename ArrayRCP<T>::const_iterator itr = ptr.begin();
00182     for( int i = 0; !( itr == ptr.end() ); ++i, itr=itr+1 )
00183       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00184   }
00185 
00186   // Iterator --
00187  
00188   {
00189     out << "\nChecking iterator --itr and >= ...\n";
00190     typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
00191     for( int i = size-1; itr >= ptr.begin(); --i, --itr )
00192       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00193   }
00194  
00195   {
00196     out << "\nChecking iterator itr-- and > ...\n";
00197     typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
00198     for( int i = size-1; itr+1 > ptr.begin(); i--, itr-- )
00199       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00200   }
00201  
00202   {
00203     out << "\nChecking iterator itr-=1 and != ...\n";
00204     typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
00205     for( int i = size-1; itr+1 != ptr.begin(); i--, itr-=1 )
00206       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00207   }
00208  
00209   {
00210     out << "\nChecking iterator itr=itr-1 and == ...\n";
00211     typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
00212     for( int i = size-1; !( itr+1 == ptr.begin() ); i--, itr=itr-1 )
00213       TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
00214   }
00215 
00216   return success;
00217 
00218 }
00219 
00220 
00221 //
00222 // Main testing function for a specific ArrayRCP
00223 //
00224 
00225 
00226 template<class T>
00227 bool test_ArrayRCP(
00228   const Teuchos::ArrayRCP<T> &ptr,
00229   Teuchos::FancyOStream &out
00230   )
00231 {
00232 
00233   using Teuchos::ArrayView;
00234   using Teuchos::ArrayRCP;
00235   using Teuchos::arcp;
00236   using Teuchos::arcp_const_cast;
00237   using Teuchos::as;
00238 
00239   bool success = true, result;
00240  
00241   out
00242     << "\n***"
00243     << "\n*** Testing ptr = " << ptr
00244     << "\n***\n";
00245 
00246   Teuchos::OSTab tab(out);
00247 
00248   const int n = ptr.size();
00249  
00250   {
00251     out << "\nInitializing data ...\n";
00252     for( int i = 0; i < n; ++i )
00253       ptr[i] = i;
00254   }
00255 
00256   TEST_FOR_EXCEPT( !(&*ptr == ptr.get()) );
00257   TEST_FOR_EXCEPT( !(&*ptr == ptr.getRawPtr()) );
00258 
00259   result = test_ArrayRCP_iterators(ptr,out);
00260   if (!result) success = false;
00261 
00262   //
00263   out << "\nTest const casting ...\n";
00264   //
00265 
00266   {
00267     const ArrayRCP<const T> cptr2 = ptr;
00268     const ArrayRCP<T> ptr3 = arcp_const_cast<T>(cptr2);
00269     TEST_COMPARE_ARRAYS( ptr3, ptr );
00270   }
00271 
00272   //
00273   out << "\nTest views ...\n";
00274   //
00275 
00276   {
00277     out << "\nTest full non-const subview ...\n";
00278     const ArrayView<T> av2 = ptr(0,n);
00279     TEST_COMPARE_ARRAYS( av2, ptr );
00280   }
00281 
00282   {
00283     out << "\nTest full shorthand non-const subview ...\n";
00284     const ArrayView<T> av2 = ptr();
00285     TEST_COMPARE_ARRAYS( av2, ptr );
00286   }
00287 
00288   {
00289     out << "\nTest full const subview ...\n";
00290     const ArrayView<const T> cav2 = ptr.getConst()(0,n);
00291     TEST_COMPARE_ARRAYS( cav2, ptr );
00292   }
00293 
00294   {
00295     out << "\nTest full non-const to const subview ...\n";
00296     const ArrayView<const T> cav2 = ptr(0,n);
00297     TEST_COMPARE_ARRAYS( cav2, ptr );
00298   }
00299 
00300   {
00301     out << "\nTest full short-hand const subview ...\n";
00302     const ArrayView<const T> cav2 = ptr.getConst()();
00303     TEST_COMPARE_ARRAYS( cav2, ptr );
00304   }
00305 
00306   {
00307     out << "\nTest implicit conversion from ArrayRCP<T> to ArrayView<T> ...\n";
00308     const ArrayView<T> av2 = ptr();
00309     TEST_COMPARE_ARRAYS( av2, ptr );
00310   }
00311 
00312   {
00313     out << "\nTest implicit conversion from ArrayRCP<const T> to ArrayView<const T> ...\n";
00314     const ArrayView<const T> av2 = ptr.getConst()();
00315     TEST_COMPARE_ARRAYS( av2, ptr );
00316   }
00317 
00318   {
00319     out << "\nTest almost implicit conversion from ArrayRCP<T> to ArrayView<const T> ...\n";
00320     const ArrayView<const T> av2 = ptr();
00321     TEST_COMPARE_ARRAYS( av2, ptr );
00322   }
00323 
00324   {
00325     out << "\nTest implicit conversion from ArrayRCP<T> to ArrayRCP<const T> ...\n";
00326     const ArrayRCP<const T> ptr2 = ptr;
00327     TEST_COMPARE_ARRAYS( ptr2, ptr );
00328   }
00329 
00330   {
00331     out << "\nTest clone of ArrayView<T> to ArrayRCP<T> ...\n";
00332     const ArrayRCP<T> ptr2 = Teuchos::arcpClone<T>(ptr());
00333     TEST_COMPARE_ARRAYS( ptr2, ptr );
00334   }
00335 
00336   {
00337     out << "\nTest clone of ArrayPtr<const T> to ArrayRCP<T> ...\n";
00338     const ArrayRCP<T> ptr2 = Teuchos::arcpClone<T>(ptr.getConst()());
00339     TEST_COMPARE_ARRAYS( ptr2, ptr );
00340   }
00341   {
00342     out << "\nTest extra data ...\n";
00343     ArrayRCP<T> ptr2 = arcp<T>(n);
00344     Teuchos::set_extra_data( as<int>(1), "int", Teuchos::inOutArg(ptr2) );
00345     TEST_EQUALITY_CONST( Teuchos::get_extra_data<int>(ptr2, "int"), 1);
00346   }
00347 
00348   return success;
00349 
00350 }
00351 
00352 
00353 //
00354 // Main driver program
00355 //
00356 
00357 
00358 int main( int argc, char* argv[] )
00359 {
00360 
00361   Teuchos::GlobalMPISession mpiSession(&argc, &argv);
00362 
00363   using Teuchos::CommandLineProcessor;
00364   using Teuchos::null;
00365   using Teuchos::RCP;
00366   using Teuchos::rcp;
00367   using Teuchos::ArrayRCP;
00368   using Teuchos::arcp;
00369   using Teuchos::arcp_reinterpret_cast;
00370   
00371   bool success = true, result;
00372  
00373   Teuchos::RCP<Teuchos::FancyOStream>
00374     out = Teuchos::VerboseObjectBase::getDefaultOStream();
00375  
00376   try {
00377 
00378     // Read options from the commandline
00379     int num_ints = 10;
00380     int num_doubles = 10;
00381     CommandLineProcessor clp(false); // Don't throw exceptions
00382     clp.setOption( "num-ints", &num_ints, "Number of ints to allocate space for" );
00383     clp.setOption( "num-doubles", &num_doubles, "Number of doubles to allocate space for" );
00384     CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
00385     if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
00386       *out << "\nEnd Result: TEST FAILED" << std::endl;
00387       return parse_return;
00388     }
00389 
00390     const int sizeOfDouble = sizeof(double);
00391     const int sizeOfInt = sizeof(int);
00392 
00393     const int total_bytes = num_doubles*sizeOfDouble + num_ints*sizeOfInt;
00394 
00395     *out << std::endl << Teuchos::Teuchos_Version() << std::endl;
00396  
00397     *out << "\nTesting basic ArrayRCP functionality ...\n";
00398 
00399     ArrayRCP<char>
00400       char_ptr1 = arcp<char>(total_bytes);
00401 
00402     *out << "\nchar_ptr1 = " << char_ptr1 << "\n";
00403 
00404     TEST_FOR_EXCEPT( !(char_ptr1.size() == total_bytes) );
00405     TEST_FOR_EXCEPT( !(char_ptr1.lowerOffset() == 0) );
00406     TEST_FOR_EXCEPT( !(char_ptr1.upperOffset() == total_bytes-1) );
00407 #ifndef __sun
00408     TEST_FOR_EXCEPT( !(char_ptr1.count() == 1) );
00409 #endif
00410     result = test_ArrayRCP(char_ptr1,*out);
00411     if (!result) success = false;
00412 
00413     ArrayRCP<char>
00414       char_ptr2 = null;
00415 
00416     *out << "\nchar_ptr2 = " << char_ptr2 << "\n";
00417 
00418     TEST_FOR_EXCEPT( !(char_ptr2.size() == 0) );
00419     TEST_FOR_EXCEPT( !(char_ptr2.get() == NULL) );
00420 #ifndef __sun
00421     TEST_FOR_EXCEPT( !(char_ptr2.count() == 0) );
00422 #endif
00423 
00424     ArrayRCP<char>
00425       char_ptr2b(char_ptr1); // excplicitly test copy constructor
00426 
00427     *out << "\nchar_ptr2b = " << char_ptr2b << "\n";
00428 
00429     TEST_FOR_EXCEPT( !(char_ptr2b.size() == total_bytes) );
00430     TEST_FOR_EXCEPT( !(char_ptr2b.lowerOffset() == 0) );
00431     TEST_FOR_EXCEPT( !(char_ptr2b.upperOffset() == total_bytes-1) );
00432 #ifndef __sun
00433     TEST_FOR_EXCEPT( !(char_ptr2b.count() == 2) );
00434 #endif
00435     result = test_ArrayRCP(char_ptr2b,*out);
00436     if (!result) success = false;
00437 
00438     char_ptr2b = null;
00439 
00440     TEST_FOR_EXCEPT( !(char_ptr2b.size() == 0) );
00441     TEST_FOR_EXCEPT( !(char_ptr2.get() == NULL) );
00442 #ifndef __sun
00443     TEST_FOR_EXCEPT( !(char_ptr2b.count() == 0) );
00444     TEST_FOR_EXCEPT( !(char_ptr1.count() == 1) );
00445 #endif
00446 
00447     ArrayRCP<char>
00448       char_ptr3 = char_ptr1.persistingView(total_bytes/2,total_bytes/2);
00449 
00450 #ifndef __sun
00451     TEST_FOR_EXCEPT( !(char_ptr1.count() == 2) );
00452     TEST_FOR_EXCEPT( !(char_ptr3.count() == 2) );
00453 #endif
00454     TEST_FOR_EXCEPT( !(char_ptr3.lowerOffset() == 0) );
00455     TEST_FOR_EXCEPT( !(char_ptr3.upperOffset() == total_bytes/2-1) );
00456     result = test_ArrayRCP(char_ptr3,*out);
00457     if (!result) success = false;
00458 
00459     *out << "\nchar_ptr3 = " << char_ptr3 << "\n";
00460 
00461     *out << "\nBreak up char_ptr1 into views of double and int data\n";
00462 
00463     int offset = 0;
00464  
00465     ArrayRCP<double> double_ptr1 = arcp_reinterpret_cast<double>(
00466       char_ptr1.persistingView(offset,sizeOfDouble*num_doubles)
00467       );
00468 
00469     *out << "\ndouble_ptr1 = " << double_ptr1 << "\n";
00470 
00471 #ifndef __sun
00472     // 2007/11/30: rabartl: Even to this day, the Sun compiler (version CC:
00473     // Sun C++ 5.7 Patch 117830-07 2006/03/15 on sass9000) does not destroy
00474     // objects as required by the C++ standard!  This is unbelievelable!
00475     TEST_FOR_EXCEPT( !(char_ptr1.count() == 3) );
00476     TEST_FOR_EXCEPT( !(double_ptr1.count() == 3) );
00477 #endif
00478     TEST_FOR_EXCEPT( !(double_ptr1.size() == num_doubles) );
00479 
00480     result = test_ArrayRCP(double_ptr1,*out);
00481     if (!result) success = false;
00482  
00483     offset += sizeOfDouble*num_doubles;
00484 
00485     ArrayRCP<int> int_ptr1 = arcp_reinterpret_cast<int>(
00486       char_ptr1.persistingView(offset,sizeOfInt*num_ints)
00487       );
00488 
00489     *out << "\nint_ptr1 = " << int_ptr1 << "\n";
00490 
00491 #ifndef __sun
00492     // 2007/11/30: rabartl: See comment above
00493     TEST_FOR_EXCEPT( !(char_ptr1.count() == 4) );
00494     TEST_FOR_EXCEPT( !(int_ptr1.count() == 4) );
00495 #endif
00496     TEST_FOR_EXCEPT( !(int_ptr1.size() == num_ints) );
00497 
00498     result = test_ArrayRCP(int_ptr1,*out);
00499     if (!result) success = false;
00500 
00501     *out << "\nCreating a constant view of double_ptr1\n";
00502  
00503     ArrayRCP<const double>
00504       double_ptr2 = double_ptr1.getConst();
00505 
00506     result = test_ArrayRCP_iterators(double_ptr2,*out);
00507     if (!result) success = false;
00508 
00509 #ifdef SHOW_COMPILE_FAILURE_1
00510     // This will not compile since this function tries to use operator[] to
00511     // change data but it can't since it returns a reference to a const
00512     // double!
00513     for( int i = 0; i < double_ptr2.size(); ++i ) {
00514       double_ptr2[i] = 1.0; // Error, you can change the value!
00515     }
00516 #endif
00517 
00518     *out << "\nCreating an array of RCP objects!\n";
00519 
00520     ArrayRCP<RCP<double> >
00521       rcp_ptr1 = arcp<RCP<double> >(num_doubles);
00522 
00523     for( int i = 0; i < num_doubles; ++i )
00524       rcp_ptr1[i] = rcp(new double(i));
00525 
00526     result = test_ArrayRCP_iterators(rcp_ptr1,*out);
00527     if (!result) success = false;
00528 
00529     *out << "\nCreating a const view of rcp_ptr1\n";
00530 
00531     ArrayRCP<const RCP<double> >
00532       rcp_ptr2 = rcp_ptr1.getConst();
00533 
00534     result = test_ArrayRCP_iterators(rcp_ptr2,*out);
00535     if (!result) success = false;
00536 
00537     *out << "\nCreating an ARCP<double*> object doubleptr_ptr1 and dynamically allocation each element\n";
00538 
00539     ArrayRCP<double*>
00540       doubleptr_ptr1 = arcp<double*>(total_bytes);
00541 
00542     for( int i = 0; i < doubleptr_ptr1.size(); ++i )
00543       doubleptr_ptr1[i] = new double(i);
00544 
00545     result = test_ArrayRCP_iterators(doubleptr_ptr1,*out);
00546     if (!result) success = false;
00547 
00548     *out << "\nCreating an ARCP<double*const> view of a doubleptr_ptr1\n";
00549  
00550     ArrayRCP<double*const>
00551       doubleptr_ptr2 = doubleptr_ptr1.getConst();
00552 
00553     result = test_ArrayRCP_iterators(doubleptr_ptr2,*out);
00554     if (!result) success = false;
00555 
00556 #ifdef SHOW_COMPILE_FAILURE_2
00557     // This will not compile since this function tries to use operator[] to
00558     // change data but it can't since it returns a reference to a double*const
00559     // object!
00560     for( int i = 0; i < doubleptr_ptr2.size(); ++i ) {
00561       *doubleptr_ptr2[i] = 1.0; // Fine, you can change the value that is being pointed to for this entry!
00562       doubleptr_ptr2[i] = NULL; // Error, you can't change the pointer entry!
00563     }
00564 #endif
00565 
00566     *out << "\nCreating an ARCP<const double * const> view of a doubleptr_ptr1\n";
00567  
00568     ArrayRCP<const double*const>
00569       doubleptr_ptr3 = Teuchos::arcp_implicit_cast<const double*const>(doubleptr_ptr1);
00570 
00571     result = test_ArrayRCP_iterators(doubleptr_ptr3,*out);
00572     if (!result) success = false;
00573 
00574 #ifdef SHOW_COMPILE_FAILURE_3
00575     // This will not compile since this function tries to use operator[] to
00576     // change data but it can't since it returns a reference to a double*const
00577     // object!
00578     for( int i = 0; i < doubleptr_ptr3.size(); ++i ) {
00579       *doubleptr_ptr3[i] = 1.0; // Error, you can't change the value that is being pointed to!
00580       doubleptr_ptr3[i] = NULL; // Error, you can't change the pointer either!
00581     }
00582 #endif
00583 
00584     for( int i = 0; i < doubleptr_ptr1.size(); ++i )
00585       delete doubleptr_ptr1[i];
00586 
00587     *out << "\nWrapping RCP<std::vector<T> > objects as ArrayRCP objects ...\n";
00588 
00589     {
00590 
00591       ArrayRCP<char>
00592         vchar_ptr1 = arcp(rcp(new std::vector<char>(total_bytes)));
00593       
00594       *out << "\nvchar_ptr1 = " << vchar_ptr1 << "\n";
00595       
00596       result = test_ArrayRCP(vchar_ptr1,*out);
00597       if (!result) success = false;
00598       
00599       ArrayRCP<const char> vchar_ptr2 = vchar_ptr1;
00600  
00601       *out << "\nvchar_ptr2 = " << vchar_ptr2 << "\n";
00602       
00603       result = test_ArrayRCP_iterators(vchar_ptr2, *out);
00604       if (!result) success = false;
00605       
00606 #ifndef __sun
00607       // RAB: 2006/07/12: The sun compiler declares this call to
00608       // get_std_vector(...) to be ambiguous (which is nonsense based on
00609       // everything I know about C++)!
00610       TEST_FOR_EXCEPT( Teuchos::get_std_vector(vchar_ptr1)->size() != static_cast<size_t>(total_bytes) );
00611 #endif
00612       TEST_FOR_EXCEPT( vchar_ptr1.size() != static_cast<Teuchos_Ordinal>(total_bytes) );
00613       TEST_FOR_EXCEPT( vchar_ptr2.size() != static_cast<Teuchos_Ordinal>(total_bytes) );
00614       
00615     }
00616 
00617     *out << "\nWrapping RCP<ARray<T> > objects as ArrayRCP objects ...\n";
00618 
00619     {
00620 
00621       ArrayRCP<char>
00622         vchar_ptr1 = arcp(rcp(new Teuchos::Array<char>(total_bytes)));
00623       
00624       *out << "\nvchar_ptr1 = " << vchar_ptr1 << "\n";
00625       
00626       result = test_ArrayRCP(vchar_ptr1,*out);
00627       if (!result) success = false;
00628 
00629 /*      
00630       ArrayRCP<const char> vchar_ptr2 =
00631         arcp(
00632           Teuchos::rcp_implicit_cast<const std::vector<char> >(
00633             Teuchos::get_std_vector(vchar_ptr1)
00634             )
00635           );
00636 */
00637 
00638     }
00639  
00640     // ToDo: Fill in the rest of the tests!
00641  
00642     *out << "\nAll tests for ArrayRCP seem to check out!\n";
00643  
00644   }
00645   TEUCHOS_STANDARD_CATCH_STATEMENTS(true,std::cerr,success);
00646  
00647   if(success)
00648     *out << "\nEnd Result: TEST PASSED" << std::endl; 
00649  
00650   return ( success ? 0 : 1 );
00651  
00652 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines