-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_widechar_files.c
More file actions
79 lines (68 loc) · 2.45 KB
/
test_widechar_files.c
File metadata and controls
79 lines (68 loc) · 2.45 KB
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
/*
* Test for wide-char file operations (CreateFileW, DeleteFileW, CopyFileW)
*/
#include <windows.h>
#include <stdio.h>
#include <wchar.h>
int main() {
printf("Testing Wide-Char File Operations...\n\n");
// Test 1: CreateFileW
printf("Test 1: CreateFileW\n");
HANDLE hFile = CreateFileW(L"C:\\temp\\test_wide.txt",
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hFile == INVALID_HANDLE_VALUE) {
printf(" ❌ CreateFileW failed!\n");
return 1;
}
printf(" ✅ CreateFileW succeeded (handle: %p)\n", hFile);
// Write some data
const char* data = "Hello from wide-char file!\n";
DWORD bytesWritten;
if (!WriteFile(hFile, data, strlen(data), &bytesWritten, NULL)) {
printf(" ❌ WriteFile failed!\n");
CloseHandle(hFile);
return 1;
}
printf(" ✅ Wrote %lu bytes\n", bytesWritten);
CloseHandle(hFile);
// Test 2: CopyFileW
printf("\nTest 2: CopyFileW\n");
if (!CopyFileW(L"C:\\temp\\test_wide.txt", L"C:\\temp\\test_wide_copy.txt", FALSE)) {
printf(" ❌ CopyFileW failed!\n");
return 1;
}
printf(" ✅ CopyFileW succeeded\n");
// Verify the copy exists by opening it
HANDLE hCopy = CreateFileW(L"C:\\temp\\test_wide_copy.txt",
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (hCopy == INVALID_HANDLE_VALUE) {
printf(" ❌ Copied file doesn't exist!\n");
return 1;
}
printf(" ✅ Copied file exists and can be opened\n");
CloseHandle(hCopy);
// Test 3: DeleteFileW
printf("\nTest 3: DeleteFileW\n");
if (!DeleteFileW(L"C:\\temp\\test_wide.txt")) {
printf(" ❌ DeleteFileW failed for original file!\n");
return 1;
}
printf(" ✅ Original file deleted\n");
if (!DeleteFileW(L"C:\\temp\\test_wide_copy.txt")) {
printf(" ❌ DeleteFileW failed for copied file!\n");
return 1;
}
printf(" ✅ Copied file deleted\n");
printf("\n🎉 All tests passed!\n");
return 0;
}