#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) ENABLED_TEST(TEST_CASE, TEST_NAME) |
|
#define | ENABLED_TEST(TEST_CASE, TEST_NAME) |
|
#define | DISABLED_TEST(TEST_CASE, TEST_NAME) static void disabled_test_##TEST_CASE##_##TEST_NAME() /* The function will be unused. */ |
|
#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, __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, __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) |
|
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 actualLine) |
|
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, int actualLine) |
|
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, int actualLine=-1) |
|
void | nx::kit::test::detail::assertStrEq (const char *expectedValue, const char *expectedExpr, const char *actualValue, const char *actualExpr, const char *file, int line, int actualLine) |
|
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, __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, __LINE__)
◆ ENABLED_TEST
#define ENABLED_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()
◆ TEST
#define TEST |
( |
|
TEST_CASE, |
|
|
|
TEST_NAME |
|
) |
| ENABLED_TEST(TEST_CASE, TEST_NAME) |
Main macro for defining a test function. Calls a helper macro - such trick allows to comment out all tests except one by redefining TEST to DISABLED_TEST, and changing that one test to use ENABLED_TEST instead of TEST.
Usage:
{
int var = 42;
ASSERT_EQ(42, var);
}
◆ runAllTests()
NX_KIT_API int nx::kit::test::runAllTests |
( |
const char * |
testSuiteName | ) |
|
Usage: call from main():
int main()
{
return nx::kit::test::runAllTests("myTests");
}
- 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).