1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-23 00:15:58 +01:00

Add support for strings in TEST_CASE()

This commit is contained in:
Elliot Gawthrop
2018-12-09 21:21:46 +00:00
parent f433480f7f
commit 5db2a3dbd9
2 changed files with 75 additions and 1 deletions

View File

@@ -46,6 +46,14 @@ void flushSpy(void) {}
int SetToOneToFailInTearDown;
int SetToOneMeanWeAlreadyCheckedThisGuy;
static unsigned NextExpectedStringIndex;
static unsigned NextExpectedCharIndex;
void suiteSetUp(void)
{
NextExpectedStringIndex = 0;
NextExpectedCharIndex = 0;
}
void setUp(void)
{
@@ -111,3 +119,56 @@ void test_NormalFailsStillWork(void)
TEST_ASSERT_TRUE(0);
VERIFY_FAILS_END
}
TEST_CASE(0, "abc")
TEST_CASE(1, "{")
TEST_CASE(2, "}")
TEST_CASE(3, ";")
TEST_CASE(4, "\"quoted\"")
void test_StringsArePreserved(unsigned index, const char * str)
{
static const char * const expected[] =
{
"abc",
"{",
"}",
";",
"\"quoted\""
};
/* Ensure that no test cases are skipped by tracking the next expected index */
TEST_ASSERT_EQUAL_UINT32(NextExpectedStringIndex, index);
TEST_ASSERT_LESS_THAN(sizeof(expected) / sizeof(expected[0]), index);
TEST_ASSERT_EQUAL_STRING(expected[index], str);
NextExpectedStringIndex++;
}
TEST_CASE(0, 'x')
TEST_CASE(1, '{')
TEST_CASE(2, '}')
TEST_CASE(3, ';')
TEST_CASE(4, '\'')
TEST_CASE(5, '"')
void test_CharsArePreserved(unsigned index, char c)
{
static const char expected[] =
{
'x',
'{',
'}',
';',
'\'',
'"'
};
/* Ensure that no test cases are skipped by tracking the next expected index */
TEST_ASSERT_EQUAL_UINT32(NextExpectedCharIndex, index);
TEST_ASSERT_LESS_THAN(sizeof(expected) / sizeof(expected[0]), index);
TEST_ASSERT_EQUAL(expected[index], c);
NextExpectedCharIndex++;
}