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