diff --git a/doc/unblank.sh b/doc/unblank.sh index 7754fdd..ab14cf9 100644 --- a/doc/unblank.sh +++ b/doc/unblank.sh @@ -25,7 +25,8 @@ rb update_srcdoc.bat rb update_srcdoc.sh rb update_srcdoc.xslt rb ../test/Jamfile +rb ../test/common.inl rb ../test/base_test.cpp -rb ../test/common.cpp rb ../test/space_optimized_test.cpp +rb ../test/iterator_test.cpp rb ../test/test.hpp diff --git a/test/base_test.cpp b/test/base_test.cpp index 3310e7a..07ca531 100644 --- a/test/base_test.cpp +++ b/test/base_test.cpp @@ -10,7 +10,7 @@ #define CB_CONTAINER circular_buffer -#include "common.cpp" +#include "common.inl" void iterator_constructor_and_assign_test() { @@ -482,7 +482,7 @@ void exception_safety_test() { } // test main -test_suite* init_unit_test_suite(int /*argc*/, char*[] /*argv*/) { +test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) { test_suite* tests = BOOST_TEST_SUITE("Unit tests for the circular_buffer."); add_common_tests(tests); diff --git a/test/cb_comparison.cpp b/test/cb_comparison.cpp index 997c1b2..b93f9ad 100644 --- a/test/cb_comparison.cpp +++ b/test/cb_comparison.cpp @@ -1,7 +1,6 @@ #define BOOST_CB_DISABLE_DEBUG 1 - #include "boost/circular_buffer.hpp" #include #include @@ -14,8 +13,16 @@ #include #include -const unsigned int queue_size = 500L; -const unsigned int total_elements = queue_size * 1000L; +const unsigned int QUEUE_SIZE = 1000L; +const unsigned int TOTAL_ELEMENTS = QUEUE_SIZE * 1000L; + +class Test { + std::string dummy; +public: + virtual ~Test(); +}; + +Test::~Test() {} template class bounded_buffer { @@ -29,29 +36,31 @@ public: void push_back(const value_type& item) { boost::mutex::scoped_lock lock(m_mutex); - m_full_condition.wait(lock, boost::bind(&bounded_buffer::is_not_full, this)); - m_empty_condition.notify_one(); + m_not_full.wait(lock, boost::bind(&bounded_buffer::is_not_full, this)); m_buffer.push_back(item); ++m_unread; + m_not_empty.notify_one(); } value_type pop_front() { boost::mutex::scoped_lock lock(m_mutex); - m_empty_condition.wait(lock, boost::bind(&bounded_buffer::is_not_empty, this)); - m_full_condition.notify_one(); + m_not_empty.wait(lock, boost::bind(&bounded_buffer::is_not_empty, this)); + m_not_full.notify_one(); // Wakes up one of the threads waiting for the buffer to free a space + // for the next item. However the woken-up thread has to regain the mutex, which + // means it will not proceed until the pop_front() method returns. return m_buffer[m_buffer.size() - (m_unread--)]; } private: - bool is_not_empty() const { return m_unread > 0;} - bool is_not_full() const { return m_unread < m_buffer.capacity();} + bool is_not_empty() const { return m_unread > 0; } + bool is_not_full() const { return m_unread < m_buffer.capacity(); } size_type m_unread; buffer_type m_buffer; boost::mutex m_mutex; - boost::condition m_empty_condition; - boost::condition m_full_condition; + boost::condition m_not_empty; + boost::condition m_not_full; }; template @@ -67,16 +76,16 @@ public: void push_back(const value_type& item) { boost::mutex::scoped_lock lock(m_mutex); m_full_condition.wait(lock, boost::bind(&deque_bounded_buffer::is_not_full, this)); - m_empty_condition.notify_one(); m_buffer.push_back(item); + m_empty_condition.notify_one(); } value_type pop_front() { boost::mutex::scoped_lock lock(m_mutex); m_empty_condition.wait(lock, boost::bind(&deque_bounded_buffer::is_not_empty, this)); - m_full_condition.notify_one(); value_type item = m_buffer.front(); m_buffer.pop_front(); + m_full_condition.notify_one(); return item; } @@ -102,7 +111,7 @@ public: reader(Queue& q) : m_q(q) { } void operator()() { - for (int i = 0; i < total_elements; ++i) { + for (int i = 0; i < TOTAL_ELEMENTS; ++i) { value_type item = m_q.pop_front(); } } @@ -118,7 +127,7 @@ public: writer(Queue& q) : m_q(q) {} void operator()() { - for (int i = 0; i < total_elements; ++i) { + for (int i = 0; i < TOTAL_ELEMENTS; ++i) { m_q.push_back(value_type()); } } @@ -127,9 +136,9 @@ public: template void fifo_test() { - boost::progress_timer t; + boost::progress_timer pt; - Queue q(queue_size); + Queue q(QUEUE_SIZE); reader reader(q); writer writer(q); @@ -149,11 +158,11 @@ int main(int argc, char* argv[]) std::cout << "deque_bounded_buffer: "; fifo_test< deque_bounded_buffer >(); - std::cout << "bounded_buffer: "; - fifo_test< bounded_buffer >(); + std::cout << "bounded_buffer: "; + fifo_test< bounded_buffer >(); - std::cout << "deque_bounded_buffer: "; - fifo_test< deque_bounded_buffer >(); + std::cout << "deque_bounded_buffer: "; + fifo_test< deque_bounded_buffer >(); return 0; } diff --git a/test/common.cpp b/test/common.inl similarity index 98% rename from test/common.cpp rename to test/common.inl index 03e2b40..db26471 100644 --- a/test/common.cpp +++ b/test/common.inl @@ -1368,30 +1368,6 @@ void const_methods_test() { BOOST_CHECK(cb.back() == 5); } -void adaptor_test() { - int array[] = {0, 1, 2, 3}; - Adaptor container(5); - container.insert(container.begin(), array, array + 4); - - BOOST_CHECK(container.size() == 4); - BOOST_CHECK(container[0] == 0); - BOOST_CHECK(container[1] == 1); - BOOST_CHECK(container[2] == 2); - BOOST_CHECK(container[3] == 3); - - container.insert(container.begin() + 1, array, array + 4); - - BOOST_CHECK(container.size() == 8); - BOOST_CHECK(container[0] == 0); - BOOST_CHECK(container[1] == 0); - BOOST_CHECK(container[2] == 1); - BOOST_CHECK(container[3] == 2); - BOOST_CHECK(container[4] == 3); - BOOST_CHECK(container[5] == 1); - BOOST_CHECK(container[6] == 2); - BOOST_CHECK(container[7] == 3); -} - // TODO - split into sections: constructor, insert, assign ... void input_range_test() { @@ -1566,6 +1542,5 @@ void add_common_tests(test_suite* tests) { tests->add(BOOST_TEST_CASE(&example_test)); tests->add(BOOST_TEST_CASE(&element_destruction_test)); tests->add(BOOST_TEST_CASE(&const_methods_test)); - tests->add(BOOST_TEST_CASE(&adaptor_test)); tests->add(BOOST_TEST_CASE(&input_range_test)); } diff --git a/test/iterator_test.cpp b/test/iterator_test.cpp index de0bca6..4806ae7 100644 --- a/test/iterator_test.cpp +++ b/test/iterator_test.cpp @@ -21,7 +21,7 @@ void validity_test() { } // test main -test_suite* init_unit_test_suite(int /*argc*/, char*[] /*argv*/) { +test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) { test_suite* tests = BOOST_TEST_SUITE("Unit tests for the iterator of the circular_buffer."); diff --git a/test/space_optimized_test.cpp b/test/space_optimized_test.cpp index 7277013..080ab12 100644 --- a/test/space_optimized_test.cpp +++ b/test/space_optimized_test.cpp @@ -12,7 +12,7 @@ #define CB_CONTAINER circular_buffer_space_optimized -#include "common.cpp" +#include "common.inl" typedef circular_buffer_space_optimized cb_space_optimized; typedef cb_space_optimized::capacity_control capacity_ctrl; @@ -61,7 +61,7 @@ void min_capacity_test() { } // test main -test_suite* init_unit_test_suite(int /*argc*/, char*[] /*argv*/) { +test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[]) { test_suite* tests = BOOST_TEST_SUITE("Unit tests for the circular_buffer_space_optimized."); add_common_tests(tests); diff --git a/test/test.hpp b/test/test.hpp index 43049f0..73fa139 100644 --- a/test/test.hpp +++ b/test/test.hpp @@ -77,6 +77,7 @@ private: static int ms_count; }; +// TODO doc class Z { public: Z() : m_num(255) {} @@ -86,39 +87,6 @@ private: int m_num; }; -// TODO doc -template class Adaptor { -private: - boost::circular_buffer m_buff; -public: - typedef typename boost::circular_buffer::iterator iterator; - typedef typename boost::circular_buffer::size_type size_type; - - Adaptor(size_type capacity) : m_buff(capacity) {} - template - Adaptor(size_type capacity, InputIterator first, InputIterator last) - : m_buff(capacity, first, last) {} - - iterator begin() { return m_buff.begin(); } - iterator end() { return m_buff.end(); } - size_type size() const { return m_buff.size(); } - size_type capacity() const { return m_buff.capacity(); } - T& operator [] (size_type index) { return m_buff[index]; } - - template - void insert(iterator pos, InputIterator first, InputIterator last) { - size_type new_size = size() + distance(first, last); - if (new_size > capacity()) { - boost::circular_buffer buff(new_size, begin(), pos); - buff.insert(buff.end(), first, last); - buff.insert(buff.end(), pos, end()); - m_buff.swap(buff); - } else { - m_buff.insert(pos, first, last); - } - } -}; - // simulator of an input iterator struct InputIteratorSimulator : boost::iterator {