Bug 37 - NS_TEST_ASSERT_EQUAL
: NS_TEST_ASSERT_EQUAL
Status: RESOLVED FIXED
: ns-3
simulation core
: pre-release
: PC Linux
: P1 blocker
Assigned To:
:
:
:
:
  Show dependency treegraph
 
Reported: 2007-06-15 12:36 EDT by
Modified: 2008-07-01 13:32 EDT (History)


Attachments
patch (adds line number, docs, adds NS_TEST_ASSERT macro) (1.72 KB, patch)
2007-06-18 08:20 EDT, Gustavo J. A. M. Carneiro
Details | Diff


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2007-06-15 12:36:22 EDT
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 From 2007-06-16 04:15:50 EDT -------
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 From 2007-06-18 08:20:46 EDT -------
Created an attachment (id=23) [details]
patch (adds line number, docs, adds NS_TEST_ASSERT macro)
------- Comment #3 From 2007-06-18 09:46:13 EDT -------
+1
------- Comment #4 From 2007-06-18 10:57:22 EDT -------
Committed to ns-3-dev.