nlib
List of testing Library Features

A list of the macros and other features defined in the testing library. Also see the description of nn::nlib::testing. More...

Files

file  NTest.h
 Defines the macro for a basic, simple test.
 
file  Pred.h
 Defines a predicate assertion.
 
file  ParamType.h
 Defines a typed test.
 

Macros

#define NLIB_TESTING_OSTREAM   ::nlib_ns::testing::detail_func::DummyStream
 Used in place of td::ostream in the testing library. More...
 
#define FRIEND_TEST(test_case, test_name)   friend class NLIB_TESTING_CLASS_NAME_(test_case, test_name)
 The test code is written with the ability to access private members. More...
 

Functions

AssertionResult nn::nlib::testing::FloatLE (const char *expr1, const char *expr2, float val1, float val2)
 Determines if val1 <= val2. [ASSERT|EXPECT] Used by including in PRED_FORMAT2. More...
 
AssertionResult nn::nlib::testing::DoubleLE (const char *expr1, const char *expr2, double val1, double val2)
 Determines if val1 <= val2. [ASSERT|EXPECT] Used by including in PRED_FORMAT2. More...
 

Definition of the Test Function

#define TEST(test_case_name, specific_test_name)   NLIB_TEST_(test_case_name, specific_test_name, ::nlib_ns::testing::Test)
 Defines the test variable. More...
 
#define TEST_F(test_fixture_name, specific_test_name)   NLIB_TEST_(test_fixture_name, specific_test_name, test_fixture_name)
 Defines a test function using the test fixture. More...
 

Definition of the Test Function That Parameterizes Values

#define TEST_P(test_case, test_name)
 Defines a test that parameterizes values. More...
 
#define INSTANTIATE_TEST_CASE_P(prefix, test_case, generator)
 Provides a parameter to test. More...
 

Definition of the Test Function That Parameterizes Types

#define TYPED_TEST_CASE(test_case, types)   typedef types::type NLIB_TESTING_TYPELIST(test_case)
 Associates the type list with the test case. More...
 
#define TYPED_TEST(test_case, test_name)
 Writes a typing test. More...
 

Start Tests

#define RUN_ALL_TESTS()   ::nlib_ns::testing::TestInfo::Run()
 Starts the testing. More...
 

Unconditional Success and Failure

#define SUCCEED()
 Does nothing.
 
#define FAIL()
 Fails unconditionally and leaves the currently running function.
 

Conditional Statement Test (ASSERT_*)

#define ASSERT_TRUE(expr)   NLIB_TESTING_BOOLEAN_IMPL_(expr, true, false, NLIB_TESTING_FATAL_)
 Evaluates whether condition is true. If the test fails, control leaves the currently running function.
 
#define ASSERT_FALSE(expr)   NLIB_TESTING_BOOLEAN_IMPL_(!(expr), false, true, NLIB_TESTING_FATAL_)
 Evaluates whether condition is false. If the test fails, control leaves the currently running function.
 

Conditional Statement Test (EXPECT_*)

#define EXPECT_TRUE(expr)   NLIB_TESTING_BOOLEAN_IMPL_(expr, true, false, NLIB_TESTING_NONFATAL_)
 If the test fails, control leaves the currently running function, just like ASSERT_TRUE.
 
#define EXPECT_FALSE(expr)   NLIB_TESTING_BOOLEAN_IMPL_(!(expr), false, true, NLIB_TESTING_NONFATAL_)
 If the test fails, control leaves the currently running function, just like ASSERT_FALSE.
 

Value Test (ASSERT_*)

#define ASSERT_EQ(expected, actual)   NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompEQ, expected, actual)
 Evaluates whether expected == actual. If the test fails, control leaves the currently running function. More...
 
#define ASSERT_NE(expected, actual)   NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompNE, expected, actual)
 Evaluates whether val1 != val2. If the test fails, control leaves the currently running function.
 
#define ASSERT_LT(val1, val2)   NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompLT, val1, val2)
 Evaluates whether val1 < val2. If the test fails, control leaves the currently running function.
 
#define ASSERT_LE(val1, val2)   NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompLE, val1, val2)
 Evaluates whether val1 <= val2. If the test fails, control leaves the currently running function.
 
#define ASSERT_GT(val1, val2)   NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompGT, val1, val2)
 Evaluates whether val1 > val2. If the test fails, control leaves the currently running function.
 
#define ASSERT_GE(val1, val2)   NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompGE, val1, val2)
 Evaluates whether val1 >= val2. If the test fails, control leaves the currently running function.
 
#define ASSERT_STREQ(expected, actual)   NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrEq, expected, actual)
 Evaluates whether the two C strings are identical. If the test fails, control leaves the currently running function.
 
#define ASSERT_STRNE(expected, actual)   NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrNe, expected, actual)
 Evaluates whether the two C strings are not identical. If the test fails, control leaves the currently running function.
 
#define ASSERT_STRCASEEQ(expected, actual)   NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrCaseEq, expected, actual)
 Tests whether two C strings are the same, ignoring case. If the test fails, control leaves the currently running function.
 
#define ASSERT_STRCASENE(expected, actual)   NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompStrCaseNe, expected, actual)
 Tests whether two C strings are not the same, ignoring case. If the test fails, control leaves the currently running function.
 
#define ASSERT_FLOAT_EQ(expected, actual)   NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompFloatEq, expected, actual)
 Evaluates whether the two float values are similar. If the test fails, control leaves the currently running function. More...
 
#define ASSERT_DOUBLE_EQ(expected, actual)   NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompDoubleEq, expected, actual)
 Evaluates whether the two double values are similar. If the test fails, control leaves the currently running function. More...
 
#define ASSERT_NEAR(val1, val2, abs_error)
 Evaluates whether the difference between val1 and val2 is within abs_error. If the test fails, control leaves the currently running function.
 

Value Test (EXPECT_*)

#define EXPECT_EQ(expected, actual)   NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompEQ, expected, actual)
 If the test failed, control leaves the currently running function, just like ASSERT_EQ.
 
#define EXPECT_NE(expected, actual)   NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompNE, expected, actual)
 If the test failed, control leaves the currently running function, just like ASSERT_NE.
 
#define EXPECT_LT(val1, val2)   NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompLT, val1, val2)
 If the test failed, control leaves the currently running function, just like ASSERT_LT.
 
#define EXPECT_LE(val1, val2)   NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompLE, val1, val2)
 If the test failed, control leaves the currently running function, just like ASSERT_LT.
 
#define EXPECT_GT(val1, val2)   NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompGT, val1, val2)
 If the test failed, control leaves the currently running function, just like ASSERT_GT.
 
#define EXPECT_GE(val1, val2)   NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompGE, val1, val2)
 If the test failed, control leaves the currently running function, just like ASSERT_GE.
 
#define EXPECT_STREQ(expected, actual)   NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrEq, expected, actual)
 If the test failed, control leaves the currently running function, just like ASSERT_STREQ.
 
#define EXPECT_STRNE(expected, actual)   NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrNe, expected, actual)
 If the test failed, control leaves the currently running function, just like ASSERT_STRNE.
 
#define EXPECT_STRCASEEQ(expected, actual)   NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrCaseEq, expected, actual)
 If the test fails, control leaves the currently running function, as in ASSERT_STRCASEEQ.
 
#define EXPECT_STRCASENE(expected, actual)   NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompStrCaseNe, expected, actual)
 If the test fails, control leaves the currently running function, as in ASSERT_STRCASENE.
 
#define EXPECT_FLOAT_EQ(expected, actual)   NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompFloatEq, expected, actual)
 If the test failed, control leaves the currently running function, just like ASSERT_FLOAT_EQ.
 
#define EXPECT_DOUBLE_EQ(expected, actual)   NLIB_TESTING_EXPECT_HELPER_(::nlib_ns::testing::CompDoubleEq, expected, actual)
 If the test failed, control leaves the currently running function, just like ASSERT_DOUBLE_EQ.
 
#define EXPECT_NEAR(val1, val2, abs_error)
 If the test failed, control leaves the currently running function, just like ASSERT_NEAR.
 

Used in cases where assertions are used in subroutines

#define SCOPED_TRACE(msg)
 Adds a message that provides information about the location of the scope when displaying a failure message. More...
 
#define ASSERT_NO_FATAL_FAILURE(statement)
 Evaluates whether ASSERT_* has failed within the subroutine (statement). If the test fails, control leaves the currently running function. More...
 
#define EXPECT_NO_FATAL_FAILURE(statement)
 The same as EXPECT_NO_FATAL_FAILURE, except control does not leave the currently running function even if it fails.
 

Test of Existing Boolean Functions (ASSERT_PREDn)

For functions that return a bool type, you can view the function arguments when the function fails by providing the function to the following macros.

#define ASSERT_PRED1(pred, v1)   NLIB_TESTING_PRED1_(pred, v1, NLIB_TESTING_FATAL_)
 Evaluates whether pred(v1) is true. If the test fails, control leaves the currently running function.
 
#define ASSERT_PRED2(pred, v1, v2)   NLIB_TESTING_PRED2_(pred, v1, v2, NLIB_TESTING_FATAL_)
 Evaluates whether pred(v1, v2) is true. If the test fails, control leaves the currently running function.
 
#define ASSERT_PRED3(pred, v1, v2, v3)   NLIB_TESTING_PRED3_(pred, v1, v2, v3, NLIB_TESTING_FATAL_)
 Evaluates whether pred(v1, v2, v3) is true. If the test fails, control leaves the currently running function.
 
#define ASSERT_PRED4(pred, v1, v2, v3, v4)   NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, NLIB_TESTING_FATAL_)
 Evaluates whether pred(v1, v2, v3, v4) is true. If the test fails, control leaves the currently running function.
 
#define ASSERT_PRED5(pred, v1, v2, v3, v4, v5)   NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, NLIB_TESTING_FATAL_)
 Evaluates whether pred(v1, v2, v3, v4, v5) is true. If the test fails, control leaves the currently running function.
 

Test of Existing Boolean Functions (EXPECT_PREDn)

For functions that return a bool type, you can view the function arguments when the function fails by providing the function to the following macros.

#define EXPECT_PRED1(pred, v1)   NLIB_TESTING_PRED1_(pred, v1, NLIB_TESTING_NONFATAL_)
 Even if the test failed, control does not leave the currently running function, just like ASSERT_PRED1.
 
#define EXPECT_PRED2(pred, v1, v2)   NLIB_TESTING_PRED2_(pred, v1, v2, NLIB_TESTING_NONFATAL_)
 Even if the test failed, control does not leave the currently running function, just like ASSERT_PRED2.
 
#define EXPECT_PRED3(pred, v1, v2, v3)   NLIB_TESTING_PRED3_(pred, v1, v2, v3, NLIB_TESTING_NONFATAL_)
 Even if the test failed, control does not leave the currently running function, just like ASSERT_PRED3.
 
#define EXPECT_PRED4(pred, v1, v2, v3, v4)   NLIB_TESTING_PRED4_(pred, v1, v2, v3, v4, NLIB_TESTING_NONFATAL_)
 Even if the test failed, control does not leave the currently running function, just like ASSERT_PRED4.
 
#define EXPECT_PRED5(pred, v1, v2, v3, v4, v5)   NLIB_TESTING_PRED5_(pred, v1, v2, v3, v4, v5, NLIB_TESTING_NONFATAL_)
 Even if the test failed, control does not leave the currently running function, just like ASSERT_PRED5.
 

Customizing the Display by Defining a Test-Only Boolean Function (ASSERT_PRED_FORMATn)

Use the following macros to customize the message when ASSERT_PREDn fails.

#define ASSERT_PRED_FORMAT1(pred_format, v1)   NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, NLIB_TESTING_FATAL_)
 ASSERT_PRED1 may be used by the user to define the display at failure. If the test fails, control leaves the currently running function. More...
 
#define ASSERT_PRED_FORMAT2(pred_format, v1, v2)   NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, NLIB_TESTING_FATAL_)
 ASSERT_PRED2 may be used by the user to define the display at failure. If the test fails, control leaves the currently running function. More...
 
#define ASSERT_PRED_FORMAT3(pred_format, v1, v2, v3)   NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, NLIB_TESTING_FATAL_)
 ASSERT_PRED3 may be used by the user to define the display at failure. If the test fails, control leaves the currently running function. More...
 
#define ASSERT_PRED_FORMAT4(pred_format, v1, v2, v3, v4)   NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, NLIB_TESTING_FATAL_)
 ASSERT_PRED4 may be used by the user to define the display at failure. If the test fails, control leaves the currently running function. More...
 
#define ASSERT_PRED_FORMAT5(pred_format, v1, v2, v3, v4, v5)   NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, NLIB_TESTING_FATAL_)
 ASSERT_PRED5 may be used by the user to define the display at failure. If the test fails, control leaves the currently running function. More...
 

Detailed Description

A list of the macros and other features defined in the testing library. Also see the description of nn::nlib::testing.

Macro Definition Documentation

#define ASSERT_DOUBLE_EQ (   expected,
  actual 
)    NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompDoubleEq, expected, actual)

Evaluates whether the two double values are similar. If the test fails, control leaves the currently running function.

Description
A value is considered similar when it is within 4 (plus or minus) as a 64-bit value. For instance, a difference of up to roughly 2e-323f is considered to be similar when compared against a value of 0.
The range of values that are considered similar grows with larger compared values due to the nature of floating point values. A comparison between NaN values is not considered similar. NaN significands are all 1, and exponents are a nonzero value.

Definition at line 492 of file NTest.h.

#define ASSERT_EQ (   expected,
  actual 
)    NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompEQ, expected, actual)

Evaluates whether expected == actual. If the test fails, control leaves the currently running function.

Description
Cannot be used to compare with NULL. It must be written as ASSERT_TRUE(NULL == actual).
Examples:
testing/failure/failure.cpp, and testing/param_type/param_type.cpp.

Definition at line 448 of file NTest.h.

#define ASSERT_FLOAT_EQ (   expected,
  actual 
)    NLIB_TESTING_ASSERT_HELPER_(::nlib_ns::testing::CompFloatEq, expected, actual)

Evaluates whether the two float values are similar. If the test fails, control leaves the currently running function.

Description
A value is considered similar when it is within 4 (plus or minus) as a 32-bit value. For instance, a difference of up to 6e-45f is considered to be similar when compared against a value of 0.
The range of values that are considered similar grows with larger compared values due to the nature of floating point values. A comparison between NaN values is not considered similar. NaN significands are all 1, and exponents are a nonzero value.

Definition at line 490 of file NTest.h.

#define ASSERT_NO_FATAL_FAILURE (   statement)
Value:
switch (0) \
case 0: \
default: \
for (;;) { \
statement; \
break; \
} \
if (!::nlib_ns::testing::UnitTest::GetInstance() \
->current_test_info() \
->result() \
->HasFatalFaiulre()) \
; \
else /* NOLINT */ \
NLIB_TESTING_FATAL_ = ::nlib_ns::testing::AssertionResult(false) \
<< "Expected: " #statement \
" doesn't generate new fatal failures.\n" \
" Actual: it does.\n"

Evaluates whether ASSERT_* has failed within the subroutine (statement). If the test fails, control leaves the currently running function.

Description
If ASSERT_* fails within a subroutine, the test continues after returning from the subroutine. Use this macro if you do not want to have this behavior.
Examples:
testing/success/success.cpp.

Definition at line 526 of file NTest.h.

#define ASSERT_PRED_FORMAT1 (   pred_format,
  v1 
)    NLIB_TESTING_PRED_FORMAT1_(pred_format, v1, NLIB_TESTING_FATAL_)

ASSERT_PRED1 may be used by the user to define the display at failure. If the test fails, control leaves the currently running function.

Description
pred_format is a function like the following.
1 ::testing::AssertionResult pred_format(
2  const char* str_v1,
3  const T1& v1
4 ) {
5  if (test condition)
6  {
7  // If successful:
8  return ::testing::AssertionSuccess();
9  }
10  else
11  {
12  // If failed:
13  return ::testing::AssertionFailure()
14  << Fail message.
15  }
16 }

Definition at line 169 of file Pred.h.

#define ASSERT_PRED_FORMAT2 (   pred_format,
  v1,
  v2 
)    NLIB_TESTING_PRED_FORMAT2_(pred_format, v1, v2, NLIB_TESTING_FATAL_)

ASSERT_PRED2 may be used by the user to define the display at failure. If the test fails, control leaves the currently running function.

Description
pred_format is a function like the following.
1 ::testing::AssertionResult pred_format(
2  const char* str_v1, const char* str_v2,
3  const T1& v1, const T2& v2
4 ) {
5  if (test condition)
6  {
7  // If successful:
8  return ::testing::AssertionSuccess();
9  }
10  else
11  {
12  // If failed:
13  return ::testing::AssertionFailure()
14  << Fail message.
15  }
16 }

Definition at line 176 of file Pred.h.

#define ASSERT_PRED_FORMAT3 (   pred_format,
  v1,
  v2,
  v3 
)    NLIB_TESTING_PRED_FORMAT3_(pred_format, v1, v2, v3, NLIB_TESTING_FATAL_)

ASSERT_PRED3 may be used by the user to define the display at failure. If the test fails, control leaves the currently running function.

Description
pred_format is a function like the following.
1 ::testing::AssertionResult pred_format(
2  const char* str_v1, const char* str_v2, const char* str_v3,
3  const T1& v1, const T2& v2, const T3& v3
4 ) {
5  if (test condition)
6  {
7  // If successful:
8  return ::testing::AssertionSuccess();
9  }
10  else
11  {
12  // If failed:
13  return ::testing::AssertionFailure()
14  << Fail message.
15  }
16 }

Definition at line 183 of file Pred.h.

#define ASSERT_PRED_FORMAT4 (   pred_format,
  v1,
  v2,
  v3,
  v4 
)    NLIB_TESTING_PRED_FORMAT4_(pred_format, v1, v2, v3, v4, NLIB_TESTING_FATAL_)

ASSERT_PRED4 may be used by the user to define the display at failure. If the test fails, control leaves the currently running function.

Description
pred_format is a function like the following.
1 ::testing::AssertionResult pred_format(
2  const char* str_v1, const char* str_v2, const char* str_v3, const char* str_v4,
3  const T1& v1, const T2& v2, const T3& v3, const T4& v4
4 ) {
5  if (test condition)
6  {
7  // If successful:
8  return ::testing::AssertionSuccess();
9  }
10  else
11  {
12  // If failed:
13  return ::testing::AssertionFailure()
14  << Fail message.
15  }
16 }

Definition at line 192 of file Pred.h.

#define ASSERT_PRED_FORMAT5 (   pred_format,
  v1,
  v2,
  v3,
  v4,
  v5 
)    NLIB_TESTING_PRED_FORMAT5_(pred_format, v1, v2, v3, v4, v5, NLIB_TESTING_FATAL_)

ASSERT_PRED5 may be used by the user to define the display at failure. If the test fails, control leaves the currently running function.

Description
pred_format is a function like the following.
1 ::testing::AssertionResult pred_format(
2  const char* str_v1, const char* str_v2, const char* str_v3, const char* str_v4, const char* str_v5,
3  const T1& v1, const T2& v2, const T3& v3, const T4& v4, const T5& v5
4 ) {
5  if (test condition)
6  {
7  // If successful:
8  return ::testing::AssertionSuccess();
9  }
10  else
11  {
12  // If failed:
13  return ::testing::AssertionFailure()
14  << Fail message.
15  }
16 }

Definition at line 201 of file Pred.h.

#define FRIEND_TEST (   test_case,
  test_name 
)    friend class NLIB_TESTING_CLASS_NAME_(test_case, test_name)

The test code is written with the ability to access private members.

Description
Write this macro within the class definitions that the test code must access. Macros make a friend declaration to the class inhabited by the test code.

Definition at line 433 of file NTest.h.

#define INSTANTIATE_TEST_CASE_P (   prefix,
  test_case,
  generator 
)
Value:
class TestParamAdder_##test_case##prefix : public ::nlib_ns::testing::TestParamAdderBase { \
public: /* NOLINT */ \
TestParamAdder_##test_case##prefix() { \
::nlib_ns::testing::TestParamAdderList::AddTestParamAdder(this); \
} \
virtual void AddParams() { \
::nlib_ns::UniquePtr<std::vector<test_case::ParamType> > vec( \
generator.Gen<test_case::ParamType>()); \
if (!vec.get()) return; \
test_case::AddParamList(vec->begin(), vec->end()); \
} \
} \
ntest_##test_case##prefix##_glbval_

Provides a parameter to test.

Description
For more information, see the description of the TEST_P macro.
Examples:
testing/param_value/param_value.cpp.

Definition at line 204 of file ParamValue.h.

#define NLIB_TESTING_OSTREAM   ::nlib_ns::testing::detail_func::DummyStream

Used in place of td::ostream in the testing library.

Description
The testing library defines its own replacement for std::ostream. As a result, Google Test compatibility is lost at this point. Using this macro allows the code for operator<< overload and defining the PrintTo function to remain the same as with the code for Google Test.
If the NLIB_USE_GTEST macro is defined when using Google Test, std::ostream is used.
Examples:
testing/failure/failure.cpp, and testing/param_type/param_type.cpp.

Definition at line 20 of file testing.h.

#define RUN_ALL_TESTS ( )    ::nlib_ns::testing::TestInfo::Run()

Starts the testing.

Description
If 0 is returned, all tests were successful, and this is used as the return value of the main function of the standard test program.
A typical test program main function looks something like this.
1 #include "nn/nlib/testing/testing.h"
2 
3 int main(int argc, char** argv) {
4  ::testing::InitNintendoTest(&argc, argv); // ::testing::InitGoogleTest(&argc, argv)
5  return RUN_ALL_TESTS()
6 }
Examples:
testing/failure/failure.cpp, testing/param_type/param_type.cpp, testing/param_value/param_value.cpp, and testing/success/success.cpp.

Definition at line 436 of file NTest.h.

#define SCOPED_TRACE (   msg)
Value:
::nlib_ns::testing::ScopedTrace NLIB_TESTING_CONCAT_TOKEN_(nlib_scopedtrace_, __LINE__)( \
::nlib_ns::testing::AssertionResult(true) << (msg), __FILE__, __LINE__)

Adds a message that provides information about the location of the scope when displaying a failure message.

Description
Clearly locates the specific point that the call caused the failure in cases where the test code is written in a subroutine and is called from multiple locations.
Adding SCOPED_TRACE to the code that calls the subroutine adds the filename that SCOPED_TRACE is called from, the line number, and the message to the error message that is displayed when an error occurs. The effect is removed when the scope of SCOPED_TRACE is escaped.
Examples:
testing/failure/failure.cpp.

Definition at line 522 of file NTest.h.

#define TEST (   test_case_name,
  specific_test_name 
)    NLIB_TEST_(test_case_name, specific_test_name, ::nlib_ns::testing::Test)

Defines the test variable.

Description
Creating a Test Using the TEST Macro
  1. Specify the test group name as the first argument, and the test name as the second argument.
  2. The test function is a C++ (member) function that does not return a value.
  3. C++ code may be freely written within the function. The values may be tested using the various assertions.
  4. The test is considered to have failed when any assertion fails.
  5. The test function is automatically registered.
The test is written as follows.
1 TEST(Group, Name)
2 {
3  ... test body ...
4 }
Examples:
testing/failure/failure.cpp, and testing/success/success.cpp.

Definition at line 428 of file NTest.h.

#define TEST_F (   test_fixture_name,
  specific_test_name 
)    NLIB_TEST_(test_fixture_name, specific_test_name, test_fixture_name)

Defines a test function using the test fixture.

Description
Using the test fixture reduces the need to repeatedly write the configuration of the objects used when writing a test that needs to set up similar data.
Creating a Test Fixture
  1. Create a class that inherits the Test base class.
  2. Define the member functions to void SetUpTestCase and void TearDownTestCase as static member functions. These functions are each run immediately before and immediately after the overall test case.
  3. Define the void SetUp and void TearDown member function in protected. These functions are each run immediately before and immediately after the test.
  4. It is acceptable to define the required data as a data member.
  5. A subroutine may be written as a member function if necessary.
The text fixture is written as follows.
1 class MyTest: public ::testing::Test
2 {
3 Protected:
4  static void SetUpTestCase()
5  {
6  // Set up for each test case. It is called once per test case.
7  ...
8  }
9 
10  static void TearDownTestCase()
11  {
12  // Set up for each test case.
13  ...
14  }
15 
16  virtual void SetUp()
17  {
18  // Setup of the data member (and other things).
19  ...
20  }
21  virtual void TearDown()
22  {
23  // Cleanup.
24  ...
25  }
26  // Write data members or member functions used in test.
27  ...
28 };
TEST_F is used in the same method as the TEST macro, but the group name must be set to the same string as the test fixture class name.
1 TEST_F(MyTest, Name)
2 {
3  ... test body ...
4 }
Examples:
testing/success/success.cpp.

Definition at line 430 of file NTest.h.

#define TEST_P (   test_case,
  test_name 
)
Value:
class NLIB_TESTING_CLASS_NAME_(test_case, test_name) \
: public test_case { \
public: \
NLIB_TESTING_CLASS_NAME_(test_case, test_name)() {} \
private: \
virtual void TestBodySub(); \
static ::nlib_ns::testing::TestInfo* m_Info; \
NLIB_DISALLOW_COPY_AND_ASSIGN(NLIB_TESTING_CLASS_NAME_(test_case, test_name)); \
}; \
::nlib_ns::testing::TestInfo* NLIB_TESTING_CLASS_NAME_(test_case, test_name)::m_Info = \
::nlib_ns::testing::TestInfo::AddTestInfo< \
NLIB_TESTING_CLASS_NAME_(test_case, test_name)>( \
#test_case, #test_name, -1, test_case::SetUpTestCase, test_case::TearDownTestCase); \
void NLIB_TESTING_CLASS_NAME_(test_case, test_name)::TestBodySub()
Implements common features and features that are highly platform-dependent. Also refer to nlib Platfo...

Defines a test that parameterizes values.

Description
In some cases, a range of values is needed as function parameters in a test. A range of parameters may be written directly in the test. Alternatively, the input values and the test may be written separately using the TEST_P macro.
When writing a test with parameterized values, first define the fixture class by inheriting nn::nlib::testing::TestWithParam<T>. T is the parameter type.
1 class MyParamTest : public nn::nlib::testing::TestWithParam<const char*>
2 {
3  // Identical to TEST_F except that it inherits TestWithParam<T>.
4 };
Write the test body using the TEST_P macro. The parameter can be found using the GetParam function. In the case of a critical internal error such as an ASSERT_* macro failing, any following parameters are not tested.
1 TEST_P(MyParamTest, mytest)
2 {
3  // Parameters can be acquired using the GetParma function.
4  const char* str = GetParam();
5 
6  // Test code using the string str.
7  ....
8 }
The parameter is written as follows, using the INSTANCE_TEST_CASE_P macro.
1 INSTANTIATE_TEST_CASE_P(
2  InstantiationName,
3  MyParamTest,
4  ::testing::Values("foo", "boo", ...));
The first argument is the identifier of this parameter list. The second argument is the name of the text fixture. The third argument is the parameter generator described below.
Various parameter generators are described below.
::testing::Range(begin, end[, step])
Generates values of {begin, begin+step, begin+step+step, ...}. Does not contain the end parameter. The default value of step is 1.
::testing::Values(v1, v2, ..., vN)
Generates values of {v1, v2, ..., vN}. The current implementation supports values of N up to and including 10.
::testing::ValuesIn(container)
Create a list of values expressed by an array and STL container.
::testing::ValuesIn(begin, end)
Generates values expressed with an iterator range [begin, end).
::testing::Bool()
Generates values of {false, true}.
Examples:
testing/param_value/param_value.cpp.

Definition at line 188 of file ParamValue.h.

#define TYPED_TEST (   test_case,
  test_name 
)
Value:
template<class T> \
class NLIB_TESTING_CLASS_NAME_(test_case, test_name) \
: public test_case<T> { \
public: \
typedef test_case<T> TestFixture; \
typedef T TypeParam; \
NLIB_TESTING_CLASS_NAME_(test_case, test_name)() {} \
private: \
virtual void TestBody(); \
NLIB_DISALLOW_COPY_AND_ASSIGN(NLIB_TESTING_CLASS_NAME_(test_case, test_name)); \
}; \
bool ntest_typed_test_##test_case##test_name##_ = ::nlib_ns::testing::TypedTestLoop< \
NLIB_TESTING_CLASS_NAME_(test_case, test_name), \
NLIB_TESTING_TYPELIST(test_case)>::AddTestInfo(#test_case, #test_name, 1); \
template<class T> \
void NLIB_TESTING_CLASS_NAME_(test_case, test_name)<T>::TestBody()

Writes a typing test.

Description
For more information, see the description of the TYPED_TEST_CASE macro.
Examples:
testing/param_type/param_type.cpp.

Definition at line 48 of file ParamType.h.

#define TYPED_TEST_CASE (   test_case,
  types 
)    typedef types::type NLIB_TESTING_TYPELIST(test_case)

Associates the type list with the test case.

Description
In some cases, you want to test the behavior of the class template instantiated in a range of types. You could write a test for each type, but that is bothersome, and it is better to use a type list.
This method is described below.
First, define the fixture class of the template class.
1 template<class T>
2 class MyTypeTest : public ::testing::Test
3 {
4 Protected:
5  ....
6  typedef std::vecotr<T> Vec;
7  static T m_SharedValue;
8  T m_Value;
9 };
Next, define the type list. Use the class provided to define the type list.
1 typedef ::testing::Types<char, int, unsigned int> MyTypeList;
Associate the fixture class using the TYPED_TEST_CASE macro.
1 TYPED_TEST_CASE(MyTypeTest, MyTypeList);
Finally, define the test.
1 TYPED_TEST(MyTypeTest, mytest)
2 {
3  // Use TypeParam to acquire the type T of MyTypeTest.
4  TypeParam x = this->m_Value;
5 
6  // Add the TestFixture:: prefix to access static data members.
7  TypeParam y = TestFixture::m_SharedValue;
8 
9  // Types declared with typedef may be used as follows.
10  typename TestFixture::Vec vec;
11  vec.push_back(x + y);
12  ...
13 }
Examples:
testing/param_type/param_type.cpp.

Definition at line 46 of file ParamType.h.

Function Documentation

nn::nlib::testing::DoubleLE ( const char *  expr1,
const char *  expr2,
double  val1,
double  val2 
)

Determines if val1 <= val2. [ASSERT|EXPECT] Used by including in PRED_FORMAT2.

Parameters
[in]expr1val1 as a string.
[in]expr2val2 as a string.
[in]val1double-type value.
[in]val2double-type value.
Returns
Object of the AssertionResult type.
Description
Unlike a standard double type comparison, this test succeeds if val1 and val2 are similar. The thresholds are the same as for ASSERT_DOUBLE_EQ.
nn::nlib::testing::FloatLE ( const char *  expr1,
const char *  expr2,
float  val1,
float  val2 
)

Determines if val1 <= val2. [ASSERT|EXPECT] Used by including in PRED_FORMAT2.

Parameters
[in]expr1val1 as a string.
[in]expr2val2 as a string.
[in]val1float-type value.
[in]val2float-type value.
Returns
Object of the AssertionResult type.
Description
Unlike a standard float type comparison, this test succeeds if val1 and val2 are similar. The thresholds are the same as for ASSERT_FLOAT_EQ.