59 return (T*)(0x777777);
79 RCPNode *rcpNode = basicRCPNodeNoAlloc<T>(p, has_ownership);
88 (*node)->delete_obj();
145 #endif // TEUCHOS_DEBUG
155 typedef RCPNodeTracer::RCPNodeStatistics RCPNodeStatistics;
159 RCPNode *node = basicRCPNode<A>(
true);
173 rcpNodeStatisticsBefore.maxNumRCPNodes);
175 rcpNodeStatisticsBefore.totalNumRCPNodeAllocations+1);
177 rcpNodeStatisticsBefore.totalNumRCPNodeDeletions);
188 rcpNodeStatisticsBefore.maxNumRCPNodes);
190 rcpNodeStatisticsBefore.totalNumRCPNodeAllocations+1);
192 rcpNodeStatisticsBefore.totalNumRCPNodeDeletions+1);
195 std::ostringstream statsOut_oss;
197 std::ostringstream expectedStatsOut_oss;
200 <<
"\n*** RCPNode Tracing statistics:"
202 <<
"\n maxNumRCPNodes = "<<rcpNodeStatistics2.maxNumRCPNodes
203 <<
"\n totalNumRCPNodeAllocations = "<<rcpNodeStatistics2.totalNumRCPNodeAllocations
204 <<
"\n totalNumRCPNodeDeletions = "<<rcpNodeStatistics2.totalNumRCPNodeDeletions
206 TEST_EQUALITY(statsOut_oss.str(), expectedStatsOut_oss.str());
216 #ifdef HAVE_TEUCHOS_STACKTRACE
218 Teuchos::store_stacktrace();
221 RCPNode *node1 = basicRCPNodeNoAlloc<A>(a_ptr,
true);
225 RCPNode *node2 = basicRCPNodeNoAlloc<A>(a_ptr,
true);
230 node2->has_ownership(
false);
239 RCPNode *node1 = basicRCPNodeNoAlloc<A>(a_ptr,
true);
243 RCPNode *node2 = basicRCPNodeNoAlloc<A>(a_ptr,
false);
260 RCPNode *node1 = basicRCPNodeNoAlloc<A>(a_ptr,
false);
264 RCPNode *node2 = basicRCPNodeNoAlloc<A>(a_ptr,
true);
281 ECHO(RCPNode *node_c = basicRCPNodeNoAlloc<C>(c_ptr,
true));
282 ECHO(RCPNode *node_b1 = basicRCPNodeNoAlloc<B1>(c_ptr,
true));
286 #ifdef HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR
298 ECHO(node_b1->has_ownership(
false));
304 #ifdef HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING
308 RCPNode *node = basicRCPNode<A>(
true);
312 #endif // HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING
315 #endif // TEUCHOS_DEBUG
333 TEST_EQUALITY( nodeRef.get_base_obj_map_key_void_ptr(),
static_cast<void*
>(p) );
335 std::invalid_argument);
337 std::invalid_argument);
338 #endif // TEUCHOS_DEBUG
378 ECHO(nodeRef2.debug_assert_valid_ptr(mockRCP));
393 TEST_THROW( nodeRef2.debug_assert_valid_ptr(mockRCP),
417 ECHO(nodeRef2.debug_assert_valid_ptr(mockRCP));
429 nodeRef1.debug_assert_valid_ptr(mockRCP);
440 #if defined(TEUCHOS_DEBUG) && !defined(HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING)
441 # define DO_RCPNODE_TRACING_TESTS 1
445 #ifdef DO_RCPNODE_TRACING_TESTS
452 RCPNodeTracer::setTracingActiveRCPNodes(
true);
458 const std::string T_name =
"T_name";
459 const std::string concreateT_name =
"concreateT_name";
460 const bool has_ownership =
true;
461 RCPNode *node =
new RCPNodeTmpl<T,DeallocDelete<T> >(
462 p, DeallocDelete<T>(), has_ownership);
464 RCPNodeHandle nodeRef(node, p, T_name, concreateT_name, has_ownership);
468 out <<
"\nMake sure output is printed when there is an active node with tracing ...\n";
472 std::ostringstream expendedOutput_oss;
476 <<
" 0: RCPNode (map_key_void_ptr=" << rcpNodeKey <<
")\n"
477 <<
" Information = {T="<<T_name<<
", ConcreteT="<<concreateT_name<<
", p="<<p<<
", has_ownership="<<has_ownership<<
"}\n"
478 <<
" RCPNode address = " << node <<
"\n"
479 <<
" insertionNumber = " << node->insertion_number()
483 std::ostringstream printActiveRCPNodes_out;
485 TEST_EQUALITY( printActiveRCPNodes_out.str(), expendedOutput_oss.str() );
501 out <<
"\nMake sure no output is printed when there are no active nodes ...\n";
502 const std::string expendedOutput =
"";
503 std::ostringstream printActiveRCPNodes_out;
505 TEST_EQUALITY( printActiveRCPNodes_out.str(), expendedOutput );
507 RCPNodeTracer::setTracingActiveRCPNodes(
false);
517 RCPNodeTracer::setTracingActiveRCPNodes(
false);
521 const std::string T_name =
"T_name";
522 const std::string concreateT_name =
"concreateT_name";
523 const bool has_ownership =
true;
524 RCPNode *node =
new RCPNodeTmpl<T,DeallocDelete<T> >(
525 p, DeallocDelete<T>(), has_ownership);
527 RCPNodeHandle nodeRef(node, p, T_name, concreateT_name, has_ownership);
531 out <<
"\nMake sure no output is printed when there are no active nodes without tracing ...\n";
532 const std::string expendedOutput =
"";
533 std::ostringstream printActiveRCPNodes_out;
535 TEST_EQUALITY( printActiveRCPNodes_out.str(), expendedOutput );
540 #endif // DO_RCPNODE_TRACING_TESTS
591 any &a4 = nodeRef2.get_extra_data(a1.
typeName(),
"a1");
634 std::invalid_argument);
637 std::invalid_argument);
639 #endif // TEUCHOS_DEBUG
664 std::invalid_argument);
667 std::invalid_argument);
669 #endif // TEUCHOS_DEBUG
685 #ifdef DO_RCPNODE_TRACING_TESTS
687 # define DEBUG_UNIT_TEST_GROUP( T ) \
688 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, debugWithNodeTracingPrint, T ) \
689 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, debugWithoutNodeTracingPrint, T )
693 # define DEBUG_UNIT_TEST_GROUP( T )
698 #define UNIT_TEST_GROUP( T ) \
699 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, basicConstruct_owns_mem, T ) \
700 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, basicConstruct_no_owns_mem, T ) \
701 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, weakPtr_basic_1, T ) \
702 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, weakPtr_basic_2, T ) \
703 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, copyConstruct, T ) \
704 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, assignmentOperator, T ) \
705 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, extraData_basic, T ) \
706 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, extraData_basic_const, T ) \
707 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, extraData_failed, T ) \
708 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, extraData_failed_const, T ) \
709 DEBUG_UNIT_TEST_GROUP(T)
Dangling reference error exception class.
Null reference error exception class.
std::string typeName(const T &t)
Template function for returning the concrete type name of a passed-in object.
#define TEST_INEQUALITY_CONST(v1, v2)
Assert the inequality of v1 and constant v2.
static void printRCPNodeStatistics(const RCPNodeStatistics &rcpNodeStatistics, std::ostream &out)
Print the RCPNode allocation statistics.
static const void * getRCPNodeBaseObjMapKeyVoidPtr(T *p)
Get a const void* address to be used as the lookup key for an RCPNode given its embedded object's typ...
#define ECHO(statement)
Echo the given statement before it is executed.
static bool isTracingActiveRCPNodes()
Return if we are tracing active nodes or not.
bool same(const any &other) const
Return if two any objects are the same or not.
any & get_extra_data(const std::string &type_name, const std::string &name)
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEST_THROW(code, ExceptType)
Assert that the statement 'code' throws the exception 'ExceptType' (otherwise the test fails)...
any * get_optional_extra_data(const std::string &type_name, const std::string &name)
static RCPNodeStatistics getRCPNodeStatistics()
Return the statistics on RCPNode allocations.
#define TEST_COMPARE(v1, comp, v2)
Assert that v1 comp v2 (where comp = '==', '>=", "!=", etc).
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
#define UNIT_TEST_GROUP(T)
Modified boost::any class, which is a container for a templated value.
static std::string getCommonDebugNotesString()
Common error message string on how to debug RCPNode problems.
RCPNodeHandle basicRCPNodeHandle(const bool has_ownership, T **p_out=0)
Policy class for deallocator that uses delete to delete a pointer which is used by RCP...
TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(RCPNodeHandle, basicConstruct_owns_mem, T)
Node class to keep track of address and the reference count for a reference-counted utility class and...
TEUCHOS_UNIT_TEST(ConstNonconstObjectContainer, create)
#define SET_RCPNODE_TRACING()
Templated implementation class of RCPNode that has the responsibility for deleting the reference-coun...
std::string concreteTypeName(const T &t)
Template function for returning the type name of the actual concrete name of a passed-in object...
void deleteRCPNode(RCPNode **node)
RCPNode * basicRCPNodeNoAlloc(T *p, const bool has_ownership)
RCPNodeHandle create_strong() const
Return a strong handle.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
void set_extra_data(const any &extra_data, const std::string &name, EPrePostDestruction destroy_when, bool force_unique)
static RCPNode * getExistingRCPNode(T *p)
Return a raw pointer to an existing owning RCPNode given the address to the underlying object if it e...
RCPNode * basicRCPNode(const bool has_ownership, T **p_out=0)
T * access_private_ptr() const
Handle class that manages the RCPNode's reference counting.
void has_ownership(bool has_ownership_in)
static void removeRCPNode(RCPNode *rcp_node)
Remove an RCPNode from global list.
std::string typeName() const
Return the name of the type.
#define TEUCHOS_ASSERT(assertion_test)
This macro is throws when an assert fails.
RCPNodeHandle create_weak() const
Return a weak handle.
int count() const
The strong count; retained for backwards compatibility.
Reference-counted pointer node classes.
static std::string getActiveRCPNodeHeaderString()
Header string used in printActiveRCPNodes().
Defines basic traits returning the name of a type in a portable and readable way. ...
static int numActiveRCPNodes()
Print the number of active RCPNode objects currently being tracked.
static void addNewRCPNode(RCPNode *rcp_node, const std::string &info)
Add new RCPNode to the global list.
static void printActiveRCPNodes(std::ostream &out)
Print the list of currently active RCP nodes.