add NS3_ASSERT and NS3_ASSERT_MSG
This commit is contained in:
@@ -15,4 +15,11 @@ int main (int argc, int argv)
|
||||
foo::OneFunction ();
|
||||
|
||||
NS3_DEBUG ("other debug output");
|
||||
|
||||
int a = 0;
|
||||
|
||||
NS3_ASSERT (a == 0);
|
||||
NS3_ASSERT_MSG (a == 0, "my msg");
|
||||
NS3_ASSERT (a != 0)
|
||||
NS3_ASSERT_MSG (a != 0, "my 2 msg");
|
||||
}
|
||||
|
||||
@@ -168,6 +168,12 @@ DebugComponentPrintList (void)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AssertBreakpoint (void)
|
||||
{
|
||||
int *a = 0;
|
||||
a = 0;
|
||||
}
|
||||
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
@@ -40,6 +40,8 @@ private:
|
||||
bool m_isEnabled;
|
||||
};
|
||||
|
||||
void AssertBreakpoint (void);
|
||||
|
||||
}; // namespace ns3
|
||||
|
||||
|
||||
@@ -53,10 +55,29 @@ private:
|
||||
{ \
|
||||
std::cout << x << std::endl; \
|
||||
}
|
||||
|
||||
#define NS3_ASSERT(condition) \
|
||||
if (!(condition)) \
|
||||
{ \
|
||||
std::cout << "assert failed. file=" << __FILE__ << \
|
||||
", line=" << __LINE__ << ", cond=\""#condition << \
|
||||
"\"" << std::endl; \
|
||||
ns3::AssertBreakpoint (); \
|
||||
}
|
||||
|
||||
#define NS3_ASSERT_MSG(condition, message) \
|
||||
if (!(condition)) \
|
||||
{ \
|
||||
std::cout << message << std::endl; \
|
||||
ns3::AssertBreakpoint (); \
|
||||
}
|
||||
|
||||
#else /* NS3_DEBUG_ENABLE */
|
||||
|
||||
#define NS3_DEBUG_COMPONENT_DEFINE(name)
|
||||
#define NS3_DEBUG(x)
|
||||
#define NS3_ASSERT(cond)
|
||||
#define NS3_ASSERT_MSG(cond)
|
||||
|
||||
#endif /* NS3_DEBUG_ENABLE */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user