Bug 37

Summary: NS_TEST_ASSERT_EQUAL
Product: ns-3 Reporter: Gustavo J. A. M. Carneiro <gjcarneiro>
Component: coreAssignee: ns-bugs <ns-bugs>
Status: RESOLVED FIXED    
Severity: blocker    
Priority: P1    
Version: pre-release   
Hardware: PC   
OS: Linux   
Attachments: patch (adds line number, docs, adds NS_TEST_ASSERT macro)

Description Gustavo J. A. M. Carneiro 2007-06-15 12:36:22 UTC
I have found this macro useful in unit tests:

#define NS_TEST_ASSERT_EQUAL(got, expected)                     \
    if (got != expected)                                        \
      {                                                         \
        Failure () << __FILE__ << ": expected " << expected     \
                   << ", but got " << got << std::endl;         \
        result = false;                                         \
      }

E.g.:
[...]
    packet.RemoveHeader (hdr);
    NS_TEST_ASSERT_EQUAL (hdr.m_packetSequenceNumber, 123);

A similar NS_TEST_ASSERT(expression_that_must_be_true) macro could easily be derived...
Comment 1 Mathieu Lacage 2007-06-16 04:15:50 UTC
Looks good. Are you willing to add this to test.h ? It would be nice to add the line number to the output too.
Comment 2 Gustavo J. A. M. Carneiro 2007-06-18 08:20:46 UTC
Created attachment 23 [details]
patch (adds line number, docs, adds NS_TEST_ASSERT macro)
Comment 3 Tom Henderson 2007-06-18 09:46:13 UTC
+1
Comment 4 Gustavo J. A. M. Carneiro 2007-06-18 10:57:22 UTC
Committed to ns-3-dev.