Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65081 - in sandbox/SOC/2010/bit_masks: . boost/integer lib/integer/test/bitfield_vector_testing
From: bbartmanboost_at_[hidden]
Date: 2010-08-28 09:01:39


Author: bbartman
Date: 2010-08-28 09:01:37 EDT (Sat, 28 Aug 2010)
New Revision: 65081
URL: http://svn.boost.org/trac/boost/changeset/65081

Log:
added testing facilities for begin and end as well as all variations of const or reverse. added tests for front and back with const testing as well.
Text files modified:
   sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp | 88 ++++++++++++++++----------
   sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_test.cpp | 130 ++++++++++++++++++++++++++++++++++++++++
   sandbox/SOC/2010/bit_masks/notes.txt | 34 +--------
   3 files changed, 191 insertions(+), 61 deletions(-)

Modified: sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp (original)
+++ sandbox/SOC/2010/bit_masks/boost/integer/bitfield_vector.hpp 2010-08-28 09:01:37 EDT (Sat, 28 Aug 2010)
@@ -495,8 +495,10 @@
         :_base(alloc)
     { }
 
- /** fill with value constructor.
+ /** fill constructor
      * Fills the vector with N items with value of value.
+ * Throws: std::bad_alloc (or anything which is thrown out of
+ * the allocators allocate function).
      */
     explicit bitfield_vector(size_type n,
                              value_type const& value = T(),
@@ -506,6 +508,7 @@
         allocate_and_fill(n,value);
     }
 
+
     template <class InputIterator>
     bitfield_vector(InputIterator first, InputIterator last,
         Allocator const& = Allocator());
@@ -540,30 +543,58 @@
         return begin() + (this->m_impl.m_bits_in_use / Width);
     }
 
- reverse_iterator rbegin();
- const_reverse_iterator rbegin() const;
+ reverse_iterator rbegin() {
+ return reverse_iterator(this->m_impl.m_end - 1,0);
+ }
 
- reverse_iterator rend();
- const_reverse_iterator rend() const;
+ const_reverse_iterator rbegin() const {
+ return const_reverse_iterator(this->m_impl.m_end - 1,0);
+ }
 
- const_iterator cbegin() const;
- const_iterator cend() const;
+ reverse_iterator rend() {
+ return rbegin() + (this->m_impl.m_bits_in_use / Width);
+ }
 
- const_reverse_iterator crbegin() const;
- const_reverse_iterator crend() const;
- //@}
+ const_reverse_iterator rend() const {
+ return rbegin() + (this->m_impl.m_bits_in_use / Width);
+ }
 
+ const_iterator cbegin() const {
+ return begin();
+ }
+
+ const_iterator cend() const {
+ return end();
+ }
 
+ const_reverse_iterator crbegin() const {
+ return rbegin();
+ }
 
+ const_reverse_iterator crend() const {
+ return rend();
+ }
+ //@}
 
     /** Direct member access to front and back for both const and non const
- * types.
+ * access.
      */
     //@{
- reference front();
- reference back();
- const_reference front() const;
- const_reference back() const;
+ reference front() {
+ return *begin();
+ }
+
+ reference back() {
+ return *(--end());
+ }
+
+ const_reference front() const {
+ return *begin();
+ }
+
+ const_reference back() const {
+ return *(--end());
+ }
     //@}
 
 
@@ -624,6 +655,8 @@
      * This is for making sure that if an exception does occur that I can
      * catch it and recover correctly with out leaking any memory.
      * Not responsible for deallocating memory.
+ * This function updates the m_start and m_end member pointers but not
+ * the m_bits_in
      */
     void allocate_storage(size_type allocation_size) {
         // must save the original pointer so that I can maintain the state
@@ -632,20 +665,12 @@
         try {
             // allocate the necessary memory to hold all of the bitfields.
             // This CAN throw std::bad_alloc
- this->m_impl.m_start
- = this->allocate_impl(allocation_size);
+ this->m_impl.m_start = this->allocate_impl(allocation_size);
         }catch(...) {
             this->m_impl.m_start = old_start;
             throw;
         }
- }
-
- /** This deallocates the storage. */
- void deallocate_storage() {
- this->deallocate_impl(
- this->m_impl.m_start,
- this->m_impl.m_end - this->m_impl.m_start
- );
+ this->m_impl.m_end = this->m_impl.m_start + allocation_size;
     }
 
     /** allocates a chunck of memory of the correct size and then
@@ -675,21 +700,18 @@
         allocate_storage( corrected_allocation_size );
 
         std::memset(this->m_impl.m_start,0,corrected_allocation_size);
- // this line will never throw because this is pointer arithmatic
- // and integer assignment.
- this->m_impl.m_end = this->m_impl.m_start + corrected_allocation_size;
 
         // once allocation is completed next comes filling the bitfields
         // with val.
- for(iterator it( begin()); it != end(); ++it) {
- *it = value;
- this->m_impl.m_bits_in_use += Width;
- }
+ this->m_impl.m_bits_in_use = n*Width;
+ using namespace std;
+ fill(begin(),end(),value);
     }
 
     void check_for_resizing() {
         size_type size_of_alloc = (this->m_impl.m_end - this->m_impl.m_start);
- difference_type remaing_bits = ((size_of_alloc*CHAR_BIT) - this->m_impl.m_bits_in_use);
+ difference_type remaing_bits = ((size_of_alloc*CHAR_BIT) -
+ this->m_impl.m_bits_in_use);
         if(remaing_bits < Width) {
             std::size_t next_allocation_size =
                 detail::next_allocation_size<Width>()(

Modified: sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_test.cpp
==============================================================================
--- sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_test.cpp (original)
+++ sandbox/SOC/2010/bit_masks/lib/integer/test/bitfield_vector_testing/bitfield_vector_test.cpp 2010-08-28 09:01:37 EDT (Sat, 28 Aug 2010)
@@ -154,6 +154,7 @@
         :_base(n,val)
     { }
 
+ // fill constructor test.
     void test_fill_with_n(typename _base::value_type val) {
         typename _base::iterator it(this->m_impl.m_start, 0);
         typename _base::iterator it_end(this->m_impl.m_start, 0);
@@ -163,6 +164,92 @@
             ++it;
         }
     }
+
+ // implementation function tests.
+ // void allocate_and_fill(size_type n, value_type value)
+ void test_allocate_and_fill(typename _base::size_type n,
+ typename _base::value_type val)
+ {
+ this->allocate_and_fill(n,val);
+
+ typename _base::size_type allocated_amount = ((n*Width)/CHAR_BIT)
+ + ((n%CHAR_BIT)>0);
+ BOOST_TEST(typename _base::size_type(this->m_impl.m_end - this->m_impl.m_start)
+ == allocated_amount);
+ BOOST_TEST(this->m_impl.m_bits_in_use == n*Width );
+ typename _base::iterator it(this->m_impl.m_start, 0);
+ typename _base::iterator it_end(this->m_impl.m_start, 0);
+ while(it != it_end) {
+ BOOST_TEST( *it == val);
+ ++it;
+ }
+ }
+
+ // testing the regular begin function.
+ void test_begin_and_end(typename _base::difference_type n) {
+ typename _base::iterator i1 = this->begin();
+ typename _base::iterator i2 = this->end();
+ BOOST_TEST( i1 != i2 );
+ BOOST_TEST( i2 - i1 == n );
+ }
+
+ // testing the const begin function.
+ void test_const_begin_and_end(typename _base::difference_type n) const {
+ typename _base::const_iterator i1 = this->begin();
+ typename _base::const_iterator i2 = this->end();
+ BOOST_TEST( i1 != i2 );
+ BOOST_TEST( i2 - i1 == n );
+ }
+
+ // reverse iterator begin and end
+ void test_reverse_begin_and_end(typename _base::difference_type n) {
+ typename _base::reverse_iterator i1 = this->rbegin();
+ typename _base::reverse_iterator i2 = this->rend();
+ std::cout << "i2 - i1: " << i2 - i1 << std::endl;
+ BOOST_TEST( i1 != i2 );
+ BOOST_TEST( i2 - i1 == n );
+ }
+
+ // const reverse iterator begin and end
+ void test_const_reverse_begin_and_end(typename _base::difference_type n) const {
+ typename _base::const_reverse_iterator i1 = this->rbegin();
+ typename _base::const_reverse_iterator i2 = this->rend();
+ BOOST_TEST( i1 != i2 );
+ BOOST_TEST( i2 - i1 == n );
+ }
+
+ // explicitly const begin and end
+ void test_cbegin_and_cend(typename _base::difference_type n) {
+ typename _base::const_iterator i1 = this->cbegin();
+ typename _base::const_iterator i2 = this->cend();
+ BOOST_TEST( i1 != i2 );
+ BOOST_TEST( i2 - i1 == n );
+ }
+
+ // explictly const reverse begin and end
+ void test_crbegin_and_crend(typename _base::difference_type n) {
+ typename _base::const_reverse_iterator i1 = this->crbegin();
+ typename _base::const_reverse_iterator i2 = this->crend();
+ BOOST_TEST( i1 != i2 );
+ BOOST_TEST( i2 - i1 == n );
+ }
+
+ // front and back
+ void test_front_and_back(typename _base::value_type f,
+ typename _base::value_type b)
+ {
+ BOOST_TEST(f == this->front());
+ BOOST_TEST(b == this->back());
+ }
+
+ // const front and back
+ void test_const_front_and_back(typename _base::value_type f,
+ typename _base::value_type b) const
+ {
+ BOOST_TEST(f == this->front());
+ BOOST_TEST(b == this->back());
+ }
+
 };
 
 
@@ -197,19 +284,62 @@
         Tester t1(4, 2);
         t1.test_fill_with_n(2);
     }
+
+ // allocate_and_fill
+ {
+ Tester t1;
+ t1.test_allocate_and_fill(4,3);
+ }
+
     // regular begin and end.
     {
+ Tester t1(5, 2);
+ t1.test_begin_and_end(5);
+
     }
+
     // const begin and end
     {
+ Tester t1(5, 2);
+ t1.test_const_begin_and_end(5);
     }
+
     // reverse begin and end
     {
+ Tester t1(4, 2);
+ t1.test_reverse_begin_and_end(4);
     }
+
     // const reverse begine and end
     {
+ Tester t1(2, 2);
+ t1.test_const_reverse_begin_and_end(2);
     }
 
+ // explicitly const begin and end
+ {
+ Tester t1(2, 2);
+ t1.test_cbegin_and_cend(2);
+ }
+
+ // explicity const reverse begin and end
+ {
+ Tester t1(2, 2);
+ t1.test_crbegin_and_crend(2);
+ }
+
+ // non const front and back.
+ {
+ Tester t1(2, 2);
+ t1.test_front_and_back(2,2);
+ }
+
+ // const front and back
+ {
+ Tester t1(2, 2);
+ *--t1.end() = 3;
+ t1.test_const_front_and_back(2,3);
+ }
 }
 
 int main() {

Modified: sandbox/SOC/2010/bit_masks/notes.txt
==============================================================================
--- sandbox/SOC/2010/bit_masks/notes.txt (original)
+++ sandbox/SOC/2010/bit_masks/notes.txt 2010-08-28 09:01:37 EDT (Sat, 28 Aug 2010)
@@ -254,41 +254,19 @@
 --------------------------------------------------------------------------------
 
 
- THINGS TO CREATE EXTERNAL DOCUMENTATION FOR
+ bitfield_vector testing
 --------------------------------------------------------------------------------
+make sure that the following functions don't leak memory when an exception is
+thrown.
 
-inside of file <boost/integer/bitfield_tuple/interface_meta_functions.hpp>
-1) template <typename BitfieldTuple, typename Name>
- struct name_exists;
+void allocate_storage(size_type allocation_size)
+ and all functions which call it
+ - fill constructor.
 
-2) template <typename BitfieldTuple, typename Name>
- struct find_by_element_name;
 
-3) template <typename BitfieldTuple, std::size_t Index>
- struct find_by_element_index;
 
-4) template <typename BitfieldTuple, typename Name>
- struct get_proxy_reference_type_by_name;
 
-5) template <typename BitfieldTuple, std::size_t Index>
- struct get_proxy_reference_type_by_index;
 
-no particular file yet.
-6) How to make your own custom policy (After I finish the pointer/custom stuff)
-
-
-General Topic
-Make note of the issue with retrieving a proxy reference type in a
-const scope and how to deal with it if they wish to create their own
-proxy reference type OR if they wish to actually return the proxy
-reference type.
-
-
-*) Update documentation for filler -> padding
-*) update documentation for bit_align -> align
-*) Create documentation for how to create your own policy.
-*) proxy_reference_policy may need additional documentation however it looks
- good currently.
 --------------------------------------------------------------------------------
 
 


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