OpenVPN 3 Core Library
Loading...
Searching...
No Matches
test_helper.hpp File Reference
#include <openvpn/log/logbase.hpp>
#include <openvpn/io/io.hpp>
#include <openvpn/common/exception.hpp>
#include <openvpn/common/hexstr.hpp>
#include <openvpn/common/format.hpp>
#include <openvpn/random/mtrandapi.hpp>
#include <iostream>
#include <gtest/gtest.h>
#include <fstream>
#include <mutex>
Include dependency graph for test_helper.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  openvpn::LogOutputCollector
 
class  openvpn::SaveCurrentLogObject
 
class  detail::line
 
class  FakeAsyncResolvable< RESOLVABLE, CTOR_ARGS >
 
class  FakeSecureRand
 
class  unit_test_uniform_int_distribution
 

Namespaces

namespace  openvpn
 Support deferred server-side state creation when client connects.
 
namespace  detail
 

Macros

#define OVPN_EXPECT_THROW(statement, expected_exception, expected_text)
 
#define JY_EXPECT_THROW   OVPN_EXPECT_THROW
 
#define JY_ASSERT_TRUE(value)
 
#define JY_ASSERT_FALSE(value)
 
#define JY_ASSERT_EQ(v1, v2)
 
#define JY_ASSERT_NE(v1, v2)
 
#define JY_ASSERT_LE(v1, v2)
 
#define JY_ASSERT_GE(v1, v2)
 
#define THROW_FMT(...)   throw Exception(printfmt(__VA_ARGS__))
 

Functions

void override_logOutput (bool doLogOutput, void(*test_func)())
 
std::string getExpectedOutput (const std::string &filename)
 
std::string getTempDirPath (const std::string &fn)
 
template<class T >
std::string getJoinedString (const std::vector< T > &r, const std::string &delim="|")
 
template<class T >
std::string getSortedJoinedString (std::vector< T > &r, const std::string &delim="|")
 
std::string getSortedString (const std::string &output)
 

Variables

openvpn::LogOutputCollectortestLog
 

Macro Definition Documentation

◆ JY_ASSERT_EQ

#define JY_ASSERT_EQ (   v1,
  v2 
)
Value:
do \
{ \
if ((v1) != (v2)) \
OPENVPN_THROW_EXCEPTION("JY_ASSERT_EQ: failure at " << __FILE__ << ':' << __LINE__); \
} while (0)

Definition at line 447 of file test_helper.hpp.

◆ JY_ASSERT_FALSE

#define JY_ASSERT_FALSE (   value)
Value:
do \
{ \
if (value) \
OPENVPN_THROW_EXCEPTION("JY_ASSERT_FALSE: failure at " << __FILE__ << ':' << __LINE__); \
} while (0)

Definition at line 440 of file test_helper.hpp.

◆ JY_ASSERT_GE

#define JY_ASSERT_GE (   v1,
  v2 
)
Value:
do \
{ \
if ((v1) < (v2)) \
OPENVPN_THROW_EXCEPTION("JY_ASSERT_GE: failure at " << __FILE__ << ':' << __LINE__); \
} while (0)

Definition at line 468 of file test_helper.hpp.

◆ JY_ASSERT_LE

#define JY_ASSERT_LE (   v1,
  v2 
)
Value:
do \
{ \
if ((v1) > (v2)) \
OPENVPN_THROW_EXCEPTION("JY_ASSERT_LE: failure at " << __FILE__ << ':' << __LINE__); \
} while (0)

Definition at line 461 of file test_helper.hpp.

◆ JY_ASSERT_NE

#define JY_ASSERT_NE (   v1,
  v2 
)
Value:
do \
{ \
if ((v1) == (v2)) \
OPENVPN_THROW_EXCEPTION("JY_ASSERT_NE: failure at " << __FILE__ << ':' << __LINE__); \
} while (0)

Definition at line 454 of file test_helper.hpp.

◆ JY_ASSERT_TRUE

#define JY_ASSERT_TRUE (   value)
Value:
do \
{ \
if (!(value)) \
OPENVPN_THROW_EXCEPTION("JY_ASSERT_TRUE: failure at " << __FILE__ << ':' << __LINE__); \
} while (0)

Definition at line 433 of file test_helper.hpp.

◆ JY_EXPECT_THROW

#define JY_EXPECT_THROW   OVPN_EXPECT_THROW

Definition at line 427 of file test_helper.hpp.

◆ OVPN_EXPECT_THROW

#define OVPN_EXPECT_THROW (   statement,
  expected_exception,
  expected_text 
)
Value:
try \
{ \
statement; \
OPENVPN_THROW_EXCEPTION("OVPN_EXPECT_THROW: no exception was thrown " << __FILE__ << ':' << __LINE__); \
} \
catch (const expected_exception &e) \
{ \
if (std::string(e.what()).find(expected_text) == std::string::npos) \
OPENVPN_THROW_EXCEPTION("OVPN_EXPECT_THROW: did not find expected text in exception at " << __FILE__ << ':' << __LINE__ \
<< ". Got: " << e.what()); \
}

Definition at line 415 of file test_helper.hpp.

◆ THROW_FMT

#define THROW_FMT (   ...)    throw Exception(printfmt(__VA_ARGS__))

Definition at line 476 of file test_helper.hpp.

Function Documentation

◆ getExpectedOutput()

std::string getExpectedOutput ( const std::string &  filename)
inline

Reads the file with the expected output and returns it as a string. This function delibrately does not include the ASSERT_EQ call since otherwise gtest will report a the assert failure in this file rather than in the right place

Parameters
filename
Returns

Definition at line 168 of file test_helper.hpp.

Here is the caller graph for this function:

◆ getJoinedString()

template<class T >
std::string getJoinedString ( const std::vector< T > &  r,
const std::string &  delim = "|" 
)
inline

Returns a string joined with the delimiter

Parameters
rthe array to join
delimthe delimiter to use
Returns
A string joined by delim from the vector r

Definition at line 207 of file test_helper.hpp.

Here is the caller graph for this function:

◆ getSortedJoinedString()

template<class T >
std::string getSortedJoinedString ( std::vector< T > &  r,
const std::string &  delim = "|" 
)
inline

Returns a sorted string join with the delimiter This function modifes the input

Parameters
rthe array to join
delimthe delimiter to use
Returns
A string joined by delim from the sorted vector r

Definition at line 222 of file test_helper.hpp.

◆ getSortedString()

std::string getSortedString ( const std::string &  output)
inline

Splits a string into lines and returns them in a sorted output string

Definition at line 250 of file test_helper.hpp.

Here is the caller graph for this function:

◆ getTempDirPath()

std::string getTempDirPath ( const std::string &  fn)
inline

Definition at line 193 of file test_helper.hpp.

Here is the caller graph for this function:

◆ override_logOutput()

void override_logOutput ( bool  doLogOutput,
void(*)()  test_func 
)
inline

Overrides stdout during the run of a function. Primarly for silencing log function that throw an exception when something is wrong

Parameters
doLogOutputUse stdout while running
test_funcfunction to run

Definition at line 152 of file test_helper.hpp.

Here is the caller graph for this function:

Variable Documentation

◆ testLog

openvpn::LogOutputCollector* testLog
extern

Definition at line 25 of file core_tests.cpp.