summaryrefslogtreecommitdiff
path: root/src/pal/tests/palsuite/pal_specific/PAL_GetUserTempDirectoryW/test1/PAL_GetUserTempDirectoryW.cpp
blob: 65cc426c74a13b77208ce355e6bac109cee46925 (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
// 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: pal_getusertempdirectoryw.c
**
** Purpose: Positive test the PAL_GetUserTempDirectoryW API.
**          Call PAL_GetUserTempDirectoryW to retrieve the user
**          temp directory.
**
**
**============================================================*/
#define UNICODE
#include <palsuite.h>

#define DIRECTORYLENGTH 1024

int __cdecl main(int argc, char *argv[])
{
    int err;
    DWORD dwFileAttribute;
    DWORD cch = DIRECTORYLENGTH;
    WCHAR wDirectoryName[DIRECTORYLENGTH];

    //Initialize the PAL environment
    err = PAL_Initialize(argc, argv);
    if(0 != err)
    {
        ExitProcess(FAIL);
    }

    //retrieve the user temp directory
    err = PAL_GetUserTempDirectory(ddtInstallationDependentDirectory, wDirectoryName, &cch);

    if(0 == err || 0 == strlen(convertC(wDirectoryName)))
    {
        Fail("Failed to call PAL_GetUserTempDirectoryW API!\n");
    }


    //retrieve the attributes of a file or directory
    dwFileAttribute = GetFileAttributesW(wDirectoryName);


    //check if the retrieved attribute indicates a directory
    if( FILE_ATTRIBUTE_DIRECTORY != (FILE_ATTRIBUTE_DIRECTORY & dwFileAttribute))
    {
        Fail("PAL_GetUserTempDirectoryW API returned a non-directory name!\n");
    }

    printf ("PAL_GetUserTempDirectoryW returns %S\n", wDirectoryName);

    PAL_Terminate();
    return PASS;

}