blob: 2c8b19e0816c4d76ed325d73fc1d01460a15de22 (
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
|
// 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: GetTempFileNameW.c (test 2)
**
** Purpose: Tests the PAL implementation of the GetTempFileNameW function.
**
**
**===================================================================*/
#include <palsuite.h>
int __cdecl main(int argc, char *argv[])
{
UINT uiError = 0;
DWORD dwError = 0;
const UINT uUnique = 0;
WCHAR* wPrefix = NULL;
WCHAR* wPath = NULL;
WCHAR wReturnedName[256];
DWORD i;
if (0 != PAL_Initialize(argc,argv))
{
return FAIL;
}
// test the number of temp files that can be created
wPrefix = convert("cfr");
wPath = convert(".");
for (i = 0; i < 0x10005; i++)
{
uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName);
if (uiError == 0)
{
dwError = GetLastError();
if (dwError == ERROR_FILE_EXISTS)
{
// file already existes so break out of the loop
i--; // decrement the count because it wasn't successful
break;
}
else
{
// it was something other than the file already existing?
free (wPath);
free (wPrefix);
Fail("GetTempFileNameW: ERROR -> Call failed with a valid "
"path and prefix with the error code: %ld\n", GetLastError());
}
}
else
{
// verify temp file was created
if (GetFileAttributesW(wReturnedName) == -1)
{
free (wPath);
free (wPrefix);
Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed "
"on the returned temp file with error code: %ld.\n",
GetLastError());
}
}
}
free (wPath);
free (wPrefix);
// did it create more than 0xffff files
if (i > 0xffff)
{
Fail("GetTempFileNameW: ERROR -> Was able to create more than 0xffff"
" temp files.\n");
}
PAL_Terminate();
return PASS;
}
|