Bug 37 - NS_TEST_ASSERT_EQUAL
NS_TEST_ASSERT_EQUAL
Status: RESOLVED FIXED
Product: ns-3
Classification: Unclassified
Component: core
pre-release
PC Linux
: P1 blocker
Assigned To: ns-bugs
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-06-15 12:36 UTC by Gustavo J. A. M. Carneiro
Modified: 2008-07-01 13:32 UTC (History)
0 users

See Also:


Attachments
patch (adds line number, docs, adds NS_TEST_ASSERT macro) (1.72 KB, patch)
2007-06-18 08:20 UTC, 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 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.