4 #define SourceStringSize 384 // test correct page passing (>256, multiple of 128 here)
6 static char SourceString[SourceStringSize+1]; // +1 room for terminating null
7 static char DestinationString[2*SourceStringSize+1]; // will contain two times the source buffer
15 for (i=0; i < SourceStringSize; ++i)
16 SourceString[i] = (i%128)+1;
20 ASSERT_AreEqual(SourceStringSize, strlen(SourceString), "%u", "Source string initialization or 'strlen()' problem!");
22 /* Ensure empty destination string */
23 DestinationString[0] = 0;
25 ASSERT_AreEqual(0, strlen(DestinationString), "%u", "Destination string initialization or 'strlen()' problem!");
27 /* Test "unlimted" concatenation to empty buffer */
29 strncat(DestinationString, SourceString, 1024);
31 ASSERT_AreEqual(SourceStringSize, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to empty buffer!");
33 /* Test limited concatenation to non empty buffer */
35 p = strncat(DestinationString, SourceString, 128);
37 ASSERT_AreEqual(SourceStringSize+128, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to non-empty buffer!");
39 /* Test return value */
41 ASSERT_IsTrue(p == DestinationString, "Invalid return value!");
45 for(i=0; i < strlen(DestinationString); ++i)
47 unsigned current = DestinationString[i];
48 unsigned expected = (i%128)+1;
49 ASSERT_AreEqual(expected, current, "%u", "Unexpected destination buffer contents at position %u!\n" COMMA i);