]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | ////////////////////////////////////////////////////////////////////////////// |
2 | // | |
3 | // (C) Copyright Ion Gaztanaga 2004-2012. Distributed under the Boost | |
4 | // Software License, Version 1.0. (See accompanying file | |
5 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
6 | // | |
7 | // See http://www.boost.org/libs/interprocess for documentation. | |
8 | // | |
9 | ////////////////////////////////////////////////////////////////////////////// | |
20effc67 TL |
10 | #include <boost/interprocess/detail/workaround.hpp> |
11 | ||
7c673cae FG |
12 | #if defined(BOOST_INTERPROCESS_MAPPED_FILES) |
13 | ||
7c673cae FG |
14 | #include <boost/interprocess/allocators/allocator.hpp> |
15 | #include <boost/interprocess/containers/vector.hpp> | |
16 | #include <boost/interprocess/detail/file_wrapper.hpp> | |
17 | #include <boost/interprocess/file_mapping.hpp> | |
18 | #include <boost/interprocess/detail/managed_open_or_create_impl.hpp> | |
19 | #include "named_creation_template.hpp" | |
20 | #include <cstdio> | |
21 | #include <cstring> | |
22 | #include <string> | |
23 | #include <boost/interprocess/detail/os_file_functions.hpp> | |
24 | #include "get_process_id_name.hpp" | |
25 | ||
26 | using namespace boost::interprocess; | |
27 | ||
28 | static const std::size_t FileSize = 1000; | |
7c673cae FG |
29 | |
30 | struct file_destroyer | |
31 | { | |
32 | ~file_destroyer() | |
33 | { | |
34 | //The last destructor will destroy the file | |
35 | file_mapping::remove(get_filename().c_str()); | |
36 | } | |
37 | }; | |
38 | ||
1e59de90 TL |
39 | typedef boost::interprocess::ipcdetail::managed_open_or_create_impl |
40 | <boost::interprocess::ipcdetail::file_wrapper, 0, true, false> mapped_file; | |
41 | ||
7c673cae FG |
42 | //This wrapper is necessary to have a common constructor |
43 | //in generic named_creation_template functions | |
44 | class mapped_file_creation_test_wrapper | |
45 | : public file_destroyer | |
1e59de90 | 46 | , public mapped_file |
7c673cae | 47 | { |
7c673cae FG |
48 | public: |
49 | mapped_file_creation_test_wrapper(boost::interprocess::create_only_t) | |
50 | : mapped_file(boost::interprocess::create_only, get_filename().c_str(), FileSize, read_write, 0, permissions()) | |
51 | {} | |
52 | ||
53 | mapped_file_creation_test_wrapper(boost::interprocess::open_only_t) | |
54 | : mapped_file(boost::interprocess::open_only, get_filename().c_str(), read_write, 0) | |
55 | {} | |
56 | ||
57 | mapped_file_creation_test_wrapper(boost::interprocess::open_or_create_t) | |
58 | : mapped_file(boost::interprocess::open_or_create, get_filename().c_str(), FileSize, read_write, 0, permissions()) | |
59 | {} | |
60 | }; | |
61 | ||
1e59de90 TL |
62 | #ifdef BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES |
63 | ||
64 | class mapped_file_creation_test_wrapper_w | |
65 | : public file_destroyer | |
66 | , public mapped_file | |
67 | { | |
68 | public: | |
69 | mapped_file_creation_test_wrapper_w(boost::interprocess::create_only_t) | |
70 | : mapped_file(boost::interprocess::create_only, get_wfilename().c_str(), FileSize, read_write, 0, permissions()) | |
71 | {} | |
72 | ||
73 | mapped_file_creation_test_wrapper_w(boost::interprocess::open_only_t) | |
74 | : mapped_file(boost::interprocess::open_only, get_wfilename().c_str(), read_write, 0) | |
75 | {} | |
76 | ||
77 | mapped_file_creation_test_wrapper_w(boost::interprocess::open_or_create_t) | |
78 | : mapped_file(boost::interprocess::open_or_create, get_wfilename().c_str(), FileSize, read_write, 0, permissions()) | |
79 | {} | |
80 | }; | |
81 | ||
82 | #endif //BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES | |
83 | ||
7c673cae FG |
84 | int main () |
85 | { | |
7c673cae FG |
86 | file_mapping::remove(get_filename().c_str()); |
87 | test::test_named_creation<mapped_file_creation_test_wrapper>(); | |
1e59de90 TL |
88 | #ifdef BOOST_INTERPROCESS_WCHAR_NAMED_RESOURCES |
89 | test::test_named_creation<mapped_file_creation_test_wrapper_w>(); | |
90 | #endif | |
7c673cae FG |
91 | |
92 | //Create and get name, size and address | |
93 | { | |
94 | mapped_file file1(create_only, get_filename().c_str(), FileSize, read_write, 0, permissions()); | |
95 | ||
96 | //Overwrite all memory | |
97 | std::memset(file1.get_user_address(), 0, file1.get_user_size()); | |
98 | ||
99 | //Now test move semantics | |
100 | mapped_file move_ctor(boost::move(file1)); | |
101 | mapped_file move_assign; | |
102 | move_assign = boost::move(move_ctor); | |
103 | } | |
104 | // file_mapping::remove(get_filename().c_str()); | |
105 | return 0; | |
106 | } | |
107 | ||
7c673cae FG |
108 | #else //#if !defined(BOOST_INTERPROCESS_MAPPED_FILES) |
109 | ||
110 | int main() | |
111 | { | |
112 | return 0; | |
113 | } | |
114 | ||
115 | #endif//#if !defined(BOOST_INTERPROCESS_MAPPED_FILES) |