summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/miscellaneous/GetCommandLineW/test1/test.c
blob: d8a81746b696685aeb7d7ecea12c8953ff05239e (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 : test.c
**
** Purpose: Test for GetCommandLineW() function
**
**
**=========================================================*/

#define UNICODE
#include <palsuite.h>

int __cdecl main(int argc, char *argv[]) 
{

    LPWSTR TheResult = NULL;	
    WCHAR *CommandLine;
    int i;
    WCHAR * p;

    /*
     * Initialize the PAL and return FAILURE if this fails
     */

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

    CommandLine = malloc(1024);
    wcscpy(CommandLine,convert(argv[0]));

    for(i=1;i<argc;++i) 
    {
        wcscat(CommandLine,convert(" "));
        wcscat(CommandLine,convert(argv[i]));
    }
  
    TheResult = GetCommandLine();
  
    /* If it is NULL, it failed. */
    if(TheResult == NULL) 
    {
        Fail("ERROR: The command line returned was NULL -- but should be "
	     "a LPWSTR.");      
    }

    // It's ok that if there is trailing white spaces in "TheResult"
    // Let's trim them.
    p = TheResult + wcslen(TheResult) - 1;
    while (* p == L' ' || * p == L'\t') { printf("%c\n", *p); * p-- = 0 ; }
  
    if(memcmp(TheResult,CommandLine,wcslen(TheResult)*2+2) != 0) 
    {
        Fail("ERROR: The command line returned was %s instead of %s "
	     "which was the command.\n",
	     convertC(TheResult), convertC(CommandLine));
    }
  
    free(CommandLine);
    
    PAL_Terminate();
    return PASS;
  
}