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: DeleteFileW.c
8**
9** Purpose: Tests the PAL implementation of the DeleteFileW function.
10**
11**
12**===================================================================*/
13
14// delete an existing file
15// delete a non-existant file
16// delete an open file
17// delete files using wild cards
18// delete a hidden file
19// delete a file without proper permissions
20//
21
22
23#include <palsuite.h>
24
25
26int __cdecl main(int argc, char *argv[])
27{
28 FILE *tempFile = NULL;
29 BOOL bRc = FALSE;
30 WCHAR* pTemp = NULL;
31
32
33 if (0 != PAL_Initialize(argc,argv))
34 {
35 return FAIL;
36 }
37
38 //
39 // deleting an existing file
40 //
41 tempFile = fopen("testFile01.tmp", "w");
42 if (tempFile == NULL)
43 {
44 Fail ("DeleteFileW: ERROR: Couldn't create \"DeleteFileW's"
45 " testFile01.tmp\"\n");
46 }
47
48 fprintf(tempFile, "DeleteFileW test file.\n");
49 if (fclose(tempFile) != 0)
50 {
51 Fail ("DeleteFileA: ERROR: Couldn't close \"DeleteFileW's"
52 " testFile01.tmp\"\n");
53 }
54
55 pTemp = convert("testFile01.tmp");
56 bRc = DeleteFileW(pTemp);
57 free(pTemp);
58 if (bRc != TRUE)
59 {
60 Fail ("DeleteFileW: ERROR: Couldn't delete DeleteFileW's"
61 " \"testFile01.tmp\"\n"
62 " Error is %d\n", GetLastError());
63 }
64
65
66 //
67 // deleting a non-existant file : should fail
68 //
69
70 pTemp = convert("testFile02.tmp");
71 bRc = DeleteFileW(pTemp);
72 free(pTemp);
73 if (bRc != FALSE)
74 {
75 Fail ("DeleteFileW: ERROR: Was able to delete the non-existant"
76 " file \"testFile02.tmp\"\n");
77 }
78
79
80
81
82 //
83 // deleting an open file
84 //
85 tempFile = fopen("testFile03.tmp", "w");
86 if (tempFile == NULL)
87 {
88 Fail("DeleteFileW: ERROR: Couldn't create \"DeleteFileW's"
89 " testFile03.tmp\"\n");
90 }
91
92 fprintf(tempFile, "DeleteFileW test file.\n");
93 if (fclose(tempFile) != 0)
94 {
95 Fail ("DeleteFileA: ERROR: Couldn't close \"DeleteFileW's"
96 " testFile03.tmp\"\n");
97 }
98
99 pTemp = convert("testFile03.tmp");
100 bRc = DeleteFileW(pTemp);
101 if (bRc != TRUE)
102 {
103 Fail("DeleteFileW: ERROR: Couldn't delete DeleteFileW's"
104 " \"testFile03.tmp\"\n"
105 " Error is %d\n", GetLastError());
106 free(pTemp);
107 }
108 bRc = DeleteFileW(pTemp);
109 free(pTemp);
110
111
112
113
114 //
115 // delete using wild cards
116 //
117
118 // create the test file
119 tempFile = fopen("testFile04.tmp", "w");
120 if (tempFile == NULL)
121 {
122 Fail("DeleteFileW: ERROR: Couldn't create DeleteFileW's"
123 " \"testFile04.tmp\"\n");
124 }
125 fprintf(tempFile, "DeleteFileW test file.\n");
126 if (fclose(tempFile) != 0)
127 {
128 Fail ("DeleteFileA: ERROR: Couldn't close \"DeleteFileW's"
129 " testFile04.tmp\"\n");
130 }
131
132 // delete using '?'
133 pTemp = convert("testFile0?.tmp");
134 bRc = DeleteFileW(pTemp);
135 free(pTemp);
136 if (bRc == TRUE)
137 {
138 Fail("DeleteFileW: ERROR: Was able to delete using the"
139 " \'?\' wildcard\n");
140 }
141
142 // delete using '*'
143 pTemp = convert("testFile*.tmp");
144 bRc = DeleteFileW(pTemp);
145 free(pTemp);
146 if (bRc == TRUE)
147 {
148 Fail("DeleteFileW: ERROR: Was able to delete using the"
149 " \'*\' wildcard\n");
150 }
151
152 pTemp = convert("testFile04.tmp");
153 bRc = DeleteFileW(pTemp);
154 free(pTemp);
155 if (bRc != TRUE)
156 {
157 Fail ("DeleteFileW: ERROR: Couldn't delete DeleteFileW's"
158 " \"testFile04.tmp\"\n"
159 " Error is %d\n", GetLastError());
160 }
161
162 PAL_Terminate();
163 return PASS;
164}
165