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