Kea: isc::test Namespace Reference

| Kea 3.2.0-git

isc::test Namespace Reference

## Classes
class | EnvVarWrapper
| Wrapper for environment variable that restores the variable to its original value. More...
class | MultiThreadingTest
| A RAII class which disables the multi threading on exit of scope. More...
class | Sandbox
| A Sandbox class that provides access to unit test unique temporary folder. More...
class | ThreadedTest
| Base class for tests requiring threads. More...

## Functions
bool | checkTryLock (std::mutex &mutex)
| Check if mutex is locked.
std::string | decommentJSONfile (const std::string &input_file)
| Removes comments from a JSON file.
bool | fileExists (const std::string &file_path)
| Checks if specified file exists.
std::string | generateDiff (std::string left, std::string right)
| Return the difference between two strings.
ConstElementPtr | moveComments (isc::data::ConstElementPtr element)
| Move comment entries to user-context (const variant).
ElementPtr | moveComments (isc::data::ElementPtr element)
| Move comment entries to user-context.
std::string | readFile (const std::string &file_path)
| Reads contents of the specified file.
template<typename Cfg>
void | runToElementTest (const std::string &expected, const Cfg &cfg)
| Run a test using toElement() method with a string.
template<typename Cfg>
void | runToElementTest (isc::data::ConstElementPtr expected, const Cfg &cfg)
| Run a test using toElement() method with an Element.
void | expectEqWithDiff (isc::data::ConstElementPtr const &left, isc::data::ConstElementPtr const &right)
| Expect two element pointers to be equal.
void | expectEqWithDiff (ElementPtr const &a, ElementPtr const &b)
void | assertEqWithDiff (ConstElementPtr const &a, ConstElementPtr const &b)
void | assertEqWithDiff (ElementPtr const &a, ConstElementPtr const &b)

## Function Documentation

## ◆ assertEqWithDiff() [1/2]

void isc::test::assertEqWithDiff | ( | ConstElementPtr const & | a,
|  | ConstElementPtr const & | b )

Definition at line 43 of file test_to_element.cc.

References generateDiff(), and isc::data::prettyPrint().

Here is the call graph for this function:

## ◆ assertEqWithDiff() [2/2]

void isc::test::assertEqWithDiff | ( | ElementPtr const & | a,
|  | ConstElementPtr const & | b )

Definition at line 54 of file test_to_element.cc.

References generateDiff(), and isc::data::prettyPrint().

Here is the call graph for this function:

## ◆ checkTryLock()

bool isc::test::checkTryLock | ( | std::mutex & | mutex | ) |
| inline

Check if mutex is locked.

Note
  This function uses a new thread to test if the mutex is locked because calling try_lock by the same thread which already acquired the lock is undefined behavior.

Parameters

  mutex | The mutex to check.

Returns
  Return true if mutex is not locked, false if mutex is locked.

Definition at line 23 of file multi_threading_utils.h.

## ◆ decommentJSONfile()

std::string isc::test::decommentJSONfile | ( | const std::string & | input_file | ) |

Removes comments from a JSON file.

Removes //, # and /* *‍/ comments from the input file and writes its content to another file. The comments are replaced with spaces, so the original token locations should remain unaffected. This is rather naive implementation, but it's probably sufficient for testing. It won't be able to pick any trickier cases, like # or // appearing in strings, nested C++ comments etc at the exception of // in URLs.

Parameters

  input_file | file to be stripped of comments

Returns
  filename of a new file that has comments stripped from it

Exceptions

  BadValue | if the input file cannot be opened

Definition at line 41 of file io_utils.cc.

References isc_throw.

## ◆ expectEqWithDiff() [1/2]

void isc::test::expectEqWithDiff | ( | ElementPtr const & | a,
|  | ElementPtr const & | b )

Definition at line 32 of file test_to_element.cc.

References generateDiff(), and isc::data::prettyPrint().

Here is the call graph for this function:

## ◆ expectEqWithDiff() [2/2]

void isc::test::expectEqWithDiff | ( | isc::data::ConstElementPtr const & | left,
|  | isc::data::ConstElementPtr const & | right )

Expect two element pointers to be equal.

Order of elements in a list or a map is also checked by default.

Definition at line 21 of file test_to_element.cc.

References generateDiff(), and isc::data::prettyPrint().

Here is the call graph for this function:

## ◆ fileExists()

bool isc::test::fileExists | ( | const std::string & | file_path | ) |

Checks if specified file exists.

Parameters

  file_path | Path to a file.

Returns
  true if the file exists, false otherwise.

Definition at line 19 of file io_utils.cc.

## ◆ generateDiff()

std::string isc::test::generateDiff | ( | std::string | left,
|  | std::string | right )

Return the difference between two strings.

Use the gtest >= 1.8.0 tool which builds the difference between two vectors of lines.

Parameters

  left | left string
  right | right string

Returns
  the unified diff between left and right

Definition at line 75 of file test_to_element.cc.

Referenced by assertEqWithDiff(), assertEqWithDiff(), expectEqWithDiff(), expectEqWithDiff(), runToElementTest(), and runToElementTest().

## ◆ moveComments() [1/2]

isc::data::ConstElementPtr isc::test::moveComments | ( | isc::data::ConstElementPtr | element | ) |

Move comment entries to user-context (const variant).

Parameters

  element |

Returns
  a processed copy of element or unmodified element

Definition at line 130 of file user_context_utils.cc.

## ◆ moveComments() [2/2]

isc::data::ElementPtr isc::test::moveComments | ( | isc::data::ElementPtr | element | ) |

Move comment entries to user-context.

Process an element looking for comment entries in maps and moving them to user-context entries. As the common case is no comment and this routine tries to maximize sharing the standard behavior is just to return the argument unchanged.

Parameters

  element |

Returns
  a processed copy of element or unmodified element

Definition at line 125 of file user_context_utils.cc.

## ◆ readFile()

std::string isc::test::readFile | ( | const std::string & | file_path | ) |

Reads contents of the specified file.

Parameters

  file_path | Path to a file.

Returns
  File contents.

Definition at line 24 of file io_utils.cc.

## ◆ runToElementTest() [1/2]

template<typename Cfg>

void isc::test::runToElementTest | ( | const std::string & | expected,
|  | const Cfg & | cfg )

Run a test using toElement() method with a string.

Template Parameters

  Cfg | the class implementing the toElement() method

Parameters

  expected | the expected textual value
  cfg | an instance of the Cfg class

Definition at line 57 of file test_to_element.h.

References Element::fromJSON(), generateDiff(), isc::data::isEquivalent(), and isc::data::prettyPrint().

Here is the call graph for this function:

## ◆ runToElementTest() [2/2]

template<typename Cfg>

void isc::test::runToElementTest | ( | isc::data::ConstElementPtr | expected,
|  | const Cfg & | cfg )

Run a test using toElement() method with an Element.

Template Parameters

  Cfg | the class implementing the toElement() method

Parameters

  expected | the expected element value
  cfg | an instance of the Cfg class

Definition at line 81 of file test_to_element.h.

References generateDiff(), isc::data::isEquivalent(), and isc::data::prettyPrint().

Here is the call graph for this function: