1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*=============================================================
6**
7** Source: createfilemappingw.c (test 8)
8**
9** Purpose: Positive test the CreateFileMappingW API.
10** Test the un-verifiable parameter combinations.
11**
12**
13**============================================================*/
14#define UNICODE
15#include <palsuite.h>
16
17const int MAPPINGSIZE = 2048;
18HANDLE SWAP_HANDLE = ((VOID *)(-1));
19
20int __cdecl main(int argc, char *argv[])
21{
22 WCHAR lpObjectName[] = {'m','y','O','b','j','e','c','t','\0'};
23
24 HANDLE hFileMap;
25
26 /* Initialize the PAL environment.
27 */
28 if(0 != PAL_Initialize(argc, argv))
29 {
30 return FAIL;
31 }
32
33 /* Create a READONLY, "swap", un-named file mapping.
34 * This test is unverifiable since there is no hook back to the file map
35 * because it is un-named. As well, since it resides in "swap", and is
36 * initialized to zero, there is nothing to read.
37 */
38 hFileMap = CreateFileMapping(
39 SWAP_HANDLE,
40 NULL, /*not inherited*/
41 PAGE_READONLY, /*read only*/
42 0, /*high-order size*/
43 MAPPINGSIZE, /*low-order size*/
44 NULL); /*un-named object*/
45
46 if(NULL == hFileMap)
47 {
48 Fail("ERROR:%u: Failed to create File Mapping.\n",
49 GetLastError());
50 }
51
52
53 /* Create a COPYWRITE, "swap", un-named file mapping.
54 * This test is unverifiable, here is a quote from MSDN:
55 *
56 * Copy on write access. If you create the map with PAGE_WRITECOPY and
57 * the view with FILE_MAP_COPY, you will receive a view to file. If you
58 * write to it, the pages are automatically swappable and the modifications
59 * you make will not go to the original data file.
60 *
61 */
62 hFileMap = CreateFileMapping(
63 SWAP_HANDLE,
64 NULL, /*not inherited*/
65 PAGE_WRITECOPY, /*write copy*/
66 0, /*high-order size*/
67 MAPPINGSIZE, /*low-order size*/
68 NULL); /*unnamed object*/
69
70 if(NULL == hFileMap)
71 {
72 Fail("ERROR:%u: Failed to create File Mapping.\n",
73 GetLastError());
74 }
75
76
77 /* Terminate the PAL.
78 */
79 PAL_Terminate();
80 return PASS;
81}
82
83