15 #if !defined(NX_KIT_API) 23 extern bool NX_KIT_API verbose;
25 #define TEST(TEST_CASE, TEST_NAME) \ 26 static void test_##TEST_CASE##_##TEST_NAME(); \ 27 static const nx::kit::test::detail::Test testDescriptor_##TEST_CASE##_##TEST_NAME = \ 28 {#TEST_CASE, #TEST_NAME, &test_##TEST_CASE##_##TEST_NAME, ""}; \ 29 static const int unused_##TEST_CASE##_##TEST_NAME = \ 30 nx::kit::test::detail::regTest(testDescriptor_##TEST_CASE##_##TEST_NAME); \ 31 static void test_##TEST_CASE##_##TEST_NAME() 34 #define ASSERT_TRUE(CONDITION) \ 35 nx::kit::test::detail::assertBool(true, (CONDITION), #CONDITION, __FILE__, __LINE__) 37 #define ASSERT_TRUE_AT_LINE(LINE, CONDITION) \ 38 nx::kit::test::detail::assertBool(true, (CONDITION), #CONDITION, __FILE__, (LINE)) 40 #define ASSERT_FALSE(CONDITION) \ 41 nx::kit::test::detail::assertBool(false, (CONDITION), #CONDITION, __FILE__, __LINE__) 43 #define ASSERT_FALSE_AT_LINE(LINE, CONDITION) \ 44 nx::kit::test::detail::assertBool(false, (CONDITION), #CONDITION, __FILE__, (LINE)) 46 #define ASSERT_EQ(EXPECTED, ACTUAL) \ 47 nx::kit::test::detail::assertEq( \ 48 (EXPECTED), #EXPECTED, (ACTUAL), #ACTUAL, __FILE__, __LINE__) 50 #define ASSERT_EQ_AT_LINE(LINE, EXPECTED, ACTUAL) \ 51 nx::kit::test::detail::assertEq( \ 52 (EXPECTED), #EXPECTED, (ACTUAL), #ACTUAL, __FILE__, (LINE)) 54 #define ASSERT_STREQ(EXPECTED, ACTUAL) \ 55 nx::kit::test::detail::assertStrEq( \ 56 nx::kit::test::detail::toCStr(EXPECTED), #EXPECTED, \ 57 nx::kit::test::detail::toCStr(ACTUAL), #ACTUAL, __FILE__, __LINE__) 59 #define ASSERT_STREQ_AT_LINE(LINE, EXPECTED, ACTUAL) \ 60 nx::kit::test::detail::assertStrEq( \ 61 nx::kit::test::detail::toCStr(EXPECTED), #EXPECTED, \ 62 nx::kit::test::detail::toCStr(ACTUAL), #ACTUAL, __FILE__, (LINE)) 71 NX_KIT_API
const char* tempDir();
80 NX_KIT_API
const char* staticTempDir();
94 NX_KIT_API
int runAllTests(
const char* testSuiteName,
int argc,
const char*
const argv[]);
96 NX_KIT_API
void createFile(
const char* filename,
const char* content);
101 #if defined(NX_KIT_TEST_KEEP_TEMP_FILES) 104 static const nx::kit::test::TempFile::KeepFilesInitializer tempFileKeepFilesInitializer;
110 NX_KIT_API
void failEq(
111 const char* expectedValue,
const char* expectedExpr,
112 const char* actualValue,
const char* actualExpr,
113 const char* file,
int line);
115 typedef std::function<void()> TestFunc;
119 std::string testCase;
120 std::string testName;
125 NX_KIT_API
int regTest(
const Test& test);
127 NX_KIT_API
void assertBool(
128 bool expected,
bool condition,
const char* conditionStr,
const char* file,
int line);
130 template<
typename Expected,
typename Actual>
132 const Expected& expected,
const char* expectedExpr,
133 const Actual& actual,
const char* actualExpr,
134 const char* file,
int line)
136 if (!(expected == actual))
139 utils::toString(expected).c_str(), expectedExpr,
140 utils::toString(actual).c_str(), actualExpr,
145 NX_KIT_API
void assertStrEq(
146 const char* expectedValue,
const char* expectedExpr,
147 const char* actualValue,
const char* actualExpr,
148 const char* file,
int line);
150 inline const char* toCStr(
const std::string& s)
155 inline const char* toCStr(
const char* s)