1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*=====================================================================
6**
7** Source: GetTempFileNameW.c (test 2)
8**
9** Purpose: Tests the PAL implementation of the GetTempFileNameW function.
10**
11**
12**===================================================================*/
13
14#include <palsuite.h>
15
16
17
18int __cdecl main(int argc, char *argv[])
19{
20 UINT uiError = 0;
21 DWORD dwError = 0;
22 const UINT uUnique = 0;
23 WCHAR* wPrefix = NULL;
24 WCHAR* wPath = NULL;
25 WCHAR wReturnedName[256];
26 DWORD i;
27
28 if (0 != PAL_Initialize(argc,argv))
29 {
30 return FAIL;
31 }
32
33
34 // test the number of temp files that can be created
35 wPrefix = convert("cfr");
36 wPath = convert(".");
37 for (i = 0; i < 0x10005; i++)
38 {
39 uiError = GetTempFileNameW(wPath, wPrefix, uUnique, wReturnedName);
40 if (uiError == 0)
41 {
42 dwError = GetLastError();
43 if (dwError == ERROR_FILE_EXISTS)
44 {
45 // file already existes so break out of the loop
46 i--; // decrement the count because it wasn't successful
47 break;
48 }
49 else
50 {
51 // it was something other than the file already existing?
52 free (wPath);
53 free (wPrefix);
54 Fail("GetTempFileNameW: ERROR -> Call failed with a valid "
55 "path and prefix with the error code: %ld\n", GetLastError());
56 }
57 }
58 else
59 {
60 // verify temp file was created
61 if (GetFileAttributesW(wReturnedName) == -1)
62 {
63 free (wPath);
64 free (wPrefix);
65 Fail("GetTempFileNameW: ERROR -> GetFileAttributes failed "
66 "on the returned temp file with error code: %ld.\n",
67 GetLastError());
68 }
69 }
70 }
71
72 free (wPath);
73 free (wPrefix);
74
75 // did it create more than 0xffff files
76 if (i > 0xffff)
77 {
78 Fail("GetTempFileNameW: ERROR -> Was able to create more than 0xffff"
79 " temp files.\n");
80 }
81
82 PAL_Terminate();
83 return PASS;
84}
85