Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ArrayRCP_UnitTests.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
12 #include "TestClasses.hpp"
13 #include "Teuchos_ArrayRCP.hpp"
14 #include "Teuchos_RCP.hpp"
16 #include "Teuchos_as.hpp"
17 #include "Teuchos_getRawPtr.hpp"
18 
19 namespace {
20 
23 
24 typedef Teuchos_Ordinal Ordinal;
25 using Teuchos::getRawPtr;
26 using Teuchos::as;
27 using Teuchos::null;
28 using Teuchos::rcp;
29 using Teuchos::RCP;
30 using Teuchos::ArrayRCP;
31 using Teuchos::Array;
32 using Teuchos::arcp;
33 using Teuchos::arcpCloneNode;
34 using Teuchos::arcp_reinterpret_cast;
35 using Teuchos::arcp_reinterpret_cast_nonpod;
36 using Teuchos::ArrayView;
37 using Teuchos::getConst;
43 using Teuchos::RCP_WEAK;
45 using Teuchos::getRawPtr;
46 
47 
48 //
49 // Non templated unit tests
50 //
51 
52 
53 TEUCHOS_UNIT_TEST( ArrayRCP, memberPointer )
54 {
55  ArrayRCP<A> a_arcp = arcp<A>(1);
56  TEST_EQUALITY_CONST( a_arcp->A_f(), A_f_return );
57 }
58 
59 
60 TEUCHOS_UNIT_TEST( ArrayRCP, getConst_null )
61 {
62  const ArrayRCP<A> a1_arcp;
63  const ArrayRCP<const A> a2_arcp = a1_arcp.getConst();
64  TEST_ASSERT(is_null(a2_arcp));
65 }
66 
67 
68 TEUCHOS_UNIT_TEST( ArrayRCP, operator_parenth_ArrayView_null )
69 {
70  const ArrayRCP<A> a_arcp;
71  const ArrayView<A> av = a_arcp();
72  TEST_ASSERT(is_null(av));
73 }
74 
75 
76 TEUCHOS_UNIT_TEST( ArrayRCP, operator_parenth_ArrayView_const_null )
77 {
78  const ArrayRCP<const A> a_arcp;
79  const ArrayView<const A> av = a_arcp();
80  TEST_ASSERT(is_null(av));
81 }
82 
83 
84 TEUCHOS_UNIT_TEST( ArrayRCP, null_zero_ArrayView_operator )
85 {
86  const ArrayRCP<const A> a_arcp;
87  const ArrayView<const A> av = a_arcp(0, 0);
88  TEST_ASSERT(is_null(av));
89 }
90 
91 
92 TEUCHOS_UNIT_TEST( ArrayRCP, null_zero_ArrayView_view_func )
93 {
94  const ArrayRCP<const A> a_arcp;
95  const ArrayView<const A> av = a_arcp.view(0, 0);
96  TEST_ASSERT(is_null(av));
97 }
98 
99 
100 TEUCHOS_UNIT_TEST( ArrayRCP, null_zero_ArrayView_persistingView )
101 {
102  const ArrayRCP<const A> a_arcp;
103  const ArrayRCP<const A> a_arcp2 = a_arcp.persistingView(0, 0);
104  TEST_ASSERT(is_null(a_arcp2));
105 }
106 
107 
108 TEUCHOS_UNIT_TEST( ArrayRCP, raw_ptr_nonowning_self_view )
109 {
110  A *data = new A[10];
111  ArrayRCP<A> arcp_view(data, 0, 10, false);
112  ArrayView<A> view = arcp_view(0, 5);
113  arcp_view = null;
114 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
115  TEST_THROW(view.size(), DanglingReferenceError);
116 #endif
117  delete [] data;
118 }
119 
120 
121 TEUCHOS_UNIT_TEST( ArrayRCP, implicit_ArrayRCP_const )
122 {
123  const ArrayRCP<A> a_arcp;
124  const ArrayRCP<const A> ac_arcp = a_arcp;
125  TEST_ASSERT(is_null(ac_arcp));
126 }
127 
128 
129 TEUCHOS_UNIT_TEST( ArrayRCP, ArrayRCP_void_throws )
130 {
131  TEST_THROW( const ArrayRCP< void> v_arcp, std::logic_error );
132  TEST_THROW( const ArrayRCP<const void> cv_arcp, std::logic_error );
133 }
134 
135 
136 TEUCHOS_UNIT_TEST( ArrayRCP, release )
137 {
138  ArrayRCP<A> a_arcp = arcp<A>(1);
139  delete [] a_arcp.release();
140 }
141 
142 
143 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_null )
144 {
145  ArrayRCP<A> a_arcp = arcp<A>(0, 0, -1, false);
146  TEST_ASSERT(is_null(a_arcp));
147 }
148 
149 
150 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_dealloc_null )
151 {
152  ArrayRCP<A> a_arcp = arcp<A, Teuchos::DeallocNull<A> >(0, 0, -1,
153  Teuchos::DeallocNull<A>(), false);
154  TEST_ASSERT(is_null(a_arcp));
155 }
156 
157 
158 TEUCHOS_UNIT_TEST( ArrayRCP, convert_from_vector_null )
159 {
160  const RCP<std::vector<int> > v_rcp;
161  const ArrayRCP<int> a_arcp = arcp(v_rcp);
162  TEST_ASSERT(is_null(a_arcp));
163 }
164 
165 
166 TEUCHOS_UNIT_TEST( ArrayRCP, convert_from_const_vector_null )
167 {
168  const RCP<const std::vector<int> > v_rcp;
169  const ArrayRCP<const int> a_arcp = arcp(v_rcp);
170  TEST_ASSERT(is_null(a_arcp));
171 }
172 
173 
174 TEUCHOS_UNIT_TEST( ArrayRCP, convert_from_vector_unsized )
175 {
176  const RCP<std::vector<int> > v_rcp = rcp(new std::vector<int>);
177  const ArrayRCP<int> a_arcp = arcp(v_rcp);
178  TEST_ASSERT(is_null(a_arcp));
179 }
180 
181 
182 TEUCHOS_UNIT_TEST( ArrayRCP, convert_from_const_vector_unsized )
183 {
184  const RCP<const std::vector<int> > v_rcp = rcp(new std::vector<int>);
185  const ArrayRCP<const int> a_arcp = arcp(v_rcp);
186  TEST_ASSERT(is_null(a_arcp));
187 }
188 
189 
191 {
192  const ArrayRCP<const int> a_arcp =
193  Teuchos::arcpWithEmbeddedObj<int>(new int[1], 0, 1, as<int>(1), true);
194  const int embeddedObj = Teuchos::getEmbeddedObj<int,int>(a_arcp);
195  TEST_EQUALITY_CONST( embeddedObj, as<int>(1) );
196 }
197 
198 
199 TEUCHOS_UNIT_TEST( ArrayRCP, nonnull )
200 {
201  ECHO(ArrayRCP<int> a_arcp = arcp<int>(10));
202  TEST_EQUALITY_CONST(is_null(a_arcp), false);
203  TEST_EQUALITY_CONST(nonnull(a_arcp), true);
204  ECHO(a_arcp = null);
205  TEST_EQUALITY_CONST(is_null(a_arcp), true);
206  TEST_EQUALITY_CONST(nonnull(a_arcp), false);
207 }
208 
209 
210 TEUCHOS_UNIT_TEST( ArrayRCP, weak_strong )
211 {
212 
213  ECHO(ArrayRCP<int> arcp1 = arcp<int>(10));
214  TEST_EQUALITY_CONST( arcp1.strength(), RCP_STRONG );
215 
216  ECHO(ArrayRCP<int> arcp2 = arcp1.create_weak());
217 
218  TEST_EQUALITY_CONST( arcp2.strength(), RCP_WEAK );
219  TEST_EQUALITY_CONST( arcp1.strong_count(), 1 );
220  TEST_EQUALITY_CONST( arcp1.weak_count(), 1 );
221  TEST_EQUALITY_CONST( arcp2.strong_count(), 1 );
222  TEST_EQUALITY_CONST( arcp2.weak_count(), 1 );
223 
224  ECHO(ArrayRCP<int> arcp3 = arcp2.create_strong());
225 
226  TEST_EQUALITY_CONST( arcp3.strength(), RCP_STRONG );
227  TEST_EQUALITY_CONST( arcp1.strong_count(), 2 );
228  TEST_EQUALITY_CONST( arcp1.weak_count(), 1 );
229  TEST_EQUALITY_CONST( arcp2.strong_count(), 2 );
230  TEST_EQUALITY_CONST( arcp2.weak_count(), 1 );
231 
232  // This will make the underlying object A gets deleted!
233  ECHO(arcp1 = null);
234  ECHO(arcp3 = null);
235 
236  ECHO(arcp2 = null); // Should make the underlying node go away
237 
238 }
239 
240 
241 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_null )
242 {
243  ECHO(ArrayRCP<char> arcp_char = null);
244  ECHO(ArrayRCP<int> arcp_int = arcp_reinterpret_cast<int>(arcp_char));
245  TEST_EQUALITY_CONST(arcp_int, null);
246 }
247 
248 
249 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_char_to_int )
250 {
251 
252  const int sizeOfInt = sizeof(int);
253  const int sizeOfChar = sizeof(char);
254  const int num_ints = n;
255  const int num_chars = (num_ints*sizeOfInt)/sizeOfChar;
256  out << "num_ints = " << num_ints << "\n";
257  out << "num_chars = " << num_chars << "\n";
258 
259  ECHO(ArrayRCP<char> arcp_char = arcp<char>(num_chars));
260  ECHO(ArrayRCP<int> arcp_int = arcp_reinterpret_cast<int>(arcp_char));
261  TEST_EQUALITY(arcp_int.size(), num_ints);
262  TEST_EQUALITY(implicit_ptr_cast<void>(&arcp_int[0]),
263  implicit_ptr_cast<void>(&arcp_char[0]));
264  TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1),
265  implicit_ptr_cast<void>((&arcp_char[num_chars-1])+1));
266 
267  ECHO(arcp_char+=sizeOfInt);
268  ECHO(arcp_int = arcp_reinterpret_cast<int>(arcp_char));
269  TEST_EQUALITY(arcp_int.size(), num_ints);
270  TEST_EQUALITY_CONST( arcp_int.lowerOffset(), -1);
271  TEST_EQUALITY( arcp_int.upperOffset(), num_ints-2);
272  TEST_EQUALITY( implicit_ptr_cast<void>(&arcp_int[-1]),
273  implicit_ptr_cast<void>(&arcp_char[-sizeOfInt])
274  );
275  TEST_EQUALITY( implicit_ptr_cast<void>((&arcp_int[num_ints-2])+1),
276  implicit_ptr_cast<void>((&arcp_char[num_chars-1-sizeOfInt])+1));
277 
278 }
279 
280 
281 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_int_to_char )
282 {
283 
284  const int sizeOfInt = sizeof(int);
285  const int sizeOfChar = sizeof(char);
286  const int num_ints = n;
287  const int num_chars = (num_ints*sizeOfInt)/sizeOfChar;
288  out << "num_ints = " << num_ints << "\n";
289  out << "num_chars = " << num_chars << "\n";
290 
291  ECHO(ArrayRCP<int> arcp_int = arcp<int>(num_ints));
292  ECHO(ArrayRCP<char> arcp_char = arcp_reinterpret_cast<char>(arcp_int));
293  TEST_EQUALITY(arcp_char.size(), num_chars);
294  TEST_EQUALITY(implicit_ptr_cast<void>(&arcp_int[0]),
295  implicit_ptr_cast<void>(&arcp_char[0]));
296  TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1),
297  implicit_ptr_cast<void>((&arcp_char[num_chars-1])+1));
298  TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1),
299  implicit_ptr_cast<void>((&arcp_char[num_chars-1])+1));
300 
301  ECHO(++arcp_int);
302  ECHO(arcp_char = arcp_reinterpret_cast<char>(arcp_int));
303  TEST_EQUALITY(as<int>(arcp_char.lowerOffset()), as<int>(-sizeOfInt));
304  TEST_EQUALITY(as<int>(arcp_char.upperOffset()), as<int>(num_chars-1-sizeOfInt));
305  TEST_EQUALITY(implicit_ptr_cast<void>(&arcp_int[-1]),
306  implicit_ptr_cast<void>(&arcp_char[-sizeOfInt]));
307  TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-2])+1),
308  implicit_ptr_cast<void>((&arcp_char[num_chars-1-sizeOfInt])+1));
309 
310 }
311 
312 
313 TEUCHOS_UNIT_TEST( ArrayRCP, evil_reinterpret_cast )
314 {
315  ECHO(ArrayRCP<ArrayRCP<int> > arcp1 = arcp<ArrayRCP<int> >(n));
316  ECHO(ArrayRCP<ArrayRCP<const int> > arcp2 =
317  arcp_reinterpret_cast<ArrayRCP<const int> >(arcp1));
318  TEST_EQUALITY(arcp2.size(), arcp1.size());
319  TEST_EQUALITY(implicit_ptr_cast<const void>(&arcp1[0]),
320  implicit_ptr_cast<const void>(&arcp2[0]));
321  ECHO(ArrayRCP<const ArrayRCP<const int> > arcp3 = arcp2);
322  TEST_EQUALITY(arcp3.size(), arcp1.size());
323  TEST_EQUALITY(implicit_ptr_cast<const void>(&arcp1[0]),
324  implicit_ptr_cast<const void>(&arcp3[0]));
325  out << "arcp3 = " << arcp3 << "\n";
326 }
327 
328 
329 //
330 // Test arcpCloneNode(...)
331 //
332 
333 
334 TEUCHOS_UNIT_TEST( ArrayRCP, arcpCloneNode_null )
335 {
336  ECHO(ArrayRCP<ArrayRCP<int> > arcp1 = null);
337  ECHO(ArrayRCP<ArrayRCP<int> > arcp2 = arcpCloneNode(arcp1));
338  TEST_EQUALITY(arcp2, null);
339 }
340 
341 
342 TEUCHOS_UNIT_TEST( ArrayRCP, arcpCloneNode_basic )
343 {
344 
345  ECHO(ArrayRCP<int> arcp1 = arcp<int>(n));
346 
347  ECHO(ArrayRCP<int> arcp2 = arcpCloneNode(arcp1));
348  TEST_ASSERT(nonnull(arcp2));
349  TEST_EQUALITY(arcp1.strong_count(), 2);
350  TEST_EQUALITY(arcp2.strong_count(), 1);
351 
352  ECHO(ArrayRCP<int> arcp3 = arcp2);
353  TEST_EQUALITY(arcp1.strong_count(), 2);
354  TEST_EQUALITY(arcp2.strong_count(), 2);
355  TEST_EQUALITY(arcp3.strong_count(), 2);
356 
357  ECHO(ArrayRCP<int> arcp4 = arcp1);
358  TEST_EQUALITY(arcp1.strong_count(), 3);
359  TEST_EQUALITY(arcp2.strong_count(), 2);
360  TEST_EQUALITY(arcp3.strong_count(), 2);
361 
362  ECHO(arcp4 = null);
363  TEST_EQUALITY(arcp1.strong_count(), 2);
364  TEST_EQUALITY(arcp2.strong_count(), 2);
365  TEST_EQUALITY(arcp3.strong_count(), 2);
366  TEST_EQUALITY(arcp4.strong_count(), 0);
367 
368  ECHO(arcp1 = null);
369  TEST_EQUALITY(arcp1.strong_count(), 0);
370  TEST_EQUALITY(arcp2.strong_count(), 2);
371  TEST_EQUALITY(arcp3.strong_count(), 2);
372  TEST_EQUALITY(arcp4.strong_count(), 0);
373 
374  ECHO(arcp2 = null);
375  TEST_EQUALITY(arcp2.strong_count(), 0);
376  TEST_EQUALITY(arcp3.strong_count(), 1);
377 
378  ECHO(arcp3 = null);
379  TEST_EQUALITY(arcp3.strong_count(), 0);
380 
381 }
382 
383 
384 //
385 // Test arcp_reinterpret_cast_nonpod(...)
386 //
387 
388 
389 class MockObject {
390  int member_;
391 public:
392 
393  MockObject(int member_in = -1) : member_(member_in) { ++(numConstructorsCalled()); }
394  MockObject(const MockObject &mo) : member_(mo.member_) { ++(numCopyConstructorsCalled()); }
395  ~MockObject() { ++(numDestructorsCalled()); }
396  int member() const { return member_; }
397 
398  static int & numConstructorsCalled()
399  { static int s_numConstructorsCalled = 0; return s_numConstructorsCalled; }
400  static int & numCopyConstructorsCalled()
401  { static int s_numCopyConstructorsCalled = 0; return s_numCopyConstructorsCalled; }
402  static int & numDestructorsCalled()
403  { static int s_numDestructorsCalled = 0; return s_numDestructorsCalled; }
404  static void reset() { numConstructorsCalled() = numCopyConstructorsCalled() = numDestructorsCalled() = 0; }
405 
406 };
407 
408 
409 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_nonpod_default_construct )
410 {
411 
412  const int sizeOfMockObject = sizeof(MockObject);
413  const int sizeOfChar = sizeof(char);
414  const int num_objs = n;
415  const int num_chars = (num_objs*sizeOfMockObject)/sizeOfChar;
416  out << "num_objs = " << num_objs << "\n";
417  out << "num_chars = " << num_chars << "\n";
418 
419  ECHO(ArrayRCP<char> arcp_chars = arcp<char>(num_chars));
420 
421  ECHO(MockObject::reset());
422  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
423  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), 0);
424  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
425  ECHO(ArrayRCP<MockObject> arcp_objs =
426  arcp_reinterpret_cast_nonpod<MockObject>(arcp_chars));
427  TEST_EQUALITY(arcp_objs.size(), num_objs);
428  TEST_EQUALITY(MockObject::numConstructorsCalled(), 1);
429  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
430  TEST_EQUALITY(MockObject::numDestructorsCalled(), 1);
431  {
432  int sum = 0; for (int i=0; i < num_objs; ++i) sum += arcp_objs[i].member();
433  TEST_EQUALITY(sum, -num_objs);
434  }
435 
436  ECHO(ArrayRCP<MockObject> arcp_objs2 = arcp_objs);
437  TEST_EQUALITY(arcp_objs.size(), num_objs);
438  TEST_EQUALITY(MockObject::numConstructorsCalled(), 1);
439  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
440  TEST_EQUALITY(MockObject::numDestructorsCalled(), 1);
441  {
442  int sum = 0; for (int i=0; i < num_objs; ++i) sum += arcp_objs[i].member();
443  TEST_EQUALITY(sum, -num_objs);
444  }
445 
446  ECHO(arcp_objs = null);
447  TEST_EQUALITY(MockObject::numConstructorsCalled(), 1);
448  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
449  TEST_EQUALITY(MockObject::numDestructorsCalled(), 1);
450 
451  ECHO(arcp_objs2 = null);
452  TEST_EQUALITY(MockObject::numConstructorsCalled(), 1);
453  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
454  TEST_EQUALITY(MockObject::numDestructorsCalled(), num_objs + 1);
455 
456 }
457 
458 
459 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_nonpod_copy_construct )
460 {
461 
462  const int sizeOfMockObject = sizeof(MockObject);
463  const int sizeOfChar = sizeof(char);
464  const int num_objs = n;
465  const int num_chars = (num_objs*sizeOfMockObject)/sizeOfChar;
466  out << "num_objs = " << num_objs << "\n";
467  out << "num_chars = " << num_chars << "\n";
468 
469  ECHO(ArrayRCP<char> arcp_chars = arcp<char>(num_chars));
470 
471  ECHO(MockObject::reset());
472  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
473  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), 0);
474  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
475  ECHO(const MockObject mockObj(1));
476  TEST_EQUALITY(MockObject::numConstructorsCalled(), 1);
477  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), 0);
478  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
479 
480  ECHO(MockObject::reset());
481  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
482  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), 0);
483  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
484  ECHO(ArrayRCP<MockObject> arcp_objs =
485  arcp_reinterpret_cast_nonpod(arcp_chars, mockObj));
486  TEST_EQUALITY(arcp_objs.size(), num_objs);
487  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
488  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
489  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
490  {
491  int sum = 0; for (int i=0; i < num_objs; ++i) sum += arcp_objs[i].member();
492  TEST_EQUALITY(sum, num_objs);
493  }
494 
495  ECHO(ArrayRCP<MockObject> arcp_objs2 = arcp_objs);
496  TEST_EQUALITY(arcp_objs.size(), num_objs);
497  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
498  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
499  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
500  {
501  int sum = 0; for (int i=0; i < num_objs; ++i) sum += arcp_objs[i].member();
502  TEST_EQUALITY(sum, num_objs);
503  }
504 
505  ECHO(arcp_objs = null);
506  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
507  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
508  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
509 
510  ECHO(arcp_objs2 = null);
511  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
512  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
513  TEST_EQUALITY(MockObject::numDestructorsCalled(), num_objs);
514 
515 }
516 
517 
518 //
519 // Test catching of duplicate owning ArrayRCP objects
520 //
521 
522 
523 TEUCHOS_UNIT_TEST( ArrayRCP, duplicate_arcp_owning )
524 {
526  ECHO(A *a_ptr = new A[n]);
527  ECHO(ArrayRCP<A> a_arcp1 = arcp(a_ptr, 0, n)); // Okay
528 #if defined(TEUCHOS_DEBUG)
529  // With node tracing turned on, the implementation knows that an RCPNode
530  // already exists pointing to this same underlying array and will therefore
531  // throw.
532  TEST_THROW(ArrayRCP<A> a_arcp2 = arcp(a_ptr, 0, n), DuplicateOwningRCPError);
533 #else
534  // Will not determine they are point to the same object!
535  ECHO(ArrayRCP<A> a_arcp2 = arcp(a_ptr, 0, n));
536  TEST_EQUALITY(a_arcp2.getRawPtr(), a_ptr);
537  ECHO(a_arcp2.release()); // Better or we will get a segfault!
538 #endif
539 }
540 
541 
542 TEUCHOS_UNIT_TEST( ArrayRCP, dangling_nonowning )
543 {
545  ECHO(A *a_ptr = new A[n]);
546  ECHO(ArrayRCP<A> a_arcp1 = arcp(a_ptr, 0, n)); // Okay
547  ECHO(ArrayRCP<A> a_arcp2 = arcp(a_ptr, 0, n, false)); // Okay
548  a_arcp1 = null;
549 #if defined(TEUCHOS_DEBUG)
550  // With node tracing turned on, the implementation knows that the original
551  // array is deleted and this is a dangling reference!
552  TEST_THROW(a_arcp2.getRawPtr(), DanglingReferenceError);
553 #else
554  // With node tracing turned off, the implemetation does not know the
555  // original array is deleted and therefore it will return a now invalid
556  // pointer.
557  TEST_NOTHROW(a_arcp2.getRawPtr());
558 #endif
559 }
560 
561 
562 class WeirdDealloc {
563  int size_;
564  RCP<std::ostream > out_;
565 public:
566  WeirdDealloc(int size, const RCP<std::ostream> &out) : size_(size), out_(out) {}
567  void free(void *ptr) const
568  {
569  int * const int_ptr = reinterpret_cast<int*>(ptr);
570  {
571  // Create an ArrayView that points to the same memory that is being
572  // deallocated by the owning ArrayRCP. Here, if RCPNode tracing is
573  // enabled, this will thrown and there is really no way around it.
574  ArrayView<const int> tmpav(int_ptr, size_, Teuchos::RCP_DISABLE_NODE_LOOKUP);
575  assert(tmpav[0] == int_ptr[0]);
576  *out_ << tmpav << std::endl;
577  // Create a copy of the ArrayView and make sure that it does not do
578  // node tracing either.
579  ArrayView<const int> tmpav2(tmpav);
580  assert(tmpav2[0] == int_ptr[0]);
581  *out_ << tmpav2 << std::endl;
582  // Assign the ArrayView and make sure that it does not do node tracing
583  // either.
584  ArrayView<const int> tmpav3;
585  tmpav3 = tmpav;
586  assert(tmpav3[0] == int_ptr[0]);
587  *out_ << tmpav2 << std::endl;
588  }
589  delete [] int_ptr;
590  }
591 };
592 
593 
594 TEUCHOS_UNIT_TEST( ArrayRCP, weirdDealloc )
595 {
596  using Teuchos::rcpFromRef;
597  const int size = 4;
598  const bool ownsMem = true;
599  int *int_ptr = new int[size];
600  std::fill_n(int_ptr, size, 0);
601  ArrayRCP<int> a = arcp<int>( int_ptr , 0, size,
602  WeirdDealloc(size, rcpFromRef(out)), ownsMem );
603  a = Teuchos::null;
604 }
605 
606 
607 //
608 // Templated unit tests
609 //
610 
611 
612 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, construct_n, T )
613 {
614  std::vector<T> a(n, as<T>(1));
615  ArrayRCP<T> a_arcp(n, as<T>(1));
616  TEST_COMPARE_ARRAYS(a, a_arcp);
617 }
618 
619 
620 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, assignSelf, T )
621 {
622  ArrayRCP<T> a_arcp;
623  a_arcp = a_arcp;
624 }
625 
626 
627 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, assign_n_val, T )
628 {
629  const T val = as<T>(1);
630  std::vector<T> a;
631  a.assign(n, val);
632  ArrayRCP<T> a_arcp;
633  a_arcp.assign(as<Ordinal>(n), val);
634  TEST_COMPARE_ARRAYS(a, a_arcp);
635 }
636 
637 
638 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, assign_begin_end, T )
639 {
640  const T val = as<T>(1);
641  std::vector<T> a;
642  a.assign(n, val);
643  ArrayRCP<T> a_arcp;
644  a_arcp.assign(a.begin(), a.end());
645  TEST_COMPARE_ARRAYS(a, a_arcp);
646 }
647 
648 
649 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, print_iterators, T )
650 {
651  typedef typename ArrayRCP<T>::const_iterator const_iterator;
652  ECHO(ArrayRCP<T> a_arcp = arcp<T>(n));
653  ECHO(const_iterator itr = a_arcp.begin());
654  out << "itr = " << itr << "\n";
655  TEST_EQUALITY(itr, a_arcp.begin());
656  ECHO(itr += n);
657  out << "itr = " << itr << "\n";
658  TEST_EQUALITY(itr, a_arcp.end());
659 }
660 
661 
662 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, deepCopy, T )
663 {
664  const T val = as<T>(1);
665  std::vector<T> a;
666  a.assign(n, val);
667  ArrayRCP<T> a_arcp = arcp<T>(n);
668  ArrayRCP<T> a_arcp_cpy = a_arcp;
669  a_arcp.deepCopy(Teuchos::arrayViewFromVector(a));
670  TEST_COMPARE_ARRAYS(a, a_arcp);
671  TEST_EQUALITY(a_arcp.getRawPtr(), a_arcp_cpy.getRawPtr());
672 }
673 
674 
675 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, resize, T )
676 {
677  const T val1 = as<T>(1);
678  const T val2 = as<T>(2);
679 
680  std::vector<T> a;
681  ArrayRCP<T> a_arcp;
682 
683  out << "\nChecking resize(n, val1) ...\n";
684  a.resize(n, val1);
685  a_arcp.resize(n, val1);
686  TEST_COMPARE_ARRAYS(a, a_arcp);
687 
688  out << "\nChecking resize(2*n, val2) ...\n";
689  a.resize(2*n, val2);
690  a_arcp.resize(2*n, val2);
691  TEST_COMPARE_ARRAYS(a, a_arcp);
692 
693  out << "\nChecking resize(n/2) ...\n";
694  a.resize(n/2);
695  a_arcp.resize(n/2);
696  TEST_COMPARE_ARRAYS(a, a_arcp);
697 
698  out << "\nChecking resize(0) ...\n";
699  a.resize(0);
700  a_arcp.resize(0);
701  TEST_COMPARE_ARRAYS(a, a_arcp);
702 
703 #ifdef TEUCHOS_DEBUG
704  a_arcp = arcp<T>(n);
705  ++a_arcp;
706  TEST_THROW(a_arcp.resize(1), std::out_of_range);
707 #endif
708 }
709 
710 
711 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, clear, T )
712 {
713  ArrayRCP<T> a_arcp = arcp<T>(n);
714  TEST_EQUALITY( a_arcp.size(), n );
715  a_arcp.clear();
716  TEST_EQUALITY( a_arcp.size(), 0 );
717 }
718 
719 
720 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, nullIterator, T )
721 {
722  typedef ArrayRCP<T> iter_t;
723  ArrayRCP<T> arcp1 = Teuchos::NullIteratorTraits<iter_t>::getNull();
725 }
726 
727 
728 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, implicitConversions, T )
729 {
730 
731  ECHO(ArrayRCP<T> arcp1 = arcp<T>(n));
732  ECHO(ArrayRCP<const T> arcp2 = arcp1);
733  TEST_ASSERT(arcp1.shares_resource(arcp2));
734 
735 }
736 
737 
738 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, weakDelete, T )
739 {
740 
741  ECHO(ArrayRCP<T> arcp_strong = arcp<T>(n));
742 
743  TEST_EQUALITY_CONST( arcp_strong.strength(), RCP_STRONG );
744  TEST_EQUALITY_CONST( arcp_strong.is_null(), false );
745  TEST_EQUALITY_CONST( arcp_strong.strong_count(), 1 );
746  TEST_EQUALITY_CONST( arcp_strong.weak_count(), 0 );
747  TEST_EQUALITY_CONST( arcp_strong.total_count(), 1 );
748 
749  ECHO(ArrayRCP<T> arcp_weak1 = arcp_strong.create_weak());
750 
751  TEST_EQUALITY_CONST( arcp_weak1.strength(), RCP_WEAK );
752  TEST_EQUALITY_CONST( arcp_weak1.is_null(), false );
753  TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 1 );
754  TEST_EQUALITY_CONST( arcp_weak1.weak_count(), 1 );
755  TEST_EQUALITY_CONST( arcp_weak1.total_count(), 2 );
756 
757  TEST_EQUALITY_CONST( arcp_strong.strong_count(), 1 );
758  TEST_EQUALITY_CONST( arcp_strong.is_null(), false );
759  TEST_EQUALITY_CONST( arcp_strong.weak_count(), 1 );
760  TEST_EQUALITY_CONST( arcp_strong.total_count(), 2 );
761 
762  TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_strong), true );
763 
764  TEST_EQUALITY( arcp_weak1.get(), arcp_weak1.getRawPtr() );
765  TEST_EQUALITY( arcp_weak1.get(), arcp_strong.get() );
766  TEST_EQUALITY( arcp_weak1.getRawPtr(), arcp_strong.getRawPtr() );
767 
768  ECHO(ArrayRCP<T> arcp_weak2 = arcp_weak1);
769 
770  TEST_EQUALITY_CONST( arcp_weak2.strength(), RCP_WEAK );
771  TEST_EQUALITY_CONST( arcp_weak2.is_null(), false );
772  TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 1 );
773  TEST_EQUALITY_CONST( arcp_weak2.weak_count(), 2 );
774  TEST_EQUALITY_CONST( arcp_weak2.total_count(), 3 );
775 
776  TEST_EQUALITY_CONST( arcp_strong.strong_count(), 1 );
777  TEST_EQUALITY_CONST( arcp_strong.is_null(), false );
778  TEST_EQUALITY_CONST( arcp_strong.weak_count(), 2 );
779  TEST_EQUALITY_CONST( arcp_strong.total_count(), 3 );
780 
781  TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_strong), true );
782  TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_weak2), true );
783  TEST_EQUALITY_CONST( arcp_weak2.shares_resource(arcp_strong), true );
784 
785  TEST_EQUALITY( arcp_weak2.get(), arcp_strong.get() );
786  TEST_EQUALITY( arcp_weak2.getRawPtr(), arcp_strong.getRawPtr() );
787 
788  ECHO(arcp_strong = null); // This deletes the underlying object of type T!
789 
790  TEST_EQUALITY_CONST( arcp_strong.strength(), RCP_STRONG );
791  TEST_EQUALITY_CONST( arcp_strong.is_null(), true );
792  TEST_EQUALITY_CONST( arcp_strong.strong_count(), 0 );
793  TEST_EQUALITY_CONST( arcp_strong.strong_count(), 0 );
794  TEST_EQUALITY_CONST( arcp_strong.weak_count(), 0 );
795  TEST_EQUALITY_CONST( arcp_strong.total_count(), 0 );
796  TEST_EQUALITY_CONST( arcp_strong.is_valid_ptr(), true );
797 
798  TEST_EQUALITY_CONST( arcp_strong.shares_resource(arcp_weak1), false );
799  TEST_EQUALITY_CONST( arcp_strong.shares_resource(arcp_weak2), false );
800 
801  TEST_EQUALITY_CONST( arcp_weak1.has_ownership(), true );
802  TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 0 );
803  TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 0 );
804  TEST_EQUALITY_CONST( arcp_weak1.weak_count(), 2 );
805  TEST_EQUALITY_CONST( arcp_weak1.total_count(), 2 );
806  TEST_EQUALITY_CONST( arcp_weak1.is_valid_ptr(), false );
807 
808  TEST_EQUALITY_CONST( arcp_weak2.has_ownership(), true );
809  TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 0 );
810  TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 0 );
811  TEST_EQUALITY_CONST( arcp_weak2.weak_count(), 2 );
812  TEST_EQUALITY_CONST( arcp_weak2.total_count(), 2 );
813  TEST_EQUALITY_CONST( arcp_weak2.is_valid_ptr(), false );
814 
815  TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_weak2), true );
816 
817  ECHO(arcp_weak1.assert_not_null()); // Does not throw!
818  ECHO(arcp_weak2.assert_not_null()); // Does not throw!
819 
820  TEST_THROW( arcp_weak1.assert_valid_ptr(), DanglingReferenceError );
821 #ifdef TEUCHOS_DEBUG
822  TEST_THROW( arcp_weak1.operator->(), DanglingReferenceError );
823  TEST_THROW( *arcp_weak1, DanglingReferenceError );
824  TEST_THROW( arcp_weak1.create_weak(), DanglingReferenceError );
825  TEST_THROW( arcp_weak1.get(), DanglingReferenceError );
826  TEST_THROW( arcp_weak1.getRawPtr(), DanglingReferenceError );
827  TEST_THROW( arcp_weak1[0], DanglingReferenceError );
828  TEST_THROW( ++arcp_weak1, DanglingReferenceError );
829  TEST_THROW( arcp_weak1++, DanglingReferenceError );
830  TEST_THROW( --arcp_weak1, DanglingReferenceError );
831  TEST_THROW( arcp_weak1--, DanglingReferenceError );
832  TEST_THROW( arcp_weak1+=1, DanglingReferenceError );
833  TEST_THROW( arcp_weak1-=1, DanglingReferenceError );
834  TEST_THROW( arcp_weak1+1, DanglingReferenceError );
835  TEST_THROW( arcp_weak1-1, DanglingReferenceError );
836  TEST_THROW( arcp_weak1.getConst(), DanglingReferenceError );
837  TEST_THROW( arcp_weak1.persistingView(0,n), DanglingReferenceError );
838  TEST_THROW( arcp_weak1.lowerOffset(), DanglingReferenceError );
839  TEST_THROW( arcp_weak1.upperOffset(), DanglingReferenceError );
840  TEST_THROW( arcp_weak1.size(), DanglingReferenceError );
841  TEST_THROW( arcp_weak1.begin(), DanglingReferenceError );
842  TEST_THROW( arcp_weak1.end(), DanglingReferenceError );
843  TEST_THROW( arcp_weak1.view(0,n), DanglingReferenceError );
844  TEST_THROW( arcp_weak1(0,n), DanglingReferenceError );
845  TEST_THROW( arcp_weak1(), DanglingReferenceError );
846  TEST_THROW( {ArrayView<T> av = arcp_weak1();}, DanglingReferenceError );
847  TEST_THROW( {ArrayRCP<const T> ap = getConst(arcp_weak1);},
848  DanglingReferenceError );
849  TEST_THROW( arcp_weak1.release(), DanglingReferenceError );
850 #endif // TEUCHOS_DEBUG
851 
852  ECHO(arcp_weak1 = null); // Just deicrements weak count!
853 
854  TEST_EQUALITY_CONST( arcp_weak1.strength(), RCP_STRONG );
855  TEST_EQUALITY_CONST( arcp_weak1.is_null(), true );
856  TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 0 );
857  TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 0 );
858  TEST_EQUALITY_CONST( arcp_weak1.weak_count(), 0 );
859  TEST_EQUALITY_CONST( arcp_weak1.total_count(), 0 );
860  TEST_EQUALITY_CONST( arcp_weak1.is_valid_ptr(), true );
861 
862  TEST_EQUALITY_CONST( arcp_weak2.has_ownership(), true );
863  TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 0 );
864  TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 0 );
865  TEST_EQUALITY_CONST( arcp_weak2.weak_count(), 1 );
866  TEST_EQUALITY_CONST( arcp_weak2.total_count(), 1 );
867  TEST_EQUALITY_CONST( arcp_weak2.is_valid_ptr(), false );
868 
869  TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_weak2), false );
870 
871  TEST_THROW( arcp_weak2.assert_valid_ptr(), DanglingReferenceError );
872 #ifdef TEUCHOS_DEBUG
873  // ToDo: Fill in
874 #endif // TEUCHOS_DEBUG
875 
876 }
877 
878 
879 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, danglingArrayView, T )
880 {
881  ArrayView<T> av;
882  {
883  ArrayRCP<T> arcp1 = arcp<T>(n);
884  av = arcp1();
885  }
886 #ifdef TEUCHOS_DEBUG
887  TEST_THROW( av.size(), DanglingReferenceError );
888  TEST_THROW( av.toString(), DanglingReferenceError );
889  TEST_THROW( av.getRawPtr(), DanglingReferenceError );
890  TEST_THROW( av[0], DanglingReferenceError );
891  TEST_THROW( av.front(), DanglingReferenceError );
892  TEST_THROW( av.back(), DanglingReferenceError );
893  TEST_THROW( av.view(0, n), DanglingReferenceError );
894  TEST_THROW( av(0, n), DanglingReferenceError );
895  TEST_THROW( av(), DanglingReferenceError );
896  TEST_THROW( av.getConst(), DanglingReferenceError );
897  TEST_THROW( av.begin(), DanglingReferenceError );
898  TEST_THROW( av.end(), DanglingReferenceError );
899 #endif
900 }
901 
902 
904 {
905  ArrayRCP<const T> cptr;
906  ArrayRCP<T> ptr;
907  TEST_EQUALITY_CONST( getRawPtr(cptr), (const T*)NULL );
908  TEST_EQUALITY_CONST( getRawPtr(ptr), (T*)NULL );
909  cptr = arcp<T>(n);
910  ptr = arcp<T>(n);
911  TEST_EQUALITY( getRawPtr(cptr), &cptr[0]);
912  TEST_EQUALITY( getRawPtr(ptr), &ptr[0] );
913 }
914 
915 
917 {
918  const T *cptr = NULL;
919  T *ptr = NULL;
920  TEST_EQUALITY_CONST( getRawPtr(cptr), (const T*)NULL );
921  TEST_EQUALITY_CONST( getRawPtr(ptr), (T*)NULL );
922  cptr = new T[n];
923  ptr = new T[n];
924  TEST_EQUALITY( getRawPtr(cptr), &cptr[0]);
925  TEST_EQUALITY( getRawPtr(ptr), &ptr[0] );
926  delete [] cptr;
927  delete [] ptr;
928 }
929 
930 
931 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, arcp_zero, T )
932 {
933  ArrayRCP<T> arcp_strong = arcp<T>(0);
934  TEST_EQUALITY(arcp_strong.size(), as<Ordinal>(0));
935 }
936 
937 
939 {
940  Array<T> a = generateArray<T>(n);
941  ArrayView<T> av = a;
942  ArrayRCP<T> arcp1 = Teuchos::arcpFromArrayView(av);
943  TEST_COMPARE_ARRAYS(arcp1, av);
944 }
945 
946 
947 #ifdef TEUCHOS_DEBUG
948 
949 
950 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, arcp_neg, T )
951 {
952  TEST_THROW(ArrayRCP<T> arcp_strong = arcp<T>(-1),
953  std::out_of_range);
954 }
955 
956 
957 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, outOfBounds, T )
958 {
959  ECHO(ArrayRCP<T> arcp1 = arcp<T>(n));
960  TEST_THROW(arcp1(-1,n), RangeError);
961  TEST_THROW(arcp1(0,n+1), RangeError);
962  TEST_THROW(arcp1(0,-1), RangeError);
963  TEST_THROW(arcp1.view(-1,n), RangeError);
964  TEST_THROW(arcp1.view(0,n+1), RangeError);
965  TEST_THROW(arcp1.view(0,-1), RangeError);
966  TEST_THROW(arcp1.persistingView(-1,n), RangeError);
967  TEST_THROW(arcp1.persistingView(0,n+1), RangeError);
968  TEST_THROW(arcp1.persistingView(0,-1), RangeError);
969 }
970 
971 
972 #endif // TEUCHOS_DEBUG
973 
974 
975 //
976 // Template Instantiations
977 //
978 
979 
980 #ifdef TEUCHOS_DEBUG
981 
982 # define DEBUG_UNIT_TEST_GROUP( T ) \
983  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, arcp_neg, T ) \
984  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, outOfBounds, T ) \
985 
986 #else
987 
988 # define DEBUG_UNIT_TEST_GROUP( T )
989 
990 #endif
991 
992 
993 #define UNIT_TEST_GROUP( T ) \
994  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, construct_n, T ) \
995  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, assignSelf, T ) \
996  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, assign_n_val, T ) \
997  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, assign_begin_end, T ) \
998  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, print_iterators, T ) \
999  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, deepCopy, T ) \
1000  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, resize, T ) \
1001  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, clear, T ) \
1002  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, nullIterator, T ) \
1003  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, implicitConversions, T ) \
1004  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, weakDelete, T ) \
1005  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, danglingArrayView, T ) \
1006  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, getRawPtr, T) \
1007  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( CPtr, getRawPtr, T) \
1008  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, arcp_zero, T ) \
1009  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, arcpFromArrayView, T ) \
1010  DEBUG_UNIT_TEST_GROUP(T)
1011 
1012 
1013 UNIT_TEST_GROUP(int)
1014 UNIT_TEST_GROUP(double)
1015 UNIT_TEST_GROUP(float)
1016 
1017 
1018 } // namespace
Dangling reference error exception class.
ArrayRCP< T2 > arcp_reinterpret_cast_nonpod(const ArrayRCP< T1 > &p1, const T2 &val=T2())
Reinterpret cast of underlying ArrayRCP type from T1* to T2* where T2 is a non-POD (non-plain-old-dat...
Null reference error exception class.
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...
#define TEST_ASSERT(v1)
Assert the given statement is true.
#define UNIT_TEST_GROUP(T)
#define TEST_NOTHROW(code)
Asserr that the statement &#39;code&#39; does not thrown any excpetions.
#define ECHO(statement)
Echo the given statement before it is executed.
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(TEST_GROUP, TEST_NAME, TYPE)
Macro for defining a templated unit test with one template parameter.
RawPointerConversionTraits< Container >::Ptr_t getRawPtr(const Container &c)
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEST_THROW(code, ExceptType)
Assert that the statement &#39;code&#39; throws the exception &#39;ExceptType&#39; (otherwise the test fails)...
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
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.
const int A_f_return
Definition: TestClasses.hpp:19
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL.
ArrayRCP< T2 > arcp_reinterpret_cast(const ArrayRCP< T1 > &p1)
Reinterpret cast of underlying ArrayRCP type from T1* to T2*.
#define SET_RCPNODE_TRACING()
ArrayRCP< T > arcpFromArrayView(const ArrayView< T > &av)
Get an ArrayRCP object out of an ArrayView object.
TEUCHOS_ORDINAL_TYPE Teuchos_Ordinal
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Unit testing support.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
ArrayRCP< T > arcpCloneNode(const ArrayRCP< T > &a)
Allocate a new ArrayRCP object with a new RCPNode with memory pointing to the initial node...
TypeTo * implicit_ptr_cast(TypeFrom *t)
Perform an implicit cast of pointer types with a pointer being returned.
int size(const Comm< Ordinal > &comm)
Get the number of processes in the communicator.
Teuchos::Array< T > generateArray(const int n_in)
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.
#define TEST_COMPARE_ARRAYS(a1, a2)
Assert that a1.size()==a2.size() and a[i]==b[i], i=0....
Nonowning array view.
RCP< T > rcpFromRef(T &r)
Return a non-owning weak RCP object from a raw object reference for a defined type.
Policy class for deallocator for non-owned RCPs.
ArrayRCP< T > arcpWithEmbeddedObj(T *p, typename ArrayRCP< T >::size_type lowerOffset, typename ArrayRCP< T >::size_type size, const Embedded &embedded, bool owns_mem=true)
Create an ArrayRCP with and also put in an embedded object.
Smart reference counting pointer class for automatic garbage collection.
Range error exception class.
Thrown if a duplicate owning RCP is creatd the the same object.
Reference-counted pointer class and non-member templated function implementations.
Definition of Teuchos::as, for conversions between types.
bool nonnull(const ArrayRCP< T > &p)
Returns true if p.get()!=NULL.
Reference-counted smart pointer for managing arrays.
Replacement for std::vector that is compatible with the Teuchos Memory Management classes...