A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Testing

Tools to define and execute unit tests. More...

+ Collaboration diagram for Testing:

Classes

class  ns3::TestCase
 encapsulates test code More...
 
class  ns3::TestRunner
 A runner to execute tests. More...
 
class  ns3::TestSuite
 A suite of tests to run. More...
 
class  ns3::TestVectors< T >
 A simple way to store test vectors (for stimulus or from responses) More...
 

Macros

#define ASSERT_ON_FAILURE
 Check if we should assert on errors, and do so. More...
 
#define CONTINUE_ON_FAILURE
 If we shouldn't continue on errors, return. More...
 
#define CONTINUE_ON_FAILURE_RETURNS_BOOL
 If we shouldn't continue on errors, return test status. More...
 
#define NS_TEST_ASSERT_MSG_EQ(actual, limit, msg)   NS_TEST_ASSERT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual and expected (limit) value are equal and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_EQ_INTERNAL(actual, limit, msg, file, line)
 Test that an actual and expected (limit) value are equal and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL(actual, limit, msg)   NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual and expected (limit) value are equal and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line)
 Test that an actual and expected (limit) value are equal and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_EQ_TOL(actual, limit, tol, msg)   NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
 Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line)
 Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL(actual, limit, tol, msg)   NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
 Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL(actual, limit, tol, msg, file, line)
 Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_GT(actual, limit, msg)   NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual value is greater than a limit and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_GT_INTERNAL(actual, limit, msg, file, line)
 Test that an actual value is greater than a limit and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_LT(actual, limit, msg)   NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual value is less than a limit and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_LT_INTERNAL(actual, limit, msg, file, line)
 Test that an actual value is less than a limit and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_NE(actual, limit, msg)   NS_TEST_ASSERT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual and expected (limit) value are not equal and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_NE_INTERNAL(actual, limit, msg, file, line)
 Test that an actual and expected (limit) value are not equal and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL(actual, limit, msg)   NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual and expected (limit) value are not equal and report and abort if not. More...
 
#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL(actual, limit, msg, file, line)
 Test that an actual and expected (limit) value are not equal and report and abort if not. More...
 
#define NS_TEST_EXPECT_MSG_EQ(actual, limit, msg)   NS_TEST_EXPECT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual and expected (limit) value are equal and report if not. More...
 
#define NS_TEST_EXPECT_MSG_EQ_INTERNAL(actual, limit, msg, file, line)
 Test that an actual and expected (limit) value are equal and report if not. More...
 
#define NS_TEST_EXPECT_MSG_EQ_TOL(actual, limit, tol, msg)   NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)
 Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if not. More...
 
#define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL(actual, limit, tol, msg, file, line)
 Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if not. More...
 
#define NS_TEST_EXPECT_MSG_GT(actual, limit, msg)   NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual value is greater than a limit and report if not. More...
 
#define NS_TEST_EXPECT_MSG_GT_INTERNAL(actual, limit, msg, file, line)
 Test that an actual value is greater than a limit and report if not. More...
 
#define NS_TEST_EXPECT_MSG_LT(actual, limit, msg)   NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual value is less than a limit and report if not. More...
 
#define NS_TEST_EXPECT_MSG_LT_INTERNAL(actual, limit, msg, file, line)
 Test that an actual value is less than a limit and report if not. More...
 
#define NS_TEST_EXPECT_MSG_NE(actual, limit, msg)   NS_TEST_EXPECT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual and expected (limit) value are not equal and report if not. More...
 
#define NS_TEST_EXPECT_MSG_NE_INTERNAL(actual, limit, msg, file, line)
 Test that an actual and expected (limit) value are not equal and report if not. More...
 

Detailed Description

Tools to define and execute unit tests.

Macro Definition Documentation

#define ASSERT_ON_FAILURE
Value:
do { \
if (MustAssertOnFailure ()) \
{ \
*(volatile int *)0 = 0; \
} \
} while (false)

Check if we should assert on errors, and do so.

Internal:

Definition at line 55 of file test.h.

#define CONTINUE_ON_FAILURE
Value:
do { \
if (!MustContinueOnFailure ()) \
{ \
return; \
} \
} while (false)

If we shouldn't continue on errors, return.

Internal:

Definition at line 68 of file test.h.

#define CONTINUE_ON_FAILURE_RETURNS_BOOL
Value:
do { \
if (!MustContinueOnFailure ()) \
{ \
return IsStatusFailure (); \
} \
} while (false)

If we shouldn't continue on errors, return test status.

Internal:

Definition at line 81 of file test.h.

#define NS_TEST_ASSERT_MSG_EQ (   actual,
  limit,
  msg 
)    NS_TEST_ASSERT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

Test that an actual and expected (limit) value are equal and report and abort if not.

Check to see if the expected (limit) value is equal to the actual value found in a test case. If the two values are equal nothing happens, but if the comparison fails, an error is reported in a consistent way and the execution of the current test case is aborted.

The message is interpreted as a stream, for example:

NS_TEST_ASSERT_MSG_EQ (result, true,
"cannot open file " << filename << " in test");

is legal.

Parameters
actualExpression for the actual value found during the test.
limitExpression for the expected value of the test.
msgMessage that is output if the test does not pass.
Warning
Do not use this macro if you are comparing floating point numbers (float or double) as it is unlikely to do what you expect. Use NS_TEST_ASSERT_MSG_EQ_TOL instead.

Definition at line 148 of file test.h.

Referenced by RrcHeaderTestCase::AssertEqualRadioResourceConfigDedicated(), ns3::int64x64::test::Int64x64Bug455TestCase::Check(), ns3::int64x64::test::Int64x64Bug863TestCase::Check(), ns3::int64x64::test::Int64x64CompareTestCase::Check(), LteRrcConnectionEstablishmentTestCase::CheckConnected(), LteX2HandoverTestCase::CheckConnected(), LteX2HandoverMeasuresTestCase::CheckConnected(), AnimationInterfaceTestCase::CheckLogic(), AnimationRemainingEnergyTestCase::CheckLogic(), LteCellSelectionTestCase::CheckPoint(), PeerManagementProtocolRegressionTest::CreateDevices(), Bug772ChainTest::CreateDevices(), HwmpProactiveRegressionTest::CreateDevices(), FlameRegressionTest::CreateDevices(), HwmpDoRfRegressionTest::CreateDevices(), HwmpSimplestRegressionTest::CreateDevices(), ChainRegressionTest::CreateDevices(), ns3::olsr::Bug780Test::CreateNodes(), ns3::olsr::HelloRegressionTest::CreateNodes(), LteInterferenceTestCase::DlScheduling(), LteLinkAdaptationTestCase::DlScheduling(), LtePathlossModelSystemTestCase::DlScheduling(), LteRlcUmTransmitterTestCase::DoCheckDataReceived(), LteRlcAmTransmitterTestCase::DoCheckDataReceived(), BufferTest::DoRun(), SampleTestCase1::DoRun(), Ipv6AddressTestCase1::DoRun(), WatchdogTestCase::DoRun(), OlsrEmfTestCase::DoRun(), BasicTracedCallbackTestCase::DoRun(), TypeTraitsTestCase::DoRun(), GlobalValueTestCase::DoRun(), FlameHeaderTest::DoRun(), IpAddressHelperTestCasev6::DoRun(), ns3::aodv::LoopbackTestCase::DoRun(), MeshHeaderTest::DoRun(), BasicCallbackTestCase::DoRun(), TimeSimpleTestCase::DoRun(), LrWpanPacketTestCase::DoRun(), BriteTopologyStructureTestCase::DoRun(), MeshInformationElementVectorBist::DoRun(), UniqueTypeIdTestCase::DoRun(), SwitchFlowTableTestCase::DoRun(), LteRlcAmE2eTestCase::DoRun(), LteRlcUmE2eTestCase::DoRun(), EpsGtpuHeaderTestCase::DoRun(), LrWpanErrorDistanceTestCase::DoRun(), StaticRoutingSlash32TestCase::DoRun(), UdpClientServerTestCase::DoRun(), Ipv4L3ProtocolTestCase::DoRun(), BasicEnergyUpdateTest::DoRun(), OlsrMidTestCase::DoRun(), DsaRequestTestCase::DoRun(), Ipv6L3ProtocolTestCase::DoRun(), Ns3TcpNoDelayTestCase::DoRun(), Ns3WimaxCsParamTlvTestCase::DoRun(), TimerStateTestCase::DoRun(), Ns3TcpSocketTestCase1::DoRun(), DsdvHeaderTestCase::DoRun(), DynamicGlobalRoutingTestCase::DoRun(), NscTcpLossTestCase1::DoRun(), Ipv4ListRoutingNegativeTestCase::DoRun(), WifiInterferenceTestCase::DoRun(), CsmaBridgeTestCase::DoRun(), BatteryLifetimeTest::DoRun(), Ipv6ListRoutingNegativeTestCase::DoRun(), EpcTftClassifierTestCase::DoRun(), RandomRoomPositionAllocatorTestCase::DoRun(), BasicAddTestCase::DoRun(), ErrorModelSimple::DoRun(), RandomVariableStreamUniformTestCase::DoRun(), SpectrumIdealPhyTestCase::DoRun(), LteNoisePsdTestCase::DoRun(), OcbWifiMacTestCase::DoRun(), EpcS1uDlTestCase::DoRun(), Ipv4ListRoutingPositiveTestCase::DoRun(), CommandLineBooleanTestCase::DoRun(), WriteModeCreateTestCase::DoRun(), Ipv6ListRoutingPositiveTestCase::DoRun(), LteEpcE2eDataTestCase::DoRun(), BuildingsHelperOneTestCase::DoRun(), RandomNumberSerializationTestCase::DoRun(), DsdvTableTestCase::DoRun(), CreateObjectTestCase::DoRun(), LteTxPsdTestCase::DoRun(), CollisionTestCase::DoRun(), UdpTraceClientServerTestCase::DoRun(), StringContextAddTestCase::DoRun(), CommandLineIntTestCase::DoRun(), Ns3WimaxSfTlvTestCase::DoRun(), RootNamespaceConfigTestCase::DoRun(), BurstErrorModelSimple::DoRun(), SameRoomPositionAllocatorTestCase::DoRun(), OlsrHelloTestCase::DoRun(), Ns3TcpSocketTestCase2::DoRun(), CsmaBroadcastTestCase::DoRun(), NscTcpLossTestCase2::DoRun(), MakeCallbackTestCase::DoRun(), AggregateObjectTestCase::DoRun(), CommandLineUnsignedIntTestCase::DoRun(), Ns3TcpCwndTestCase1::DoRun(), RandomVariableStreamUniformAntitheticTestCase::DoRun(), IpAddressHelperTestCasev4::DoRun(), PacketLossCounterTestCase::DoRun(), FullyQualifiedAddTestCase::DoRun(), AcousticModemEnergyDepletionTestCase::DoRun(), ReadModeCreateTestCase::DoRun(), UnderRootNamespaceConfigTestCase::DoRun(), CommandLineStringTestCase::DoRun(), BasicEnergyDepletionTest::DoRun(), OlsrTcTestCase::DoRun(), Ns2MobilityHelperTest::DoRun(), RrcConnectionRequestTestCase::DoRun(), OlsrHnaTestCase::DoRun(), RelativeAddTestCase::DoRun(), EpcS1uUlTestCase::DoRun(), CsmaMulticastTestCase::DoRun(), GlobalRoutingSlash32TestCase::DoRun(), RrcConnectionSetupTestCase::DoRun(), MakeBoundCallbackTestCase::DoRun(), ObjectVectorConfigTestCase::DoRun(), AttributeTestCase< T >::DoRun(), BasicRenameTestCase::DoRun(), RrcConnectionSetupCompleteTestCase::DoRun(), ObjectFactoryTestCase::DoRun(), MatrixPropagationLossModelTestCase::DoRun(), Bug555TestCase::DoRun(), Ns3TcpCwndTestCase2::DoRun(), RrcConnectionReconfigurationCompleteTestCase::DoRun(), StringContextRenameTestCase::DoRun(), FileHeaderTestCase::DoRun(), RrcConnectionReconfigurationTestCase::DoRun(), CsmaOneSubnetTestCase::DoRun(), FullyQualifiedRenameTestCase::DoRun(), ObjectVectorTraceConfigTestCase::DoRun(), RelativeRenameTestCase::DoRun(), NullifyCallbackTestCase::DoRun(), FindPathTestCase::DoRun(), CsmaPacketSocketTestCase::DoRun(), BasicFindTestCase::DoRun(), HandoverPreparationInfoTestCase::DoRun(), RecordHeaderTestCase::DoRun(), CsmaPingTestCase::DoRun(), StringContextFindTestCase::DoRun(), RrcConnectionReestablishmentRequestTestCase::DoRun(), RandomVariableStreamAttributeTestCase::DoRun(), FullyQualifiedFindTestCase::DoRun(), RrcConnectionReestablishmentTestCase::DoRun(), ObjectVectorAttributeTestCase::DoRun(), CsmaRawIpSocketTestCase::DoRun(), RrcConnectionReestablishmentCompleteTestCase::DoRun(), RelativeFindTestCase::DoRun(), RrcConnectionRejectTestCase::DoRun(), ObjectMapAttributeTestCase::DoRun(), AlternateFindTestCase::DoRun(), CsmaStarTestCase::DoRun(), MeasurementReportTestCase::DoRun(), IntegerTraceSourceAttributeTestCase::DoRun(), ReadFileTestCase::DoRun(), IntegerTraceSourceTestCase::DoRun(), DiffTestCase::DoRun(), TracedCallbackTestCase::DoRun(), PointerAttributeTestCase::DoRun(), CallbackValueTestCase::DoRun(), LteHandoverTargetTestCase::DoTeardown(), LteUeMeasurementsPiecewiseTestCase1::DoTeardown(), LteUeMeasurementsPiecewiseTestCase2::DoTeardown(), LteUeMeasurementsHandoverTestCase::DoTeardown(), LteHandoverTargetTestCase::HandoverStartCallback(), LteUeMeasurementsTestCase::RecvMeasurementReport(), LteUeMeasurementsPiecewiseTestCase1::RecvMeasurementReportCallback(), LteUeMeasurementsPiecewiseTestCase2::RecvMeasurementReportCallback(), LteUeMeasurementsHandoverTestCase::RecvMeasurementReportCallback(), SpectrumInterferenceTestCase::RetrieveTestResult(), Ipv6PacketInfoTagTest::RxCb(), Ipv4PacketInfoTagTest::RxCb(), PbbTestCase::TestDeserialize(), PbbTestCase::TestSerialize(), LteInterferenceTestCase::UlScheduling(), and Ns3TcpCwndTestCase2::VerifyCwndRun().

#define NS_TEST_ASSERT_MSG_EQ_INTERNAL (   actual,
  limit,
  msg,
  file,
  line 
)
Value:
do { \
if (!((actual) == (limit))) \
{ \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) == " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
#define ASSERT_ON_FAILURE
Check if we should assert on errors, and do so.
Definition: test.h:55
#define CONTINUE_ON_FAILURE
If we shouldn't continue on errors, return.
Definition: test.h:68

Test that an actual and expected (limit) value are equal and report and abort if not.

Internal:

Definition at line 101 of file test.h.

Referenced by PacketMetadataTest::CheckHistory(), and BufferTest::EnsureWrittenBytes().

#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL (   actual,
  limit,
  msg 
)    NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

Test that an actual and expected (limit) value are equal and report and abort if not.

Check to see if the expected (limit) value is equal to the actual value found in a test case. If the two values are equal nothing happens, but if the comparison fails, an error is reported in a consistent way and the execution of the current test case is aborted.

The message is interpreted as a stream, for example:

"cannot open file " << filename << " in test");

is legal.

Parameters
actualExpression for the actual value found during the test.
limitExpression for the expected value of the test.
msgMessage that is output if the test does not pass.
Warning
Do not use this macro if you are comparing floating point numbers (float or double) as it is unlikely to do what you expect. Use NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_TOL instead.

This function returns a boolean value.

Definition at line 207 of file test.h.

Referenced by BatteryLifetimeTest::ConstantLoadTest(), BasicEnergyDepletionTest::DepletionTestCase(), UanTest::DoPhyTests(), BasicEnergyUpdateTest::StateSwitchTest(), and Ns2MobilityHelperTest::WriteTrace().

#define NS_TEST_ASSERT_MSG_EQ_RETURNS_BOOL_INTERNAL (   actual,
  limit,
  msg,
  file,
  line 
)
Value:
do { \
if (!((actual) == (limit))) \
{ \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) == " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
#define ASSERT_ON_FAILURE
Check if we should assert on errors, and do so.
Definition: test.h:55
#define CONTINUE_ON_FAILURE_RETURNS_BOOL
If we shouldn't continue on errors, return test status.
Definition: test.h:81

Test that an actual and expected (limit) value are equal and report and abort if not.

Internal:

Definition at line 157 of file test.h.

#define NS_TEST_ASSERT_MSG_EQ_TOL (   actual,
  limit,
  tol,
  msg 
)    NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)

Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and abort if not.

Check to see if the expected (limit) value is equal to the actual value found in a test case to some tolerance. This is not the same thing as asking if two floating point are equal to within some epsilon, but is useful for that case. This assertion is geared toward more of a measurement problem. Consider measuring a physical rod of some kind that you have ordered. You need to determine if it is "good." You want to measure the rod to an arbitrary precision of sixteen significant figures, you will measure the rod to determine if its length is within the tolerances you provided. For example, 12.00 inches plus or minus .005 inch may be just fine.

In ns-3, you might want to measure a signal to noise ratio and check to see if the answer is what you expect. If you naively measure (double)1128.93 and compare this number with a constant 1128.93 you are almost certainly going to have your test fail because of floating point rounding errors. We provide a floating point comparison function ns3::TestDoubleIsEqual() but you will probably quickly find that is not what you want either. It may turn out to be the case that when you measured an snr that printed as 1128.93, what was actually measured was something more like 1128.9287653857625442 for example. Given that the double epsilon is on the order of 0.0000000000000009, you would need to provide sixteen significant figures of expected value for this kind of test to pass even with a typical test for floating point "approximate equality." That is clearly not required or desired. You really want to be able to provide 1128.93 along with a tolerance just like you provided 12 inches +- 0.005 inch above.

This assertion is designed for real measurements by taking into account measurement tolerances. By doing so it also automatically compensates for floating point rounding errors. If you really want to check floating point equality down to the numeric_limits<double>::epsilon () range, consider using ns3::TestDoubleIsEqual().

Note
Mixing signed and unsigned types can lead to misleading results.

The message is interpreted as a stream, for example:

NS_TEST_ASSERT_MSG_EQ_TOL (snr, 1128.93, 0.005, "wrong snr (" << snr << ") in test");

is legal.

Parameters
actualExpression for the actual value found during the test.
limitExpression for the expected value of the test.
tolTolerance of the test.
msgMessage that is output if the test does not pass.

Definition at line 355 of file test.h.

Referenced by ns3::int64x64::test::Int64x64ArithmeticTestCase::Check(), ns3::int64x64::test::Int64x64DoubleTestCase::Check(), ns3::int64x64::test::Int64x64InvertTestCase::CheckCase(), AnimationRemainingEnergyTestCase::CheckLogic(), SampleTestCase1::DoRun(), RttTestCase::DoRun(), LrWpanSpectrumValueHelperTestCase::DoRun(), LiIonEnergyTestCase::DoRun(), TimeSimpleTestCase::DoRun(), OneIntegerAverageTestCase::DoRun(), OneIntegerTestCase::DoRun(), LenaMimoTestCase::DoRun(), UanTest::DoRun(), LteEarfcnTestCase::DoRun(), ItuR1411LosPropagationLossModelTestCase::DoRun(), ItuR1411NlosOverRooftopPropagationLossModelTestCase::DoRun(), Kun2600MhzPropagationLossModelTestCase::DoRun(), OkumuraHataPropagationLossModelTestCase::DoRun(), LenaHarqTestCase::DoRun(), BuildingsShadowingTestCase::DoRun(), LenaRrFfMacSchedulerTestCase::DoRun(), BuildingsPathlossTestCase::DoRun(), LenaCqaFfMacSchedulerTestCase1::DoRun(), LenaDataPhyErrorModelTestCase::DoRun(), LenaPfFfMacSchedulerTestCase1::DoRun(), LenaFdBetFfMacSchedulerTestCase1::DoRun(), LenaFdMtFfMacSchedulerTestCase::DoRun(), LenaFdTbfqFfMacSchedulerTestCase1::DoRun(), LenaPssFfMacSchedulerTestCase1::DoRun(), LenaTdBetFfMacSchedulerTestCase1::DoRun(), LenaTdMtFfMacSchedulerTestCase::DoRun(), LenaTdTbfqFfMacSchedulerTestCase1::DoRun(), LenaTtaFfMacSchedulerTestCase::DoRun(), LteLinkAdaptationTestCase::DoRun(), AcousticModemEnergyTestCase::DoRun(), LteInterferenceTestCase::DoRun(), LtePathlossModelSystemTestCase::DoRun(), LteEnbAntennaTestCase::DoRun(), LrWpanErrorModelTestCase::DoRun(), LenaPfFfMacSchedulerTestCase2::DoRun(), LenaCqaFfMacSchedulerTestCase2::DoRun(), LenaFdBetFfMacSchedulerTestCase2::DoRun(), LenaTdBetFfMacSchedulerTestCase2::DoRun(), LenaTdTbfqFfMacSchedulerTestCase2::DoRun(), LenaFdTbfqFfMacSchedulerTestCase2::DoRun(), LenaPssFfMacSchedulerTestCase2::DoRun(), LenaDlCtrlPhyErrorModelTestCase::DoRun(), LteEarfcnDlTestCase::DoRun(), SpectrumIdealPhyTestCase::DoRun(), LteEarfcnUlTestCase::DoRun(), FiveIntegersAverageTestCase::DoRun(), TimesWithSignsTestCase::DoRun(), FiveIntegersTestCase::DoRun(), FiveDoublesAverageTestCase::DoRun(), FiveDoublesTestCase::DoRun(), RandomVariableStreamConstantTestCase::DoRun(), RandomVariableStreamSequentialTestCase::DoRun(), RandomVariableStreamNormalTestCase::DoRun(), RandomVariableStreamNormalAntitheticTestCase::DoRun(), RandomVariableStreamExponentialTestCase::DoRun(), RandomVariableStreamExponentialAntitheticTestCase::DoRun(), RandomVariableStreamParetoTestCase::DoRun(), RandomVariableStreamParetoAntitheticTestCase::DoRun(), RandomVariableStreamWeibullTestCase::DoRun(), RandomVariableStreamWeibullAntitheticTestCase::DoRun(), RandomVariableStreamLogNormalTestCase::DoRun(), RandomVariableStreamLogNormalAntitheticTestCase::DoRun(), RandomVariableStreamGammaTestCase::DoRun(), RandomVariableStreamGammaAntitheticTestCase::DoRun(), RandomVariableStreamErlangTestCase::DoRun(), RandomVariableStreamErlangAntitheticTestCase::DoRun(), RandomVariableStreamZipfTestCase::DoRun(), RandomVariableStreamZipfAntitheticTestCase::DoRun(), RandomVariableStreamZetaTestCase::DoRun(), RandomVariableStreamZetaAntitheticTestCase::DoRun(), RandomVariableStreamDeterministicTestCase::DoRun(), RandomVariableStreamEmpiricalTestCase::DoRun(), RandomVariableStreamEmpiricalAntitheticTestCase::DoRun(), LteUeMeasurementsTestCase::ReportUeMeasurements(), and ProbeTestCase1::TraceSink().

#define NS_TEST_ASSERT_MSG_EQ_TOL_INTERNAL (   actual,
  limit,
  tol,
  msg,
  file,
  line 
)
Value:
do { \
if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
{ \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit << " +- " << tol; \
std::ostringstream condStream; \
condStream << #actual << " (actual) < " << #limit \
<< " (limit) + " << #tol << " (tol) && " \
<< #actual << " (actual) > " << #limit \
<< " (limit) - " << #tol << " (tol)"; \
ReportTestFailure (condStream.str (), actualStream.str (), \
limitStream.str (), msgStream.str (), \
file, line); \
} \
} while (false)
#define ASSERT_ON_FAILURE
Check if we should assert on errors, and do so.
Definition: test.h:55
#define CONTINUE_ON_FAILURE
If we shouldn't continue on errors, return.
Definition: test.h:68

Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and abort if not.

Internal:

Definition at line 279 of file test.h.

#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL (   actual,
  limit,
  tol,
  msg 
)    NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)

Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and abort if not.

Check to see if the expected (limit) value is equal to the actual value found in a test case to some tolerance. This is not the same thing as asking if two floating point are equal to within some epsilon, but is useful for that case. This assertion is geared toward more of a measurement problem. Consider measuring a physical rod of some kind that you have ordered. You need to determine if it is "good." You want to measure the rod to an arbitrary precision of sixteen significant figures, you will measure the rod to determine if its length is within the tolerances you provided. For example, 12.00 inches plus or minus .005 inch may be just fine.

In ns-3, you might want to measure a signal to noise ratio and check to see if the answer is what you expect. If you naively measure (double)1128.93 and compare this number with a constant 1128.93 you are almost certainly going to have your test fail because of floating point rounding errors. We provide a floating point comparison function ns3::TestDoubleIsEqual() but you will probably quickly find that is not what you want either. It may turn out to be the case that when you measured an snr that printed as 1128.93, what was actually measured was something more like 1128.9287653857625442 for example. Given that the double epsilon is on the order of 0.0000000000000009, you would need to provide sixteen significant figures of expected value for this kind of test to pass even with a typical test for floating point "approximate equality." That is clearly not required or desired. You really want to be able to provide 1128.93 along with a tolerance just like you provided 12 inches +- 0.005 inch above.

This assertion is designed for real measurements by taking into account measurement tolerances. By doing so it also automatically compensates for floating point rounding errors. If you really want to check floating point equality down to the numeric_limits<double>::epsilon () range, consider using ns3::TestDoubleIsEqual().

Note
Mixing signed and unsigned types can lead to misleading results.

The message is interpreted as a stream, for example:

NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL (snr, 1128.93, 0.005, "wrong snr (" << snr << ") in test");

is legal.

Parameters
actualExpression for the actual value found during the test.
limitExpression for the expected value of the test.
tolTolerance of the test.
msgMessage that is output if the test does not pass.

This function returns a boolean value.

Definition at line 443 of file test.h.

Referenced by BasicEnergyUpdateTest::StateSwitchTest(), and BatteryLifetimeTest::VariableLoadTest().

#define NS_TEST_ASSERT_MSG_EQ_TOL_RETURNS_BOOL_INTERNAL (   actual,
  limit,
  tol,
  msg,
  file,
  line 
)
Value:
do { \
if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
{ \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit << " +- " << tol; \
std::ostringstream condStream; \
condStream << #actual << " (actual) < " << #limit \
<< " (limit) + " << #tol << " (tol) && " \
<< #actual << " (actual) > " << #limit \
<< " (limit) - " << #tol << " (tol)"; \
ReportTestFailure (condStream.str (), actualStream.str (), \
limitStream.str (), msgStream.str (), \
file, line); \
} \
} while (false)
#define ASSERT_ON_FAILURE
Check if we should assert on errors, and do so.
Definition: test.h:55
#define CONTINUE_ON_FAILURE_RETURNS_BOOL
If we shouldn't continue on errors, return test status.
Definition: test.h:81

Test that actual and expected (limit) values are equal to plus or minus some tolerance and report and abort if not.

Internal:

Definition at line 364 of file test.h.

#define NS_TEST_ASSERT_MSG_GT (   actual,
  limit,
  msg 
)    NS_TEST_ASSERT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

Test that an actual value is greater than a limit and report and abort if not.

Check to see if the actual value found in a test case is greater than the limit value. If the actual value is greater nothing happens, but if the check fails, an error is reported in a consistent way and the execution of the current test case is aborted.

The message is interpreted as a stream.

Parameters
actualExpression for the actual value found during the test.
limitExpression for the limit value of the test.
msgMessage that is output if the test does not pass.

Definition at line 847 of file test.h.

Referenced by LteX2HandoverMeasuresTestCase::CheckStats(), LteX2HandoverTestCase::CheckStatsAWhileAfterHandover(), OneUniformRandomVariableManyGetValueCallsTestCase::DoRun(), ManyUniformRandomVariablesOneGetValueCallTestCase::DoRun(), BuildingsShadowingTestCase::DoRun(), WifiMsduAggregatorThroughputTest::DoRun(), ProbeTestCase1::DoRun(), RandomRoomPositionAllocatorTestCase::DoRun(), OcbWifiMacTestCase::DoRun(), LteHandoverTargetTestCase::HandoverStartCallback(), and ProbeTestCase1::TraceSink().

#define NS_TEST_ASSERT_MSG_GT_INTERNAL (   actual,
  limit,
  msg,
  file,
  line 
)
Value:
do { \
if (!((actual) > (limit))) \
{ \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) > " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
#define ASSERT_ON_FAILURE
Check if we should assert on errors, and do so.
Definition: test.h:55
#define CONTINUE_ON_FAILURE
If we shouldn't continue on errors, return.
Definition: test.h:68

Test that an actual value is greater than a limit and report and abort if not.

Internal:

Definition at line 811 of file test.h.

#define NS_TEST_ASSERT_MSG_LT (   actual,
  limit,
  msg 
)    NS_TEST_ASSERT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

Test that an actual value is less than a limit and report and abort if not.

Check to see if the actual value found in a test case is less than the limit value. If the actual value is lesser nothing happens, but if the check fails, an error is reported in a consistent way and the execution of the current test case is aborted.

The message is interpreted as a stream.

Parameters
actualExpression for the actual value found during the test.
limitExpression for the limit value of the test.
msgMessage that is output if the test does not pass.

Definition at line 753 of file test.h.

Referenced by ManyUniformRandomVariablesOneGetValueCallTestCase::DoRun(), OneUniformRandomVariableManyGetValueCallsTestCase::DoRun(), BuildingsShadowingTestCase::DoRun(), RngUniformTestCase::DoRun(), RandomRoomPositionAllocatorTestCase::DoRun(), RandomVariableStreamUniformTestCase::DoRun(), OcbWifiMacTestCase::DoRun(), RngNormalTestCase::DoRun(), RandomVariableStreamUniformAntitheticTestCase::DoRun(), RngExponentialTestCase::DoRun(), RngParetoTestCase::DoRun(), RandomVariableStreamNormalTestCase::DoRun(), RandomVariableStreamNormalAntitheticTestCase::DoRun(), RandomVariableStreamExponentialTestCase::DoRun(), RandomVariableStreamExponentialAntitheticTestCase::DoRun(), RandomVariableStreamParetoTestCase::DoRun(), RandomVariableStreamParetoAntitheticTestCase::DoRun(), RandomVariableStreamWeibullTestCase::DoRun(), RandomVariableStreamWeibullAntitheticTestCase::DoRun(), RandomVariableStreamLogNormalTestCase::DoRun(), RandomVariableStreamLogNormalAntitheticTestCase::DoRun(), RandomVariableStreamGammaTestCase::DoRun(), RandomVariableStreamGammaAntitheticTestCase::DoRun(), RandomVariableStreamErlangTestCase::DoRun(), RandomVariableStreamErlangAntitheticTestCase::DoRun(), LteHandoverDelayTestCase::EnbHandoverEndOkCallback(), ProbeTestCase1::TraceSink(), and LteHandoverDelayTestCase::UeHandoverEndOkCallback().

#define NS_TEST_ASSERT_MSG_LT_INTERNAL (   actual,
  limit,
  msg,
  file,
  line 
)
Value:
do { \
if (!((actual) < (limit))) \
{ \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) < " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
#define ASSERT_ON_FAILURE
Check if we should assert on errors, and do so.
Definition: test.h:55
#define CONTINUE_ON_FAILURE
If we shouldn't continue on errors, return.
Definition: test.h:68

Test that an actual value is less than a limit and report and abort if not.

Internal:

Definition at line 717 of file test.h.

#define NS_TEST_ASSERT_MSG_NE (   actual,
  limit,
  msg 
)    NS_TEST_ASSERT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

Test that an actual and expected (limit) value are not equal and report and abort if not.

Check to see if the expected (limit) value is not equal to the actual value found in a test case. If the two values are not equal nothing happens, but if the comparison fails, an error is reported in a consistent way and the execution of the current test case is aborted.

The message is interpreted as a stream, for example:

NS_TEST_ASSERT_MSG_NE (result, false,
"cannot open file " << filename << " in test");

is legal.

Parameters
actualExpression for the actual value found during the test.
limitExpression for the value that actual is tested against.
msgMessage that is output if the test does not pass.
Warning
Do not use this macro if you are comparing floating point numbers (float or double). Use NS_TEST_ASSERT_MSG_FLNE instead.

Definition at line 589 of file test.h.

Referenced by LteRrcConnectionEstablishmentTestCase::CheckConnected(), LteX2HandoverTestCase::CheckConnected(), LteX2HandoverMeasuresTestCase::CheckConnected(), AbstractAnimationInterfaceTestCase::CheckFileExistence(), BufferTest::DoRun(), RocketfuelTopologyReaderTest::DoRun(), SwitchFlowTableTestCase::DoRun(), CreateObjectTestCase::DoRun(), CollisionTestCase::DoRun(), AggregateObjectTestCase::DoRun(), RandomVariableStreamConstantTestCase::DoRun(), AttributeTestCase< T >::DoRun(), ObjectFactoryTestCase::DoRun(), FileHeaderTestCase::DoRun(), RecordHeaderTestCase::DoRun(), RandomVariableStreamAttributeTestCase::DoRun(), ObjectVectorAttributeTestCase::DoRun(), ObjectMapAttributeTestCase::DoRun(), IntegerTraceSourceAttributeTestCase::DoRun(), IntegerTraceSourceTestCase::DoRun(), TracedCallbackTestCase::DoRun(), PointerAttributeTestCase::DoRun(), and CallbackValueTestCase::DoRun().

#define NS_TEST_ASSERT_MSG_NE_INTERNAL (   actual,
  limit,
  msg,
  file,
  line 
)
Value:
do { \
if (!((actual) != (limit))) \
{ \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) != " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
#define ASSERT_ON_FAILURE
Check if we should assert on errors, and do so.
Definition: test.h:55
#define CONTINUE_ON_FAILURE
If we shouldn't continue on errors, return.
Definition: test.h:68

Test that an actual and expected (limit) value are not equal and report and abort if not.

Internal:

Definition at line 543 of file test.h.

#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL (   actual,
  limit,
  msg 
)    NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

Test that an actual and expected (limit) value are not equal and report and abort if not.

Check to see if the expected (limit) value is not equal to the actual value found in a test case. If the two values are equal nothing happens, but if the comparison fails, an error is reported in a consistent way and the execution of the current test case is aborted.

The message is interpreted as a stream, for example:

"cannot open file " << filename << " in test");

is legal.

Parameters
actualExpression for the actual value found during the test.
limitExpression for the expected value of the test.
msgMessage that is output if the test does not pass.
Warning
Do not use this macro if you are comparing floating point numbers (float or double). Use NS_TEST_ASSERT_MSG_FLNE instead.

This function returns a boolean value.

Definition at line 647 of file test.h.

Referenced by Ns2MobilityHelperTest::CheckInitialPositions(), and BasicEnergyUpdateTest::StateSwitchTest().

#define NS_TEST_ASSERT_MSG_NE_RETURNS_BOOL_INTERNAL (   actual,
  limit,
  msg,
  file,
  line 
)
Value:
do { \
if (!((actual) != (limit))) \
{ \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) != " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
#define ASSERT_ON_FAILURE
Check if we should assert on errors, and do so.
Definition: test.h:55
#define CONTINUE_ON_FAILURE_RETURNS_BOOL
If we shouldn't continue on errors, return test status.
Definition: test.h:81

Test that an actual and expected (limit) value are not equal and report and abort if not.

Internal:

Definition at line 598 of file test.h.

#define NS_TEST_EXPECT_MSG_EQ (   actual,
  limit,
  msg 
)    NS_TEST_EXPECT_MSG_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

Test that an actual and expected (limit) value are equal and report if not.

Check to see if the expected (lmit) value is equal to the actual value found in a test case. If the two values are equal nothing happens, but if the comparison fails, an error is reported in a consistent way. EXPECT* macros do not return if an error is detected.

The message is interpreted as a stream, for example:

NS_TEST_EXPECT_MSG_EQUAL (result, true,
"cannot open file " << filename << " in test");

is legal.

Parameters
actualExpression for the actual value found during the test.
limitExpression for the expected value of the test.
msgMessage that is output if the test does not pass.
Warning
Do not use this macro if you are comparing floating point numbers (float or double) as it is unlikely to do what you expect. Use NS_TEST_EXPECT_MSG_EQ_TOL instead.

Definition at line 265 of file test.h.

Referenced by HashTestCase::Check(), ns3::int64x64::test::Int64x64HiLoTestCase::Check(), ns3::int64x64::test::Int64x64InputTestCase::Check(), ns3::int64x64::test::Int64x64Bug1786TestCase::Check(), Ns2MobilityHelperTest::CheckInitialPositions(), PacketTagListTest::CheckRef(), ns3::aodv::AodvRqueueTest::CheckSizeLimit(), DsrSendBuffTest::CheckSizeLimit(), ns3::aodv::AodvRqueueTest::CheckTimeout(), DsrSendBuffTest::CheckTimeout(), ns3::aodv::NeighborTest::CheckTimeout1(), ns3::aodv::IdCacheTest::CheckTimeout1(), ns3::aodv::NeighborTest::CheckTimeout2(), ns3::aodv::IdCacheTest::CheckTimeout2(), ns3::aodv::NeighborTest::CheckTimeout3(), ns3::aodv::IdCacheTest::CheckTimeout3(), Ns2MobilityHelperTest::CourseChange(), WaypointMobilityModelNotifyTest::CourseChangeCallback(), HwmpReactiveRegressionTest::CreateDevices(), ns3::olsr::TcRegressionTest::CreateNodes(), PacketTest::DoCheck(), BufferTest::DoRun(), NetworkNumberAllocatorTestCase::DoRun(), DropTailQueueTestCase::DoRun(), HistogramTestCase::DoRun(), NetworkNumber6AllocatorTestCase::DoRun(), NetworkAllocatorHelperTestCase::DoRun(), SimulatorEventsTestCase::DoRun(), ns3::aodv::NeighborTest::DoRun(), RttTestCase::DoRun(), EventGarbageCollectorTestCase::DoRun(), TestEmptyOptionField::DoRun(), RocketfuelTopologyReaderTest::DoRun(), ns3::aodv::IdCacheTest::DoRun(), LrWpanCollisionTestCase::DoRun(), LrWpanEdTestCase::DoRun(), OlsrMprTestCase::DoRun(), Ns3WimaxFragmentationTestCase::DoRun(), LrWpanCcaTestCase::DoRun(), Ns3WimaxNetworkEntryTestCase::DoRun(), PtrTestCase::DoRun(), DualStackTestCase::DoRun(), Ipv6RipngTest::DoRun(), ThreadedSimulatorEventsTestCase::DoRun(), DsrFsHeaderTest::DoRun(), TcpTestCase::DoRun(), PacketBufferingCaseA::DoRun(), Ipv6ForwardingTest::DoRun(), Ipv4ForwardingTest::DoRun(), AddressAllocator6TestCase::DoRun(), AddressAllocatorHelperTestCase::DoRun(), SixlowpanHc1ImplTest::DoRun(), SixlowpanIphcImplTest::DoRun(), Ipv6RawSocketImplTest::DoRun(), AddressAllocatorTestCase::DoRun(), Ipv4HeaderTest::DoRun(), Ipv4RawSocketImplTest::DoRun(), TestOptionWithoutAlignment::DoRun(), DsrRreqHeaderTest::DoRun(), SixlowpanFragmentationTest::DoRun(), ns3::aodv::TypeHeaderTest::DoRun(), DsdvTableTestCase::DoRun(), UdpSocketLoopbackTest::DoRun(), Ns3WimaxManagementConnectionsTestCase::DoRun(), Ipv4FragmentationTest::DoRun(), ResetAllocatorHelperTestCase::DoRun(), ns3::aodv::RreqHeaderTest::DoRun(), NetworkAndAddress6TestCase::DoRun(), NetworkAndAddressTestCase::DoRun(), Ipv6FragmentationTest::DoRun(), DsrRrepHeaderTest::DoRun(), TestOptionWithAlignment::DoRun(), PacketBufferingCaseB::DoRun(), Udp6SocketLoopbackTest::DoRun(), ExampleAddress6GeneratorTestCase::DoRun(), ns3::aodv::RrepHeaderTest::DoRun(), DsrSRHeaderTest::DoRun(), TestFulfilledAlignment::DoRun(), ExampleAddressGeneratorTestCase::DoRun(), QosUtilsIsOldPacketTest::DoRun(), UdpSocketImplTest::DoRun(), AddressCollision6TestCase::DoRun(), ns3::aodv::RrepAckHeaderTest::DoRun(), PeerLinkFrameStartTest::DoRun(), CtrlBAckResponseHeaderTest::DoRun(), PacketTest::DoRun(), DsrRerrHeaderTest::DoRun(), ns3::aodv::RerrHeaderTest::DoRun(), AddressCollisionTestCase::DoRun(), PacketMetadataTest::DoRun(), ns3::aodv::QueueEntryTest::DoRun(), DsrAckReqHeaderTest::DoRun(), Ipv6RipngCountToInfinityTest::DoRun(), ns3::aodv::AodvRqueueTest::DoRun(), DsrAckHeaderTest::DoRun(), DsrCacheEntryTest::DoRun(), DsrSendBuffTest::DoRun(), ns3::aodv::AodvRtableEntryTest::DoRun(), Udp6SocketImplTest::DoRun(), PacketTagListTest::DoRun(), Ipv6RipngSplitHorizonStrategyTest::DoRun(), ns3::aodv::AodvRtableTest::DoRun(), DsrRreqTableTest::DoRun(), DiffTestCase::DoRun(), Ipv6RipngTest::DoSendData(), Ipv6ForwardingTest::DoSendData(), Ipv4ForwardingTest::DoSendData(), SixlowpanHc1ImplTest::DoSendData(), SixlowpanIphcImplTest::DoSendData(), Ipv6RawSocketImplTest::DoSendData(), Ipv6PacketInfoTagTest::DoSendData(), Ipv4RawSocketImplTest::DoSendData(), Ipv4PacketInfoTagTest::DoSendData(), UdpSocketImplTest::DoSendData(), Ipv6RipngCountToInfinityTest::DoSendData(), Udp6SocketImplTest::DoSendData(), Ipv4RawSocketImplTest::DoSendData_IpHdr(), Ipv4HeaderTest::DoSendData_IpHdr_Dscp(), DcfManagerTest::EndTest(), Ns3TcpStateTestCase::Ipv4L3Tx(), Ns3TcpLossTestCase::Ipv4L3Tx(), Ns3TcpInteroperabilityTestCase::Ipv4L3Tx(), DcfManagerTest::NotifyAccessGranted(), DcfManagerTest::NotifyChannelSwitching(), DcfManagerTest::NotifyCollision(), DcfManagerTest::NotifyInternalCollision(), Ipv6RawSocketImplTest::ReceivePkt2(), Ipv6RipngSplitHorizonStrategyTest::ReceivePktProbe(), RedQueueTestCase::RunRedTest(), TcpTestCase::ServerHandleRecv(), TcpTestCase::ServerHandleSend(), TcpTestCase::SourceHandleRecv(), TcpTestCase::SourceHandleSend(), FlameRtableTest::TestExpire(), HwmpRtableTest::TestExpire(), FlameRtableTest::TestLookup(), HwmpRtableTest::TestLookup(), WaypointInitialPositionIsWaypoint::TestNumWaypoints(), and HwmpRtableTest::TestPrecursorFind().

#define NS_TEST_EXPECT_MSG_EQ_INTERNAL (   actual,
  limit,
  msg,
  file,
  line 
)
Value:
do { \
if (!((actual) == (limit))) \
{ \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) == " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
#define ASSERT_ON_FAILURE
Check if we should assert on errors, and do so.
Definition: test.h:55

Test that an actual and expected (limit) value are equal and report if not.

Required to avoid use of return statement which allows use in methods (esp. callbacks) returning void.

Internal:

Definition at line 219 of file test.h.

Referenced by PacketTest::DoCheck().

#define NS_TEST_EXPECT_MSG_EQ_TOL (   actual,
  limit,
  tol,
  msg 
)    NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (actual, limit, tol, msg, __FILE__, __LINE__)

Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if not.

Check to see if the expected (limit) value is equal to the actual value found in a test case to some tolerance. This is not the same thing as asking if two floating point are equal to within some epsilon, but is useful for that case. This assertion is geared toward more of a measurement problem. Consider measuring a physical rod of some kind that you have ordered. You need to determine if it is "good." You want to measure the rod to an arbitrary precision of sixteen significant figures, you will measure the rod to determine if its length is within the tolerances you provided. For example, 12.00 inches plus or minus .005 inch may be just fine.

In ns-3, you might want to measure a signal to noise ratio and check to see if the answer is what you expect. If you naively measure (double)1128.93 and compare this number with a constant 1128.93 you are almost certainly going to have your test fail because of floating point rounding errors. We provide a floating point comparison function ns3::TestDoubleIsEqual() but you will probably quickly find that is not what you want either. It may turn out to be the case that when you measured an snr that printed as 1128.93, what was actually measured was something more like 1128.9287653857625442 for example. Given that the double epsilon is on the order of 0.0000000000000009, you would need to provide sixteen significant figures of expected value for this kind of test to pass even with a typical test for floating point "approximate equality." That is clearly not required or desired. You really want to be able to provide 1128.93 along with a tolerance just like you provided 12 inches +- 0.005 inch above.

This assertion is designed for real measurements by taking into account measurement tolerances. By doing so it also automatically compensates for floating point rounding errors. If you really want to check floating point equality down to the numeric_limits<double>::epsilon () range, consider using ns3::TestDoubleIsEqual().

Note
Mixing signed and unsigned types can lead to misleading results.

The message is interpreted as a stream, for example:

NS_TEST_EXPECT_MSG_EQ_TOL (snr, 1128.93, 0.005, "wrong snr (" << snr << ") in test");

is legal.

Parameters
actualExpression for the actual value found during the test.
limitExpression for the expected value of the test.
tolTolerance of the test.
msgMessage that is output if the test does not pass.

Definition at line 530 of file test.h.

Referenced by ns3::int64x64::test::Int64x64HiLoTestCase::Check(), ns3::int64x64::test::Int64x64InputTestCase::Check(), ns3::int64x64::test::Int64x64InputOutputTestCase::Check(), SteadyStateRandomWaypointTest::DistribCompare(), HistogramTestCase::DoRun(), OneVectorConstructorTestCase::DoRun(), DegreesToRadiansTestCase::DoRun(), IsotropicAntennaModelTestCase::DoRun(), BasicRandomNumberTestCase::DoRun(), FriisPropagationLossModelTestCase::DoRun(), CosineAntennaModelTestCase::DoRun(), ParabolicAntennaModelTestCase::DoRun(), RadiansToDegreesTestCase::DoRun(), TwoVectorsConstructorTestCase::DoRun(), TwoRayGroundPropagationLossModelTestCase::DoRun(), LogDistancePropagationLossModelTestCase::DoRun(), and RangePropagationLossModelTestCase::DoRun().

#define NS_TEST_EXPECT_MSG_EQ_TOL_INTERNAL (   actual,
  limit,
  tol,
  msg,
  file,
  line 
)
Value:
do { \
if ((actual) > (limit) + (tol) || (actual) < (limit) - (tol)) \
{ \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit << " +- " << tol; \
std::ostringstream condStream; \
condStream << #actual << " (actual) < " << #limit \
<< " (limit) + " << #tol << " (tol) && " \
<< #actual << " (actual) > " << #limit \
<< " (limit) - " << #tol << " (tol)"; \
ReportTestFailure (condStream.str (), actualStream.str (), \
limitStream.str (), msgStream.str (), \
file, line); \
} \
} while (false)
#define ASSERT_ON_FAILURE
Check if we should assert on errors, and do so.
Definition: test.h:55

Test that actual and expected (limit) values are equal to plus or minus some tolerance and report if not.

Required to avoid use of return statement which allows use in methods (esp. callbacks) returning void.

Internal:

Definition at line 455 of file test.h.

Referenced by WaypointLazyNotifyFalse::CourseChangeCallback(), WaypointLazyNotifyTrue::CourseChangeCallback(), WaypointLazyNotifyFalse::TestXPosition(), WaypointLazyNotifyTrue::TestXPosition(), WaypointInitialPositionIsWaypoint::TestXPosition(), and WaypointMobilityModelViaHelper::TestXPosition().

#define NS_TEST_EXPECT_MSG_GT (   actual,
  limit,
  msg 
)    NS_TEST_EXPECT_MSG_GT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

Test that an actual value is greater than a limit and report if not.

Check to see if the actual value found in a test case is greater than the limit value. If the actual value is greater nothing happens, but if the check fails, an error is reported in a consistent way. EXPECT* macros do not return if an error is detected.

The message is interpreted as a stream.

Parameters
actualExpression for the actual value found during the test.
limitExpression for the limit value of the test.
msgMessage that is output if the test does not pass.

Definition at line 892 of file test.h.

Referenced by RedQueueTestCase::RunRedTest().

#define NS_TEST_EXPECT_MSG_GT_INTERNAL (   actual,
  limit,
  msg,
  file,
  line 
)
Value:
do { \
if (!((actual) > (limit))) \
{ \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) > " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
#define ASSERT_ON_FAILURE
Check if we should assert on errors, and do so.
Definition: test.h:55

Test that an actual value is greater than a limit and report if not.

Required to avoid use of return statement which allows use in methods (callbacks) returning void.

Internal:

Definition at line 858 of file test.h.

#define NS_TEST_EXPECT_MSG_LT (   actual,
  limit,
  msg 
)    NS_TEST_EXPECT_MSG_LT_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

Test that an actual value is less than a limit and report if not.

Check to see if the actual value found in a test case is less than the limit value. If the actual value is lesser nothing happens, but if the check fails, an error is reported in a consistent way. EXPECT* macros do not return if an error is detected.

The message is interpreted as a stream.

Parameters
actualExpression for the actual value found during the test.
limitExpression for the limit value of the test.
msgMessage that is output if the test does not pass.

Definition at line 798 of file test.h.

Referenced by Ns2MobilityHelperTest::CourseChange(), ParabolicAntennaModelTestCase::DoRun(), CosineAntennaModelTestCase::DoRun(), and LrWpanAckTestCase::DoRun().

#define NS_TEST_EXPECT_MSG_LT_INTERNAL (   actual,
  limit,
  msg,
  file,
  line 
)
Value:
do { \
if (!((actual) < (limit))) \
{ \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) < " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
#define ASSERT_ON_FAILURE
Check if we should assert on errors, and do so.
Definition: test.h:55

Test that an actual value is less than a limit and report if not.

Required to avoid use of return statement which allows use in methods (callbacks) returning void.

Internal:

Definition at line 764 of file test.h.

#define NS_TEST_EXPECT_MSG_NE (   actual,
  limit,
  msg 
)    NS_TEST_EXPECT_MSG_NE_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

Test that an actual and expected (limit) value are not equal and report if not.

Check to see if the expected (limit) value is not equal to the actual value found in a test case. If the two values are not equal nothing happens, but if the comparison fails, an error is reported in a consistent way. EXPECT* macros do not return if an error is detected.

The message is interpreted as a stream, for example:

NS_TEST_EXPECT_MSG_NE (result, false,
"cannot open file " << filename << " in test");

is legal.

Parameters
actualExpression for the actual value found during the test.
limitExpression for the value that actual is tested against.
msgMessage that is output if the test does not pass.
Warning
Do not use this macro if you are comparing floating point numbers (float or double). Use NS_TEST_EXPECT_MSG_FLNE instead.

Definition at line 704 of file test.h.

Referenced by PacketTest::DoCheck(), Ipv4FragmentationTest::DoRun(), Ipv6FragmentationTest::DoRun(), and RedQueueTestCase::RunRedTest().

#define NS_TEST_EXPECT_MSG_NE_INTERNAL (   actual,
  limit,
  msg,
  file,
  line 
)
Value:
do { \
if (!((actual) != (limit))) \
{ \
std::ostringstream msgStream; \
msgStream << msg; \
std::ostringstream actualStream; \
actualStream << actual; \
std::ostringstream limitStream; \
limitStream << limit; \
ReportTestFailure (std::string (#actual) + " (actual) != " + \
std::string (#limit) + " (limit)", \
actualStream.str (), limitStream.str (), \
msgStream.str (), file, line); \
} \
} while (false)
#define ASSERT_ON_FAILURE
Check if we should assert on errors, and do so.
Definition: test.h:55

Test that an actual and expected (limit) value are not equal and report if not.

Required to avoid use of return statement which allows use in methods (callbacks) returning void.

Internal:

Definition at line 659 of file test.h.