ReactOS 0.4.15-dev-7897-g78dc504
CAtlFileMapping.cpp File Reference
#include <atlfile.h>
#include "atltest.h"
Include dependency graph for CAtlFileMapping.cpp:

Go to the source code of this file.

Classes

struct  TestData
 

Functions

static void test_SharedMem ()
 
static void test_FileMapping ()
 
 START_TEST (CAtlFileMapping)
 

Function Documentation

◆ START_TEST()

START_TEST ( CAtlFileMapping  )

Definition at line 193 of file CAtlFileMapping.cpp.

194{
197}
static void test_SharedMem()
static void test_FileMapping()

◆ test_FileMapping()

static void test_FileMapping ( )
static

Definition at line 140 of file CAtlFileMapping.cpp.

141{
142 WCHAR Buf[MAX_PATH] = {0};
144
145 GetModuleFileNameW(NULL, Buf, _countof(Buf));
146
148 HRESULT hr;
149
150 {
152 ok(hFile != INVALID_HANDLE_VALUE, "Could not open %S, aborting test\n", Buf);
154 return;
155
157
158 hr = test1.MapFile(hFile, 0, 0, PAGE_READONLY, FILE_MAP_READ);
159 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
160 ok(test1.GetData() != NULL, "Expected ptr, got %p\n", test1.GetData());
161 ok(test1.GetHandle() != NULL, "Expected handle, got %p\n", test1.GetHandle());
162 ok(test1.GetMappingSize() == FileSize.LowPart, "Expected %lu, got %lu\n", FileSize.LowPart, test1.GetMappingSize());
163
164 hr = test2.MapFile(hFile, 0, 0x10000, PAGE_READONLY, FILE_MAP_READ);
165 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
166 ok(test2.GetData() != NULL, "Expected ptr, got %p\n", test2.GetData());
167 ok(test2.GetHandle() != NULL, "Expected handle, got %p\n", test2.GetHandle());
168 // Offset is subtracted
169 ok(test2.GetMappingSize() == FileSize.LowPart - 0x10000, "Expected %lu, got %lu\n", FileSize.LowPart-0x10000, test2.GetMappingSize());
170
171 hr = test1.Unmap();
172 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
173 ok(test1.GetData() == NULL, "Expected NULL, got %p\n", test1.GetData());
174 ok(test1.GetHandle() == NULL, "Expected NULL, got %p\n", test1.GetHandle());
175 ok(test1.GetMappingSize() == FileSize.LowPart, "Expected %lu, got %lu\n", FileSize.LowPart, test1.GetMappingSize());
176
177 hr = test1.MapFile(hFile, 0x1000);
178 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
179 ok(test1.GetData() != NULL, "Expected ptr, got %p\n", test1.GetData());
180 ok(test1.GetHandle() != NULL, "Expected handle, got %p\n", test1.GetHandle());
181 ok(test1.GetMappingSize() == 0x1000, "Expected 0x1000, got %lu\n", test1.GetMappingSize());
182 }
183
184 // We can still access it after the file is closed
186 if (dos)
187 {
188 ok(dos->e_magic == IMAGE_DOS_SIGNATURE, "Expected IMAGE_DOS_SIGNATURE, got 0x%x\n", dos->e_magic);
189 }
190}
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define PAGE_READONLY
Definition: compat.h:138
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define MAX_PATH
Definition: compat.h:34
#define CreateFileW
Definition: compat.h:741
#define FILE_MAP_READ
Definition: compat.h:776
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
void test2()
Definition: ehthrow.cxx:284
void test1()
Definition: ehthrow.cxx:277
_Must_inspect_result_ _Out_ PLARGE_INTEGER FileSize
Definition: fsrtlfuncs.h:108
#define S_OK
Definition: intsafe.h:52
IMAGE_DOS_HEADER dos
Definition: module.c:49
_In_ HANDLE hFile
Definition: mswsock.h:90
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
HRESULT hr
Definition: shlfolder.c:183
#define _countof(array)
Definition: sndvol32.h:68
ULONG LowPart
Definition: typedefs.h:106
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ test_SharedMem()

static void test_SharedMem ( )
static

Definition at line 22 of file CAtlFileMapping.cpp.

23{
26 BOOL bAlreadyExisted;
27 HRESULT hr;
28
29 ok(test1.GetData() == NULL, "Expected NULL, got %p\n", test1.GetData());
30 ok(test3.GetData() == NULL, "Expected NULL, got %p\n", test3.GetData());
31 ok(test1.GetHandle() == NULL, "Expected NULL, got %p\n", test1.GetHandle());
32 ok(test3.GetHandle() == NULL, "Expected NULL, got %p\n", test3.GetHandle());
33 ok(test1.GetMappingSize() == 0, "Expected 0, got %lu\n", test1.GetMappingSize());
34 ok(test3.GetMappingSize() == 0, "Expected 0, got %lu\n", test3.GetMappingSize());
35
36 test1 = test1;
37 //test1 = test2; // Asserts on orig.m_pData != NULL, same with CopyFrom
38 //test1 = test3; // does not compile
39 hr = test1.Unmap();
40 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
41
42 // Asserts on name == NULL
43 hr = test1.OpenMapping(_T("TEST_MAPPING"), 123, 0, FILE_MAP_ALL_ACCESS);
44 ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND), got 0x%lx\n", hr);
45 ok(test1.GetData() == NULL, "Expected NULL, got %p\n", test1.GetData());
46 ok(test1.GetHandle() == NULL, "Expected NULL, got %p\n", test1.GetHandle());
47 ok(test1.GetMappingSize() == 123, "Expected 123, got %lu\n", test1.GetMappingSize());
48
49 hr = test1.Unmap();
50 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
51 ok(test1.GetData() == NULL, "Expected NULL, got %p\n", test1.GetData());
52 ok(test1.GetHandle() == NULL, "Expected NULL, got %p\n", test1.GetHandle());
53 ok(test1.GetMappingSize() == 123, "Expected 123, got %lu\n", test1.GetMappingSize());
54
55 bAlreadyExisted = 123;
56 hr = test1.MapSharedMem(sizeof(TestData), _T("TEST_MAPPING"), &bAlreadyExisted, (LPSECURITY_ATTRIBUTES)0, PAGE_READWRITE, FILE_MAP_ALL_ACCESS);
57 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
58 ok(test1.GetData() != NULL, "Expected ptr, got %p\n", test1.GetData());
59 ok(test1.GetHandle() != NULL, "Expected handle, got %p\n", test1.GetHandle());
60 ok(test1.GetMappingSize() == sizeof(TestData), "Expected sizeof(TestData), got %lu\n", test1.GetMappingSize());
61 ok(bAlreadyExisted == FALSE, "Expected FALSE, got %u\n", bAlreadyExisted);
62
63 if (test1.GetData())
64 {
65 memset(test1.GetData(), 0x35, sizeof(TestData));
66 }
67
68 hr = test2.CopyFrom(test1);
69 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
70 ok(test2.GetData() != NULL, "Expected ptr, got %p\n", test2.GetData());
71 ok(test2.GetHandle() != NULL, "Expected handle, got %p\n", test2.GetHandle());
72 ok(test2.GetMappingSize() == sizeof(TestData), "Expected sizeof(TestData), got %lu\n", test2.GetMappingSize());
73
74 // test1 is not closed:
75 ok(test1.GetData() != NULL, "Expected ptr, got %p\n", test1.GetData());
76 ok(test1.GetHandle() != NULL, "Expected handle, got %p\n", test1.GetHandle());
77 ok(test1.GetMappingSize() == sizeof(TestData), "Expected sizeof(TestData), got %lu\n", test1.GetMappingSize());
78
79 // test2 does not equal test1
80 ok(test1.GetData() != test2.GetData(), "Expected different ptrs\n");
81 ok(test1.GetHandle() != test2.GetHandle(), "Expected different handles\n");
82
83 TestData* t1 = test1;
84 TestData* t2 = test2;
85 if (t1 && t2)
86 {
87 ok(t1->data[0] == 0x35353535, "Expected 0x35353535, got 0x%x\n", t1->data[0]);
88 ok(t2->data[0] == 0x35353535, "Expected 0x35353535, got 0x%x\n", t2->data[0]);
89
90 t1->data[0] = 0xbeefbeef;
91 ok(t1->data[0] == (int)0xbeefbeef, "Expected 0xbeefbeef, got 0x%x\n", t1->data[0]);
92 ok(t2->data[0] == (int)0xbeefbeef, "Expected 0xbeefbeef, got 0x%x\n", t2->data[0]);
93 }
94
95 hr = test3.OpenMapping(_T("TEST_MAPPING"), sizeof(TestData), offsetof(TestData, data[1]));
96 ok(hr == HRESULT_FROM_WIN32(ERROR_MAPPED_ALIGNMENT), "Expected HRESULT_FROM_WIN32(ERROR_MAPPED_ALIGNMENT), got 0x%lx\n", hr);
97 ok(test3.GetData() == NULL, "Expected NULL, got %p\n", test3.GetData());
98 ok(test3.GetHandle() == NULL, "Expected NULL, got %p\n", test3.GetHandle());
99 ok(test3.GetMappingSize() == sizeof(TestData), "Expected sizeof(TestData), got %lu\n", test3.GetMappingSize());
100
101 hr = test2.Unmap();
102 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
103 ok(test2.GetData() == NULL, "Expected NULL, got %p\n", test2.GetData());
104 ok(test2.GetHandle() == NULL, "Expected NULL, got %p\n", test2.GetHandle());
105 ok(test2.GetMappingSize() == sizeof(TestData), "Expected sizeof(TestData), got %lu\n", test2.GetMappingSize());
106
107 bAlreadyExisted = 123;
108 // Wrong access flag
109 hr = test2.MapSharedMem(sizeof(TestData), _T("TEST_MAPPING"), &bAlreadyExisted, (LPSECURITY_ATTRIBUTES)0, PAGE_EXECUTE_READ, FILE_MAP_ALL_ACCESS);
110 ok(hr == E_ACCESSDENIED, "Expected E_ACCESSDENIED, got 0x%lx\n", hr);
111 ok(test2.GetData() == NULL, "Expected NULL, got %p\n", test2.GetData());
112 ok(test2.GetHandle() == NULL, "Expected NULL, got %p\n", test2.GetHandle());
113 ok(test2.GetMappingSize() == sizeof(TestData), "Expected sizeof(TestData), got %lu\n", test2.GetMappingSize());
114 ok(bAlreadyExisted == TRUE, "Expected TRUE, got %u\n", bAlreadyExisted);
115
116 bAlreadyExisted = 123;
117 hr = test2.MapSharedMem(sizeof(TestData), _T("TEST_MAPPING"), &bAlreadyExisted, (LPSECURITY_ATTRIBUTES)0, PAGE_READWRITE, FILE_MAP_ALL_ACCESS);
118 ok(hr == S_OK, "Expected S_OK, got 0x%lx\n", hr);
119 ok(test2.GetData() != NULL, "Expected ptr, got %p\n", test2.GetData());
120 ok(test2.GetHandle() != NULL, "Expected handle, got %p\n", test2.GetHandle());
121 ok(test2.GetMappingSize() == sizeof(TestData), "Expected sizeof(TestData), got %lu\n", test2.GetMappingSize());
122 ok(bAlreadyExisted == TRUE, "Expected TRUE, got %u\n", bAlreadyExisted);
123
124 // test2 does not equal test1
125 ok(test1.GetData() != test2.GetData(), "Expected different ptrs\n");
126 ok(test1.GetHandle() != test2.GetHandle(), "Expected different handles\n");
127
128 t2 = test2;
129 if (t1 && t2)
130 {
131 ok(t1->data[0] == (int)0xbeefbeef, "Expected 0xbeefbeef, got 0x%x\n", t1->data[0]);
132 ok(t2->data[0] == (int)0xbeefbeef, "Expected 0xbeefbeef, got 0x%x\n", t2->data[0]);
133
134 t1->data[0] = 0xdeaddead;
135 ok(t1->data[0] == (int)0xdeaddead, "Expected 0xdeaddead, got 0x%x\n", t1->data[0]);
136 ok(t2->data[0] == (int)0xdeaddead, "Expected 0xdeaddead, got 0x%x\n", t2->data[0]);
137 }
138}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
void test3()
Definition: ehthrow.cxx:291
unsigned int BOOL
Definition: ntddk_ex.h:94
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
#define PAGE_READWRITE
Definition: nt_native.h:1304
#define PAGE_EXECUTE_READ
Definition: nt_native.h:1307
#define offsetof(TYPE, MEMBER)
#define memset(x, y, z)
Definition: compat.h:39
#define _T(x)
Definition: vfdio.h:22
#define FILE_MAP_ALL_ACCESS
Definition: winbase.h:156
#define E_ACCESSDENIED
Definition: winerror.h:2849
#define HRESULT_FROM_WIN32(x)
Definition: winerror.h:92
#define ERROR_MAPPED_ALIGNMENT
Definition: winerror.h:668

Referenced by START_TEST().