diff --git a/proj/vc7ide/Interprocess.sln b/proj/vc7ide/Interprocess.sln index 742f30f..4758668 100644 --- a/proj/vc7ide/Interprocess.sln +++ b/proj/vc7ide/Interprocess.sln @@ -411,6 +411,10 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "doc_managed_grow", "doc_man ProjectSection(ProjectDependencies) = postProject EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "offset_ptr_test", "offset_ptr_test.vcproj", "{5CE11C83-096A-84FE-4FA2-D3A6BA792002}" + ProjectSection(ProjectDependencies) = postProject + EndProjectSection +EndProject Global GlobalSection(SolutionConfiguration) = preSolution Debug = Debug @@ -831,6 +835,10 @@ Global {818C43EE-3561-F3AE-4FD7-8A2076E76A31}.Debug.Build.0 = Debug|Win32 {818C43EE-3561-F3AE-4FD7-8A2076E76A31}.Release.ActiveCfg = Release|Win32 {818C43EE-3561-F3AE-4FD7-8A2076E76A31}.Release.Build.0 = Release|Win32 + {5CE11C83-096A-84FE-4FA2-D3A6BA792002}.Debug.ActiveCfg = Debug|Win32 + {5CE11C83-096A-84FE-4FA2-D3A6BA792002}.Debug.Build.0 = Debug|Win32 + {5CE11C83-096A-84FE-4FA2-D3A6BA792002}.Release.ActiveCfg = Release|Win32 + {5CE11C83-096A-84FE-4FA2-D3A6BA792002}.Release.Build.0 = Release|Win32 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution EndGlobalSection diff --git a/proj/vc7ide/offset_ptr_test.vcproj b/proj/vc7ide/offset_ptr_test.vcproj new file mode 100644 index 0000000..fdb9235 --- /dev/null +++ b/proj/vc7ide/offset_ptr_test.vcproj @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/expand_bwd_test_template.hpp b/test/expand_bwd_test_template.hpp index 4ccf0ca..ff1dba0 100644 --- a/test/expand_bwd_test_template.hpp +++ b/test/expand_bwd_test_template.hpp @@ -76,7 +76,7 @@ typedef triple_value_holder triple_int_holder; //Function to check if both sets are equal template -bool CheckEqualVector(const Vector1 &vector1, const Vector2 &vector2) +static bool CheckEqualVector(const Vector1 &vector1, const Vector2 &vector2) { if(vector1.size() != vector2.size()) return false; @@ -84,7 +84,7 @@ bool CheckEqualVector(const Vector1 &vector1, const Vector2 &vector2) } template -bool CheckUninitializedIsZero(const Vector & v) +static bool CheckUninitializedIsZero(const Vector & v) { typedef typename Vector::value_type value_type; typename Vector::size_type sz = v.size(); diff --git a/test/named_creation_template.hpp b/test/named_creation_template.hpp index 38dabee..ef6815f 100644 --- a/test/named_creation_template.hpp +++ b/test/named_creation_template.hpp @@ -20,7 +20,7 @@ namespace boost { namespace interprocess { namespace test { template -inline void create_then_open_then_open_or_create() +static inline void create_then_open_then_open_or_create() { try{ //Create it and open it twice @@ -35,7 +35,7 @@ inline void create_then_open_then_open_or_create() } template -inline void open_or_create_then_create() +static inline void open_or_create_then_create() { //Create it with open_or_create and try to create it twice NamedResource nresource1(open_or_create); @@ -48,7 +48,7 @@ inline void open_or_create_then_create() } template -inline void dont_create_and_open() +static inline void dont_create_and_open() { //Try to open it without creating try{ @@ -63,7 +63,7 @@ inline void dont_create_and_open() } template -void test_named_creation() +static inline void test_named_creation() { std::cout << "create_then_open_then_open_or_create<" << typeid(NamedResource).name() << ">" << std::endl; diff --git a/test/offset_ptr_test.cpp b/test/offset_ptr_test.cpp new file mode 100644 index 0000000..dbd6a99 --- /dev/null +++ b/test/offset_ptr_test.cpp @@ -0,0 +1,192 @@ +////////////////////////////////////////////////////////////////////////////// +// +// (C) Copyright Ion Gaztanaga 2007. Distributed under the Boost +// Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// +// See http://www.boost.org/libs/interprocess for documentation. +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include + +using namespace boost::interprocess; + +bool test_types_and_convertions() +{ + typedef offset_ptr pint_t; + typedef offset_ptr pcint_t; + typedef offset_ptr pvint_t; + typedef offset_ptr pcvint_t; + + if(!detail::is_same::value) + return false; + if(!detail::is_same::value) + return false; + if(!detail::is_same::value) + return false; + if(!detail::is_same::value) + return false; + int dummy_int = 9; + + { pint_t pint(&dummy_int); pcint_t pcint(pint); + if(pcint.get() != &dummy_int) return false; } + { pint_t pint(&dummy_int); pvint_t pvint(pint); + if(pvint.get() != &dummy_int) return false; } + { pint_t pint(&dummy_int); pcvint_t pcvint(pint); + if(pcvint.get() != &dummy_int) return false; } + { pcint_t pcint(&dummy_int); pcvint_t pcvint(pcint); + if(pcvint.get() != &dummy_int) return false; } + { pvint_t pvint(&dummy_int); pcvint_t pcvint(pvint); + if(pcvint.get() != &dummy_int) return false; } + + pint_t pint(0); + pcint_t pcint(0); + pvint_t pvint(0); + pcvint_t pcvint(0); + + pint = &dummy_int; + pcint = &dummy_int; + pvint = &dummy_int; + pcvint = &dummy_int; + + { pcint = pint; if(pcint.get() != &dummy_int) return false; } + { pvint = pint; if(pvint.get() != &dummy_int) return false; } + { pcvint = pint; if(pcvint.get() != &dummy_int) return false; } + { pcvint = pcint; if(pcvint.get() != &dummy_int) return false; } + { pcvint = pvint; if(pcvint.get() != &dummy_int) return false; } + + if(!pint) + return false; + + pint = 0; + if(pint) + return false; + + return true; +} + +bool test_arithmetic() +{ + typedef offset_ptr pint_t; + const int NumValues = 5; + int values[NumValues]; + + //Initialize p + pint_t p = values; + if(p.get() != values) + return false; + + //Initialize p + NumValues + pint_t pe = &values[NumValues]; + if(pe == p) + return false; + if(pe.get() != &values[NumValues]) + return false; + + //ptr - ptr + if((pe - p) != NumValues) + return false; + //ptr - integer + if((pe - NumValues) != p) + return false; + //ptr + integer + if((p + NumValues) != pe) + return false; + //integer + ptr + if((NumValues + p) != pe) + return false; + //indexing + if(pint_t(&p[NumValues]) != pe) + return false; + if(pint_t(&pe[-NumValues]) != p) + return false; + + //ptr -= integer + pint_t p0 = pe; + p0-= NumValues; + if(p != p0) + return false; + //ptr += integer + pint_t penew = p0; + penew += NumValues; + if(penew != pe) + return false; + + //++ptr + penew = p0; + for(int j = 0; j != NumValues; ++j, ++penew); + if(penew != pe) + return false; + //--ptr + p0 = pe; + for(int j = 0; j != NumValues; ++j, --p0); + if(p != p0) + return false; + //ptr++ + penew = p0; + for(int j = 0; j != NumValues; ++j){ + pint_t p = penew; + if(p != penew++) + return false; + } + //ptr-- + p0 = pe; + for(int j = 0; j != NumValues; ++j){ + pint_t p = p0; + if(p != p0--) + return false; + } + + return true; +} + +bool test_comparison() +{ + typedef offset_ptr pint_t; + const int NumValues = 5; + int values[NumValues]; + + //Initialize p + pint_t p = values; + if(p.get() != values) + return false; + + //Initialize p + NumValues + pint_t pe = &values[NumValues]; + if(pe == p) + return false; + if(pe.get() != &values[NumValues]) + return false; + + //operators + if(p == pe) + return false; + if(p != p) + return false; + if(!(p < pe)) + return false; + if(!(p <= pe)) + return false; + if(!(pe > p)) + return false; + if(!(pe >= p)) + return false; + + return true; +} + +int main() +{ + if(!test_types_and_convertions()) + return 1; + if(!test_arithmetic()) + return 1; + if(!test_comparison()) + return 1; + return 0; +} + +#include diff --git a/test/vector_test.cpp b/test/vector_test.cpp index f17a206..f6e9031 100644 --- a/test/vector_test.cpp +++ b/test/vector_test.cpp @@ -31,7 +31,6 @@ #include "dummy_test_allocator.hpp" #include #include "get_process_id_name.hpp" -#include using namespace boost::interprocess; @@ -142,11 +141,12 @@ bool do_test() } if(!test::CheckEqualContainers(shmvector, stdvector)) return false; - typename MyShmVector::iterator it; - typename MyShmVector::const_iterator cit = it; - - shmvector->erase(boost::next(shmvector->begin())); - stdvector->erase(boost::next(stdvector->begin())); + typename MyShmVector::iterator shmit(shmvector->begin()); + typename MyStdVector::iterator stdit(stdvector->begin()); + typename MyShmVector::const_iterator cshmit = shmit; + ++shmit; ++stdit; + shmvector->erase(shmit); + stdvector->erase(stdit); if(!test::CheckEqualContainers(shmvector, stdvector)) return false; shmvector->erase(shmvector->begin());