Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73240 - trunk/libs/pool/test
From: john_at_[hidden]
Date: 2011-07-19 06:39:33


Author: johnmaddock
Date: 2011-07-19 06:39:32 EDT (Tue, 19 Jul 2011)
New Revision: 73240
URL: http://svn.boost.org/trac/boost/changeset/73240

Log:
Make test code independent of sizeof(void*).
Make test stricter in it's checking (how much memory the allocator will allocate).
Text files modified:
   trunk/libs/pool/test/test_bug_2696.cpp | 15 ++++++++-------
   1 files changed, 8 insertions(+), 7 deletions(-)

Modified: trunk/libs/pool/test/test_bug_2696.cpp
==============================================================================
--- trunk/libs/pool/test/test_bug_2696.cpp (original)
+++ trunk/libs/pool/test/test_bug_2696.cpp 2011-07-19 06:39:32 EDT (Tue, 19 Jul 2011)
@@ -18,7 +18,7 @@
    static char * malloc BOOST_PREVENT_MACRO_SUBSTITUTION(const size_type bytes)
    {
 #ifndef BOOST_POOL_VALGRIND
- static const unsigned max_size = 4 * 40 + sizeof(void*) + 2 * sizeof(std::size_t);
+ static const unsigned max_size = 4 * 40 + boost::math::static_lcm<sizeof(size_type), sizeof(void *)>::value + sizeof(size_type);
 #else
       static const unsigned max_size = 4 * 40;
 #endif
@@ -34,7 +34,8 @@
 
 int main()
 {
- boost::pool<limited_allocator_new_delete> p1(4, 10, 40);
+ static const unsigned alloc_size = sizeof(void*);
+ boost::pool<limited_allocator_new_delete> p1(alloc_size, 10, 40);
    for(int i = 1; i <= 40; ++i)
       BOOST_TEST((p1.ordered_malloc)(i));
    BOOST_TEST(p1.ordered_malloc(42) == 0);
@@ -42,23 +43,23 @@
    // If the largest block is 40, and we start with 10, we get 10+20+40 elements before
    // we actually run out of memory:
    //
- boost::pool<limited_allocator_new_delete> p2(4, 10, 40);
+ boost::pool<limited_allocator_new_delete> p2(alloc_size, 10, 40);
    for(int i = 1; i <= 70; ++i)
       BOOST_TEST((p2.malloc)());
- boost::pool<limited_allocator_new_delete> p2b(4, 10, 40);
+ boost::pool<limited_allocator_new_delete> p2b(alloc_size, 10, 40);
    for(int i = 1; i <= 100; ++i)
       BOOST_TEST((p2b.ordered_malloc)());
    //
    // Try again with no explicit upper limit:
    //
- boost::pool<limited_allocator_new_delete> p3(4);
+ boost::pool<limited_allocator_new_delete> p3(alloc_size);
    for(int i = 1; i <= 40; ++i)
       BOOST_TEST((p3.ordered_malloc)(i));
    BOOST_TEST(p3.ordered_malloc(42) == 0);
- boost::pool<limited_allocator_new_delete> p4(4, 10);
+ boost::pool<limited_allocator_new_delete> p4(alloc_size, 10);
    for(int i = 1; i <= 100; ++i)
       BOOST_TEST((p4.ordered_malloc)());
- boost::pool<limited_allocator_new_delete> p5(4, 10);
+ boost::pool<limited_allocator_new_delete> p5(alloc_size, 10);
    for(int i = 1; i <= 100; ++i)
       BOOST_TEST((p5.malloc)());
    return boost::report_errors();


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