bb50fa8c5435c9db0cdb6bb5ac4c22ffb1b3206f
[reactos.git] / reactos / regtests / win32base / file-1.c
1 #include <windows.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4
5 #include "regtests.h"
6
7 static int RunTest(char *Buffer)
8 {
9 char buffer[4096];
10 HANDLE file;
11 DWORD wrote;
12 int c;
13
14 file = CreateFile("test.dat",
15 GENERIC_READ | GENERIC_WRITE,
16 0,
17 NULL,
18 CREATE_ALWAYS,
19 0,
20 0);
21
22 if (file == INVALID_HANDLE_VALUE)
23 {
24 sprintf(Buffer, "Error opening file (Status %x)", GetLastError());
25 return TS_FAILED;
26 }
27
28 for (c = 0; c < sizeof(buffer); c++)
29 buffer[c] = (char)c;
30
31 if (WriteFile( file, buffer, 4096, &wrote, NULL) == FALSE)
32 {
33 sprintf(Buffer, "Error writing file (Status %x)", GetLastError());
34 return TS_FAILED;
35 }
36
37 SetFilePointer(file, 0, 0, FILE_BEGIN);
38
39 if (ReadFile( file, buffer, 4096, &wrote, NULL) == FALSE)
40 {
41 sprintf(Buffer, "Error reading file (Status %x)", GetLastError());
42 return TS_FAILED;
43 }
44 for (c = 0; c < sizeof(buffer); c++)
45 {
46 if (buffer[c] != (char)c)
47 {
48 strcpy(Buffer, "Error: data read back is not what was written");
49 CloseHandle(file);
50 return TS_FAILED;
51 }
52 }
53
54 CloseHandle(file);
55 return TS_OK;
56 }
57
58 int
59 File_1Test(int Command, char *Buffer)
60 {
61 switch (Command)
62 {
63 case TESTCMD_RUN:
64 return RunTest(Buffer);
65 case TESTCMD_TESTNAME:
66 strcpy(Buffer, "File read/write");
67 return TS_OK;
68 default:
69 break;
70 }
71 return TS_FAILED;
72 }