13 #if !defined(NX_KIT_API) 21 #define TEST(TEST_CASE, TEST_NAME) \ 22 static void test_##TEST_CASE##_##TEST_NAME(); \ 23 static const nx::kit::test::detail::Test testDescriptor_##TEST_CASE##_##TEST_NAME = \ 24 {#TEST_CASE, #TEST_NAME, &test_##TEST_CASE##_##TEST_NAME}; \ 25 static const int unused_##TEST_CASE##_##TEST_NAME = \ 26 nx::kit::test::detail::regTest(testDescriptor_##TEST_CASE##_##TEST_NAME); \ 27 static void test_##TEST_CASE##_##TEST_NAME() 30 #define ASSERT_TRUE(CONDITION) \ 31 nx::kit::test::detail::assertBool(true, (CONDITION), #CONDITION, __FILE__, __LINE__) 33 #define ASSERT_FALSE(CONDITION) \ 34 nx::kit::test::detail::assertBool(false, (CONDITION), #CONDITION, __FILE__, __LINE__) 36 #define ASSERT_EQ(EXPECTED, ACTUAL) \ 37 nx::kit::test::detail::assertEq( \ 38 (EXPECTED), #EXPECTED, (ACTUAL), #ACTUAL, __FILE__, __LINE__) 40 #define ASSERT_EQ_AT_LINE(LINE, EXPECTED, ACTUAL) \ 41 nx::kit::test::detail::assertEq( \ 42 (EXPECTED), #EXPECTED, (ACTUAL), #ACTUAL, __FILE__, (LINE)) 44 #define ASSERT_STREQ(EXPECTED, ACTUAL) \ 45 nx::kit::test::detail::assertStrEq( \ 46 nx::kit::test::detail::toCStr(EXPECTED), #EXPECTED, \ 47 nx::kit::test::detail::toCStr(ACTUAL), #ACTUAL, __FILE__, __LINE__) 49 #define ASSERT_STREQ_AT_LINE(LINE, EXPECTED, ACTUAL) \ 50 nx::kit::test::detail::assertStrEq( \ 51 nx::kit::test::detail::toCStr(EXPECTED), #EXPECTED, \ 52 nx::kit::test::detail::toCStr(ACTUAL), #ACTUAL, __FILE__, (LINE)) 60 NX_KIT_API
const char* tempDir();
74 NX_KIT_API
int runAllTests(
const char* testSuiteName,
int argc,
const char*
const argv[]);
76 NX_KIT_API
void createFile(
const char* filename,
const char* content);
81 #if defined(NX_KIT_TEST_KEEP_TEMP_FILES) 84 static const nx::kit::test::TempFile::KeepFilesInitializer tempFileKeepFilesInitializer;
90 NX_KIT_API
void failEq(
91 const char* expectedValue,
const char* expectedExpr,
92 const char* actualValue,
const char* actualExpr,
93 const char* file,
int line);
95 typedef std::function<void()> TestFunc;
100 std::string testName;
105 NX_KIT_API
int regTest(
const Test& test);
107 NX_KIT_API
void assertBool(
108 bool expected,
bool condition,
const char* conditionStr,
const char* file,
int line);
110 template<
typename Expected,
typename Actual>
112 const Expected& expected,
const char* expectedExpr,
113 const Actual& actual,
const char* actualExpr,
114 const char* file,
int line)
116 if (!(expected == actual))
118 std::ostringstream expectedValue;
119 expectedValue << expected;
120 std::ostringstream actualValue;
121 actualValue << actual;
123 expectedValue.str().c_str(), expectedExpr,
124 actualValue.str().c_str(), actualExpr,
129 NX_KIT_API
void assertStrEq(
130 const char* expectedValue,
const char* expectedExpr,
131 const char* actualValue,
const char* actualExpr,
132 const char* file,
int line);
134 inline const char* toCStr(
const std::string& s)
139 inline const char* toCStr(
const char* s)