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, raw_ptr_nonowning_self_view )
143 {
144  A *data = new A[10];
145  ArrayRCP<A> arcp_view(data, 0, 10, false);
146  ArrayView<A> view = arcp_view(0, 5);
147  arcp_view = null;
148 #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK
149  TEST_THROW(view.size(), DanglingReferenceError);
150 #endif
151  delete [] data;
152 }
153 
154 
155 TEUCHOS_UNIT_TEST( ArrayRCP, implicit_ArrayRCP_const )
156 {
157  const ArrayRCP<A> a_arcp;
158  const ArrayRCP<const A> ac_arcp = a_arcp;
159  TEST_ASSERT(is_null(ac_arcp));
160 }
161 
162 
163 TEUCHOS_UNIT_TEST( ArrayRCP, ArrayRCP_void_throws )
164 {
165  TEST_THROW( const ArrayRCP< void> v_arcp, std::logic_error );
166  TEST_THROW( const ArrayRCP<const void> cv_arcp, std::logic_error );
167 }
168 
169 
170 TEUCHOS_UNIT_TEST( ArrayRCP, release )
171 {
172  ArrayRCP<A> a_arcp = arcp<A>(1);
173  delete [] a_arcp.release();
174 }
175 
176 
177 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_null )
178 {
179  ArrayRCP<A> a_arcp = arcp<A>(0, 0, -1, false);
180  TEST_ASSERT(is_null(a_arcp));
181 }
182 
183 
184 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_dealloc_null )
185 {
186  ArrayRCP<A> a_arcp = arcp<A, Teuchos::DeallocNull<A> >(0, 0, -1,
187  Teuchos::DeallocNull<A>(), false);
188  TEST_ASSERT(is_null(a_arcp));
189 }
190 
191 
192 TEUCHOS_UNIT_TEST( ArrayRCP, convert_from_vector_null )
193 {
194  const RCP<std::vector<int> > v_rcp;
195  const ArrayRCP<int> a_arcp = arcp(v_rcp);
196  TEST_ASSERT(is_null(a_arcp));
197 }
198 
199 
200 TEUCHOS_UNIT_TEST( ArrayRCP, convert_from_const_vector_null )
201 {
202  const RCP<const std::vector<int> > v_rcp;
203  const ArrayRCP<const int> a_arcp = arcp(v_rcp);
204  TEST_ASSERT(is_null(a_arcp));
205 }
206 
207 
208 TEUCHOS_UNIT_TEST( ArrayRCP, convert_from_vector_unsized )
209 {
210  const RCP<std::vector<int> > v_rcp = rcp(new std::vector<int>);
211  const ArrayRCP<int> a_arcp = arcp(v_rcp);
212  TEST_ASSERT(is_null(a_arcp));
213 }
214 
215 
216 TEUCHOS_UNIT_TEST( ArrayRCP, convert_from_const_vector_unsized )
217 {
218  const RCP<const std::vector<int> > v_rcp = rcp(new std::vector<int>);
219  const ArrayRCP<const int> a_arcp = arcp(v_rcp);
220  TEST_ASSERT(is_null(a_arcp));
221 }
222 
223 
225 {
226  const ArrayRCP<const int> a_arcp =
227  Teuchos::arcpWithEmbeddedObj<int>(new int[1], 0, 1, as<int>(1), true);
228  const int embeddedObj = Teuchos::getEmbeddedObj<int,int>(a_arcp);
229  TEST_EQUALITY_CONST( embeddedObj, as<int>(1) );
230 }
231 
232 
233 TEUCHOS_UNIT_TEST( ArrayRCP, nonnull )
234 {
235  ECHO(ArrayRCP<int> a_arcp = arcp<int>(10));
236  TEST_EQUALITY_CONST(is_null(a_arcp), false);
237  TEST_EQUALITY_CONST(nonnull(a_arcp), true);
238  ECHO(a_arcp = null);
239  TEST_EQUALITY_CONST(is_null(a_arcp), true);
240  TEST_EQUALITY_CONST(nonnull(a_arcp), false);
241 }
242 
243 
244 TEUCHOS_UNIT_TEST( ArrayRCP, weak_strong )
245 {
246 
247  ECHO(ArrayRCP<int> arcp1 = arcp<int>(10));
248  TEST_EQUALITY_CONST( arcp1.strength(), RCP_STRONG );
249 
250  ECHO(ArrayRCP<int> arcp2 = arcp1.create_weak());
251 
252  TEST_EQUALITY_CONST( arcp2.strength(), RCP_WEAK );
253  TEST_EQUALITY_CONST( arcp1.strong_count(), 1 );
254  TEST_EQUALITY_CONST( arcp1.weak_count(), 1 );
255  TEST_EQUALITY_CONST( arcp2.strong_count(), 1 );
256  TEST_EQUALITY_CONST( arcp2.weak_count(), 1 );
257 
258  ECHO(ArrayRCP<int> arcp3 = arcp2.create_strong());
259 
260  TEST_EQUALITY_CONST( arcp3.strength(), RCP_STRONG );
261  TEST_EQUALITY_CONST( arcp1.strong_count(), 2 );
262  TEST_EQUALITY_CONST( arcp1.weak_count(), 1 );
263  TEST_EQUALITY_CONST( arcp2.strong_count(), 2 );
264  TEST_EQUALITY_CONST( arcp2.weak_count(), 1 );
265 
266  // This will make the underlying object A gets deleted!
267  ECHO(arcp1 = null);
268  ECHO(arcp3 = null);
269 
270  ECHO(arcp2 = null); // Should make the underlying node go away
271 
272 }
273 
274 
275 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_null )
276 {
277  ECHO(ArrayRCP<char> arcp_char = null);
278  ECHO(ArrayRCP<int> arcp_int = arcp_reinterpret_cast<int>(arcp_char));
279  TEST_EQUALITY_CONST(arcp_int, null);
280 }
281 
282 
283 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_char_to_int )
284 {
285 
286  const int sizeOfInt = sizeof(int);
287  const int sizeOfChar = sizeof(char);
288  const int num_ints = n;
289  const int num_chars = (num_ints*sizeOfInt)/sizeOfChar;
290  out << "num_ints = " << num_ints << "\n";
291  out << "num_chars = " << num_chars << "\n";
292 
293  ECHO(ArrayRCP<char> arcp_char = arcp<char>(num_chars));
294  ECHO(ArrayRCP<int> arcp_int = arcp_reinterpret_cast<int>(arcp_char));
295  TEST_EQUALITY(arcp_int.size(), num_ints);
296  TEST_EQUALITY(implicit_ptr_cast<void>(&arcp_int[0]),
297  implicit_ptr_cast<void>(&arcp_char[0]));
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_char+=sizeOfInt);
302  ECHO(arcp_int = arcp_reinterpret_cast<int>(arcp_char));
303  TEST_EQUALITY(arcp_int.size(), num_ints);
304  TEST_EQUALITY_CONST( arcp_int.lowerOffset(), -1);
305  TEST_EQUALITY( arcp_int.upperOffset(), num_ints-2);
306  TEST_EQUALITY( implicit_ptr_cast<void>(&arcp_int[-1]),
307  implicit_ptr_cast<void>(&arcp_char[-sizeOfInt])
308  );
309  TEST_EQUALITY( implicit_ptr_cast<void>((&arcp_int[num_ints-2])+1),
310  implicit_ptr_cast<void>((&arcp_char[num_chars-1-sizeOfInt])+1));
311 
312 }
313 
314 
315 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_int_to_char )
316 {
317 
318  const int sizeOfInt = sizeof(int);
319  const int sizeOfChar = sizeof(char);
320  const int num_ints = n;
321  const int num_chars = (num_ints*sizeOfInt)/sizeOfChar;
322  out << "num_ints = " << num_ints << "\n";
323  out << "num_chars = " << num_chars << "\n";
324 
325  ECHO(ArrayRCP<int> arcp_int = arcp<int>(num_ints));
326  ECHO(ArrayRCP<char> arcp_char = arcp_reinterpret_cast<char>(arcp_int));
327  TEST_EQUALITY(arcp_char.size(), num_chars);
328  TEST_EQUALITY(implicit_ptr_cast<void>(&arcp_int[0]),
329  implicit_ptr_cast<void>(&arcp_char[0]));
330  TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1),
331  implicit_ptr_cast<void>((&arcp_char[num_chars-1])+1));
332  TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-1])+1),
333  implicit_ptr_cast<void>((&arcp_char[num_chars-1])+1));
334 
335  ECHO(++arcp_int);
336  ECHO(arcp_char = arcp_reinterpret_cast<char>(arcp_int));
337  TEST_EQUALITY(as<int>(arcp_char.lowerOffset()), as<int>(-sizeOfInt));
338  TEST_EQUALITY(as<int>(arcp_char.upperOffset()), as<int>(num_chars-1-sizeOfInt));
339  TEST_EQUALITY(implicit_ptr_cast<void>(&arcp_int[-1]),
340  implicit_ptr_cast<void>(&arcp_char[-sizeOfInt]));
341  TEST_EQUALITY(implicit_ptr_cast<void>((&arcp_int[num_ints-2])+1),
342  implicit_ptr_cast<void>((&arcp_char[num_chars-1-sizeOfInt])+1));
343 
344 }
345 
346 
347 TEUCHOS_UNIT_TEST( ArrayRCP, evil_reinterpret_cast )
348 {
349  ECHO(ArrayRCP<ArrayRCP<int> > arcp1 = arcp<ArrayRCP<int> >(n));
350  ECHO(ArrayRCP<ArrayRCP<const int> > arcp2 =
351  arcp_reinterpret_cast<ArrayRCP<const int> >(arcp1));
352  TEST_EQUALITY(arcp2.size(), arcp1.size());
353  TEST_EQUALITY(implicit_ptr_cast<const void>(&arcp1[0]),
354  implicit_ptr_cast<const void>(&arcp2[0]));
355  ECHO(ArrayRCP<const ArrayRCP<const int> > arcp3 = arcp2);
356  TEST_EQUALITY(arcp3.size(), arcp1.size());
357  TEST_EQUALITY(implicit_ptr_cast<const void>(&arcp1[0]),
358  implicit_ptr_cast<const void>(&arcp3[0]));
359  out << "arcp3 = " << arcp3 << "\n";
360 }
361 
362 
363 //
364 // Test arcpCloneNode(...)
365 //
366 
367 
368 TEUCHOS_UNIT_TEST( ArrayRCP, arcpCloneNode_null )
369 {
370  ECHO(ArrayRCP<ArrayRCP<int> > arcp1 = null);
371  ECHO(ArrayRCP<ArrayRCP<int> > arcp2 = arcpCloneNode(arcp1));
372  TEST_EQUALITY(arcp2, null);
373 }
374 
375 
376 TEUCHOS_UNIT_TEST( ArrayRCP, arcpCloneNode_basic )
377 {
378 
379  ECHO(ArrayRCP<int> arcp1 = arcp<int>(n));
380 
381  ECHO(ArrayRCP<int> arcp2 = arcpCloneNode(arcp1));
382  TEST_ASSERT(nonnull(arcp2));
383  TEST_EQUALITY(arcp1.strong_count(), 2);
384  TEST_EQUALITY(arcp2.strong_count(), 1);
385 
386  ECHO(ArrayRCP<int> arcp3 = arcp2);
387  TEST_EQUALITY(arcp1.strong_count(), 2);
388  TEST_EQUALITY(arcp2.strong_count(), 2);
389  TEST_EQUALITY(arcp3.strong_count(), 2);
390 
391  ECHO(ArrayRCP<int> arcp4 = arcp1);
392  TEST_EQUALITY(arcp1.strong_count(), 3);
393  TEST_EQUALITY(arcp2.strong_count(), 2);
394  TEST_EQUALITY(arcp3.strong_count(), 2);
395 
396  ECHO(arcp4 = null);
397  TEST_EQUALITY(arcp1.strong_count(), 2);
398  TEST_EQUALITY(arcp2.strong_count(), 2);
399  TEST_EQUALITY(arcp3.strong_count(), 2);
400  TEST_EQUALITY(arcp4.strong_count(), 0);
401 
402  ECHO(arcp1 = null);
403  TEST_EQUALITY(arcp1.strong_count(), 0);
404  TEST_EQUALITY(arcp2.strong_count(), 2);
405  TEST_EQUALITY(arcp3.strong_count(), 2);
406  TEST_EQUALITY(arcp4.strong_count(), 0);
407 
408  ECHO(arcp2 = null);
409  TEST_EQUALITY(arcp2.strong_count(), 0);
410  TEST_EQUALITY(arcp3.strong_count(), 1);
411 
412  ECHO(arcp3 = null);
413  TEST_EQUALITY(arcp3.strong_count(), 0);
414 
415 }
416 
417 
418 //
419 // Test arcp_reinterpret_cast_nonpod(...)
420 //
421 
422 
423 class MockObject {
424  int member_;
425 public:
426 
427  MockObject(int member_in = -1) : member_(member_in) { ++(numConstructorsCalled()); }
428  MockObject(const MockObject &mo) : member_(mo.member_) { ++(numCopyConstructorsCalled()); }
429  ~MockObject() { ++(numDestructorsCalled()); }
430  int member() const { return member_; }
431 
432  static int & numConstructorsCalled()
433  { static int s_numConstructorsCalled = 0; return s_numConstructorsCalled; }
434  static int & numCopyConstructorsCalled()
435  { static int s_numCopyConstructorsCalled = 0; return s_numCopyConstructorsCalled; }
436  static int & numDestructorsCalled()
437  { static int s_numDestructorsCalled = 0; return s_numDestructorsCalled; }
438  static void reset() { numConstructorsCalled() = numCopyConstructorsCalled() = numDestructorsCalled() = 0; }
439 
440 };
441 
442 
443 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_nonpod_default_construct )
444 {
445 
446  const int sizeOfMockObject = sizeof(MockObject);
447  const int sizeOfChar = sizeof(char);
448  const int num_objs = n;
449  const int num_chars = (num_objs*sizeOfMockObject)/sizeOfChar;
450  out << "num_objs = " << num_objs << "\n";
451  out << "num_chars = " << num_chars << "\n";
452 
453  ECHO(ArrayRCP<char> arcp_chars = arcp<char>(num_chars));
454 
455  ECHO(MockObject::reset());
456  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
457  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), 0);
458  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
459  ECHO(ArrayRCP<MockObject> arcp_objs =
460  arcp_reinterpret_cast_nonpod<MockObject>(arcp_chars));
461  TEST_EQUALITY(arcp_objs.size(), num_objs);
462  TEST_EQUALITY(MockObject::numConstructorsCalled(), 1);
463  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
464  TEST_EQUALITY(MockObject::numDestructorsCalled(), 1);
465  {
466  int sum = 0; for (int i=0; i < num_objs; ++i) sum += arcp_objs[i].member();
467  TEST_EQUALITY(sum, -num_objs);
468  }
469 
470  ECHO(ArrayRCP<MockObject> arcp_objs2 = arcp_objs);
471  TEST_EQUALITY(arcp_objs.size(), num_objs);
472  TEST_EQUALITY(MockObject::numConstructorsCalled(), 1);
473  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
474  TEST_EQUALITY(MockObject::numDestructorsCalled(), 1);
475  {
476  int sum = 0; for (int i=0; i < num_objs; ++i) sum += arcp_objs[i].member();
477  TEST_EQUALITY(sum, -num_objs);
478  }
479 
480  ECHO(arcp_objs = null);
481  TEST_EQUALITY(MockObject::numConstructorsCalled(), 1);
482  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
483  TEST_EQUALITY(MockObject::numDestructorsCalled(), 1);
484 
485  ECHO(arcp_objs2 = null);
486  TEST_EQUALITY(MockObject::numConstructorsCalled(), 1);
487  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
488  TEST_EQUALITY(MockObject::numDestructorsCalled(), num_objs + 1);
489 
490 }
491 
492 
493 TEUCHOS_UNIT_TEST( ArrayRCP, arcp_reinterpret_cast_nonpod_copy_construct )
494 {
495 
496  const int sizeOfMockObject = sizeof(MockObject);
497  const int sizeOfChar = sizeof(char);
498  const int num_objs = n;
499  const int num_chars = (num_objs*sizeOfMockObject)/sizeOfChar;
500  out << "num_objs = " << num_objs << "\n";
501  out << "num_chars = " << num_chars << "\n";
502 
503  ECHO(ArrayRCP<char> arcp_chars = arcp<char>(num_chars));
504 
505  ECHO(MockObject::reset());
506  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
507  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), 0);
508  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
509  ECHO(const MockObject mockObj(1));
510  TEST_EQUALITY(MockObject::numConstructorsCalled(), 1);
511  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), 0);
512  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
513 
514  ECHO(MockObject::reset());
515  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
516  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), 0);
517  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
518  ECHO(ArrayRCP<MockObject> arcp_objs =
519  arcp_reinterpret_cast_nonpod(arcp_chars, mockObj));
520  TEST_EQUALITY(arcp_objs.size(), num_objs);
521  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
522  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
523  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
524  {
525  int sum = 0; for (int i=0; i < num_objs; ++i) sum += arcp_objs[i].member();
526  TEST_EQUALITY(sum, num_objs);
527  }
528 
529  ECHO(ArrayRCP<MockObject> arcp_objs2 = arcp_objs);
530  TEST_EQUALITY(arcp_objs.size(), num_objs);
531  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
532  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
533  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
534  {
535  int sum = 0; for (int i=0; i < num_objs; ++i) sum += arcp_objs[i].member();
536  TEST_EQUALITY(sum, num_objs);
537  }
538 
539  ECHO(arcp_objs = null);
540  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
541  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
542  TEST_EQUALITY(MockObject::numDestructorsCalled(), 0);
543 
544  ECHO(arcp_objs2 = null);
545  TEST_EQUALITY(MockObject::numConstructorsCalled(), 0);
546  TEST_EQUALITY(MockObject::numCopyConstructorsCalled(), num_objs);
547  TEST_EQUALITY(MockObject::numDestructorsCalled(), num_objs);
548 
549 }
550 
551 
552 //
553 // Test catching of duplicate owning ArrayRCP objects
554 //
555 
556 
557 TEUCHOS_UNIT_TEST( ArrayRCP, duplicate_arcp_owning )
558 {
560  ECHO(A *a_ptr = new A[n]);
561  ECHO(ArrayRCP<A> a_arcp1 = arcp(a_ptr, 0, n)); // Okay
562 #if defined(TEUCHOS_DEBUG)
563  // With node tracing turned on, the implementation knows that an RCPNode
564  // already exists pointing to this same underlying array and will therefore
565  // throw.
566  TEST_THROW(ArrayRCP<A> a_arcp2 = arcp(a_ptr, 0, n), DuplicateOwningRCPError);
567 #else
568  // Will not determine they are point to the same object!
569  ECHO(ArrayRCP<A> a_arcp2 = arcp(a_ptr, 0, n));
570  TEST_EQUALITY(a_arcp2.getRawPtr(), a_ptr);
571  ECHO(a_arcp2.release()); // Better or we will get a segfault!
572 #endif
573 }
574 
575 
576 TEUCHOS_UNIT_TEST( ArrayRCP, dangling_nonowning )
577 {
579  ECHO(A *a_ptr = new A[n]);
580  ECHO(ArrayRCP<A> a_arcp1 = arcp(a_ptr, 0, n)); // Okay
581  ECHO(ArrayRCP<A> a_arcp2 = arcp(a_ptr, 0, n, false)); // Okay
582  a_arcp1 = null;
583 #if defined(TEUCHOS_DEBUG)
584  // With node tracing turned on, the implementation knows that the original
585  // array is deleted and this is a dangling reference!
586  TEST_THROW(a_arcp2.getRawPtr(), DanglingReferenceError);
587 #else
588  // With node tracing turned off, the implemetation does not know the
589  // original array is deleted and therefore it will return a now invalid
590  // pointer.
591  TEST_NOTHROW(a_arcp2.getRawPtr());
592 #endif
593 }
594 
595 
596 class WeirdDealloc {
597  int size_;
598  RCP<std::ostream > out_;
599 public:
600  WeirdDealloc(int size, const RCP<std::ostream> &out) : size_(size), out_(out) {}
601  void free(void *ptr) const
602  {
603  int * const int_ptr = reinterpret_cast<int*>(ptr);
604  {
605  // Create an ArrayView that points to the same memory that is being
606  // deallocated by the owning ArrayRCP. Here, if RCPNode tracing is
607  // enabled, this will thrown and there is really no way around it.
608  ArrayView<const int> tmpav(int_ptr, size_, Teuchos::RCP_DISABLE_NODE_LOOKUP);
609  assert(tmpav[0] == int_ptr[0]);
610  *out_ << tmpav << std::endl;
611  // Create a copy of the ArrayView and make sure that it does not do
612  // node tracing either.
613  ArrayView<const int> tmpav2(tmpav);
614  assert(tmpav2[0] == int_ptr[0]);
615  *out_ << tmpav2 << std::endl;
616  // Assign the ArrayView and make sure that it does not do node tracing
617  // either.
618  ArrayView<const int> tmpav3;
619  tmpav3 = tmpav;
620  assert(tmpav3[0] == int_ptr[0]);
621  *out_ << tmpav2 << std::endl;
622  }
623  delete [] int_ptr;
624  }
625 };
626 
627 
628 TEUCHOS_UNIT_TEST( ArrayRCP, weirdDealloc )
629 {
630  using Teuchos::rcpFromRef;
631  const int size = 4;
632  const bool ownsMem = true;
633  int *int_ptr = new int[size];
634  std::fill_n(int_ptr, size, 0);
635  ArrayRCP<int> a = arcp<int>( int_ptr , 0, size,
636  WeirdDealloc(size, rcpFromRef(out)), ownsMem );
637  a = Teuchos::null;
638 }
639 
640 
641 //
642 // Templated unit tests
643 //
644 
645 
646 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, construct_n, T )
647 {
648  std::vector<T> a(n, as<T>(1));
649  ArrayRCP<T> a_arcp(n, as<T>(1));
650  TEST_COMPARE_ARRAYS(a, a_arcp);
651 }
652 
653 
654 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, assignSelf, T )
655 {
656  ArrayRCP<T> a_arcp;
657  a_arcp = a_arcp;
658 }
659 
660 
661 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, assign_n_val, T )
662 {
663  const T val = as<T>(1);
664  std::vector<T> a;
665  a.assign(n, val);
666  ArrayRCP<T> a_arcp;
667  a_arcp.assign(as<Ordinal>(n), val);
668  TEST_COMPARE_ARRAYS(a, a_arcp);
669 }
670 
671 
672 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, assign_begin_end, T )
673 {
674  const T val = as<T>(1);
675  std::vector<T> a;
676  a.assign(n, val);
677  ArrayRCP<T> a_arcp;
678  a_arcp.assign(a.begin(), a.end());
679  TEST_COMPARE_ARRAYS(a, a_arcp);
680 }
681 
682 
683 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, print_iterators, T )
684 {
685  typedef typename ArrayRCP<T>::const_iterator const_iterator;
686  ECHO(ArrayRCP<T> a_arcp = arcp<T>(n));
687  ECHO(const_iterator itr = a_arcp.begin());
688  out << "itr = " << itr << "\n";
689  TEST_EQUALITY(itr, a_arcp.begin());
690  ECHO(itr += n);
691  out << "itr = " << itr << "\n";
692  TEST_EQUALITY(itr, a_arcp.end());
693 }
694 
695 
696 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, deepCopy, T )
697 {
698  const T val = as<T>(1);
699  std::vector<T> a;
700  a.assign(n, val);
701  ArrayRCP<T> a_arcp = arcp<T>(n);
702  ArrayRCP<T> a_arcp_cpy = a_arcp;
703  a_arcp.deepCopy(Teuchos::arrayViewFromVector(a));
704  TEST_COMPARE_ARRAYS(a, a_arcp);
705  TEST_EQUALITY(a_arcp.getRawPtr(), a_arcp_cpy.getRawPtr());
706 }
707 
708 
709 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, resize, T )
710 {
711  const T val1 = as<T>(1);
712  const T val2 = as<T>(2);
713 
714  std::vector<T> a;
715  ArrayRCP<T> a_arcp;
716 
717  out << "\nChecking resize(n, val1) ...\n";
718  a.resize(n, val1);
719  a_arcp.resize(n, val1);
720  TEST_COMPARE_ARRAYS(a, a_arcp);
721 
722  out << "\nChecking resize(2*n, val2) ...\n";
723  a.resize(2*n, val2);
724  a_arcp.resize(2*n, val2);
725  TEST_COMPARE_ARRAYS(a, a_arcp);
726 
727  out << "\nChecking resize(n/2) ...\n";
728  a.resize(n/2);
729  a_arcp.resize(n/2);
730  TEST_COMPARE_ARRAYS(a, a_arcp);
731 
732  out << "\nChecking resize(0) ...\n";
733  a.resize(0);
734  a_arcp.resize(0);
735  TEST_COMPARE_ARRAYS(a, a_arcp);
736 
737 #ifdef TEUCHOS_DEBUG
738  a_arcp = arcp<T>(n);
739  ++a_arcp;
740  TEST_THROW(a_arcp.resize(1), std::out_of_range);
741 #endif
742 }
743 
744 
745 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, clear, T )
746 {
747  ArrayRCP<T> a_arcp = arcp<T>(n);
748  TEST_EQUALITY( a_arcp.size(), n );
749  a_arcp.clear();
750  TEST_EQUALITY( a_arcp.size(), 0 );
751 }
752 
753 
754 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, nullIterator, T )
755 {
756  typedef ArrayRCP<T> iter_t;
757  ArrayRCP<T> arcp1 = Teuchos::NullIteratorTraits<iter_t>::getNull();
759 }
760 
761 
762 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, implicitConversions, T )
763 {
764 
765  ECHO(ArrayRCP<T> arcp1 = arcp<T>(n));
766  ECHO(ArrayRCP<const T> arcp2 = arcp1);
767  TEST_ASSERT(arcp1.shares_resource(arcp2));
768 
769 }
770 
771 
772 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, weakDelete, T )
773 {
774 
775  ECHO(ArrayRCP<T> arcp_strong = arcp<T>(n));
776 
777  TEST_EQUALITY_CONST( arcp_strong.strength(), RCP_STRONG );
778  TEST_EQUALITY_CONST( arcp_strong.is_null(), false );
779  TEST_EQUALITY_CONST( arcp_strong.strong_count(), 1 );
780  TEST_EQUALITY_CONST( arcp_strong.weak_count(), 0 );
781  TEST_EQUALITY_CONST( arcp_strong.total_count(), 1 );
782 
783  ECHO(ArrayRCP<T> arcp_weak1 = arcp_strong.create_weak());
784 
785  TEST_EQUALITY_CONST( arcp_weak1.strength(), RCP_WEAK );
786  TEST_EQUALITY_CONST( arcp_weak1.is_null(), false );
787  TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 1 );
788  TEST_EQUALITY_CONST( arcp_weak1.weak_count(), 1 );
789  TEST_EQUALITY_CONST( arcp_weak1.total_count(), 2 );
790 
791  TEST_EQUALITY_CONST( arcp_strong.strong_count(), 1 );
792  TEST_EQUALITY_CONST( arcp_strong.is_null(), false );
793  TEST_EQUALITY_CONST( arcp_strong.weak_count(), 1 );
794  TEST_EQUALITY_CONST( arcp_strong.total_count(), 2 );
795 
796  TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_strong), true );
797 
798  TEST_EQUALITY( arcp_weak1.get(), arcp_weak1.getRawPtr() );
799  TEST_EQUALITY( arcp_weak1.get(), arcp_strong.get() );
800  TEST_EQUALITY( arcp_weak1.getRawPtr(), arcp_strong.getRawPtr() );
801 
802  ECHO(ArrayRCP<T> arcp_weak2 = arcp_weak1);
803 
804  TEST_EQUALITY_CONST( arcp_weak2.strength(), RCP_WEAK );
805  TEST_EQUALITY_CONST( arcp_weak2.is_null(), false );
806  TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 1 );
807  TEST_EQUALITY_CONST( arcp_weak2.weak_count(), 2 );
808  TEST_EQUALITY_CONST( arcp_weak2.total_count(), 3 );
809 
810  TEST_EQUALITY_CONST( arcp_strong.strong_count(), 1 );
811  TEST_EQUALITY_CONST( arcp_strong.is_null(), false );
812  TEST_EQUALITY_CONST( arcp_strong.weak_count(), 2 );
813  TEST_EQUALITY_CONST( arcp_strong.total_count(), 3 );
814 
815  TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_strong), true );
816  TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_weak2), true );
817  TEST_EQUALITY_CONST( arcp_weak2.shares_resource(arcp_strong), true );
818 
819  TEST_EQUALITY( arcp_weak2.get(), arcp_strong.get() );
820  TEST_EQUALITY( arcp_weak2.getRawPtr(), arcp_strong.getRawPtr() );
821 
822  ECHO(arcp_strong = null); // This deletes the underlying object of type T!
823 
824  TEST_EQUALITY_CONST( arcp_strong.strength(), RCP_STRONG );
825  TEST_EQUALITY_CONST( arcp_strong.is_null(), true );
826  TEST_EQUALITY_CONST( arcp_strong.strong_count(), 0 );
827  TEST_EQUALITY_CONST( arcp_strong.strong_count(), 0 );
828  TEST_EQUALITY_CONST( arcp_strong.weak_count(), 0 );
829  TEST_EQUALITY_CONST( arcp_strong.total_count(), 0 );
830  TEST_EQUALITY_CONST( arcp_strong.is_valid_ptr(), true );
831 
832  TEST_EQUALITY_CONST( arcp_strong.shares_resource(arcp_weak1), false );
833  TEST_EQUALITY_CONST( arcp_strong.shares_resource(arcp_weak2), false );
834 
835  TEST_EQUALITY_CONST( arcp_weak1.has_ownership(), true );
836  TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 0 );
837  TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 0 );
838  TEST_EQUALITY_CONST( arcp_weak1.weak_count(), 2 );
839  TEST_EQUALITY_CONST( arcp_weak1.total_count(), 2 );
840  TEST_EQUALITY_CONST( arcp_weak1.is_valid_ptr(), false );
841 
842  TEST_EQUALITY_CONST( arcp_weak2.has_ownership(), true );
843  TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 0 );
844  TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 0 );
845  TEST_EQUALITY_CONST( arcp_weak2.weak_count(), 2 );
846  TEST_EQUALITY_CONST( arcp_weak2.total_count(), 2 );
847  TEST_EQUALITY_CONST( arcp_weak2.is_valid_ptr(), false );
848 
849  TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_weak2), true );
850 
851  ECHO(arcp_weak1.assert_not_null()); // Does not throw!
852  ECHO(arcp_weak2.assert_not_null()); // Does not throw!
853 
854  TEST_THROW( arcp_weak1.assert_valid_ptr(), DanglingReferenceError );
855 #ifdef TEUCHOS_DEBUG
856  TEST_THROW( arcp_weak1.operator->(), DanglingReferenceError );
857  TEST_THROW( *arcp_weak1, DanglingReferenceError );
858  TEST_THROW( arcp_weak1.create_weak(), DanglingReferenceError );
859  TEST_THROW( arcp_weak1.get(), DanglingReferenceError );
860  TEST_THROW( arcp_weak1.getRawPtr(), DanglingReferenceError );
861  TEST_THROW( arcp_weak1[0], DanglingReferenceError );
862  TEST_THROW( ++arcp_weak1, DanglingReferenceError );
863  TEST_THROW( arcp_weak1++, DanglingReferenceError );
864  TEST_THROW( --arcp_weak1, DanglingReferenceError );
865  TEST_THROW( arcp_weak1--, DanglingReferenceError );
866  TEST_THROW( arcp_weak1+=1, DanglingReferenceError );
867  TEST_THROW( arcp_weak1-=1, DanglingReferenceError );
868  TEST_THROW( arcp_weak1+1, DanglingReferenceError );
869  TEST_THROW( arcp_weak1-1, DanglingReferenceError );
870  TEST_THROW( arcp_weak1.getConst(), DanglingReferenceError );
871  TEST_THROW( arcp_weak1.persistingView(0,n), DanglingReferenceError );
872  TEST_THROW( arcp_weak1.lowerOffset(), DanglingReferenceError );
873  TEST_THROW( arcp_weak1.upperOffset(), DanglingReferenceError );
874  TEST_THROW( arcp_weak1.size(), DanglingReferenceError );
875  TEST_THROW( arcp_weak1.begin(), DanglingReferenceError );
876  TEST_THROW( arcp_weak1.end(), DanglingReferenceError );
877  TEST_THROW( arcp_weak1.view(0,n), DanglingReferenceError );
878  TEST_THROW( arcp_weak1(0,n), DanglingReferenceError );
879  TEST_THROW( arcp_weak1(), DanglingReferenceError );
880  TEST_THROW( {ArrayView<T> av = arcp_weak1();}, DanglingReferenceError );
881  TEST_THROW( {ArrayRCP<const T> ap = getConst(arcp_weak1);},
882  DanglingReferenceError );
883  TEST_THROW( arcp_weak1.release(), DanglingReferenceError );
884 #endif // TEUCHOS_DEBUG
885 
886  ECHO(arcp_weak1 = null); // Just deicrements weak count!
887 
888  TEST_EQUALITY_CONST( arcp_weak1.strength(), RCP_STRONG );
889  TEST_EQUALITY_CONST( arcp_weak1.is_null(), true );
890  TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 0 );
891  TEST_EQUALITY_CONST( arcp_weak1.strong_count(), 0 );
892  TEST_EQUALITY_CONST( arcp_weak1.weak_count(), 0 );
893  TEST_EQUALITY_CONST( arcp_weak1.total_count(), 0 );
894  TEST_EQUALITY_CONST( arcp_weak1.is_valid_ptr(), true );
895 
896  TEST_EQUALITY_CONST( arcp_weak2.has_ownership(), true );
897  TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 0 );
898  TEST_EQUALITY_CONST( arcp_weak2.strong_count(), 0 );
899  TEST_EQUALITY_CONST( arcp_weak2.weak_count(), 1 );
900  TEST_EQUALITY_CONST( arcp_weak2.total_count(), 1 );
901  TEST_EQUALITY_CONST( arcp_weak2.is_valid_ptr(), false );
902 
903  TEST_EQUALITY_CONST( arcp_weak1.shares_resource(arcp_weak2), false );
904 
905  TEST_THROW( arcp_weak2.assert_valid_ptr(), DanglingReferenceError );
906 #ifdef TEUCHOS_DEBUG
907  // ToDo: Fill in
908 #endif // TEUCHOS_DEBUG
909 
910 }
911 
912 
913 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, danglingArrayView, T )
914 {
915  ArrayView<T> av;
916  {
917  ArrayRCP<T> arcp1 = arcp<T>(n);
918  av = arcp1();
919  }
920 #ifdef TEUCHOS_DEBUG
921  TEST_THROW( av.size(), DanglingReferenceError );
922  TEST_THROW( av.toString(), DanglingReferenceError );
923  TEST_THROW( av.getRawPtr(), DanglingReferenceError );
924  TEST_THROW( av[0], DanglingReferenceError );
925  TEST_THROW( av.front(), DanglingReferenceError );
926  TEST_THROW( av.back(), DanglingReferenceError );
927  TEST_THROW( av.view(0, n), DanglingReferenceError );
928  TEST_THROW( av(0, n), DanglingReferenceError );
929  TEST_THROW( av(), DanglingReferenceError );
930  TEST_THROW( av.getConst(), DanglingReferenceError );
931  TEST_THROW( av.begin(), DanglingReferenceError );
932  TEST_THROW( av.end(), DanglingReferenceError );
933 #endif
934 }
935 
936 
938 {
939  ArrayRCP<const T> cptr;
940  ArrayRCP<T> ptr;
941  TEST_EQUALITY_CONST( getRawPtr(cptr), (const T*)NULL );
942  TEST_EQUALITY_CONST( getRawPtr(ptr), (T*)NULL );
943  cptr = arcp<T>(n);
944  ptr = arcp<T>(n);
945  TEST_EQUALITY( getRawPtr(cptr), &cptr[0]);
946  TEST_EQUALITY( getRawPtr(ptr), &ptr[0] );
947 }
948 
949 
951 {
952  const T *cptr = NULL;
953  T *ptr = NULL;
954  TEST_EQUALITY_CONST( getRawPtr(cptr), (const T*)NULL );
955  TEST_EQUALITY_CONST( getRawPtr(ptr), (T*)NULL );
956  cptr = new T[n];
957  ptr = new T[n];
958  TEST_EQUALITY( getRawPtr(cptr), &cptr[0]);
959  TEST_EQUALITY( getRawPtr(ptr), &ptr[0] );
960  delete [] cptr;
961  delete [] ptr;
962 }
963 
964 
965 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, arcp_zero, T )
966 {
967  ArrayRCP<T> arcp_strong = arcp<T>(0);
968  TEST_EQUALITY(arcp_strong.size(), as<Ordinal>(0));
969 }
970 
971 
973 {
974  Array<T> a = generateArray<T>(n);
975  ArrayView<T> av = a;
976  ArrayRCP<T> arcp1 = Teuchos::arcpFromArrayView(av);
977  TEST_COMPARE_ARRAYS(arcp1, av);
978 }
979 
980 
981 #ifdef TEUCHOS_DEBUG
982 
983 
984 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, arcp_neg, T )
985 {
986  TEST_THROW(ArrayRCP<T> arcp_strong = arcp<T>(-1),
987  std::out_of_range);
988 }
989 
990 
991 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( ArrayRCP, outOfBounds, T )
992 {
993  ECHO(ArrayRCP<T> arcp1 = arcp<T>(n));
994  TEST_THROW(arcp1(-1,n), RangeError);
995  TEST_THROW(arcp1(0,n+1), RangeError);
996  TEST_THROW(arcp1(0,-1), RangeError);
997  TEST_THROW(arcp1.view(-1,n), RangeError);
998  TEST_THROW(arcp1.view(0,n+1), RangeError);
999  TEST_THROW(arcp1.view(0,-1), RangeError);
1000  TEST_THROW(arcp1.persistingView(-1,n), RangeError);
1001  TEST_THROW(arcp1.persistingView(0,n+1), RangeError);
1002  TEST_THROW(arcp1.persistingView(0,-1), RangeError);
1003 }
1004 
1005 
1006 #endif // TEUCHOS_DEBUG
1007 
1008 
1009 //
1010 // Template Instantiations
1011 //
1012 
1013 
1014 #ifdef TEUCHOS_DEBUG
1015 
1016 # define DEBUG_UNIT_TEST_GROUP( T ) \
1017  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, arcp_neg, T ) \
1018  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, outOfBounds, T ) \
1019 
1020 #else
1021 
1022 # define DEBUG_UNIT_TEST_GROUP( T )
1023 
1024 #endif
1025 
1026 
1027 #define UNIT_TEST_GROUP( T ) \
1028  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, construct_n, T ) \
1029  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, assignSelf, T ) \
1030  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, assign_n_val, T ) \
1031  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, assign_begin_end, T ) \
1032  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, print_iterators, T ) \
1033  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, deepCopy, T ) \
1034  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, resize, T ) \
1035  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, clear, T ) \
1036  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, nullIterator, T ) \
1037  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, implicitConversions, T ) \
1038  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, weakDelete, T ) \
1039  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, danglingArrayView, T ) \
1040  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, getRawPtr, T) \
1041  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( CPtr, getRawPtr, T) \
1042  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, arcp_zero, T ) \
1043  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( ArrayRCP, arcpFromArrayView, T ) \
1044  DEBUG_UNIT_TEST_GROUP(T)
1045 
1046 
1047 UNIT_TEST_GROUP(int)
1048 UNIT_TEST_GROUP(double)
1049 UNIT_TEST_GROUP(float)
1050 
1051 
1052 } // 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.
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...