diff options
Diffstat (limited to 'libs/interprocess/test/named_creation_template.hpp')
-rw-r--r-- | libs/interprocess/test/named_creation_template.hpp | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/libs/interprocess/test/named_creation_template.hpp b/libs/interprocess/test/named_creation_template.hpp index d2d543d43e..e24cda90bf 100644 --- a/libs/interprocess/test/named_creation_template.hpp +++ b/libs/interprocess/test/named_creation_template.hpp @@ -14,6 +14,7 @@ #include <boost/interprocess/detail/config_begin.hpp> #include <boost/interprocess/exceptions.hpp> #include "boost_interprocess_check.hpp" +#include "get_process_id_name.hpp" #include <iostream> #include <typeinfo> #include <boost/interprocess/creation_tags.hpp> @@ -22,7 +23,7 @@ namespace boost { namespace interprocess { namespace test { template <class NamedResource> inline void create_then_open_then_open_or_create() -{ +{ try{ //Create it and open it twice NamedResource nresource1(create_only); @@ -37,7 +38,7 @@ inline void create_then_open_then_open_or_create() template <class NamedResource> inline void open_or_create_then_create() -{ +{ //Create it with open_or_create and try to create it twice NamedResource nresource1(open_or_create); try{ @@ -50,7 +51,7 @@ inline void open_or_create_then_create() template <class NamedResource> inline void dont_create_and_open() -{ +{ //Try to open it without creating try{ NamedResource nresource1(open_only); @@ -72,11 +73,58 @@ inline void test_named_creation() std::cout << "open_or_create_then_create<" << typeid(NamedResource).name() << ">" << std::endl; open_or_create_then_create<NamedResource>(); - std::cout << "dont_create_and_open<" + std::cout << "dont_create_and_open<" << typeid(NamedResource).name() << ">" << std::endl; dont_create_and_open<NamedResource>(); } +template<class NamedSync> +class named_sync_wrapper + : public NamedSync +{ + public: + named_sync_wrapper() + : NamedSync(open_or_create, test::get_process_id_ptr_name(this)) + {} + + ~named_sync_wrapper() + { + NamedSync::remove(test::get_process_id_ptr_name(this)); + } +}; + +template<class NamedSync> +struct named_sync_deleter +{ + ~named_sync_deleter() + { NamedSync::remove(test::get_process_id_name()); } +}; + + +//This wrapper is necessary to have a common constructor +//in generic named_creation_template functions +template<class NamedSync> +class named_sync_creation_test_wrapper + : public test::named_sync_deleter<NamedSync>, public NamedSync +{ + public: + named_sync_creation_test_wrapper(create_only_t) + : NamedSync(create_only, test::get_process_id_name()) + {} + + named_sync_creation_test_wrapper(open_only_t) + : NamedSync(open_only, test::get_process_id_name()) + {} + + named_sync_creation_test_wrapper(open_or_create_t) + : NamedSync(open_or_create, test::get_process_id_name()) + {} + + ~named_sync_creation_test_wrapper() + {} +}; + + }}} //namespace boost { namespace interprocess { namespace test { #include <boost/interprocess/detail/config_end.hpp> |