Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ArrayRCP_test.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Teuchos: Common Tools Package
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include "Teuchos_ArrayRCP.hpp"
43 #include "Teuchos_Array.hpp"
48 #include "Teuchos_Version.hpp"
49 #include "Teuchos_Assert.hpp"
51 
52 
53 // Temporarily uncomment any or all of these macros to see compilation
54 // failures for code that is rightfully not supposed to compile (which is a
55 // wonderful thing)! The fact that this code does not compile show that the
56 // design of the Teuchos::ArrayRCP class supports full support of
57 // const projection in all of its forms when dealing with arrays of objects.
58 //#define SHOW_COMPILE_FAILURE_1
59 //#define SHOW_COMPILE_FAILURE_2
60 //#define SHOW_COMPILE_FAILURE_3
61 
62 
63 //
64 // Iterator testing function
65 //
66 
67 template<class T>
71  )
72 {
73 
74  using Teuchos::ArrayRCP;
75  using Teuchos::null;
76  using Teuchos::arcp;
77 
78  bool success = true;
79 
80  out
81  << "\n***"
82  << "\n*** Testing iterators and accessors for ptr = " << ptr
83  << "\n***\n";
84 
85  Teuchos::OSTab tab(out);
86 
87  const int size = ptr.size();
88 
89  // Pointer ++
90 
91  {
92  out << "\nChecking ++itr and < ...\n";
93  ArrayRCP<T> itr = ptr;
94  for( int i = 0; itr < ptr+size; ++i, ++itr )
95  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
96  }
97 
98  {
99  out << "\nChecking itr++ and <= ...\n";
100  ArrayRCP<T> itr = ptr;
101  for( int i = 0; itr <= ptr+size-1; ++i, itr++ )
102  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
103  }
104 
105  {
106  out << "\nChecking itr+=1 and != ...\n";
107  ArrayRCP<T> itr = ptr;
108  for( int i = 0; itr != ptr+size; ++i, itr+=1 )
109  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
110  }
111 
112  {
113  out << "\nChecking itr=itr+1 and == ...\n";
114  ArrayRCP<T> itr = ptr;
115  for( int i = 0; !( itr == ptr+size ); ++i, itr=itr+1 )
116  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
117  }
118 
119  // Pointer --
120 
121  {
122  out << "\nChecking --itr and >= ...\n";
123  ArrayRCP<T> itr = ptr+size-1;
124  for( int i = size-1; itr >= ptr; --i, --itr )
125  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
126  }
127 
128  {
129  out << "\nChecking itr-- and > ...\n";
130  ArrayRCP<T> itr = ptr+size-1;
131  for( int i = size-1; itr+1 > ptr; i--, itr-- )
132  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
133  }
134 
135  {
136  out << "\nChecking itr-=1 and != ...\n";
137  ArrayRCP<T> itr = ptr+size-1;
138  for( int i = size-1; itr+1 != ptr; i--, itr-=1 )
139  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
140  }
141 
142  {
143  out << "\nChecking itr=itr-1 and == ...\n";
144  ArrayRCP<T> itr = ptr+size-1;
145  for( int i = size-1; !( itr+1 == ptr ); i--, itr=itr-1 )
146  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
147  }
148 
149  // Iterator - Iterator
150 
151  {
152  out << "\nChecking ptr.end() - ptr.begin() == ptr.size() ...\n";
153  TEUCHOS_ASSERT_EQUALITY( ptr.end() - ptr.begin(), ptr.size() );
154  }
155 
156  // Iterator ++
157 
158  {
159  out << "\nChecking iterator ++itr and < ...\n";
160  typename ArrayRCP<T>::const_iterator itr = ptr.begin();
161  for( int i = 0; itr < ptr.end(); ++i, ++itr )
162  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
163  }
164 
165  {
166  out << "\nChecking iterator itr++ and <= ...\n";
167  typename ArrayRCP<T>::const_iterator itr = ptr.begin();
168  for( int i = 0; itr <= ptr.end()-1; ++i, itr++ )
169  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
170  }
171 
172  {
173  out << "\nChecking iterator itr+=1 and != ...\n";
174  typename ArrayRCP<T>::const_iterator itr = ptr.begin();
175  for( int i = 0; itr != ptr.end(); ++i, itr+=1 )
176  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
177  }
178 
179  {
180  out << "\nChecking iterator itr=itr+1 and == ...\n";
181  typename ArrayRCP<T>::const_iterator itr = ptr.begin();
182  for( int i = 0; !( itr == ptr.end() ); ++i, itr=itr+1 )
183  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
184  }
185 
186  // Iterator --
187 
188  {
189  out << "\nChecking iterator --itr and >= ...\n";
190  typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
191  for( int i = size-1; itr >= ptr.begin(); --i, --itr )
192  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
193  }
194 
195  {
196  out << "\nChecking iterator itr-- and > ...\n";
197  typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
198  for( int i = size-1; itr+1 > ptr.begin(); i--, itr-- )
199  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
200  }
201 
202  {
203  out << "\nChecking iterator itr-=1 and != ...\n";
204  typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
205  for( int i = size-1; itr+1 != ptr.begin(); i--, itr-=1 )
206  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
207  }
208 
209  {
210  out << "\nChecking iterator itr=itr-1 and == ...\n";
211  typename ArrayRCP<T>::const_iterator itr = ptr.begin()+size-1;
212  for( int i = size-1; !( itr+1 == ptr.begin() ); i--, itr=itr-1 )
213  TEUCHOS_TEST_FOR_EXCEPT( !(*itr == ptr[i]) );
214  }
215 
216  return success;
217 
218 }
219 
220 
221 //
222 // Main testing function for a specific ArrayRCP
223 //
224 
225 
226 template<class T>
228  const Teuchos::ArrayRCP<T> &ptr,
230  )
231 {
232 
233  using Teuchos::ArrayView;
234  using Teuchos::ArrayRCP;
235  using Teuchos::arcp;
236  using Teuchos::arcp_const_cast;
237  using Teuchos::as;
238 
239  bool success = true, result;
240 
241  out
242  << "\n***"
243  << "\n*** Testing ptr = " << ptr
244  << "\n***\n";
245 
246  Teuchos::OSTab tab(out);
247 
248  const int n = ptr.size();
249 
250  {
251  out << "\nInitializing data ...\n";
252  for( int i = 0; i < n; ++i )
253  ptr[i] = i;
254  }
255 
256  TEUCHOS_TEST_FOR_EXCEPT( !(&*ptr == ptr.get()) );
257  TEUCHOS_TEST_FOR_EXCEPT( !(&*ptr == ptr.getRawPtr()) );
258 
259  result = test_ArrayRCP_iterators(ptr,out);
260  if (!result) success = false;
261 
262  //
263  out << "\nTest const casting ...\n";
264  //
265 
266  {
267  const ArrayRCP<const T> cptr2 = ptr;
268  const ArrayRCP<T> ptr3 = arcp_const_cast<T>(cptr2);
269  TEST_COMPARE_ARRAYS( ptr3, ptr );
270  }
271 
272  //
273  out << "\nTest views ...\n";
274  //
275 
276  {
277  out << "\nTest full non-const subview ...\n";
278  const ArrayView<T> av2 = ptr(0,n);
279  TEST_COMPARE_ARRAYS( av2, ptr );
280  }
281 
282  {
283  out << "\nTest full shorthand non-const subview ...\n";
284  const ArrayView<T> av2 = ptr();
285  TEST_COMPARE_ARRAYS( av2, ptr );
286  }
287 
288  {
289  out << "\nTest full const subview ...\n";
290  const ArrayView<const T> cav2 = ptr.getConst()(0,n);
291  TEST_COMPARE_ARRAYS( cav2, ptr );
292  }
293 
294  {
295  out << "\nTest full non-const to const subview ...\n";
296  const ArrayView<const T> cav2 = ptr(0,n);
297  TEST_COMPARE_ARRAYS( cav2, ptr );
298  }
299 
300  {
301  out << "\nTest full short-hand const subview ...\n";
302  const ArrayView<const T> cav2 = ptr.getConst()();
303  TEST_COMPARE_ARRAYS( cav2, ptr );
304  }
305 
306  {
307  out << "\nTest implicit conversion from ArrayRCP<T> to ArrayView<T> ...\n";
308  const ArrayView<T> av2 = ptr();
309  TEST_COMPARE_ARRAYS( av2, ptr );
310  }
311 
312  {
313  out << "\nTest implicit conversion from ArrayRCP<const T> to ArrayView<const T> ...\n";
314  const ArrayView<const T> av2 = ptr.getConst()();
315  TEST_COMPARE_ARRAYS( av2, ptr );
316  }
317 
318  {
319  out << "\nTest almost implicit conversion from ArrayRCP<T> to ArrayView<const T> ...\n";
320  const ArrayView<const T> av2 = ptr();
321  TEST_COMPARE_ARRAYS( av2, ptr );
322  }
323 
324  {
325  out << "\nTest implicit conversion from ArrayRCP<T> to ArrayRCP<const T> ...\n";
326  const ArrayRCP<const T> ptr2 = ptr;
327  TEST_COMPARE_ARRAYS( ptr2, ptr );
328  }
329 
330  {
331  out << "\nTest clone of ArrayView<T> to ArrayRCP<T> ...\n";
332  const ArrayRCP<T> ptr2 = Teuchos::arcpClone<T>(ptr());
333  TEST_COMPARE_ARRAYS( ptr2, ptr );
334  }
335 
336  {
337  out << "\nTest clone of ArrayPtr<const T> to ArrayRCP<T> ...\n";
338  const ArrayRCP<T> ptr2 = Teuchos::arcpClone<T>(ptr.getConst()());
339  TEST_COMPARE_ARRAYS( ptr2, ptr );
340  }
341  {
342  out << "\nTest extra data ...\n";
343  ArrayRCP<T> ptr2 = arcp<T>(n);
344  Teuchos::set_extra_data( as<int>(1), "int", Teuchos::inOutArg(ptr2) );
345  TEST_EQUALITY_CONST( Teuchos::get_extra_data<int>(ptr2, "int"), 1);
346  }
347 
348  return success;
349 
350 }
351 
352 
353 //
354 // Main driver program
355 //
356 
357 
358 int main( int argc, char* argv[] )
359 {
360 
361  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
362 
364  using Teuchos::null;
365  using Teuchos::RCP;
366  using Teuchos::rcp;
367  using Teuchos::ArrayRCP;
368  using Teuchos::arcp;
369  using Teuchos::arcp_reinterpret_cast;
370 
371  bool success = true, result;
372 
375 
376  try {
377 
378  // Read options from the commandline
379  int num_ints = 10;
380  int num_doubles = 10;
381  CommandLineProcessor clp(false); // Don't throw exceptions
382  clp.setOption( "num-ints", &num_ints, "Number of ints to allocate space for" );
383  clp.setOption( "num-doubles", &num_doubles, "Number of doubles to allocate space for" );
384  CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc,argv);
385  if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL ) {
386  *out << "\nEnd Result: TEST FAILED" << std::endl;
387  return parse_return;
388  }
389 
390  const int sizeOfDouble = sizeof(double);
391  const int sizeOfInt = sizeof(int);
392 
393  const int total_bytes = num_doubles*sizeOfDouble + num_ints*sizeOfInt;
394 
395  *out << std::endl << Teuchos::Teuchos_Version() << std::endl;
396 
397  *out << "\nTesting basic ArrayRCP functionality ...\n";
398 
399  ArrayRCP<char>
400  char_ptr1 = arcp<char>(total_bytes);
401 
402  *out << "\nchar_ptr1 = " << char_ptr1 << "\n";
403 
404  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.size() == total_bytes) );
405  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.lowerOffset() == 0) );
406  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.upperOffset() == total_bytes-1) );
407  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.strong_count() == 1) );
408  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.weak_count() == 0) );
409  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.total_count() == 1) );
410  result = test_ArrayRCP(char_ptr1,*out);
411  if (!result) success = false;
412 
413  ArrayRCP<char>
414  char_ptr2 = null;
415 
416  *out << "\nchar_ptr2 = " << char_ptr2 << "\n";
417 
418  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2.size() == 0) );
419  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2.get() == NULL) );
420  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2.strong_count() == 0) );
421  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2.weak_count() == 0) );
422  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2.total_count() == 0) );
423 
424  ArrayRCP<char>
425  char_ptr2b(char_ptr1); // excplicitly test copy constructor
426 
427  *out << "\nchar_ptr2b = " << char_ptr2b << "\n";
428 
429  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.size() == total_bytes) );
430  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.lowerOffset() == 0) );
431  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.upperOffset() == total_bytes-1) );
432  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.strong_count() == 2) );
433  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.weak_count() == 0) );
434  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.total_count() == 2) );
435  result = test_ArrayRCP(char_ptr2b,*out);
436  if (!result) success = false;
437 
438  char_ptr2b = null;
439 
440  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.size() == 0) );
441  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2.get() == NULL) );
442  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr2b.strong_count() == 0) );
443  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.strong_count() == 1) );
444 
445  ArrayRCP<char>
446  char_ptr3 = char_ptr1.persistingView(total_bytes/2,total_bytes/2);
447 
448  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.strong_count() == 2) );
449  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr3.strong_count() == 2) );
450  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr3.lowerOffset() == 0) );
451  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr3.upperOffset() == total_bytes/2-1) );
452  result = test_ArrayRCP(char_ptr3,*out);
453  if (!result) success = false;
454 
455  *out << "\nchar_ptr3 = " << char_ptr3 << "\n";
456 
457  *out << "\nBreak up char_ptr1 into views of double and int data\n";
458 
459  int offset = 0;
460 
461  ArrayRCP<double> double_ptr1 = arcp_reinterpret_cast<double>(
462  char_ptr1.persistingView(offset,sizeOfDouble*num_doubles)
463  );
464 
465  *out << "\ndouble_ptr1 = " << double_ptr1 << "\n";
466 
467  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.strong_count() == 3) );
468  TEUCHOS_TEST_FOR_EXCEPT( !(double_ptr1.strong_count() == 3) );
469  TEUCHOS_TEST_FOR_EXCEPT( !(double_ptr1.size() == num_doubles) );
470 
471  result = test_ArrayRCP(double_ptr1,*out);
472  if (!result) success = false;
473 
474  offset += sizeOfDouble*num_doubles;
475 
476  ArrayRCP<int> int_ptr1 = arcp_reinterpret_cast<int>(
477  char_ptr1.persistingView(offset,sizeOfInt*num_ints)
478  );
479 
480  *out << "\nint_ptr1 = " << int_ptr1 << "\n";
481 
482  TEUCHOS_TEST_FOR_EXCEPT( !(char_ptr1.strong_count() == 4) );
483  TEUCHOS_TEST_FOR_EXCEPT( !(int_ptr1.strong_count() == 4) );
484  TEUCHOS_TEST_FOR_EXCEPT( !(int_ptr1.size() == num_ints) );
485 
486  result = test_ArrayRCP(int_ptr1,*out);
487  if (!result) success = false;
488 
489  *out << "\nCreating a constant view of double_ptr1\n";
490 
491  ArrayRCP<const double>
492  double_ptr2 = double_ptr1.getConst();
493 
494  result = test_ArrayRCP_iterators(double_ptr2,*out);
495  if (!result) success = false;
496 
497 #ifdef SHOW_COMPILE_FAILURE_1
498  // This will not compile since this function tries to use operator[] to
499  // change data but it can't since it returns a reference to a const
500  // double!
501  for( int i = 0; i < double_ptr2.size(); ++i ) {
502  double_ptr2[i] = 1.0; // Error, you can change the value!
503  }
504 #endif
505 
506  *out << "\nCreating an array of RCP objects!\n";
507 
508  ArrayRCP<RCP<double> >
509  rcp_ptr1 = arcp<RCP<double> >(num_doubles);
510 
511  for( int i = 0; i < num_doubles; ++i )
512  rcp_ptr1[i] = rcp(new double(i));
513 
514  result = test_ArrayRCP_iterators(rcp_ptr1,*out);
515  if (!result) success = false;
516 
517  *out << "\nCreating a const view of rcp_ptr1\n";
518 
519  ArrayRCP<const RCP<double> >
520  rcp_ptr2 = rcp_ptr1.getConst();
521 
522  result = test_ArrayRCP_iterators(rcp_ptr2,*out);
523  if (!result) success = false;
524 
525  *out << "\nCreating an ARCP<double*> object doubleptr_ptr1 and dynamically allocation each element\n";
526 
527  ArrayRCP<double*>
528  doubleptr_ptr1 = arcp<double*>(total_bytes);
529 
530  for( int i = 0; i < doubleptr_ptr1.size(); ++i )
531  doubleptr_ptr1[i] = new double(i);
532 
533  result = test_ArrayRCP_iterators(doubleptr_ptr1,*out);
534  if (!result) success = false;
535 
536  *out << "\nCreating an ARCP<double*const> view of a doubleptr_ptr1\n";
537 
538  ArrayRCP<double*const>
539  doubleptr_ptr2 = doubleptr_ptr1.getConst();
540 
541  result = test_ArrayRCP_iterators(doubleptr_ptr2,*out);
542  if (!result) success = false;
543 
544 #ifdef SHOW_COMPILE_FAILURE_2
545  // This will not compile since this function tries to use operator[] to
546  // change data but it can't since it returns a reference to a double*const
547  // object!
548  for( int i = 0; i < doubleptr_ptr2.size(); ++i ) {
549  *doubleptr_ptr2[i] = 1.0; // Fine, you can change the value that is being pointed to for this entry!
550  doubleptr_ptr2[i] = NULL; // Error, you can't change the pointer entry!
551  }
552 #endif
553 
554  *out << "\nCreating an ARCP<const double * const> view of a doubleptr_ptr1\n";
555 
556  ArrayRCP<const double*const>
557  doubleptr_ptr3 = Teuchos::arcp_implicit_cast<const double*const>(doubleptr_ptr1);
558 
559  result = test_ArrayRCP_iterators(doubleptr_ptr3,*out);
560  if (!result) success = false;
561 
562 #ifdef SHOW_COMPILE_FAILURE_3
563  // This will not compile since this function tries to use operator[] to
564  // change data but it can't since it returns a reference to a double*const
565  // object!
566  for( int i = 0; i < doubleptr_ptr3.size(); ++i ) {
567  *doubleptr_ptr3[i] = 1.0; // Error, you can't change the value that is being pointed to!
568  doubleptr_ptr3[i] = NULL; // Error, you can't change the pointer either!
569  }
570 #endif
571 
572  for( int i = 0; i < doubleptr_ptr1.size(); ++i )
573  delete doubleptr_ptr1[i];
574 
575  *out << "\nWrapping RCP<std::vector<T> > objects as ArrayRCP objects ...\n";
576 
577  {
578 
579  ArrayRCP<char>
580  vchar_ptr1 = arcp(rcp(new std::vector<char>(total_bytes)));
581 
582  *out << "\nvchar_ptr1 = " << vchar_ptr1 << "\n";
583 
584  result = test_ArrayRCP(vchar_ptr1,*out);
585  if (!result) success = false;
586 
587  ArrayRCP<const char> vchar_ptr2 = vchar_ptr1;
588 
589  *out << "\nvchar_ptr2 = " << vchar_ptr2 << "\n";
590 
591  result = test_ArrayRCP_iterators(vchar_ptr2, *out);
592  if (!result) success = false;
593 
594 #ifndef __sun
595  // RAB: 2006/07/12: The sun compiler declares this call to
596  // get_std_vector(...) to be ambiguous (which is nonsense based on
597  // everything I know about C++)!
598  TEUCHOS_TEST_FOR_EXCEPT( Teuchos::get_std_vector(vchar_ptr1)->size() != static_cast<size_t>(total_bytes) );
599 #endif
600  TEUCHOS_TEST_FOR_EXCEPT( vchar_ptr1.size() != static_cast<Teuchos_Ordinal>(total_bytes) );
601  TEUCHOS_TEST_FOR_EXCEPT( vchar_ptr2.size() != static_cast<Teuchos_Ordinal>(total_bytes) );
602 
603  }
604 
605  *out << "\nWrapping RCP<ARray<T> > objects as ArrayRCP objects ...\n";
606 
607  {
608 
609  ArrayRCP<char>
610  vchar_ptr1 = arcp(rcp(new Teuchos::Array<char>(total_bytes)));
611 
612  *out << "\nvchar_ptr1 = " << vchar_ptr1 << "\n";
613 
614  result = test_ArrayRCP(vchar_ptr1,*out);
615  if (!result) success = false;
616 
617 /*
618  ArrayRCP<const char> vchar_ptr2 =
619  arcp(
620  Teuchos::rcp_implicit_cast<const std::vector<char> >(
621  Teuchos::get_std_vector(vchar_ptr1)
622  )
623  );
624 */
625 
626  }
627 
628  // ToDo: Fill in the rest of the tests!
629 
630  *out << "\nAll tests for ArrayRCP seem to check out!\n";
631 
632  }
633  TEUCHOS_STANDARD_CATCH_STATEMENTS(true,std::cerr,success);
634 
635  if(success)
636  *out << "\nEnd Result: TEST PASSED" << std::endl;
637 
638  return ( success ? 0 : 1 );
639 
640 }
bool test_ArrayRCP(const Teuchos::ArrayRCP< T > &ptr, Teuchos::FancyOStream &out)
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object...
RCP< const T > getConst() const
Return an RCP&lt;const T&gt; version of *this.
ArrayRCP< T > arcp(const RCP< Array< T > > &v)
Wrap an RCP&lt;Array&lt;T&gt; &gt; object as an ArrayRCP&lt;T&gt; object.
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
Initialize, finalize, and query the global MPI session.
ArrayRCP< T2 > arcp_reinterpret_cast(const ArrayRCP< T1 > &p1)
Reinterpret cast of underlying ArrayRCP type from T1* to T2*.
TEUCHOS_ORDINAL_TYPE Teuchos_Ordinal
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Utilities to make writing tests easier.
std::ostream subclass that performs the magic of indenting data sent to an std::ostream object among ...
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Simple macro that catches and reports standard exceptions and other exceptions.
static RCP< FancyOStream > getDefaultOStream()
Get the default output stream object.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
std::string Teuchos_Version()
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
Ptr< T > ptr(T *p)
Create a pointer to an object from a raw pointer.
int main(int argc, char *argv[])
Templated array class derived from the STL std::vector.
#define TEST_COMPARE_ARRAYS(a1, a2)
Assert that a1.size()==a2.size() and a[i]==b[i], i=0....
Nonowning array view.
A MPI utilities class, providing methods for initializing, finalizing, and querying the global MPI se...
Basic command line parser for input from (argc,argv[])
ArrayRCP< T2 > arcp_const_cast(const ArrayRCP< T1 > &p1)
Const cast of underlying ArrayRCP type from const T* to T*.
Smart reference counting pointer class for automatic garbage collection.
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
This macro is checks that to numbers are equal and if not then throws an exception with a good error ...
RCP< basic_FancyOStream< CharT, Traits > > tab(const RCP< basic_FancyOStream< CharT, Traits > > &out, const int tabs=1, const std::basic_string< CharT, Traits > linePrefix="")
Create a tab for an RCP-wrapped basic_FancyOStream object to cause the indentation of all output auto...
bool test_ArrayRCP_iterators(const Teuchos::ArrayRCP< T > &ptr, Teuchos::FancyOStream &out)
Class that helps parse command line input arguments from (argc,argv[]) and set options.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
This macro is designed to be a short version of TEUCHOS_TEST_FOR_EXCEPTION() that is easier to call...
Reference-counted smart pointer for managing arrays.