summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/c_runtime/wcscat/test1/test1.cpp
blob: e9a79d3880d6b9c668f85db0c6dd009aab6fa2e3 (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
// 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: 
** Test to that wcscat correctly concatanates wide strings, including placing 
** null pointers.
**
**
**==========================================================================*/



#include <palsuite.h>

/*
 * Notes: uses memcmp and the (pal) sprintf_s
 */

int __cdecl main(int argc, char *argv[])
{
    WCHAR dest[80];
    WCHAR test[] = {'f','o','o',' ','b','a','r',' ','b','a','z',0};
    WCHAR str1[] = {'f','o','o',' ',0};
    WCHAR str2[] = {'b','a','r',' ',0};
    WCHAR str3[] = {'b','a','z',0};
    WCHAR *ptr;
    char buffer[256];

    
    if (PAL_Initialize(argc, argv))
    {
        return FAIL;
    }


    dest[0] = 0;

    ptr = wcscat(dest, str1);
    if (ptr != dest)
    {
        Fail("ERROR: Expected wcscat to return ptr to %p, got %p", dest, ptr);
    }

    ptr = wcscat(dest, str2);
    if (ptr != dest)
    {
        Fail("ERROR: Expected wcscat to return ptr to %p, got %p", dest, ptr);
    }

    ptr = wcscat(dest, str3);
    if (ptr != dest)
    {
        Fail("ERROR: Expected wcscat to return ptr to %p, got %p", dest, ptr);
    }

    if (memcmp(dest, test, sizeof(test)) != 0)
    {
        sprintf_s(buffer, _countof(buffer), "%S", dest);
        Fail("ERROR: Expected wcscat to give \"%s\", got \"%s\"\n", 
            "foo bar baz", buffer);
    }

    PAL_Terminate();
    return PASS;
}