25 return (T*)(0x777777);
45 RCPNode *rcpNode = basicRCPNodeNoAlloc<T>(p, has_ownership);
54 (*node)->delete_obj();
111 #endif // TEUCHOS_DEBUG
121 typedef RCPNodeTracer::RCPNodeStatistics RCPNodeStatistics;
125 RCPNode *node = basicRCPNode<A>(
true);
139 rcpNodeStatisticsBefore.maxNumRCPNodes);
141 rcpNodeStatisticsBefore.totalNumRCPNodeAllocations+1);
143 rcpNodeStatisticsBefore.totalNumRCPNodeDeletions);
154 rcpNodeStatisticsBefore.maxNumRCPNodes);
156 rcpNodeStatisticsBefore.totalNumRCPNodeAllocations+1);
158 rcpNodeStatisticsBefore.totalNumRCPNodeDeletions+1);
161 std::ostringstream statsOut_oss;
163 std::ostringstream expectedStatsOut_oss;
166 <<
"\n*** RCPNode Tracing statistics:"
168 <<
"\n maxNumRCPNodes = "<<rcpNodeStatistics2.maxNumRCPNodes
169 <<
"\n totalNumRCPNodeAllocations = "<<rcpNodeStatistics2.totalNumRCPNodeAllocations
170 <<
"\n totalNumRCPNodeDeletions = "<<rcpNodeStatistics2.totalNumRCPNodeDeletions
172 TEST_EQUALITY(statsOut_oss.str(), expectedStatsOut_oss.str());
182 #ifdef HAVE_TEUCHOS_STACKTRACE
184 Teuchos::store_stacktrace();
187 RCPNode *node1 = basicRCPNodeNoAlloc<A>(a_ptr,
true);
191 RCPNode *node2 = basicRCPNodeNoAlloc<A>(a_ptr,
true);
196 node2->has_ownership(
false);
205 RCPNode *node1 = basicRCPNodeNoAlloc<A>(a_ptr,
true);
209 RCPNode *node2 = basicRCPNodeNoAlloc<A>(a_ptr,
false);
226 RCPNode *node1 = basicRCPNodeNoAlloc<A>(a_ptr,
false);
230 RCPNode *node2 = basicRCPNodeNoAlloc<A>(a_ptr,
true);
247 ECHO(RCPNode *node_c = basicRCPNodeNoAlloc<C>(c_ptr,
true));
248 ECHO(RCPNode *node_b1 = basicRCPNodeNoAlloc<B1>(c_ptr,
true));
252 #ifdef HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR
264 ECHO(node_b1->has_ownership(
false));
270 #ifdef HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING
274 RCPNode *node = basicRCPNode<A>(
true);
278 #endif // HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING
281 #endif // TEUCHOS_DEBUG
299 TEST_EQUALITY( nodeRef.get_base_obj_map_key_void_ptr(),
static_cast<void*
>(p) );
301 std::invalid_argument);
303 std::invalid_argument);
304 #endif // TEUCHOS_DEBUG
344 ECHO(nodeRef2.debug_assert_valid_ptr(mockRCP));
359 TEST_THROW( nodeRef2.debug_assert_valid_ptr(mockRCP),
383 ECHO(nodeRef2.debug_assert_valid_ptr(mockRCP));
395 nodeRef1.debug_assert_valid_ptr(mockRCP);
406 #if defined(TEUCHOS_DEBUG) && !defined(HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING)
407 # define DO_RCPNODE_TRACING_TESTS 1
411 #ifdef DO_RCPNODE_TRACING_TESTS
418 RCPNodeTracer::setTracingActiveRCPNodes(
true);
424 const std::string T_name =
"T_name";
425 const std::string concreateT_name =
"concreateT_name";
426 const bool has_ownership =
true;
427 RCPNode *node =
new RCPNodeTmpl<T,DeallocDelete<T> >(
428 p, DeallocDelete<T>(), has_ownership);
430 RCPNodeHandle nodeRef(node, p, T_name, concreateT_name, has_ownership);
434 out <<
"\nMake sure output is printed when there is an active node with tracing ...\n";
438 std::ostringstream expendedOutput_oss;
442 <<
" 0: RCPNode (map_key_void_ptr=" << rcpNodeKey <<
")\n"
443 <<
" Information = {T="<<T_name<<
", ConcreteT="<<concreateT_name<<
", p="<<p<<
", has_ownership="<<has_ownership<<
"}\n"
444 <<
" RCPNode address = " << node <<
"\n"
445 <<
" insertionNumber = " << node->insertion_number()
449 std::ostringstream printActiveRCPNodes_out;
451 TEST_EQUALITY( printActiveRCPNodes_out.str(), expendedOutput_oss.str() );
467 out <<
"\nMake sure no output is printed when there are no active nodes ...\n";
468 const std::string expendedOutput =
"";
469 std::ostringstream printActiveRCPNodes_out;
471 TEST_EQUALITY( printActiveRCPNodes_out.str(), expendedOutput );
473 RCPNodeTracer::setTracingActiveRCPNodes(
false);
483 RCPNodeTracer::setTracingActiveRCPNodes(
false);
487 const std::string T_name =
"T_name";
488 const std::string concreateT_name =
"concreateT_name";
489 const bool has_ownership =
true;
490 RCPNode *node =
new RCPNodeTmpl<T,DeallocDelete<T> >(
491 p, DeallocDelete<T>(), has_ownership);
493 RCPNodeHandle nodeRef(node, p, T_name, concreateT_name, has_ownership);
497 out <<
"\nMake sure no output is printed when there are no active nodes without tracing ...\n";
498 const std::string expendedOutput =
"";
499 std::ostringstream printActiveRCPNodes_out;
501 TEST_EQUALITY( printActiveRCPNodes_out.str(), expendedOutput );
506 #endif // DO_RCPNODE_TRACING_TESTS
552 nodeRef2 = std::move(nodeRef1);
588 any &a4 = nodeRef2.get_extra_data(a1.
typeName(),
"a1");
631 std::invalid_argument);
634 std::invalid_argument);
636 #endif // TEUCHOS_DEBUG
661 std::invalid_argument);
664 std::invalid_argument);
666 #endif // TEUCHOS_DEBUG
682 #ifdef DO_RCPNODE_TRACING_TESTS
684 # define DEBUG_UNIT_TEST_GROUP( T ) \
685 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, debugWithNodeTracingPrint, T ) \
686 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, debugWithoutNodeTracingPrint, T )
690 # define DEBUG_UNIT_TEST_GROUP( T )
695 #define UNIT_TEST_GROUP( T ) \
696 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, basicConstruct_owns_mem, T ) \
697 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, basicConstruct_no_owns_mem, T ) \
698 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, weakPtr_basic_1, T ) \
699 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, weakPtr_basic_2, T ) \
700 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, copyConstruct, T ) \
701 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, moveConstruct, T ) \
702 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, copyAssignmentOperator, T ) \
703 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, moveAssignmentOperator, T ) \
704 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, extraData_basic, T ) \
705 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, extraData_basic_const, T ) \
706 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, extraData_failed, T ) \
707 TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCPNodeHandle, extraData_failed_const, T ) \
708 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.
int strong_count() const
The strong count for this RCPNode, or 0 if the node is NULL.
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.
bool same_node(const RCPNodeHandle &node2) const
Whether the RCPNode for which node2 is a handle is the same RCPNode as this object's RCPNode...
#define TEUCHOS_ASSERT(assertion_test)
This macro is throws when an assert fails.
RCPNode * node_ptr() const
Return a pointer to the underlying RCPNode.
RCPNodeHandle create_weak() const
Return a weak handle.
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.