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 RrcHeaderTestCase::AssertEqualRadioResourceConfigDedicated(), ns3::TcpBytesInFlightTest::BytesInFlightTrace(), ns3::int64x64::test::Int64x64Bug455TestCase::Check(), ns3::int64x64::test::Int64x64Bug863TestCase::Check(), ns3::int64x64::test::Int64x64CompareTestCase::Check(), LteX2HandoverTestCase::CheckConnected(), LteRrcConnectionEstablishmentTestCase::CheckConnected(), LteX2HandoverMeasuresTestCase::CheckConnected(), ns3::TcpHeaderWithRFC793OptionTestCase::CheckCorrectDeserialize(), AnimationInterfaceTestCase::CheckLogic(), AnimationRemainingEnergyTestCase::CheckLogic(), ns3::TcpHeaderWithRFC793OptionTestCase::CheckNoPadding(), LteRrcConnectionEstablishmentTestCase::CheckNotConnected(), LteCellSelectionTestCase::CheckPoint(), TracedValueCallbackTestCase::CheckType(), ns3::TcpFastRetrTest::CongStateTrace(), PeerManagementProtocolRegressionTest::CreateDevices(), Bug772ChainTest::CreateDevices(), HwmpProactiveRegressionTest::CreateDevices(), FlameRegressionTest::CreateDevices(), HwmpDoRfRegressionTest::CreateDevices(), HwmpSimplestRegressionTest::CreateDevices(), ChainRegressionTest::CreateDevices(), ns3::olsr::HelloRegressionTest::CreateNodes(), ns3::TcpSlowStartNormalTest::CWndTrace(), LteCqiGenerationTestCase::DlScheduling(), LteInterferenceTestCase::DlScheduling(), LteLinkAdaptationTestCase::DlScheduling(), LtePathlossModelSystemTestCase::DlScheduling(), LteCqiGenerationDlPowerControlTestCase::DlScheduling(), LteRlcUmTransmitterTestCase::DoCheckDataReceived(), LteRlcAmTransmitterTestCase::DoCheckDataReceived(), ns3::LenaDeactivateBearerTestCase::DoRun(), WatchdogTestCase::DoRun(), Ipv6AddressTestCase1::DoRun(), TypeTraitsTestCase::DoRun(), BasicTracedCallbackTestCase::DoRun(), OlsrEmfTestCase::DoRun(), BuildProfileTestCase::DoRun(), BufferTest::DoRun(), SampleTestCase1::DoRun(), GlobalValueTestCase::DoRun(), DsaRequestTestCase::DoRun(), FlameHeaderTest::DoRun(), IpAddressHelperTestCasev6::DoRun(), WaveformGeneratorTestCase::DoRun(), MeshHeaderTest::DoRun(), BasicCallbackTestCase::DoRun(), ns3::TcpHighSpeedIncrementTest::DoRun(), TimeSimpleTestCase::DoRun(), LrWpanPacketTestCase::DoRun(), ns3::TcpHyblaIncrementTest::DoRun(), BriteTopologyStructureTestCase::DoRun(), PfifoFastQueueDiscTosPrioritization::DoRun(), Ns3WimaxCsParamTlvTestCase::DoRun(), MeshInformationElementVectorBist::DoRun(), SwitchFlowTableTestCase::DoRun(), LteRlcUmE2eTestCase::DoRun(), ns3::TcpHeaderGetSetTestCase::DoRun(), EpsGtpuHeaderTestCase::DoRun(), ns3::TcpHtcpIncrementTest::DoRun(), FqCoDelQueueDiscNoSuitableFilter::DoRun(), ns3::TcpScalableIncrementTest::DoRun(), LrWpanErrorDistanceTestCase::DoRun(), UniqueTypeIdTestCase::DoRun(), UdpClientServerTestCase::DoRun(), Ipv4L3ProtocolTestCase::DoRun(), ns3::TcpVegasTest::DoRun(), ns3::TcpYeahIncrementTest::DoRun(), WifiAcMappingTest::DoRun(), SpectrumWifiPhyBasicTest::DoRun(), LteRlcAmE2eTestCase::DoRun(), Ipv6L3ProtocolTestCase::DoRun(), ns3::TcpIllinoisTest::DoRun(), Ns3TcpNoDelayTestCase::DoRun(), OlsrMidTestCase::DoRun(), TimerStateTestCase::DoRun(), Ns3TcpSocketTestCase1::DoRun(), LteDownlinkPowerControlSpectrumValueTestCase::DoRun(), DsdvHeaderTestCase::DoRun(), NscTcpLossTestCase1::DoRun(), Ipv4ListRoutingNegativeTestCase::DoRun(), WifiInterferenceTestCase::DoRun(), CsmaBridgeTestCase::DoRun(), Ipv6ListRoutingNegativeTestCase::DoRun(), ns3::aodv::LoopbackTestCase::DoRun(), RandomRoomPositionAllocatorTestCase::DoRun(), EpcTftClassifierTestCase::DoRun(), ErrorModelSimple::DoRun(), SpectrumIdealPhyTestCase::DoRun(), EpcS1uDlTestCase::DoRun(), LteNoisePsdTestCase::DoRun(), LteHardFrTestCase::DoRun(), OcbWifiMacTestCase::DoRun(), BasicAddTestCase::DoRun(), Ipv4ListRoutingPositiveTestCase::DoRun(), ns3::TcpHighSpeedDecrementTest::DoRun(), LteDownlinkPowerControlRrcConnectionReconfigurationTestCase::DoRun(), ns3::TcpVenoTest::DoRun(), LteEpcE2eDataTestCase::DoRun(), WriteModeCreateTestCase::DoRun(), Ipv6ListRoutingPositiveTestCase::DoRun(), ns3::RlcAmStatusPduTestCase::DoRun(), BuildingsHelperOneTestCase::DoRun(), FqCoDelQueueDiscIPFlowsSeparationAndPacketLimit::DoRun(), LteStrictFrTestCase::DoRun(), ns3::TcpScalableDecrementTest::DoRun(), DsdvTableTestCase::DoRun(), CommandLineBooleanTestCase::DoRun(), LteTxPsdTestCase::DoRun(), PfifoFastQueueDiscDscpPrioritization::DoRun(), LinkTest::DoRun(), UdpTraceClientServerTestCase::DoRun(), CollisionTestCase::DoRun(), RandomVariableStreamUniformTestCase::DoRun(), CreateObjectTestCase::DoRun(), Ns3WimaxSfTlvTestCase::DoRun(), StringContextAddTestCase::DoRun(), SameRoomPositionAllocatorTestCase::DoRun(), BurstErrorModelSimple::DoRun(), Ns3TcpSocketTestCase2::DoRun(), CommandLineIntTestCase::DoRun(), OlsrHelloTestCase::DoRun(), LteStrictFrAreaTestCase::DoRun(), NscTcpLossTestCase2::DoRun(), CsmaBroadcastTestCase::DoRun(), MakeCallbackTestCase::DoRun(), FqCoDelQueueDiscDeficit::DoRun(), LteSoftFrAreaTestCase::DoRun(), LteSoftFfrAreaTestCase::DoRun(), IpAddressHelperTestCasev4::DoRun(), PacketLossCounterTestCase::DoRun(), LteEnhancedFfrAreaTestCase::DoRun(), CommandLineUnsignedIntTestCase::DoRun(), PfifoFastQueueDiscOverflow::DoRun(), AggregateObjectTestCase::DoRun(), AcousticModemEnergyDepletionTestCase::DoRun(), LanTest::DoRun(), Ns3TcpCwndTestCase1::DoRun(), LteDistributedFfrAreaTestCase::DoRun(), ReadModeCreateTestCase::DoRun(), FullyQualifiedAddTestCase::DoRun(), SpectrumWifiPhyListenerTest::DoRun(), RootNamespaceConfigTestCase::DoRun(), ns3::TcpYeahDecrementTest::DoRun(), OlsrTcTestCase::DoRun(), CommandLineStringTestCase::DoRun(), Ns2MobilityHelperTest::DoRun(), RrcConnectionRequestTestCase::DoRun(), OlsrHnaTestCase::DoRun(), UnderRootNamespaceConfigTestCase::DoRun(), PfifoFastQueueDiscNoPriority::DoRun(), EpcS1uUlTestCase::DoRun(), DeprecatedAttributeTestCase::DoRun(), TwoLinkTest::DoRun(), RelativeAddTestCase::DoRun(), RandomVariableStreamUniformAntitheticTestCase::DoRun(), CsmaMulticastTestCase::DoRun(), MakeBoundCallbackTestCase::DoRun(), CoDelQueueDiscNewtonStepTest::DoRun(), RrcConnectionSetupTestCase::DoRun(), FqCoDelQueueDiscTCPFlowsSeparation::DoRun(), ns3::TcpHeaderFlagsToString::DoRun(), BasicRenameTestCase::DoRun(), RrcConnectionSetupCompleteTestCase::DoRun(), AttributeTestCase< T >::DoRun(), MatrixPropagationLossModelTestCase::DoRun(), ObjectFactoryTestCase::DoRun(), ObjectVectorConfigTestCase::DoRun(), DcfImmediateAccessBroadcastTestCase::DoRun(), TwoLanTest::DoRun(), Ns3TcpCwndTestCase2::DoRun(), RrcConnectionReconfigurationCompleteTestCase::DoRun(), StringContextRenameTestCase::DoRun(), FqCoDelQueueDiscUDPFlowsSeparation::DoRun(), FileHeaderTestCase::DoRun(), CsmaOneSubnetTestCase::DoRun(), RrcConnectionReconfigurationTestCase::DoRun(), FullyQualifiedRenameTestCase::DoRun(), BridgeTest::DoRun(), Bug730TestCase::DoRun(), RelativeRenameTestCase::DoRun(), NullifyCallbackTestCase::DoRun(), ObjectVectorTraceConfigTestCase::DoRun(), CsmaPacketSocketTestCase::DoRun(), FindPathTestCase::DoRun(), BasicFindTestCase::DoRun(), SetChannelFrequencyTest::DoRun(), TwoBridgeTest::DoRun(), HandoverPreparationInfoTestCase::DoRun(), RecordHeaderTestCase::DoRun(), CsmaPingTestCase::DoRun(), SearchAttributesOfParentObjectsTestCase::DoRun(), StringContextFindTestCase::DoRun(), RrcConnectionReestablishmentRequestTestCase::DoRun(), FullyQualifiedFindTestCase::DoRun(), RrcConnectionReestablishmentTestCase::DoRun(), CsmaRawIpSocketTestCase::DoRun(), RandomVariableStreamAttributeTestCase::DoRun(), Ipv4DynamicGlobalRoutingTestCase::DoRun(), RelativeFindTestCase::DoRun(), RrcConnectionReestablishmentCompleteTestCase::DoRun(), ObjectVectorAttributeTestCase::DoRun(), RrcConnectionRejectTestCase::DoRun(), AlternateFindTestCase::DoRun(), CsmaStarTestCase::DoRun(), ObjectMapAttributeTestCase::DoRun(), MeasurementReportTestCase::DoRun(), ReadFileTestCase::DoRun(), IntegerTraceSourceAttributeTestCase::DoRun(), Bug2222TestCase::DoRun(), IntegerTraceSourceTestCase::DoRun(), DiffTestCase::DoRun(), TracedCallbackTestCase::DoRun(), PointerAttributeTestCase::DoRun(), CallbackValueTestCase::DoRun(), LteHandoverTargetTestCase::DoTeardown(), LteUeMeasurementsPiecewiseTestCase1::DoTeardown(), LteUeMeasurementsPiecewiseTestCase2::DoTeardown(), LteUeMeasurementsHandoverTestCase::DoTeardown(), ns3::TcpBicIncrementTest::ExecuteTest(), ns3::TcpBicDecrementTest::ExecuteTest(), ns3::TcpZeroWindowTest::FinalChecks(), ns3::TcpRtoTest::FinalChecks(), ns3::TcpRttEstimationTest::FinalChecks(), ns3::TcpBytesInFlightTest::FinalChecks(), ns3::TcpPktsAckedOpenTest::FinalChecks(), ns3::TcpFastRetrTest::FinalChecks(), ns3::TcpTimeRtoTest::FinalChecks(), ns3::TcpDataSentCbTestCase::FinalChecks(), LteHandoverTargetTestCase::HandoverStartCallback(), ns3::TcpHeaderWithRFC793OptionTestCase::OneOptionAtTime(), ns3::TcpFastRetrTest::PktDropped(), ns3::TcpZeroWindowTest::ProcessedAck(), ns3::TcpRtoTest::ProcessedAck(), ns3::TcpFastRetrTest::ProcessedAck(), ns3::TcpRtoTest::RcvAck(), ns3::TcpFastRetrTest::RcvAck(), LteUeMeasurementsTestCase::RecvMeasurementReport(), LteUeMeasurementsPiecewiseTestCase1::RecvMeasurementReportCallback(), LteUeMeasurementsPiecewiseTestCase2::RecvMeasurementReportCallback(), LteUeMeasurementsHandoverTestCase::RecvMeasurementReportCallback(), SpectrumInterferenceTestCase::RetrieveTestResult(), ns3::TcpRtoTest::RTOExpired(), ns3::TcpTimeRtoTest::RTOExpired(), ns3::TcpZeroWindowTest::Rx(), Ipv6PacketInfoTagTest::RxCb(), Ipv4PacketInfoTagTest::RxCb(), PowerRateAdaptationTest::TestAparf(), PbbTestCase::TestDeserialize(), PfifoFastQueueDiscDscpPrioritization::TestDscpValue(), PowerRateAdaptationTest::TestParf(), PbbTestCase::TestSerialize(), PfifoFastQueueDiscTosPrioritization::TestTosValue(), ns3::TcpZeroWindowTest::Tx(), ns3::TimestampTestCase::Tx(), ns3::WScalingTestCase::Tx(), ns3::TcpFastRetrTest::Tx(), ns3::TcpTimeRtoTest::Tx(), LteCqiGenerationTestCase::UlScheduling(), LteInterferenceTestCase::UlScheduling(), LteCqiGenerationDlPowerControlTestCase::UlScheduling(), ns3::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 ns3::TimestampValueTestCase::Check(), ns3::int64x64::test::Int64x64ArithmeticTestCase::Check(), ns3::int64x64::test::Int64x64DoubleTestCase::Check(), ns3::int64x64::test::Int64x64InvertTestCase::CheckCase(), AnimationRemainingEnergyTestCase::CheckLogic(), LteFrAreaTestCase::DlDataRxStart(), ns3::LenaDeactivateBearerTestCase::DoRun(), SampleTestCase1::DoRun(), RttEstimatorTestCase::DoRun(), LrWpanSpectrumValueHelperTestCase::DoRun(), LiIonEnergyTestCase::DoRun(), TimeSimpleTestCase::DoRun(), ns3::TcpHyblaIncrementTest::DoRun(), OneIntegerAverageTestCase::DoRun(), OneIntegerTestCase::DoRun(), LenaMimoTestCase::DoRun(), BasicEnergyHarvesterTestCase::DoRun(), UanTest::DoRun(), ItuR1411LosPropagationLossModelTestCase::DoRun(), ItuR1411NlosOverRooftopPropagationLossModelTestCase::DoRun(), Kun2600MhzPropagationLossModelTestCase::DoRun(), OkumuraHataPropagationLossModelTestCase::DoRun(), LteEarfcnTestCase::DoRun(), LenaHarqTestCase::DoRun(), BuildingsShadowingTestCase::DoRun(), LenaRrFfMacSchedulerTestCase::DoRun(), BuildingsPathlossTestCase::DoRun(), LenaDataPhyErrorModelTestCase::DoRun(), LenaCqaFfMacSchedulerTestCase1::DoRun(), WifiErrorRateModelsTestCaseDsss::DoRun(), LteInterferenceHardFrTestCase::DoRun(), LenaPfFfMacSchedulerTestCase1::DoRun(), LenaPssFfMacSchedulerTestCase1::DoRun(), LenaTdBetFfMacSchedulerTestCase1::DoRun(), LenaTdMtFfMacSchedulerTestCase::DoRun(), LenaTdTbfqFfMacSchedulerTestCase1::DoRun(), LenaTtaFfMacSchedulerTestCase::DoRun(), LenaFdMtFfMacSchedulerTestCase::DoRun(), LenaFdTbfqFfMacSchedulerTestCase1::DoRun(), LenaFdBetFfMacSchedulerTestCase1::DoRun(), LteLinkAdaptationTestCase::DoRun(), AcousticModemEnergyTestCase::DoRun(), TvSpectrumTransmitterTestCase::DoRun(), LteInterferenceTestCase::DoRun(), LtePathlossModelSystemTestCase::DoRun(), LteEnbAntennaTestCase::DoRun(), LrWpanErrorModelTestCase::DoRun(), LteInterferenceStrictFrTestCase::DoRun(), LenaPfFfMacSchedulerTestCase2::DoRun(), LenaTdBetFfMacSchedulerTestCase2::DoRun(), LenaCqaFfMacSchedulerTestCase2::DoRun(), LenaFdBetFfMacSchedulerTestCase2::DoRun(), LenaPssFfMacSchedulerTestCase2::DoRun(), LenaTdTbfqFfMacSchedulerTestCase2::DoRun(), LteDownlinkPowerControlTestCase::DoRun(), LenaFdTbfqFfMacSchedulerTestCase2::DoRun(), LenaDlCtrlPhyErrorModelTestCase::DoRun(), LteEarfcnDlTestCase::DoRun(), SpectrumIdealPhyTestCase::DoRun(), LteEarfcnUlTestCase::DoRun(), FiveIntegersAverageTestCase::DoRun(), TimeWithSignTestCase::DoRun(), FiveIntegersTestCase::DoRun(), WifiErrorRateModelsTestCaseNist::DoRun(), FiveDoublesAverageTestCase::DoRun(), FiveDoublesTestCase::DoRun(), RandomVariableStreamConstantTestCase::DoRun(), RandomVariableStreamSequentialTestCase::DoRun(), GeoToCartesianTestCase::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(), LteUplinkPowerControlTestCase::PucchTxPowerTrace(), LteUplinkPowerControlTestCase::PuschTxPowerTrace(), LteUeMeasurementsTestCase::ReportUeMeasurements(), ns3::TcpTimeRtoTest::RTOExpired(), LteUplinkPowerControlTestCase::SrsTxPowerTrace(), ProbeTestCase1::TraceSink(), ns3::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 ns3::TcpSlowStartNormalTest::CWndTrace(), and ns3::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(), RandCartAroundGeoTestCase::DoRun(), RandomRoomPositionAllocatorTestCase::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 ns3::TcpNewRenoCongAvoidNormalTest::Check(), ns3::TcpSlowStartNormalTest::CWndTrace(), and ns3::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(), BufferTest::DoRun(), ns3::TcpHyblaIncrementTest::DoRun(), RocketfuelTopologyReaderTest::DoRun(), SwitchFlowTableTestCase::DoRun(), LinkTest::DoRun(), CollisionTestCase::DoRun(), CreateObjectTestCase::DoRun(), AggregateObjectTestCase::DoRun(), LanTest::DoRun(), DeprecatedAttributeTestCase::DoRun(), TwoLinkTest::DoRun(), AttributeTestCase< T >::DoRun(), ObjectFactoryTestCase::DoRun(), TwoLanTest::DoRun(), RandomVariableStreamConstantTestCase::DoRun(), FileHeaderTestCase::DoRun(), BridgeTest::DoRun(), TwoBridgeTest::DoRun(), RecordHeaderTestCase::DoRun(), RandomVariableStreamAttributeTestCase::DoRun(), ObjectVectorAttributeTestCase::DoRun(), ObjectMapAttributeTestCase::DoRun(), IntegerTraceSourceAttributeTestCase::DoRun(), IntegerTraceSourceTestCase::DoRun(), TracedCallbackTestCase::DoRun(), PointerAttributeTestCase::DoRun(), CallbackValueTestCase::DoRun(), and ns3::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(), Ns2MobilityHelperTest::CheckInitialPositions(), 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(), DropTailQueueTestCase::DoRun(), NetworkNumberAllocatorTestCase::DoRun(), NetworkNumber6AllocatorTestCase::DoRun(), HistogramTestCase::DoRun(), NetworkAllocatorHelperTestCase::DoRun(), SimulatorEventsTestCase::DoRun(), BufferTest::DoRun(), ns3::aodv::NeighborTest::DoRun(), RttEstimatorTestCase::DoRun(), EventGarbageCollectorTestCase::DoRun(), ns3::olsr::Bug780Test::DoRun(), PacketSocketAppsTest::DoRun(), TestEmptyOptionField::DoRun(), RocketfuelTopologyReaderTest::DoRun(), TxDurationTest::DoRun(), Ns3WimaxNetworkEntryTestCase::DoRun(), Ns3WimaxFragmentationTestCase::DoRun(), ns3::aodv::IdCacheTest::DoRun(), AmpduAggregationTest::DoRun(), LrWpanCollisionTestCase::DoRun(), LrWpanEdTestCase::DoRun(), OlsrMprTestCase::DoRun(), SixlowpanHc1ImplTest::DoRun(), SixlowpanIphcImplTest::DoRun(), ChannelCoordinationTestCase::DoRun(), Ipv4StaticRoutingSlash32TestCase::DoRun(), LrWpanCcaTestCase::DoRun(), Ipv6ForwardingTest::DoRun(), PtrTestCase::DoRun(), Ipv6RipngTest::DoRun(), DualStackTestCase::DoRun(), Ipv4RipTest::DoRun(), SixlowpanFragmentationTest::DoRun(), ThreadedSimulatorEventsTestCase::DoRun(), DsrFsHeaderTest::DoRun(), Ipv6RawSocketImplTest::DoRun(), Ipv4RawSocketImplTest::DoRun(), TcpTestCase::DoRun(), UdpSocketLoopbackTest::DoRun(), PacketBufferingCaseA::DoRun(), AddressAllocator6TestCase::DoRun(), AddressAllocatorHelperTestCase::DoRun(), AddressAllocatorTestCase::DoRun(), Ipv4ForwardingTest::DoRun(), Ipv4HeaderTest::DoRun(), TestOptionWithoutAlignment::DoRun(), CoDelQueueDiscBasicEnqueueDequeue::DoRun(), Ipv4FragmentationTest::DoRun(), DsrRreqHeaderTest::DoRun(), Ns3WimaxManagementConnectionsTestCase::DoRun(), ns3::aodv::TypeHeaderTest::DoRun(), DsdvTableTestCase::DoRun(), Udp6SocketLoopbackTest::DoRun(), ResetAllocatorHelperTestCase::DoRun(), NetworkAndAddress6TestCase::DoRun(), ns3::aodv::RreqHeaderTest::DoRun(), NetworkAndAddressTestCase::DoRun(), Ipv6FragmentationTest::DoRun(), DsrRrepHeaderTest::DoRun(), TestOptionWithAlignment::DoRun(), PacketBufferingCaseB::DoRun(), UdpSocketImplTest::DoRun(), ExampleAddress6GeneratorTestCase::DoRun(), ns3::aodv::RrepHeaderTest::DoRun(), DsrSRHeaderTest::DoRun(), TestFulfilledAlignment::DoRun(), ExampleAddressGeneratorTestCase::DoRun(), QosUtilsIsOldPacketTest::DoRun(), PeerLinkFrameStartTest::DoRun(), CoDelQueueDiscBasicOverflow::DoRun(), AddressCollision6TestCase::DoRun(), ns3::aodv::RrepAckHeaderTest::DoRun(), DsrRerrHeaderTest::DoRun(), ns3::aodv::RerrHeaderTest::DoRun(), CtrlBAckResponseHeaderTest::DoRun(), AddressCollisionTestCase::DoRun(), TwoLevelAggregationTest::DoRun(), PacketMetadataTest::DoRun(), Ipv6RipngCountToInfinityTest::DoRun(), Ipv4RipCountToInfinityTest::DoRun(), DsrAckReqHeaderTest::DoRun(), ns3::aodv::QueueEntryTest::DoRun(), PacketTest::DoRun(), ns3::aodv::AodvRqueueTest::DoRun(), DsrAckHeaderTest::DoRun(), DsrCacheEntryTest::DoRun(), CoDelQueueDiscControlLawTest::DoRun(), CoDelQueueDiscBasicDrop::DoRun(), DsrSendBuffTest::DoRun(), ns3::aodv::AodvRtableEntryTest::DoRun(), Udp6SocketImplTest::DoRun(), Ipv6RipngSplitHorizonStrategyTest::DoRun(), Ipv4RipSplitHorizonStrategyTest::DoRun(), ChannelAccessTestCase::DoRun(), ns3::aodv::AodvRtableTest::DoRun(), DsrRreqTableTest::DoRun(), PacketTagListTest::DoRun(), Ipv4GlobalRoutingSlash32TestCase::DoRun(), DiffTestCase::DoRun(), SixlowpanIphcImplTest::DoSendData(), SixlowpanHc1ImplTest::DoSendData(), Ipv4StaticRoutingSlash32TestCase::DoSendData(), Ipv6ForwardingTest::DoSendData(), Ipv6RipngTest::DoSendData(), Ipv4RipTest::DoSendData(), Ipv4RawSocketImplTest::DoSendData(), Ipv6RawSocketImplTest::DoSendData(), Ipv4ForwardingTest::DoSendData(), Ipv6PacketInfoTagTest::DoSendData(), Ipv4PacketInfoTagTest::DoSendData(), UdpSocketImplTest::DoSendData(), Ipv6RipngCountToInfinityTest::DoSendData(), Ipv4RipCountToInfinityTest::DoSendData(), Udp6SocketImplTest::DoSendData(), Ipv4GlobalRoutingSlash32TestCase::DoSendData(), Ipv4RawSocketImplTest::DoSendData_IpHdr(), Ipv4HeaderTest::DoSendData_IpHdr_Dscp(), UdpSocketImplTest::DoSendDataTo(), DcfManagerTest::EndTest(), UdpSocketImplTest::GetPriority(), Ns3TcpLossTestCase::Ipv4L3Tx(), Ns3TcpStateTestCase::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(), AdaptiveRedQueueDiscTestCase::RunAdaptiveRedDiscTest(), AutoRedQueueDiscTestCase::RunAutoRedDiscTest(), 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(), ns3::TcpOptionWSTestCase::TestDeserialize(), ns3::TcpOptionTSTestCase::TestDeserialize(), FlameRtableTest::TestExpire(), HwmpRtableTest::TestExpire(), ChannelAccessTestCase::TestExtended(), ChannelAccessTestCase::TestExtendedAfter(), ChannelCoordinationTestCase::TestIntervalAfter(), FlameRtableTest::TestLookup(), HwmpRtableTest::TestLookup(), WaypointInitialPositionIsWaypoint::TestNumWaypoints(), HwmpRtableTest::TestPrecursorFind(), ns3::TcpOptionWSTestCase::TestSerialize(), and ns3::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(), HistogramTestCase::DoRun(), OneVectorConstructorTestCase::DoRun(), DegreesToRadiansTestCase::DoRun(), IsotropicAntennaModelTestCase::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(), AutoRedQueueDiscTestCase::RunAutoRedDiscTest(), 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(), and AdaptiveRedQueueDiscTestCase::RunAdaptiveRedDiscTest().

#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(), AutoRedQueueDiscTestCase::RunAutoRedDiscTest(), 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.