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