2000-07-22 11:14:00 +00:00
|
|
|
#include <string.h>
|
2017-03-05 01:09:12 +00:00
|
|
|
#include "unittest.h"
|
2000-07-22 11:14:00 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
|
2000-07-22 11:14:00 +00:00
|
|
|
/* Test string. Must NOT have duplicate characters! */
|
|
|
|
static char S[] = "Helo wrd!\n";
|
|
|
|
|
|
|
|
static char Found[256];
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
TEST
|
2000-07-22 11:14:00 +00:00
|
|
|
{
|
|
|
|
unsigned Len;
|
|
|
|
unsigned I;
|
|
|
|
char* P;
|
|
|
|
|
|
|
|
/* Get the length of the string */
|
|
|
|
Len = strlen (S);
|
|
|
|
|
|
|
|
/* Search for all characters in the string, including the terminator */
|
2017-03-05 01:09:12 +00:00
|
|
|
for (I = 0; I < Len+1; ++I)
|
|
|
|
{
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Search for this char */
|
|
|
|
P = strchr (S, S[I]);
|
2000-07-22 11:14:00 +00:00
|
|
|
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Check if we found it */
|
2017-03-05 01:09:12 +00:00
|
|
|
ASSERT_IsFalse(P == 0 || (P - S) != I, "For code 0x%02X, offset %u!\nP = %04X offset = %04X\n" COMMA S[I] COMMA I COMMA P COMMA P-S);
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Mark the char as checked */
|
|
|
|
Found[S[I]] = 1;
|
2000-07-22 11:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Search for all other characters and make sure they aren't found */
|
2017-03-05 01:09:12 +00:00
|
|
|
for (I = 0; I < 256; ++I)
|
|
|
|
{
|
|
|
|
if (Found[I] == 0)
|
|
|
|
{
|
|
|
|
ASSERT_IsFalse(strchr (S, (char)I), "Failed for code 0x%02X\n" COMMA I);
|
2013-05-09 11:56:54 +00:00
|
|
|
}
|
2000-07-22 11:14:00 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-05 01:09:12 +00:00
|
|
|
ENDTEST
|