1 //////////////////////////////////////////////////////////////////////////////
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)
7 // See http://www.boost.org/libs/interprocess for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #include <boost/interprocess/detail/config_begin.hpp>
12 #include <boost/interprocess/allocators/allocator.hpp>
13 #include <boost/interprocess/containers/vector.hpp>
14 #include <boost/interprocess/detail/file_wrapper.hpp>
15 #include <boost/interprocess/file_mapping.hpp>
16 #include <boost/interprocess/detail/managed_open_or_create_impl.hpp>
17 #include "named_creation_template.hpp"
21 #include <boost/interprocess/detail/os_file_functions.hpp>
22 #include "get_process_id_name.hpp"
24 using namespace boost::interprocess;
26 static const std::size_t FileSize = 1000;
27 inline std::string get_filename()
29 std::string ret (ipcdetail::get_temporary_path());
31 ret += test::get_process_id_name();
39 //The last destructor will destroy the file
40 file_mapping::remove(get_filename().c_str());
44 //This wrapper is necessary to have a common constructor
45 //in generic named_creation_template functions
46 class mapped_file_creation_test_wrapper
47 : public file_destroyer
48 , public boost::interprocess::ipcdetail::managed_open_or_create_impl
49 <boost::interprocess::ipcdetail::file_wrapper, 0, true, false>
51 typedef boost::interprocess::ipcdetail::managed_open_or_create_impl
52 <boost::interprocess::ipcdetail::file_wrapper, 0, true, false> mapped_file;
54 mapped_file_creation_test_wrapper(boost::interprocess::create_only_t)
55 : mapped_file(boost::interprocess::create_only, get_filename().c_str(), FileSize, read_write, 0, permissions())
58 mapped_file_creation_test_wrapper(boost::interprocess::open_only_t)
59 : mapped_file(boost::interprocess::open_only, get_filename().c_str(), read_write, 0)
62 mapped_file_creation_test_wrapper(boost::interprocess::open_or_create_t)
63 : mapped_file(boost::interprocess::open_or_create, get_filename().c_str(), FileSize, read_write, 0, permissions())
69 typedef boost::interprocess::ipcdetail::managed_open_or_create_impl
70 <boost::interprocess::ipcdetail::file_wrapper, 0, true, false> mapped_file;
71 file_mapping::remove(get_filename().c_str());
72 test::test_named_creation<mapped_file_creation_test_wrapper>();
74 //Create and get name, size and address
76 mapped_file file1(create_only, get_filename().c_str(), FileSize, read_write, 0, permissions());
78 //Overwrite all memory
79 std::memset(file1.get_user_address(), 0, file1.get_user_size());
81 //Now test move semantics
82 mapped_file move_ctor(boost::move(file1));
83 mapped_file move_assign;
84 move_assign = boost::move(move_ctor);
86 // file_mapping::remove(get_filename().c_str());
90 #include <boost/interprocess/detail/config_end.hpp>