add NS3_ASSERT and NS3_ASSERT_MSG

This commit is contained in:
Mathieu Lacage
2007-02-13 09:45:32 +01:00
parent 7abd854183
commit bd19595461
3 changed files with 34 additions and 0 deletions

View File

@@ -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");
}

View File

@@ -168,6 +168,12 @@ DebugComponentPrintList (void)
}
}
void
AssertBreakpoint (void)
{
int *a = 0;
a = 0;
}
}; // namespace ns3

View File

@@ -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 */