A Discrete-Event Network Simulator
API
Testing

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

+ Collaboration diagram for Testing:

Modules

 Testing Implementation
 Internal implementation of the Testing system.
 

Files

file  test.cc
 Implementation of the testing classes and functions.
 
file  test.h
 Definition of the testing macros and declaration of the testing classes.
 

Classes

class  ns3::TestCase
 encapsulates test code 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_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_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_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_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_OR_EQ(actual, limit, msg)   NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual value is greater than or equal to 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_OR_EQ(actual, limit, msg)   NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual value is less than or equal to 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_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_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_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_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_OR_EQ(actual, limit, msg)   NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual value is greater than or equal to 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_OR_EQ(actual, limit, msg)   NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)
 Test that an actual value is less than or equal to 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...
 

Enumerations

enum  ns3::TestCase::TestDuration { ns3::TestCase::QUICK = 1, ns3::TestCase::EXTENSIVE = 2, ns3::TestCase::TAKES_FOREVER = 3 }
 How long the test takes to execute. More...
 
enum  ns3::TestSuite::Type {
  ns3::TestSuite::ALL = 0, ns3::TestSuite::BVT = 1, ns3::TestSuite::UNIT, ns3::TestSuite::SYSTEM,
  ns3::TestSuite::EXAMPLE, ns3::TestSuite::PERFORMANCE
}
 Type of test. More...
 

Functions

bool ns3::TestDoubleIsEqual (const double a, const double b, const double epsilon=std::numeric_limits< double >::epsilon())
 Compare two double precision floating point numbers and declare them equal if they are within some epsilon of each other. More...
 

Detailed Description

Tools to define and execute unit tests.

This module lists the normal Testing API. Most of these macros forward to the implementation macros in testingimpl. You should generally use these macros only.

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.

Definition at line 70 of file test.h.

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

If we shouldn't continue on errors, return.

Definition at line 82 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.

Definition at line 94 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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the expected value of the test.
[in]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 161 of file test.h.

Referenced by TcpRtoTest::AfterRTOExpired(), TcpTimeRtoTest::AfterRTOExpired(), RrcHeaderTestCase::AssertEqualRadioResourceConfigDedicated(), TcpBytesInFlightTest::BytesInFlightTrace(), ns3::int64x64::test::Int64x64Bug455TestCase::Check(), ns3::int64x64::test::Int64x64Bug863TestCase::Check(), ns3::int64x64::test::Int64x64CompareTestCase::Check(), LteX2HandoverTestCase::CheckConnected(), LteRrcConnectionEstablishmentTestCase::CheckConnected(), LteX2HandoverMeasuresTestCase::CheckConnected(), TcpHeaderWithRFC793OptionTestCase::CheckCorrectDeserialize(), AnimationInterfaceTestCase::CheckLogic(), AnimationRemainingEnergyTestCase::CheckLogic(), TcpHeaderWithRFC793OptionTestCase::CheckNoPadding(), LteRrcConnectionEstablishmentTestCase::CheckNotConnected(), LteCellSelectionTestCase::CheckPoint(), TracedValueCallbackTestCase::CheckType(), TcpFastRetrTest::CongStateTrace(), PeerManagementProtocolRegressionTest::CreateDevices(), Bug772ChainTest::CreateDevices(), HwmpProactiveRegressionTest::CreateDevices(), FlameRegressionTest::CreateDevices(), HwmpDoRfRegressionTest::CreateDevices(), HwmpSimplestRegressionTest::CreateDevices(), ChainRegressionTest::CreateDevices(), ns3::olsr::HelloRegressionTest::CreateNodes(), TcpSlowStartNormalTest::CWndTrace(), LteLinkAdaptationTestCase::DlScheduling(), LteCqiGenerationTestCase::DlScheduling(), LteInterferenceTestCase::DlScheduling(), LtePathlossModelSystemTestCase::DlScheduling(), LteCqiGenerationDlPowerControlTestCase::DlScheduling(), LteRlcUmTransmitterTestCase::DoCheckDataReceived(), LteRlcAmTransmitterTestCase::DoCheckDataReceived(), WatchdogTestCase::DoRun(), TypeTraitsTestCase::DoRun(), BasicTracedCallbackTestCase::DoRun(), BuildProfileTestCase::DoRun(), Ipv6AddressTestCase::DoRun(), SampleTestCase1::DoRun(), GlobalValueTestCase::DoRun(), OlsrEmfTestCase::DoRun(), WaveformGeneratorTestCase::DoRun(), BasicCallbackTestCase::DoRun(), TimeSimpleTestCase::DoRun(), BriteTopologyStructureTestCase::DoRun(), FlameHeaderTest::DoRun(), PfifoFastQueueDiscTosPrioritization::DoRun(), IpAddressHelperTestCasev6::DoRun(), LrWpanPacketTestCase::DoRun(), DsaRequestTestCase::DoRun(), Ipv4L3ProtocolTestCase::DoRun(), Ns3WimaxCsParamTlvTestCase::DoRun(), Ipv6L3ProtocolTestCase::DoRun(), SwitchFlowTableTestCase::DoRun(), TcpHighSpeedIncrementTest::DoRun(), FqCoDelQueueDiscNoSuitableFilter::DoRun(), ns3::LenaDeactivateBearerTestCase::DoRun(), MeshHeaderTest::DoRun(), BufferTest::DoRun(), UniqueTypeIdTestCase::DoRun(), TcpHyblaIncrementTest::DoRun(), MeshInformationElementVectorBist::DoRun(), Ns3TcpNoDelayTestCase::DoRun(), Ns3TcpSocketTestCase1::DoRun(), TimerStateTestCase::DoRun(), WifiAcMappingTest::DoRun(), NscTcpLossTestCase1::DoRun(), DsdvHeaderTestCase::DoRun(), UdpClientServerTestCase::DoRun(), TcpScalableIncrementTest::DoRun(), WifiInterferenceTestCase::DoRun(), EpsGtpuHeaderTestCase::DoRun(), TcpHeaderGetSetTestCase::DoRun(), CsmaBridgeTestCase::DoRun(), LrWpanErrorDistanceTestCase::DoRun(), TcpHtcpIncrementTest::DoRun(), TcpVegasTest::DoRun(), LteRlcUmE2eTestCase::DoRun(), TcpVenoTest::DoRun(), LteRlcAmE2eTestCase::DoRun(), TcpYeahIncrementTest::DoRun(), OlsrMidTestCase::DoRun(), TcpIllinoisTest::DoRun(), RandomRoomPositionAllocatorTestCase::DoRun(), Ipv4ListRoutingNegativeTestCase::DoRun(), SpectrumIdealPhyTestCase::DoRun(), ns3::aodv::LoopbackTestCase::DoRun(), ErrorModelSimple::DoRun(), SpectrumWifiPhyBasicTest::DoRun(), CarrierAggregationTestCase::DoRun(), BasicAddTestCase::DoRun(), Ipv6ListRoutingNegativeTestCase::DoRun(), LteDownlinkPowerControlSpectrumValueTestCase::DoRun(), OcbWifiMacTestCase::DoRun(), WriteModeCreateTestCase::DoRun(), BuildingsHelperOneTestCase::DoRun(), FqCoDelQueueDiscIPFlowsSeparationAndPacketLimit::DoRun(), EpcTftClassifierTestCase::DoRun(), TcpHighSpeedDecrementTest::DoRun(), DsdvTableTestCase::DoRun(), Ipv4ListRoutingPositiveTestCase::DoRun(), EpcS1uDlTestCase::DoRun(), LteNoisePsdTestCase::DoRun(), CommandLineBooleanTestCase::DoRun(), Ipv6ListRoutingPositiveTestCase::DoRun(), PfifoFastQueueDiscDscpPrioritization::DoRun(), LteEpcE2eDataTestCase::DoRun(), TcpScalableDecrementTest::DoRun(), CollisionTestCase::DoRun(), LinkTest::DoRun(), LteHardFrTestCase::DoRun(), ns3::RlcAmStatusPduTestCase::DoRun(), UdpTraceClientServerTestCase::DoRun(), RandomVariableStreamUniformTestCase::DoRun(), CreateObjectTestCase::DoRun(), Ns3WimaxSfTlvTestCase::DoRun(), StringContextAddTestCase::DoRun(), SameRoomPositionAllocatorTestCase::DoRun(), Ns3TcpSocketTestCase2::DoRun(), CommandLineIntTestCase::DoRun(), NscTcpLossTestCase2::DoRun(), LteTxPsdTestCase::DoRun(), CsmaBroadcastTestCase::DoRun(), LteDownlinkPowerControlRrcConnectionReconfigurationTestCase::DoRun(), MakeCallbackTestCase::DoRun(), FqCoDelQueueDiscDeficit::DoRun(), BurstErrorModelSimple::DoRun(), LteStrictFrTestCase::DoRun(), OlsrHelloTestCase::DoRun(), CommandLineUnsignedIntTestCase::DoRun(), PfifoFastQueueDiscOverflow::DoRun(), AggregateObjectTestCase::DoRun(), PacketLossCounterTestCase::DoRun(), Ns3TcpCwndTestCase1::DoRun(), FullyQualifiedAddTestCase::DoRun(), IpAddressHelperTestCasev4::DoRun(), ReadModeCreateTestCase::DoRun(), LanTest::DoRun(), RootNamespaceConfigTestCase::DoRun(), CommandLineStringTestCase::DoRun(), AcousticModemEnergyDepletionTestCase::DoRun(), Ns2MobilityHelperTest::DoRun(), OlsrTcTestCase::DoRun(), TcpYeahDecrementTest::DoRun(), SpectrumWifiPhyListenerTest::DoRun(), CommandLineOrderTestCase::DoRun(), UnderRootNamespaceConfigTestCase::DoRun(), PfifoFastQueueDiscNoPriority::DoRun(), DeprecatedAttributeTestCase::DoRun(), RelativeAddTestCase::DoRun(), RandomVariableStreamUniformAntitheticTestCase::DoRun(), CsmaMulticastTestCase::DoRun(), OlsrHnaTestCase::DoRun(), TwoLinkTest::DoRun(), MakeBoundCallbackTestCase::DoRun(), CommandLineInvalidTestCase::DoRun(), LteStrictFrAreaTestCase::DoRun(), RrcConnectionRequestTestCase::DoRun(), FqCoDelQueueDiscTCPFlowsSeparation::DoRun(), LteSoftFrAreaTestCase::DoRun(), EpcS1uUlTestCase::DoRun(), BasicRenameTestCase::DoRun(), LteSoftFfrAreaTestCase::DoRun(), RrcConnectionSetupTestCase::DoRun(), AttributeTestCase< T >::DoRun(), MatrixPropagationLossModelTestCase::DoRun(), TcpHeaderFlagsToString::DoRun(), LteEnhancedFfrAreaTestCase::DoRun(), ObjectFactoryTestCase::DoRun(), CoDelQueueDiscNewtonStepTest::DoRun(), ObjectVectorConfigTestCase::DoRun(), LteDistributedFfrAreaTestCase::DoRun(), Ns3TcpCwndTestCase2::DoRun(), StringContextRenameTestCase::DoRun(), FqCoDelQueueDiscUDPFlowsSeparation::DoRun(), RrcConnectionSetupCompleteTestCase::DoRun(), TwoLanTest::DoRun(), DcfImmediateAccessBroadcastTestCase::DoRun(), FileHeaderTestCase::DoRun(), CsmaOneSubnetTestCase::DoRun(), RrcConnectionReconfigurationCompleteTestCase::DoRun(), FullyQualifiedRenameTestCase::DoRun(), RrcConnectionReconfigurationTestCase::DoRun(), BridgeTest::DoRun(), RelativeRenameTestCase::DoRun(), NullifyCallbackTestCase::DoRun(), ObjectVectorTraceConfigTestCase::DoRun(), Bug730TestCase::DoRun(), CsmaPacketSocketTestCase::DoRun(), FindPathTestCase::DoRun(), BasicFindTestCase::DoRun(), CsmaPingTestCase::DoRun(), RecordHeaderTestCase::DoRun(), SearchAttributesOfParentObjectsTestCase::DoRun(), TwoBridgeTest::DoRun(), SetChannelFrequencyTest::DoRun(), StringContextFindTestCase::DoRun(), HandoverPreparationInfoTestCase::DoRun(), FullyQualifiedFindTestCase::DoRun(), RandomVariableStreamAttributeTestCase::DoRun(), CsmaRawIpSocketTestCase::DoRun(), RrcConnectionReestablishmentRequestTestCase::DoRun(), RelativeFindTestCase::DoRun(), ObjectVectorAttributeTestCase::DoRun(), Ipv4DynamicGlobalRoutingTestCase::DoRun(), RrcConnectionReestablishmentTestCase::DoRun(), AlternateFindTestCase::DoRun(), CsmaStarTestCase::DoRun(), RrcConnectionReestablishmentCompleteTestCase::DoRun(), ObjectMapAttributeTestCase::DoRun(), RrcConnectionRejectTestCase::DoRun(), IntegerTraceSourceAttributeTestCase::DoRun(), ReadFileTestCase::DoRun(), MeasurementReportTestCase::DoRun(), Bug2222TestCase::DoRun(), IntegerTraceSourceTestCase::DoRun(), DiffTestCase::DoRun(), TracedCallbackTestCase::DoRun(), PointerAttributeTestCase::DoRun(), CallbackValueTestCase::DoRun(), LteHandoverTargetTestCase::DoTeardown(), LteUeMeasurementsPiecewiseTestCase1::DoTeardown(), LteUeMeasurementsPiecewiseTestCase2::DoTeardown(), LteUeMeasurementsHandoverTestCase::DoTeardown(), TcpLedbatToNewReno::ExecuteTest(), TcpBicIncrementTest::ExecuteTest(), TcpLedbatIncrementTest::ExecuteTest(), TcpBicDecrementTest::ExecuteTest(), TcpLedbatDecrementTest::ExecuteTest(), TcpZeroWindowTest::FinalChecks(), TcpRttEstimationTest::FinalChecks(), TcpRtoTest::FinalChecks(), TcpPktsAckedOpenTest::FinalChecks(), TcpFastRetrTest::FinalChecks(), TcpBytesInFlightTest::FinalChecks(), TcpDataSentCbTestCase::FinalChecks(), TcpTimeRtoTest::FinalChecks(), LteHandoverTargetTestCase::HandoverStartCallback(), TcpAdvertisedWindowTest::InvalidAwndCb(), TcpHeaderWithRFC793OptionTestCase::OneOptionAtTime(), TcpFastRetrTest::PktDropped(), TcpZeroWindowTest::ProcessedAck(), TcpFastRetrTest::ProcessedAck(), TcpRtoTest::ProcessedAck(), TcpFastRetrTest::RcvAck(), TcpRtoTest::RcvAck(), LteUeMeasurementsTestCase::RecvMeasurementReport(), LteUeMeasurementsPiecewiseTestCase1::RecvMeasurementReportCallback(), LteUeMeasurementsPiecewiseTestCase2::RecvMeasurementReportCallback(), LteUeMeasurementsHandoverTestCase::RecvMeasurementReportCallback(), SpectrumInterferenceTestCase::RetrieveTestResult(), TcpZeroWindowTest::Rx(), Ipv4PacketInfoTagTest::RxCb(), Ipv6PacketInfoTagTest::RxCb(), PowerRateAdaptationTest::TestAparf(), PbbTestCase::TestDeserialize(), PfifoFastQueueDiscDscpPrioritization::TestDscpValue(), TcpTxBufferTestCase::TestNewBlock(), TcpTxBufferTestCase::TestNextSeg(), PowerRateAdaptationTest::TestParf(), PowerRateAdaptationTest::TestRrpaa(), PbbTestCase::TestSerialize(), PfifoFastQueueDiscTosPrioritization::TestTosValue(), TcpRxBufferTestCase::TestUpdateSACKList(), TcpTxBufferTestCase::TestUpdateScoreboardWithCraftedSACK(), TcpZeroWindowTest::Tx(), SackPermittedTestCase::Tx(), TimestampTestCase::Tx(), TcpFastRetrTest::Tx(), WScalingTestCase::Tx(), TcpTimeRtoTest::Tx(), LteCqiGenerationTestCase::UlScheduling(), LteInterferenceTestCase::UlScheduling(), LteCqiGenerationDlPowerControlTestCase::UlScheduling(), TcpRttEstimationTest::UpdatedRttHistory(), and Ns3TcpCwndTestCase2::VerifyCwndRun().

#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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the expected value of the test.
[in]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 220 of file test.h.

Referenced by UanTest::DoPhyTests(), and Ns2MobilityHelperTest::WriteTrace().

#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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the expected value of the test.
[in]tolTolerance of the test.
[in]msgMessage that is output if the test does not pass.

Definition at line 373 of file test.h.

Referenced by TcpTimeRtoTest::AfterRTOExpired(), TimestampValueTestCase::Check(), ns3::int64x64::test::Int64x64ArithmeticTestCase::Check(), ns3::int64x64::test::Int64x64DoubleTestCase::Check(), ns3::int64x64::test::Int64x64InvertTestCase::CheckCase(), AnimationRemainingEnergyTestCase::CheckLogic(), LteFrAreaTestCase::DlDataRxStart(), SampleTestCase1::DoRun(), LiIonEnergyTestCase::DoRun(), TimeSimpleTestCase::DoRun(), OneIntegerTestCase::DoRun(), BasicEnergyHarvesterTestCase::DoRun(), RttEstimatorTestCase::DoRun(), LrWpanSpectrumValueHelperTestCase::DoRun(), ItuR1411LosPropagationLossModelTestCase::DoRun(), ItuR1411NlosOverRooftopPropagationLossModelTestCase::DoRun(), Kun2600MhzPropagationLossModelTestCase::DoRun(), OkumuraHataPropagationLossModelTestCase::DoRun(), OneIntegerAverageTestCase::DoRun(), BuildingsShadowingTestCase::DoRun(), BuildingsPathlossTestCase::DoRun(), UanTest::DoRun(), ns3::LenaDeactivateBearerTestCase::DoRun(), TcpHyblaIncrementTest::DoRun(), WifiErrorRateModelsTestCaseDsss::DoRun(), TvSpectrumTransmitterTestCase::DoRun(), LenaMimoTestCase::DoRun(), LenaHarqTestCase::DoRun(), LteEarfcnTestCase::DoRun(), LenaRrFfMacSchedulerTestCase::DoRun(), LenaDataPhyErrorModelTestCase::DoRun(), LenaPfFfMacSchedulerTestCase1::DoRun(), LenaTdBetFfMacSchedulerTestCase1::DoRun(), LenaTdMtFfMacSchedulerTestCase::DoRun(), LenaTtaFfMacSchedulerTestCase::DoRun(), LenaCqaFfMacSchedulerTestCase1::DoRun(), LenaFdMtFfMacSchedulerTestCase::DoRun(), LenaFdBetFfMacSchedulerTestCase1::DoRun(), LenaPssFfMacSchedulerTestCase1::DoRun(), LenaTdTbfqFfMacSchedulerTestCase1::DoRun(), LteInterferenceHardFrTestCase::DoRun(), LenaFdTbfqFfMacSchedulerTestCase1::DoRun(), LteLinkAdaptationTestCase::DoRun(), AcousticModemEnergyTestCase::DoRun(), SpectrumIdealPhyTestCase::DoRun(), LtePathlossModelSystemTestCase::DoRun(), LteEnbAntennaTestCase::DoRun(), LrWpanErrorModelTestCase::DoRun(), LteInterferenceTestCase::DoRun(), LteEarfcnDlTestCase::DoRun(), LteInterferenceStrictFrTestCase::DoRun(), LenaPfFfMacSchedulerTestCase2::DoRun(), LenaTdBetFfMacSchedulerTestCase2::DoRun(), LenaDlCtrlPhyErrorModelTestCase::DoRun(), LenaFdBetFfMacSchedulerTestCase2::DoRun(), LenaTdTbfqFfMacSchedulerTestCase2::DoRun(), TimeWithSignTestCase::DoRun(), FiveIntegersAverageTestCase::DoRun(), LenaPssFfMacSchedulerTestCase2::DoRun(), LenaCqaFfMacSchedulerTestCase2::DoRun(), LteDownlinkPowerControlTestCase::DoRun(), FiveIntegersTestCase::DoRun(), LenaFdTbfqFfMacSchedulerTestCase2::DoRun(), LteEarfcnUlTestCase::DoRun(), WifiErrorRateModelsTestCaseNist::DoRun(), FiveDoublesAverageTestCase::DoRun(), FiveDoublesTestCase::DoRun(), RandomVariableStreamConstantTestCase::DoRun(), RandomVariableStreamSequentialTestCase::DoRun(), RandomVariableStreamNormalTestCase::DoRun(), GeoToCartesianTestCase::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(), LteUplinkPowerControlTestCase::PucchTxPowerTrace(), LteUplinkPowerControlTestCase::PuschTxPowerTrace(), LteUeMeasurementsTestCase::ReportUeMeasurements(), LteUplinkPowerControlTestCase::SrsTxPowerTrace(), ProbeTestCase1::TraceSink(), TcpTimeRtoTest::Tx(), and LteFrAreaTestCase::UlDataRxStart().

#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:

"wrong snr (" << snr << ") in test");

is legal.

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

This function returns a boolean value.

Definition at line 466 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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the limit value of the test.
[in]msgMessage that is output if the test does not pass.

Definition at line 990 of file test.h.

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

#define NS_TEST_ASSERT_MSG_GT_OR_EQ (   actual,
  limit,
  msg 
)    NS_TEST_ASSERT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

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

Check to see if the actual value found in a test case is greater than or equal to 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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the limit value of the test.
[in]msgMessage that is output if the test does not pass.

Definition at line 1011 of file test.h.

Referenced by TcpSlowStartNormalTest::CWndTrace(), WifiAcMappingTest::DoRun(), and TcpFastRetrTest::ProcessedAck().

#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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the limit value of the test.
[in]msgMessage that is output if the test does not pass.

Definition at line 804 of file test.h.

Referenced by ManyUniformRandomVariablesOneGetValueCallTestCase::DoRun(), OneUniformRandomVariableManyGetValueCallsTestCase::DoRun(), BuildingsShadowingTestCase::DoRun(), TvHelperDistributionTestCase::DoRun(), RngUniformTestCase::DoRun(), RandomRoomPositionAllocatorTestCase::DoRun(), RandCartAroundGeoTestCase::DoRun(), OcbWifiMacTestCase::DoRun(), ns3::RlcAmStatusPduTestCase::DoRun(), RandomVariableStreamUniformTestCase::DoRun(), RngNormalTestCase::DoRun(), RngExponentialTestCase::DoRun(), RandomVariableStreamUniformAntitheticTestCase::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(), RandomVariableStreamEmpiricalTestCase::DoRun(), LteHandoverDelayTestCase::EnbHandoverEndOkCallback(), ProbeTestCase1::TraceSink(), and LteHandoverDelayTestCase::UeHandoverEndOkCallback().

#define NS_TEST_ASSERT_MSG_LT_OR_EQ (   actual,
  limit,
  msg 
)    NS_TEST_ASSERT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

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

Check to see if the actual value found in a test case is less than or equal to the limit value. If the actual value is lesser or equal 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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the limit value of the test.
[in]msgMessage that is output if the test does not pass.

Definition at line 825 of file test.h.

Referenced by TcpNewRenoCongAvoidNormalTest::Check(), TcpSlowStartNormalTest::CWndTrace(), and TcpHyblaIncrementTest::DoRun().

#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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the value that actual is tested against.
[in]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 617 of file test.h.

Referenced by LteX2HandoverTestCase::CheckConnected(), LteX2HandoverMeasuresTestCase::CheckConnected(), AbstractAnimationInterfaceTestCase::CheckFileExistence(), SwitchFlowTableTestCase::DoRun(), BufferTest::DoRun(), RocketfuelTopologyReaderTest::DoRun(), TcpHyblaIncrementTest::DoRun(), CollisionTestCase::DoRun(), LinkTest::DoRun(), CreateObjectTestCase::DoRun(), AggregateObjectTestCase::DoRun(), LanTest::DoRun(), DeprecatedAttributeTestCase::DoRun(), TwoLinkTest::DoRun(), AttributeTestCase< T >::DoRun(), ObjectFactoryTestCase::DoRun(), RandomVariableStreamConstantTestCase::DoRun(), TwoLanTest::DoRun(), FileHeaderTestCase::DoRun(), BridgeTest::DoRun(), RecordHeaderTestCase::DoRun(), TwoBridgeTest::DoRun(), RandomVariableStreamAttributeTestCase::DoRun(), ObjectVectorAttributeTestCase::DoRun(), ObjectMapAttributeTestCase::DoRun(), IntegerTraceSourceAttributeTestCase::DoRun(), IntegerTraceSourceTestCase::DoRun(), TracedCallbackTestCase::DoRun(), PointerAttributeTestCase::DoRun(), CallbackValueTestCase::DoRun(), and TcpRttEstimationTest::Tx().

#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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the expected value of the test.
[in]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 675 of file test.h.

Referenced by Ns2MobilityHelperTest::CheckInitialPositions().

#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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the expected value of the test.
[in]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 278 of file test.h.

Referenced by HashTestCase::Check(), ns3::int64x64::test::Int64x64HiLoTestCase::Check(), ns3::int64x64::test::Int64x64InputTestCase::Check(), ns3::int64x64::test::Int64x64Bug1786TestCase::Check(), TcFlowControlTestCase::CheckDeviceQueueStopped(), Ns2MobilityHelperTest::CheckInitialPositions(), TcFlowControlTestCase::CheckPacketsInDeviceQueue(), TcFlowControlTestCase::CheckPacketsInQueueDisc(), PacketTagListTest::CheckRef(), Bug772ChainTest::CheckResults(), 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(), RttEstimatorTestCase::CheckValues(), Ns2MobilityHelperTest::CourseChange(), WaypointMobilityModelNotifyTest::CourseChangeCallback(), WaypointMobilityModelAddWaypointTest::CourseChangeCallback(), HwmpReactiveRegressionTest::CreateDevices(), ns3::olsr::Bug780Test::CreateNodes(), ns3::olsr::TcRegressionTest::CreateNodes(), CoDelQueueDiscBasicDrop::Dequeue(), PacketTest::DoCheck(), SimulatorEventsTestCase::DoRun(), DropTailQueueTestCase::DoRun(), NetworkNumberAllocatorTestCase::DoRun(), NetworkNumber6AllocatorTestCase::DoRun(), EventGarbageCollectorTestCase::DoRun(), NetworkAllocatorHelperTestCase::DoRun(), HistogramTestCase::DoRun(), ns3::aodv::NeighborTest::DoRun(), RttEstimatorTestCase::DoRun(), TxDurationTest::DoRun(), ns3::olsr::Bug780Test::DoRun(), Ns3WimaxNetworkEntryTestCase::DoRun(), Ns3WimaxFragmentationTestCase::DoRun(), PacketSocketAppsTest::DoRun(), AmpduAggregationTest::DoRun(), TestEmptyOptionField::DoRun(), BufferTest::DoRun(), RocketfuelTopologyReaderTest::DoRun(), LrWpanEdTestCase::DoRun(), ns3::aodv::IdCacheTest::DoRun(), LrWpanCollisionTestCase::DoRun(), PtrTestCase::DoRun(), OlsrMprTestCase::DoRun(), ThreadedSimulatorEventsTestCase::DoRun(), DualStackTestCase::DoRun(), SixlowpanFragmentationTest::DoRun(), SixlowpanHc1ImplTest::DoRun(), Ipv6ForwardingTest::DoRun(), UdpSocketLoopbackTest::DoRun(), Ipv6RipngTest::DoRun(), PacketBufferingCaseA::DoRun(), Ipv4ForwardingTest::DoRun(), Ipv4RipTest::DoRun(), Ipv4StaticRoutingSlash32TestCase::DoRun(), SixlowpanIphcImplTest::DoRun(), DsrFsHeaderTest::DoRun(), Ipv6RawSocketImplTest::DoRun(), ChannelCoordinationTestCase::DoRun(), TcpTestCase::DoRun(), Ipv4HeaderTest::DoRun(), AddressAllocator6TestCase::DoRun(), AddressAllocatorHelperTestCase::DoRun(), Ipv4RawSocketImplTest::DoRun(), AddressAllocatorTestCase::DoRun(), LrWpanCcaTestCase::DoRun(), Ns3WimaxManagementConnectionsTestCase::DoRun(), DsdvTableTestCase::DoRun(), TestOptionWithoutAlignment::DoRun(), DsrRreqHeaderTest::DoRun(), Ipv4FragmentationTest::DoRun(), ns3::aodv::TypeHeaderTest::DoRun(), Udp6SocketLoopbackTest::DoRun(), Ipv6FragmentationTest::DoRun(), CoDelQueueDiscBasicEnqueueDequeue::DoRun(), ResetAllocatorHelperTestCase::DoRun(), NetworkAndAddress6TestCase::DoRun(), NetworkAndAddressTestCase::DoRun(), ns3::aodv::RreqHeaderTest::DoRun(), DsrRrepHeaderTest::DoRun(), PacketBufferingCaseB::DoRun(), TestOptionWithAlignment::DoRun(), ExampleAddress6GeneratorTestCase::DoRun(), ns3::aodv::RrepHeaderTest::DoRun(), DsrSRHeaderTest::DoRun(), QosUtilsIsOldPacketTest::DoRun(), ExampleAddressGeneratorTestCase::DoRun(), UdpSocketImplTest::DoRun(), PeerLinkFrameStartTest::DoRun(), TestFulfilledAlignment::DoRun(), AddressCollision6TestCase::DoRun(), ns3::aodv::RrepAckHeaderTest::DoRun(), CtrlBAckResponseHeaderTest::DoRun(), DsrRerrHeaderTest::DoRun(), TwoLevelAggregationTest::DoRun(), CoDelQueueDiscBasicOverflow::DoRun(), AddressCollisionTestCase::DoRun(), ns3::aodv::RerrHeaderTest::DoRun(), Ipv4RipCountToInfinityTest::DoRun(), Ipv6RipngCountToInfinityTest::DoRun(), DsrAckReqHeaderTest::DoRun(), PacketMetadataTest::DoRun(), ns3::aodv::QueueEntryTest::DoRun(), DsrAckHeaderTest::DoRun(), ns3::aodv::AodvRqueueTest::DoRun(), DsrCacheEntryTest::DoRun(), CoDelQueueDiscControlLawTest::DoRun(), PacketTest::DoRun(), DsrSendBuffTest::DoRun(), CoDelQueueDiscBasicDrop::DoRun(), Udp6SocketImplTest::DoRun(), ns3::aodv::AodvRtableEntryTest::DoRun(), Ipv6RipngSplitHorizonStrategyTest::DoRun(), Ipv4RipSplitHorizonStrategyTest::DoRun(), DsrRreqTableTest::DoRun(), ChannelAccessTestCase::DoRun(), ns3::aodv::AodvRtableTest::DoRun(), PacketTagListTest::DoRun(), DiffTestCase::DoRun(), Ipv4GlobalRoutingSlash32TestCase::DoRun(), SixlowpanHc1ImplTest::DoSendData(), Ipv4StaticRoutingSlash32TestCase::DoSendData(), Ipv6ForwardingTest::DoSendData(), Ipv6RipngTest::DoSendData(), SixlowpanIphcImplTest::DoSendData(), Ipv4ForwardingTest::DoSendData(), Ipv4RipTest::DoSendData(), Ipv4RawSocketImplTest::DoSendData(), Ipv6RawSocketImplTest::DoSendData(), Ipv4PacketInfoTagTest::DoSendData(), Ipv6PacketInfoTagTest::DoSendData(), UdpSocketImplTest::DoSendData(), Ipv4RipCountToInfinityTest::DoSendData(), Ipv6RipngCountToInfinityTest::DoSendData(), Ipv4GlobalRoutingSlash32TestCase::DoSendData(), Ipv4RawSocketImplTest::DoSendData_IpHdr(), Ipv4HeaderTest::DoSendData_IpHdr_Dscp(), UdpSocketImplTest::DoSendDataTo(), Udp6SocketImplTest::DoSendDataTo(), DcfManagerTest::EndTest(), UdpSocketImplTest::GetPriority(), Ns3TcpStateTestCase::Ipv4L3Tx(), Ns3TcpLossTestCase::Ipv4L3Tx(), Ns3TcpInteroperabilityTestCase::Ipv4L3Tx(), DcfManagerTest::NotifyAccessGranted(), ChannelCoordinationTestCase::NotifyCchStartNow(), DcfManagerTest::NotifyChannelSwitching(), DcfManagerTest::NotifyCollision(), ChannelCoordinationTestCase::NotifyGuardStartNow(), DcfManagerTest::NotifyInternalCollision(), ChannelCoordinationTestCase::NotifySchStartNow(), CoDelQueueDiscBasicEnqueueDequeue::QueueTestSize(), CoDelQueueDiscBasicOverflow::QueueTestSize(), CoDelQueueDiscBasicDrop::QueueTestSize(), ChannelAccessTestCase::Receive(), Ipv6RawSocketImplTest::ReceivePkt2(), Ipv6RipngSplitHorizonStrategyTest::ReceivePktProbe(), Ipv4RipSplitHorizonStrategyTest::ReceivePktProbe(), ns3::olsr::HelloRegressionTest::ReceivePktProbeA(), ns3::olsr::TcRegressionTest::ReceivePktProbeA(), ns3::olsr::HelloRegressionTest::ReceivePktProbeB(), ns3::olsr::TcRegressionTest::ReceivePktProbeB(), ns3::olsr::TcRegressionTest::ReceivePktProbeC(), AredQueueDiscTestCase::RunAredDiscTest(), PieQueueDiscTestCase::RunPieTest(), RedQueueDiscTestCase::RunRedTest(), ChannelRoutingTestCase::SendIp(), ChannelRoutingTestCase::SendWsa(), ChannelRoutingTestCase::SendWsmp(), TcpTestCase::ServerHandleRecv(), TcpTestCase::ServerHandleSend(), TcpTestCase::SetupDefaultSim(), TcpTestCase::SetupDefaultSim6(), TcpTestCase::SourceHandleRecv(), TcpTestCase::SourceHandleSend(), ChannelAccessTestCase::TestAlternating(), ChannelAccessTestCase::TestAlternatingAfter(), ChannelAccessTestCase::TestContinuous(), ChannelAccessTestCase::TestContinuousAfter(), TcpOptionWSTestCase::TestDeserialize(), TcpOptionTSTestCase::TestDeserialize(), FlameRtableTest::TestExpire(), HwmpRtableTest::TestExpire(), ChannelAccessTestCase::TestExtended(), ChannelAccessTestCase::TestExtendedAfter(), ChannelCoordinationTestCase::TestIntervalAfter(), FlameRtableTest::TestLookup(), HwmpRtableTest::TestLookup(), WaypointInitialPositionIsWaypoint::TestNumWaypoints(), HwmpRtableTest::TestPrecursorFind(), TcpOptionWSTestCase::TestSerialize(), and TcpOptionTSTestCase::TestSerialize().

#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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the expected value of the test.
[in]tolTolerance of the test.
[in]msgMessage that is output if the test does not pass.

Definition at line 558 of file test.h.

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

#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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the limit value of the test.
[in]msgMessage that is output if the test does not pass.

Definition at line 1083 of file test.h.

Referenced by AnnexC_TestCase::Receive(), PieQueueDiscTestCase::RunPieTest(), and RedQueueDiscTestCase::RunRedTest().

#define NS_TEST_EXPECT_MSG_GT_OR_EQ (   actual,
  limit,
  msg 
)    NS_TEST_EXPECT_MSG_GT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

Test that an actual value is greater than or equal to limit and report if not.

Check to see if the actual value found in a test case is greater than or equal to 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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the limit value of the test.
[in]msgMessage that is output if the test does not pass.

Definition at line 1104 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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the limit value of the test.
[in]msgMessage that is output if the test does not pass.

Definition at line 896 of file test.h.

Referenced by Ns2MobilityHelperTest::CourseChange(), CosineAntennaModelTestCase::DoRun(), ParabolicAntennaModelTestCase::DoRun(), LrWpanAckTestCase::DoRun(), AnnexC_TestCase::Receive(), AredQueueDiscTestCase::RunAredDiscTest(), PieQueueDiscTestCase::RunPieTest(), and RedQueueDiscTestCase::RunRedTest().

#define NS_TEST_EXPECT_MSG_LT_OR_EQ (   actual,
  limit,
  msg 
)    NS_TEST_EXPECT_MSG_LT_OR_EQ_INTERNAL (actual, limit, msg, __FILE__, __LINE__)

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

Check to see if the actual value found in a test case is less than or equal to the limit value. If the actual value is lesser or equal 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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the limit value of the test.
[in]msgMessage that is output if the test does not pass.

Definition at line 917 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
[in]actualExpression for the actual value found during the test.
[in]limitExpression for the value that actual is tested against.
[in]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 732 of file test.h.

Referenced by PacketTest::DoCheck(), LteUplinkDataSinrTestCase::DoRun(), Ipv4FragmentationTest::DoRun(), Ipv6FragmentationTest::DoRun(), AredQueueDiscTestCase::RunAredDiscTest(), PieQueueDiscTestCase::RunPieTest(), RedQueueDiscTestCase::RunRedTest(), and UdpSocketImplTest::SentPkt().

Enumeration Type Documentation

How long the test takes to execute.

Enumerator
QUICK 

Fast test.

EXTENSIVE 

Medium length test.

TAKES_FOREVER 

Very long running test.

Definition at line 1151 of file test.h.

Type of test.

Enumerator
ALL 
BVT 

This test suite implements a Build Verification Test.

UNIT 

This test suite implements a Unit Test.

SYSTEM 

This test suite implements a System Test.

EXAMPLE 

This test suite implements an Example Test.

PERFORMANCE 

This test suite implements a Performance Test.

Definition at line 1340 of file test.h.

Function Documentation

bool ns3::TestDoubleIsEqual ( const double  a,
const double  b,
const double  epsilon = std::numeric_limits< double >::epsilon() 
)

Compare two double precision floating point numbers and declare them equal if they are within some epsilon of each other.

Approximate comparison of floating point numbers near equality is trickier than one may expect and is well-discussed in the literature. Basic strategies revolve around a suggestion by Knuth to compare the floating point numbers as binary integers, supplying a maximum difference between them . This max difference is specified in Units in the Last Place (ulps) or a floating point epsilon.

This routine is based on the GNU Scientific Library function gsl_fcmp.

Parameters
[in]aThe first of double precision floating point numbers to compare
[in]bThe second of double precision floating point numbers to compare
[in]epsilonThe tolerance to use in the comparison.
Returns
Returns true if the doubles are equal to a precision defined by epsilon

Definition at line 44 of file test.cc.

References max, and NS_LOG_FUNCTION.