|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r81958 - in sandbox-branches/geometry/index: boost/geometry/extensions/index test
From: adam.wulkiewicz_at_[hidden]
Date: 2012-12-14 17:35:47
Author: awulkiew
Date: 2012-12-14 17:35:46 EST (Fri, 14 Dec 2012)
New Revision: 81958
URL: http://svn.boost.org/trac/boost/changeset/81958
Log:
Error fixed in static_vector::at().
Added test for static_vector.
Added:
sandbox-branches/geometry/index/test/static_vector.cpp (contents, props changed)
Text files modified:
sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp | 10 +++++-----
sandbox-branches/geometry/index/test/Jamfile.v2 | 9 +++++++--
2 files changed, 12 insertions(+), 7 deletions(-)
Modified: sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp
==============================================================================
--- sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp (original)
+++ sandbox-branches/geometry/index/boost/geometry/extensions/index/static_vector.hpp 2012-12-14 17:35:46 EST (Fri, 14 Dec 2012)
@@ -188,7 +188,7 @@
// strong
Value & at(size_type i)
{
- if ( Capacity <= i )
+ if ( m_size <= i )
throw std::out_of_range("static_vector element index out of bounds");
return *(this->ptr(i));
}
@@ -196,7 +196,7 @@
// strong
Value const& at(size_type i) const
{
- if ( Capacity <= i )
+ if ( m_size <= i )
throw std::out_of_range("static_vector element index out of bounds");
return *(this->ptr(i));
}
@@ -305,7 +305,7 @@
new (ptr) value_type(v); // may throw
}
- void destroy(const value_type *, const value_type *,
+ void destroy(const value_type * /*first*/, const value_type * /*last*/,
boost::true_type const& /*has_trivial_destructor*/)
{}
@@ -316,7 +316,7 @@
first->~value_type();
}
- void destroy(const value_type *,
+ void destroy(const value_type * /*ptr*/,
boost::true_type const& /*has_trivial_destructor*/)
{}
@@ -341,7 +341,7 @@
}
}
- void construct(value_type * first, value_type * last,
+ void construct(value_type * /*first*/, value_type * /*last*/,
boost::false_type const& /*has_trivial_constructor*/)
{}
Modified: sandbox-branches/geometry/index/test/Jamfile.v2
==============================================================================
--- sandbox-branches/geometry/index/test/Jamfile.v2 (original)
+++ sandbox-branches/geometry/index/test/Jamfile.v2 2012-12-14 17:35:46 EST (Fri, 14 Dec 2012)
@@ -19,5 +19,10 @@
<toolset>msvc:<asynch-exceptions>on
;
-build-project algorithms ;
-build-project rtree ;
+test-suite boost-geometry-index
+ :
+ [ run static_vector.cpp ]
+ ;
+
+#build-project algorithms ;
+#build-project rtree ;
Added: sandbox-branches/geometry/index/test/static_vector.cpp
==============================================================================
--- (empty file)
+++ sandbox-branches/geometry/index/test/static_vector.cpp 2012-12-14 17:35:46 EST (Fri, 14 Dec 2012)
@@ -0,0 +1,107 @@
+// Boost.Geometry Index
+// Unit Test
+
+// Copyright (c) 2011-2012 Adam Wulkiewicz, Lodz, Poland.
+
+// Use, modification and distribution is subject to 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)
+
+#include <boost/test/included/test_exec_monitor.hpp>
+#include <boost/test/impl/execution_monitor.ipp>
+
+#include <boost/geometry/extensions/index/static_vector.hpp>
+
+using namespace boost::geometry::index;
+
+class value_ndc
+{
+public:
+ value_ndc(int a) : aa(a) {}
+ bool operator==(value_ndc const& v) const { return aa == v.aa; }
+private:
+ value_ndc(value_ndc const&) {}
+ value_ndc & operator=(value_ndc const&) { return *this; }
+ int aa;
+};
+
+class value_nd
+{
+public:
+ value_nd(int a) : aa(a) {}
+ bool operator==(value_nd const& v) const { return aa == v.aa; }
+private:
+ int aa;
+};
+
+class value_nc
+{
+public:
+ value_nc(int a = 0) : aa(a) {}
+ bool operator==(value_nc const& v) const { return aa == v.aa; }
+private:
+ value_nc(value_nc const&) {}
+ value_nc & operator=(value_ndc const&) { return *this; }
+ int aa;
+};
+
+template <typename T, size_t N>
+void test_ctor_d()
+{
+ static_vector<T, N> s;
+ BOOST_CHECK(s.size() == 0);
+ BOOST_CHECK(s.capacity() == N);
+ BOOST_CHECK_THROW( s.at(0), std::out_of_range );
+}
+
+template <typename T, size_t N>
+void test_ctor_r(size_t n)
+{
+ static_vector<T, N> s(n);
+ BOOST_CHECK(s.size() == n);
+ BOOST_CHECK(s.capacity() == N);
+ BOOST_CHECK_THROW( s.at(n), std::out_of_range );
+ if ( 1 < n )
+ {
+ s[0] = T(10);
+ BOOST_CHECK(T(10) == s[0]);
+ BOOST_CHECK(T(10) == s.at(0));
+ s.at(1) = T(20);
+ BOOST_CHECK(T(20) == s[1]);
+ BOOST_CHECK(T(20) == s.at(1));
+ }
+}
+
+template <typename T, size_t N>
+void test_ctor_rv(size_t n, T const& v)
+{
+ static_vector<T, N> s(n, v);
+ BOOST_CHECK(s.size() == n);
+ BOOST_CHECK(s.capacity() == N);
+ BOOST_CHECK_THROW( s.at(n), std::out_of_range );
+ if ( 1 < n )
+ {
+ BOOST_CHECK(v == s[0]);
+ BOOST_CHECK(v == s.at(0));
+ BOOST_CHECK(v == s[1]);
+ BOOST_CHECK(v == s.at(1));
+ s[0] = T(10);
+ BOOST_CHECK(T(10) == s[0]);
+ BOOST_CHECK(T(10) == s.at(0));
+ s.at(1) = T(20);
+ BOOST_CHECK(T(20) == s[1]);
+ BOOST_CHECK(T(20) == s.at(1));
+ }
+}
+
+int test_main(int, char* [])
+{
+ test_ctor_d<int, 10>();
+ test_ctor_d<value_ndc, 10>();
+ test_ctor_r<int, 10>(5);
+ test_ctor_r<value_nc, 10>(5);
+ test_ctor_rv<int, 10>(5, 0);
+ test_ctor_rv<value_nd, 10>(5, 0);
+
+ return 0;
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk