more tests, fix bugs uncovered by tests
This commit is contained in:
@@ -52,6 +52,7 @@ public:
|
||||
private:
|
||||
void DestroyNotify (void);
|
||||
Ptr<NoCount> CallTest (Ptr<NoCount> p);
|
||||
Ptr<NoCount> const CallTestConst (Ptr<NoCount> const p);
|
||||
uint32_t m_nDestroyed;
|
||||
};
|
||||
|
||||
@@ -73,6 +74,12 @@ PtrTest::CallTest (Ptr<NoCount> p)
|
||||
return p;
|
||||
}
|
||||
|
||||
Ptr<NoCount> const
|
||||
PtrTest::CallTestConst (Ptr<NoCount> const p)
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
bool
|
||||
PtrTest::RunTests (void)
|
||||
{
|
||||
@@ -92,6 +99,7 @@ PtrTest::RunTests (void)
|
||||
{
|
||||
Ptr<NoCount> p;
|
||||
p = new NoCount (cb);
|
||||
p = p;
|
||||
}
|
||||
if (m_nDestroyed != 1)
|
||||
{
|
||||
@@ -194,6 +202,48 @@ PtrTest::RunTests (void)
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
|
||||
{
|
||||
Ptr<NoCount> p1;
|
||||
Ptr<NoCount> const p2 = CallTest (p1);
|
||||
Ptr<NoCount> const p3 = CallTestConst (p1);
|
||||
Ptr<NoCount> p4 = CallTestConst (p1);
|
||||
Ptr<NoCount const> p5 = p4;
|
||||
//p4 = p5; You cannot make a const pointer be a non-const pointer.
|
||||
// but if you use const_pointer_cast, you can.
|
||||
p4 = const_pointer_cast<NoCount> (p5);
|
||||
p5 = p1;
|
||||
Ptr<NoCount> p;
|
||||
if (p == 0)
|
||||
{}
|
||||
if (p != 0)
|
||||
{}
|
||||
if (0 == p)
|
||||
{}
|
||||
if (0 != p)
|
||||
{}
|
||||
if (p)
|
||||
{}
|
||||
if (!p)
|
||||
{}
|
||||
}
|
||||
|
||||
m_nDestroyed = 0;
|
||||
{
|
||||
NoCount *raw;
|
||||
{
|
||||
Ptr<NoCount> p = new NoCount (cb);
|
||||
{
|
||||
Ptr<NoCount const> p1 = p;
|
||||
}
|
||||
raw = p.Remove ();
|
||||
}
|
||||
if (m_nDestroyed != 0)
|
||||
{
|
||||
ok = false;
|
||||
}
|
||||
delete raw;
|
||||
}
|
||||
|
||||
|
||||
return ok;
|
||||
|
||||
@@ -53,6 +53,7 @@ private:
|
||||
};
|
||||
static uint32_t *AllocCount (void);
|
||||
static void DeallocCount (uint32_t *count);
|
||||
friend class Ptr<const T>;
|
||||
public:
|
||||
/**
|
||||
* Create an empty smart pointer
|
||||
@@ -93,6 +94,10 @@ public:
|
||||
template <typename T1, typename T2>
|
||||
inline friend bool operator != (T1 const *lhs, Ptr<T2> &rhs);
|
||||
|
||||
template <typename T1, typename T2>
|
||||
inline friend Ptr<T1> const_pointer_cast (Ptr<T2> const&p);
|
||||
|
||||
|
||||
/**
|
||||
* \returns raw pointer
|
||||
*
|
||||
@@ -233,7 +238,7 @@ template <typename T>
|
||||
T *
|
||||
Ptr<T>::Remove (void)
|
||||
{
|
||||
assert (m_ptr.m_count == 1);
|
||||
assert ((*m_count) == 1);
|
||||
T *retval = m_ptr;
|
||||
m_ptr = 0;
|
||||
return retval;
|
||||
@@ -265,6 +270,14 @@ operator != (T1 const *lhs, Ptr<T2> &rhs)
|
||||
return lhs != rhs.m_ptr;
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
Ptr<T1>
|
||||
const_pointer_cast (Ptr<T2> const&p)
|
||||
{
|
||||
return Ptr<T1> (const_cast<T1 *> (p.m_ptr));
|
||||
}
|
||||
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
#endif /* PTR_H */
|
||||
|
||||
Reference in New Issue
Block a user