1
0
mirror of https://github.com/cc65/cc65.git synced 2024-11-06 15:06:07 +00:00
cc65/test/val/lib_common_strcat.c

55 lines
1.8 KiB
C
Raw Normal View History

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