]> git.sur5r.net Git - cc65/blob - test/val/lib_common_strncat.c
temporarily disable optimizations altogether until a fine grain control
[cc65] / test / val / lib_common_strncat.c
1 // temporarily disable optimizations altogether until a fine grain control
2 // is implemented on Makefile level only disabling the compiler option -Os
3 #pragma optimize (off)
4
5 #include <string.h>
6 #include "unittest.h"
7
8 #define SourceStringSize 384                            // test correct page passing (>256, multiple of 128 here)
9
10 static char SourceString[SourceStringSize+1];           // +1 room for terminating null
11 static char DestinationString[2*SourceStringSize+1];    // will contain two times the source buffer
12
13
14 TEST
15 {
16     unsigned i;
17     char*    p;
18     
19     for (i=0; i < SourceStringSize; ++i)
20       SourceString[i] = (i%128)+1;
21
22     SourceString[i] = 0;
23
24     ASSERT_AreEqual(SourceStringSize, strlen(SourceString), "%u", "Source string initialization or 'strlen()' problem!");
25
26     /* Ensure empty destination string */
27     DestinationString[0] = 0;
28
29     ASSERT_AreEqual(0, strlen(DestinationString), "%u", "Destination string initialization or 'strlen()' problem!");
30     
31     /* Test "unlimted" concatenation to empty buffer */
32
33     strncat(DestinationString, SourceString, 1024);
34     
35     ASSERT_AreEqual(SourceStringSize, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to empty buffer!");
36     
37     /* Test limited concatenation to non empty buffer */
38
39     p = strncat(DestinationString, SourceString, 128);
40
41     ASSERT_AreEqual(SourceStringSize+128, strlen(DestinationString), "%u", "Unexpected string length while string concatenation to non-empty buffer!");
42
43     /* Test return value */
44
45     ASSERT_IsTrue(p == DestinationString, "Invalid return value!");
46
47     /* Test contents */
48
49     for(i=0; i < strlen(DestinationString); ++i)
50     {
51         unsigned current = DestinationString[i];
52         unsigned expected = (i%128)+1;
53         ASSERT_AreEqual(expected, current, "%u", "Unexpected destination buffer contents at position %u!\n" COMMA i);
54     }
55 }
56 ENDTEST
57
58