]> git.sur5r.net Git - cc65/blob - test/val/lib_common_strncat.c
Removed workaround.
[cc65] / test / val / lib_common_strncat.c
1 #include <string.h>
2 #include "unittest.h"
3
4 #define SourceStringSize 384                            // test correct page passing (>256, multiple of 128 here)
5
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
8
9
10 TEST
11 {
12     unsigned i;
13     char*    p;
14     
15     for (i=0; i < SourceStringSize; ++i)
16       SourceString[i] = (i%128)+1;
17
18     SourceString[i] = 0;
19
20     ASSERT_AreEqual(SourceStringSize, strlen(SourceString), "%u", "Source string initialization or 'strlen()' problem!");
21
22     /* Ensure empty destination string */
23     DestinationString[0] = 0;
24
25     ASSERT_AreEqual(0, strlen(DestinationString), "%u", "Destination string initialization or 'strlen()' problem!");
26     
27     /* Test "unlimted" concatenation to empty buffer */
28
29     strncat(DestinationString, SourceString, 1024);
30     
31     ASSERT_AreEqual(SourceStringSize, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to empty buffer!");
32     
33     /* Test limited concatenation to non empty buffer */
34
35     p = strncat(DestinationString, SourceString, 128);
36
37     ASSERT_AreEqual(SourceStringSize+128, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to non-empty buffer!");
38
39     /* Test return value */
40
41     ASSERT_IsTrue(p == DestinationString, "Invalid return value!");
42
43     /* Test contents */
44
45     for(i=0; i < strlen(DestinationString); ++i)
46     {
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);
50     }
51 }
52 ENDTEST