summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/c_runtime/memcpy/test1/test1.c
blob: 9da98d6573b5e548d8bb2fab986ba54fdd54987b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

/*============================================================================
**
** Source:  test1.c
**
** Purpose: Calls memcpy and verifies that the buffer was copied correctly.
**
**
**==========================================================================*/

#include <palsuite.h>

int __cdecl main(int argc, char **argv)
{
    char testA[20];
    char testB[20];
    void *retVal;
    long i;
   
    if (PAL_Initialize(argc, argv))
    {
        return FAIL;
    }


    memset(testA, 'a', 20);
    memset(testB, 'b', 20);

    retVal = (char *)memcpy(testB, testA, 0);
    if (retVal != testB)
    {
        Fail("memcpy should return a pointer to the destination buffer, "
             "but doesn't.\n");
    }
    for(i = 0; i<20; i++)
    {
        if (testB[i]!= 'b')
        {
            Fail("The destination buffer overflowed by memcpy.\n");
        }
    }

    retVal = (char *)memcpy(testB+1, testA, 18);
    if (retVal != testB+1)
    {
        Fail("memcpy should return a pointer to the destination buffer, "
             "but doesn't.\n");
    }

    if (testB[0] != 'b' || testB[19] != 'b')
    {
        Fail("The destination buffer was written out of bounds by memcpy!\n");
    }

    for(i = 1; i<19; i++)
    {
        if (testB[i]!= 'a')
        {
            Fail("The destination buffer copied to by memcpy doesn't match "
                 "the source buffer.\n");
        }
    }

    PAL_Terminate();

    return PASS;
}