2017-02-25 19:19:34 +00:00
|
|
|
#include <string.h>
|
2017-02-28 07:05:11 +00:00
|
|
|
#include "unittest.h"
|
2017-02-25 19:19:34 +00:00
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
#define SourceStringSize 384 // test correct page passing (>256, multiple of 128 here)
|
2017-02-25 19:19:34 +00:00
|
|
|
|
2017-02-26 21:36:19 +00:00
|
|
|
static char SourceString[SourceStringSize+1]; // +1 room for terminating null
|
2017-02-25 19:19:34 +00:00
|
|
|
static char DestinationString[2*SourceStringSize+1]; // will contain two times the source buffer
|
|
|
|
|
|
|
|
|
2017-02-26 19:03:05 +00:00
|
|
|
TEST
|
2017-02-25 19:19:34 +00:00
|
|
|
{
|
2017-03-05 01:09:12 +00:00
|
|
|
unsigned i;
|
2017-02-25 19:19:34 +00:00
|
|
|
char* p;
|
2017-02-26 19:03:05 +00:00
|
|
|
|
2017-02-25 19:19:34 +00:00
|
|
|
for (i=0; i < SourceStringSize; ++i)
|
|
|
|
SourceString[i] = (i%128)+1;
|
|
|
|
|
|
|
|
SourceString[i] = 0;
|
|
|
|
|
2017-02-26 19:03:05 +00:00
|
|
|
ASSERT_AreEqual(SourceStringSize, strlen(SourceString), "%u", "Source string initialization or 'strlen()' problem!");
|
2017-02-25 19:19:34 +00:00
|
|
|
|
|
|
|
/* Ensure empty destination string */
|
|
|
|
DestinationString[0] = 0;
|
|
|
|
|
2017-02-26 19:03:05 +00:00
|
|
|
ASSERT_AreEqual(0, strlen(DestinationString), "%u", "Destination string initialization or 'strlen()' problem!");
|
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
/* Test "unlimted" concatenation to empty buffer */
|
2017-02-25 19:19:34 +00:00
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
strncat(DestinationString, SourceString, 1024);
|
2017-02-26 19:03:05 +00:00
|
|
|
|
|
|
|
ASSERT_AreEqual(SourceStringSize, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to empty buffer!");
|
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
/* Test limited concatenation to non empty buffer */
|
2017-02-25 19:19:34 +00:00
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
p = strncat(DestinationString, SourceString, 128);
|
2017-02-25 19:19:34 +00:00
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
ASSERT_AreEqual(SourceStringSize+128, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to non-empty buffer!");
|
2017-02-25 19:19:34 +00:00
|
|
|
|
|
|
|
/* Test return value */
|
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
ASSERT_IsTrue(p == DestinationString, "Invalid return value!");
|
2017-02-25 19:19:34 +00:00
|
|
|
|
|
|
|
/* Test contents */
|
|
|
|
|
2017-03-05 01:09:12 +00:00
|
|
|
for(i=0; i < strlen(DestinationString); ++i)
|
|
|
|
{
|
|
|
|
unsigned current = DestinationString[i];
|
|
|
|
unsigned expected = (i%128)+1;
|
|
|
|
ASSERT_AreEqual(expected, current, "%u", "Unexpected destination buffer contents at position %u!\n" COMMA i);
|
|
|
|
}
|
2017-02-25 19:19:34 +00:00
|
|
|
}
|
2017-02-26 19:03:05 +00:00
|
|
|
ENDTEST
|