A Discrete-Event Network Simulator
API
ns3::tests::EnvVarTestCase Class Reference

EnvironmentVariable tests. More...

+ Inheritance diagram for ns3::tests::EnvVarTestCase:
+ Collaboration diagram for ns3::tests::EnvVarTestCase:

Public Member Functions

 EnvVarTestCase ()
 Constructor. More...
 
 ~EnvVarTestCase () override
 Destructor. More...
 
- Public Member Functions inherited from ns3::TestCase
 TestCase (const TestCase &)=delete
 
virtual ~TestCase ()
 Destructor. More...
 
std::string GetName () const
 
TestCaseoperator= (const TestCase &)=delete
 

Private Types

using KeyFoundType = EnvironmentVariable::KeyFoundType
 The return type from EnvironmentVariable::Get() More...
 
using KeyValueStore = EnvironmentVariable::Dictionary::KeyValueStore
 The key,value store. More...
 

Private Member Functions

void Check (const std::string &where, const std::string &envValue, KeyValueStore expect)
 Read envValue and check that it contains only the key,value pairs from expect. More...
 
void CheckGet (const std::string &where, const std::string &key, KeyFoundType expect)
 Check the result from a Get. More...
 
void DoRun () override
 Run the tests. More...
 
void SetAndCheck (const std::string &where, const std::string &envValue, KeyValueStore expect)
 Set and Check the variable. More...
 
void SetCheckAndGet (const std::string &where, const std::string &envValue, KeyValueStore expectDict, const std::string &key, KeyFoundType expectValue)
 Set, Check, and Get a variable. More...
 
void SetVariable (const std::string &where, const std::string &value)
 Set the test environment variable. More...
 
void UnsetVariable (const std::string &where)
 Unset the test environment variable. More...
 

Private Attributes

const std::string m_delimiter {"|"}
 Always use a non-default delimiter. More...
 
const std::string m_variable {"NS_ENVVAR_TEST"}
 Test environment variable name. More...
 

Additional Inherited Members

- Public Types inherited from ns3::TestCase
enum  TestDuration { QUICK = 1 , EXTENSIVE = 2 , TAKES_FOREVER = 3 }
 How long the test takes to execute. More...
 
- Protected Member Functions inherited from ns3::TestCase
 TestCase (std::string name)
 Constructor. More...
 
void AddTestCase (TestCase *testCase, TestDuration duration=QUICK)
 Add an individual child TestCase to this test suite. More...
 
TestCaseGetParent () const
 Get the parent of this TestCase. More...
 
bool IsStatusFailure () const
 Check if any tests failed. More...
 
bool IsStatusSuccess () const
 Check if all tests passed. More...
 
void SetDataDir (std::string directory)
 Set the data directory where reference trace files can be found. More...
 
void ReportTestFailure (std::string cond, std::string actual, std::string limit, std::string message, std::string file, int32_t line)
 Log the failure of this TestCase. More...
 
bool MustAssertOnFailure () const
 Check if this run should assert on failure. More...
 
bool MustContinueOnFailure () const
 Check if this run should continue on failure. More...
 
std::string CreateDataDirFilename (std::string filename)
 Construct the full path to a file in the data directory. More...
 
std::string CreateTempDirFilename (std::string filename)
 Construct the full path to a file in a temporary directory. More...
 

Detailed Description

EnvironmentVariable tests.

Definition at line 47 of file environment-variable-test-suite.cc.

Member Typedef Documentation

◆ KeyFoundType

◆ KeyValueStore

Constructor & Destructor Documentation

◆ EnvVarTestCase()

ns3::tests::EnvVarTestCase::EnvVarTestCase ( )

Constructor.

Definition at line 126 of file environment-variable-test-suite.cc.

◆ ~EnvVarTestCase()

ns3::tests::EnvVarTestCase::~EnvVarTestCase ( )
override

Destructor.

Definition at line 131 of file environment-variable-test-suite.cc.

References UnsetVariable().

+ Here is the call graph for this function:

Member Function Documentation

◆ Check()

void ns3::tests::EnvVarTestCase::Check ( const std::string &  where,
const std::string &  envValue,
KeyValueStore  expect 
)
private

Read envValue and check that it contains only the key,value pairs from expect.

Parameters
whereThe test condition being checked.
envValueThe environment variable to parse and check.
expectThe set of key,values expected.

Definition at line 158 of file environment-variable-test-suite.cc.

References ns3::EnvironmentVariable::GetDictionary(), m_delimiter, m_variable, and NS_TEST_EXPECT_MSG_EQ.

Referenced by DoRun(), and SetAndCheck().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CheckGet()

void ns3::tests::EnvVarTestCase::CheckGet ( const std::string &  where,
const std::string &  key,
KeyFoundType  expect 
)
private

Check the result from a Get.

Parameters
whereThe test condition being checked.
keyThe key to check.
expectThe expected result.

Definition at line 223 of file environment-variable-test-suite.cc.

References ns3::EnvironmentVariable::Get(), m_delimiter, m_variable, and NS_TEST_EXPECT_MSG_EQ.

Referenced by DoRun(), and SetCheckAndGet().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoRun()

void ns3::tests::EnvVarTestCase::DoRun ( void  )
overrideprivatevirtual

Run the tests.

Implements ns3::TestCase.

Definition at line 247 of file environment-variable-test-suite.cc.

References Check(), CheckGet(), ns3::EnvironmentVariable::Get(), m_variable, NS_TEST_EXPECT_MSG_EQ, SetCheckAndGet(), and UnsetVariable().

+ Here is the call graph for this function:

◆ SetAndCheck()

void ns3::tests::EnvVarTestCase::SetAndCheck ( const std::string &  where,
const std::string &  envValue,
KeyValueStore  expect 
)
private

Set and Check the variable.

Parameters
whereThe test condition being checked.
envValueThe environment variable to parse and check.
expectThe set of key,values expected.

Definition at line 214 of file environment-variable-test-suite.cc.

References Check(), and SetVariable().

Referenced by SetCheckAndGet().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetCheckAndGet()

void ns3::tests::EnvVarTestCase::SetCheckAndGet ( const std::string &  where,
const std::string &  envValue,
KeyValueStore  expectDict,
const std::string &  key,
KeyFoundType  expectValue 
)
private

Set, Check, and Get a variable.

Parameters
whereThe test condition being checked.
envValueThe environment variable to parse and check.
expectDictThe set of key,values expected.
keyThe key to check.
expectValueThe expected result.

Definition at line 236 of file environment-variable-test-suite.cc.

References CheckGet(), and SetAndCheck().

Referenced by DoRun().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SetVariable()

void ns3::tests::EnvVarTestCase::SetVariable ( const std::string &  where,
const std::string &  value 
)
private

Set the test environment variable.

Parameters
whereThe test condition being checked.
valueThe value to set.

Definition at line 137 of file environment-variable-test-suite.cc.

References ns3::EnvironmentVariable::Clear(), m_variable, NS_TEST_EXPECT_MSG_EQ, NS_TEST_EXPECT_MSG_NE, and ns3::EnvironmentVariable::Set().

Referenced by SetAndCheck().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ UnsetVariable()

void ns3::tests::EnvVarTestCase::UnsetVariable ( const std::string &  where)
private

Unset the test environment variable.

Parameters
whereThe test condition being checked.

Definition at line 150 of file environment-variable-test-suite.cc.

References ns3::EnvironmentVariable::Clear(), NS_TEST_EXPECT_MSG_EQ, and ns3::EnvironmentVariable::Unset().

Referenced by ~EnvVarTestCase(), and DoRun().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ m_delimiter

const std::string ns3::tests::EnvVarTestCase::m_delimiter {"|"}
private

Always use a non-default delimiter.

Definition at line 119 of file environment-variable-test-suite.cc.

Referenced by Check(), and CheckGet().

◆ m_variable

const std::string ns3::tests::EnvVarTestCase::m_variable {"NS_ENVVAR_TEST"}
private

Test environment variable name.

Definition at line 122 of file environment-variable-test-suite.cc.

Referenced by Check(), CheckGet(), DoRun(), and SetVariable().


The documentation for this class was generated from the following file: