2017-02-26 19:03:05 +00:00
|
|
|
#include <string.h>
|
2017-02-28 07:05:11 +00:00
|
|
|
#include "unittest.h"
|
2022-04-17 14:07:52 +00:00
|
|
|
|
2017-02-26 21:36:19 +00:00
|
|
|
static char TestString[] = "01234567890123456789"; // two times the same string
|
2017-02-26 19:03:05 +00:00
|
|
|
static char Found[256];
|
|
|
|
|
|
|
|
TEST
|
|
|
|
{
|
|
|
|
unsigned len;
|
|
|
|
unsigned i;
|
|
|
|
char* p;
|
|
|
|
|
2017-02-26 21:36:19 +00:00
|
|
|
len = strlen(TestString)/2; // test only one half of the string, to find last appearance
|
2017-02-26 19:03:05 +00:00
|
|
|
|
|
|
|
/* Search for all characters in the string, including the terminator */
|
|
|
|
for (i = 0; i < len; ++i)
|
|
|
|
{
|
|
|
|
/* Search for this char */
|
|
|
|
p = strrchr (TestString, TestString[i]);
|
|
|
|
ASSERT_AreEqual(i+len, p-TestString, "%u", "Unexpected location of character '%c' found!" COMMA TestString[i]);
|
|
|
|
|
|
|
|
/* Mark the char as checked */
|
|
|
|
Found[TestString[i]] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for all other characters and make sure they aren't found */
|
|
|
|
for (i = 0; i < 256; ++i)
|
|
|
|
{
|
|
|
|
if (!Found[i])
|
|
|
|
{
|
|
|
|
p = strrchr (TestString, i);
|
|
|
|
ASSERT_IsFalse(p, "Unexpected location of character '%c' found!" COMMA TestString[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ENDTEST
|
|
|
|
|
|
|
|
|