Public Member Functions | Protected Member Functions

ns3::TestCase Class Reference

A single test case. More...

#include <test.h>

Inheritance diagram for ns3::TestCase:
Inheritance graph
[legend]
Collaboration diagram for ns3::TestCase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TestCase (std::string name)
bool Run (void)
 Run this test case.
void SetVerbose (bool verbose)
 Set the verbosity of this test case.
void SetContinueOnFailure (bool continueOnFailure)
 Tell the test case whether or not to continue testing if an error is detected.
void SetName (std::string name)
 Set the name of this test case.
std::string GetName (void)
 Get the name of this test case.
void SetBaseDir (std::string dir)
 Set the base directory of the ns-3 distribution.
std::string GetBaseDir (void)
 Get the base directory of the ns-3 distribution.
void SetTempDir (std::string dir)
 Set the temporary file directory (where to write temporary files).
std::string GetTempDir (void)
 Get the temporary file directory .
std::string GetSourceDir (std::string file)
 Get the source directory of the current source file.
void SetStream (std::ofstream *ofs)
 Set the stream to which status and result messages will be written.
std::ofstream * GetStream (void)
 Get the stream to which status and result messages will be written.
void UpdateErrorStatus (bool error)
 Manually update the error status of this test case.
void SetErrorStatus (bool error)
 Manually set the error status of this test case.
bool GetErrorStatus (void)
 Get the error status of this test case.
bool ContinueOnFailure (void)
 Should test cases continue running in the presence of errors?
void ReportStart (void)
 Issue a test report than the test suite has started running.
void ReportCaseSuccess (void)
 Issue a test report than the test case has declared success.
void ReportCaseFailure (void)
 Issue a test report than the test case has declared failure.
void ReportTestFailure (std::string cond, std::string actual, std::string limit, std::string message, std::string file, int32_t line)
 Issue a test report than the test case has found an error and report the details.
void ReportEnd (void)
 Issue a test report than the test case has completed its run.

Protected Member Functions

virtual void DoReportStart (void)
virtual void DoReportCaseSuccess (void)
virtual void DoReportCaseFailure (void)
virtual void DoReportTestFailure (std::string cond, std::string actual, std::string limit, std::string message, std::string file, int32_t line)
virtual void DoReportEnd (void)
virtual void DoSetup (void)
virtual bool DoRun (void)=0
virtual void DoTeardown (void)

Detailed Description

A single test case.


Member Function Documentation

bool ns3::TestCase::ContinueOnFailure ( void   ) 

Should test cases continue running in the presence of errors?

Returns:
True if the test case should continue, false otherwise.
std::string ns3::TestCase::GetSourceDir ( std::string  file  ) 

Get the source directory of the current source file.

One of the basic models of the test environment is that dedicated test- and response vectors live in the same directory as the source file. So it is a common operation to figure out what directory a given source file lives in.

__FILE__ provides almost all of what we need, but in the gnu toolchain it comes out as something like "../src/core/pcap-file-test-suite.cc".

We really don't want to have any dependency on the directory out of which a test is run, so we ask that any test-runner give us the base directory of the distribution, which is set via TestCase::SetBaseDir(). That string will look something like "/home/user/repos/ns-3-allinone/ns-3-dev".

This function stitches the two pieces together and removes the file name to return something like "/home/user/repos/ns-3-allinone/ns-3-dev/src/core/".

Parameters:
file The current source file name relative to the base directory.
Returns:
The current source directory.
Warning:
Always call this function as GetSourceDir (__FILE__) or use the convenience macro NS_TEST_SOURCEDIR.
bool ns3::TestCase::Run ( void   ) 

Run this test case.

Returns:
Boolean sense of "an error has occurred."
void ns3::TestCase::SetContinueOnFailure ( bool  continueOnFailure  ) 

Tell the test case whether or not to continue testing if an error is detected.

Typically, test cases depend on some number of individual tests. Often, these tests build on functionality that has been previously verified. In this case, subsequent test failures may simply be alternate manifestations of previously detected errors. Some developers may only be interested in seeing the first failure. Other developers may want to see all the information they can get, and want to see all failures. This is a matter of individual preference, so we allow this behavior to be configured.

Parameters:
continueOnFailure If true, run tests after a failure has been detected, otherwise stop on the first error.
void ns3::TestCase::SetErrorStatus ( bool  error  ) 

Manually set the error status of this test case.

This sets the current error status to the argument provided. Can be used to reset any previous errors if the argument is false.

Parameters:
error The status to use to set the test case error status
void ns3::TestCase::SetStream ( std::ofstream *  ofs  ) 

Set the stream to which status and result messages will be written.

We really don't want to have to pass an ofstream around to every function and we especially don't want to have to make our clients plumb an ofstream around so we need to save it. Since file streams are not designed to be copied or assigned (what does it mean to have duplicate streams to a file) we have to stash a pointer to the stream.

Parameters:
ofs output file stream
void ns3::TestCase::SetVerbose ( bool  verbose  ) 

Set the verbosity of this test case.

Parameters:
verbose Whether or not to print "stuff."
void ns3::TestCase::UpdateErrorStatus ( bool  error  ) 

Manually update the error status of this test case.

This does a logical OR of the error argument with the current error status. If the argument is false, it does nothing. If the argument is true, it sets the error status to "an error has occurred."

Parameters:
error The status to use to update the test case error status

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