#include <functional>
#include <iostream>
#include <sstream>
#include <string>
#include <nx/kit/utils.h>
Go to the source code of this file.
|
#define | NX_KIT_API |
|
#define | TEST(TEST_CASE, TEST_NAME) |
|
#define | ASSERT_TRUE(CONDITION) ::nx::kit::test::detail::assertBool(true, (CONDITION), #CONDITION, __FILE__, __LINE__) |
|
#define | ASSERT_TRUE_AT_LINE(LINE, CONDITION) ::nx::kit::test::detail::assertBool(true, (CONDITION), #CONDITION, __FILE__, (LINE)) |
|
#define | ASSERT_FALSE(CONDITION) ::nx::kit::test::detail::assertBool(false, (CONDITION), #CONDITION, __FILE__, __LINE__) |
|
#define | ASSERT_FALSE_AT_LINE(LINE, CONDITION) ::nx::kit::test::detail::assertBool(false, (CONDITION), #CONDITION, __FILE__, (LINE)) |
|
#define | ASSERT_EQ(EXPECTED, ACTUAL) |
|
#define | ASSERT_EQ_AT_LINE(LINE, EXPECTED, ACTUAL) |
|
#define | ASSERT_STREQ(EXPECTED, ACTUAL) |
|
#define | ASSERT_STREQ_AT_LINE(LINE, EXPECTED, ACTUAL) |
|
|
typedef std::function< void()> | nx::kit::test::detail::TestFunc |
|
|
const char * | nx::kit::test::tempDir () |
|
const char * | nx::kit::test::staticTempDir () |
|
int | nx::kit::test::runAllTests (const char *testSuiteName, int argc, const char *const argv[]) |
|
void | nx::kit::test::createFile (const char *filename, const char *content) |
|
void | nx::kit::test::detail::failEq (const char *expectedValue, const char *expectedExpr, const char *actualValue, const char *actualExpr, const char *const file, int line) |
|
int | nx::kit::test::detail::regTest (const Test &test) |
|
void | nx::kit::test::detail::assertBool (bool expected, bool condition, const char *conditionStr, const char *file, int line) |
|
template<typename Expected , typename Actual > |
void | nx::kit::test::detail::assertEq (const Expected &expected, const char *expectedExpr, const Actual &actual, const char *actualExpr, const char *file, int line) |
|
void | nx::kit::test::detail::assertStrEq (const char *expectedValue, const char *expectedExpr, const char *actualValue, const char *actualExpr, const char *file, int line) |
|
const char * | nx::kit::test::detail::toCStr (const std::string &s) |
|
const char * | nx::kit::test::detail::toCStr (const char *s) |
|
Rudimentary standalone unit testing framework designed to mimic Google Test to a certain degree.
◆ ASSERT_EQ
#define ASSERT_EQ |
( |
|
EXPECTED, |
|
|
|
ACTUAL |
|
) |
| |
Value:::nx::kit::test::detail::assertEq( \
(EXPECTED), #EXPECTED, (ACTUAL), #ACTUAL, __FILE__, __LINE__)
◆ ASSERT_EQ_AT_LINE
#define ASSERT_EQ_AT_LINE |
( |
|
LINE, |
|
|
|
EXPECTED, |
|
|
|
ACTUAL |
|
) |
| |
Value:::nx::kit::test::detail::assertEq( \
(EXPECTED), #EXPECTED, (ACTUAL), #ACTUAL, __FILE__, (LINE))
◆ ASSERT_STREQ
#define ASSERT_STREQ |
( |
|
EXPECTED, |
|
|
|
ACTUAL |
|
) |
| |
Value:::nx::kit::test::detail::assertStrEq( \
::nx::kit::test::detail::toCStr(EXPECTED), #EXPECTED, \
::nx::kit::test::detail::toCStr(ACTUAL), #ACTUAL, __FILE__, __LINE__)
◆ ASSERT_STREQ_AT_LINE
#define ASSERT_STREQ_AT_LINE |
( |
|
LINE, |
|
|
|
EXPECTED, |
|
|
|
ACTUAL |
|
) |
| |
Value:::nx::kit::test::detail::assertStrEq( \
::nx::kit::test::detail::toCStr(EXPECTED), #EXPECTED, \
::nx::kit::test::detail::toCStr(ACTUAL), #ACTUAL, __FILE__, (LINE))
◆ TEST
#define TEST |
( |
|
TEST_CASE, |
|
|
|
TEST_NAME |
|
) |
| |
Value:static void test_##TEST_CASE##_##TEST_NAME(); \
int unused_##TEST_CASE##_##TEST_NAME = \
::nx::kit::test::detail::regTest( \
{#TEST_CASE, #TEST_NAME, #TEST_CASE "." #TEST_NAME, test_##TEST_CASE##_##TEST_NAME, \
""}); \
static void test_##TEST_CASE##_##TEST_NAME()
◆ runAllTests()
NX_KIT_API int nx::kit::test::runAllTests |
( |
const char * |
testSuiteName, |
|
|
int |
argc, |
|
|
const char *const |
argv[] |
|
) |
| |
Usage: call from main():
int main(int argc, const char* const argv[])
{
return nx::kit::test::runAllTests("myTests", argc, argv);
}
- Returns
- Number of failed tests.
◆ staticTempDir()
NX_KIT_API const char * nx::kit::test::staticTempDir |
( |
| ) |
|
Should be called for tests that require temp dir outside the TEST() body, e.g. from a static initialization code.
- Returns
- Path to the directory to create temp files in, including the trailing path separator: "base-temp-dir/static/", where "base-temp-dir" is the same as for tempDir(). The directory is created (if already exists - a fatal error is produced).
◆ tempDir()
NX_KIT_API const char * nx::kit::test::tempDir |
( |
| ) |
|
Should be called for regular tests, from the TEST() body.
- Returns
- Path to the directory to create temp files in, including the trailing path separator: "base-temp-dir/case.test/", where "base-temp-dir" can be assigned with "--tmp" command line option and by default is "system-temp-dir/nx_kit_test_#", where # is a random number. The directory is created (if already exists - a fatal error is produced).