nlib
nn::nlib::testing Namespace Reference

Framework to test C++ code. View the description of List of testing Library Features. More...

Classes

class  Environment
 Defines the SetUp and TearDown functions that inherit this class and are run globally. More...
 

Functions

void InitNintendoTest (int *argc, char **argv)
 Processes command-line options for the test program.
 
void InitNintendoTest (int *argc, wchar_t **argv)
 Processes command-line options for the test program.
 
EnvironmentAddGlobalTestEnvironment (Environment *env)
 Passes the pointer to Environment and registers the code to run before and after all tests.
 
AssertionResult 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 DoubleLE (const char *expr1, const char *expr2, double val1, double val2)
 Determines if val1 <= val2. [ASSERT|EXPECT] Used by including in PRED_FORMAT2. More...
 

Detailed Description

Framework to test C++ code. View the description of List of testing Library Features.

Description
This test framework is designed and implemented to operate in an environment more constrained than a PC.
It contains the following features.
  • Auto-detection of the test function. (It does not need to be explicitly registered using the addTest method, as with CppUnit.)
  • Support of simple display of user defined failure messages using operator<<. (For example: ASSERT_EQ(5, Foo(i)) << ” where i = ” << i;.)
  • Export JUnit-formatted XML reports that are usable by systems such as Jenkins.
  • Floating point comparison that considers errors.
  • Test private function.
  • Tests that parameterize values.
  • A typed test against the template class using a type list.
  • Predicate assertion (a test that takes a function and its arguments as values).
The testing library maintains limited macro and function name compatibility with Google Test, and is built to compile test code that is written using Google Test.
Unlike Google Test, the testing library may be used in an environment that does not support std::ostream, or in environments that do not support calling new before the main function.
This capability enables you to simplify the execution of test code created using Google Test in a PC environment on a wide range of target devices.
The testing library has implemented the following macros.
These macros maintain a limited compatibility with the Google Test macros.
If an ASSERT_* macro fails, the process returns directly from that function, but continues tests within the function if EXPECT_* macros fail.
View List of testing Library Features for a description of macros.

Basics Usage

In test code, the header file provided by the testing library must be included instead of the header file code when using Google Test as shown below.
// Include nn/nlib/testing/testing.h instead of gtest/gtest.h
#include "gtest/gtest.h" // Remove this line in your test program.
When the NLIB_USE_GTEST macro is defined before including testing.h, Google Test can be used by including the Google Test header.
Basic test code looks like the following example.
TEST(MyTest, simple) {
// Write test code.
// Tests are automatically registered. Code to register the test is not required.
ASSERT_TRUE(conditional_statement_expected_to_be_TRUE);
ASSERT_EQ(expected_value, actual_value) << "Message shown when an error occurs." << ...;
ASSERT_STREQ("expected_string", "actual_string");
.....
}
.....
int main(int argc, char** argv) {
return RUN_ALL_TESTS(); // Returns a nonzero value on failure.
}
For more information about writing more advanced tests, see the Google Test documentation or the supplemental samples and references.

Differences From Google Test

The major differences and limitations compared to Google Test at this point are described below.
  • With the ASSERT_EQ and EXPECT_EQ functions, a comparison with NULL causes a warning or a compiler error. This issue requires you to write comparisons as ASSERT_TRUE(NULL == val);.
  • Display does not use std::ostream. As a result, use the NLIB_TESTING_OSTREAM() macro instead of std::ostream to implement an operator<< overload or PrintTo function.
  • Fewer object types may be displayed using operator<<. std::endl or functions such as manipulators cannot be used because std::ostream is not real.
  • Not designed to be thread-safe.
  • Only the following command-line options are implemented.
    • --gtest_output (the GTEST_OUTPUT environment variable)
    • --gtest_color (the GTEST_COLOR environment variable)
    • --gtest_break_on_failure (the GTEST_BREAK_ON_FAILURE environment variable)
    • --gtest_also_run_disabled_tests (the GTEST_ALSO_RUN_DISABLED_TESTS environment variable)
    • --gtest_repeat (the GTEST_REPEAT environment variable)
    • --gtest_filter (the GTEST_FILTER environment variable)
    • --gtest_shuffle (the GTEST_SHUFFLE environment variable)
    • --gtest_random_seed (the GTEST_RANDOM_SEED environment variable)
    • --gtest_print_time (the GTEST_PRINT_TIME environment variable)
  • Death tests such as ASSERT_DEATH are not implemented.
  • The event listener API is not supported.