Remove the unneeded $Id$ blabla from the source code.
[reactos.git] / rostests / tests / sectest / sectest.c
1 #define UNICODE
2 #define _UNICODE
3 #include <windows.h>
4 #include <stdio.h>
5 #include <string.h>
6
7 #include <tchar.h>
8
9 int main(int argc, char* argv[])
10 {
11 HANDLE hFile;
12 HANDLE Section;
13 PVOID BaseAddress;
14
15 printf("Section Test\n");
16
17 hFile = CreateFile(_T("sectest.txt"),
18 GENERIC_READ | GENERIC_WRITE,
19 0,
20 NULL,
21 CREATE_ALWAYS,
22 0,
23 0);
24 if (hFile == INVALID_HANDLE_VALUE)
25 {
26 printf("Failed to create file (err=%ld)", GetLastError());
27 return 1;
28 }
29
30 Section = CreateFileMapping(hFile,
31 NULL,
32 PAGE_READWRITE,
33 0,
34 4096,
35 NULL);
36 if (Section == NULL)
37 {
38 printf("Failed to create section (err=%ld)", GetLastError());
39 return 1;
40 }
41
42 printf("Mapping view of section\n");
43 BaseAddress = MapViewOfFile(Section,
44 FILE_MAP_ALL_ACCESS,
45 0,
46 0,
47 4096);
48 printf("BaseAddress %x\n", (UINT) BaseAddress);
49 if (BaseAddress == NULL)
50 {
51 printf("Failed to map section (%ld)\n", GetLastError());
52 return 1;
53 }
54
55 printf("Clearing section\n");
56 FillMemory(BaseAddress, 4096, ' ');
57 printf("Copying test data to section\n");
58 strcpy(BaseAddress, "test data");
59
60 if (!UnmapViewOfFile(BaseAddress))
61 {
62 printf("Failed to unmap view of file (%ld)\n", GetLastError());
63 return 1;
64 }
65
66 if (!CloseHandle(hFile))
67 {
68 printf("Failed to close file (%ld)\n", GetLastError());
69 return 1;
70 }
71
72 return 0;
73 }
74