1 // Header file for the test of the circular buffer library.
3 // Copyright (c) 2003-2008 Jan Gaspar
5 // Use, modification, and distribution is subject to the Boost Software
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 #if !defined(BOOST_CIRCULAR_BUFFER_TEST_HPP)
10 #define BOOST_CIRCULAR_BUFFER_TEST_HPP
12 #if defined(_MSC_VER) && _MSC_VER >= 1200
18 #include <boost/circular_buffer.hpp>
19 #include <boost/test/included/unit_test.hpp>
20 #include <boost/iterator.hpp>
24 #if !defined(BOOST_NO_EXCEPTIONS)
28 // Integer (substitute for int) - more appropriate for testing
32 static int ms_exception_trigger;
33 void check_exception() {
34 if (ms_exception_trigger > 0) {
35 if (--ms_exception_trigger == 0) {
38 #if !defined(BOOST_NO_EXCEPTIONS)
39 throw std::exception();
45 MyInteger() : m_pValue(new int(0)) { check_exception(); }
46 MyInteger(int i) : m_pValue(new int(i)) { check_exception(); }
47 MyInteger(const MyInteger& src) : m_pValue(new int(src)) { check_exception(); }
48 ~MyInteger() { delete m_pValue; }
49 MyInteger& operator = (const MyInteger& src) {
54 m_pValue = new int(src);
57 operator int () const { return *m_pValue; }
58 static void set_exception_trigger(int n) { ms_exception_trigger = n; }
61 // default constructible class
62 class MyDefaultConstructible
65 MyDefaultConstructible() : m_n(1) {}
66 MyDefaultConstructible(int n) : m_n(n) {}
70 // class counting instances of self
71 class InstanceCounter {
73 InstanceCounter() { increment(); }
74 InstanceCounter(const InstanceCounter& y) { y.increment(); }
75 ~InstanceCounter() { decrement(); }
76 static int count() { return ms_count; }
78 void increment() const { ++ms_count; }
79 void decrement() const { --ms_count; }
83 // dummy class suitable for iterator referencing test
92 Dummy() : m_n(eVar) {}
93 DummyEnum fnc() { return eFnc; }
94 DummyEnum const_fnc() const { return eConst; }
95 virtual DummyEnum virtual_fnc() { return eVirtual; }
99 // simulator of an input iterator
100 struct MyInputIterator
101 : boost::iterator<std::input_iterator_tag, int, ptrdiff_t, int*, int&> {
102 typedef std::vector<int>::iterator vector_iterator;
103 typedef int value_type;
104 typedef int* pointer;
105 typedef int& reference;
106 typedef size_t size_type;
107 typedef ptrdiff_t difference_type;
108 explicit MyInputIterator(const vector_iterator& it) : m_it(it) {}
109 MyInputIterator& operator = (const MyInputIterator& it) {
115 reference operator * () const { return *m_it; }
116 pointer operator -> () const { return &(operator*()); }
117 MyInputIterator& operator ++ () {
121 MyInputIterator operator ++ (int) {
122 MyInputIterator tmp = *this;
126 bool operator == (const MyInputIterator& it) const { return m_it == it.m_it; }
127 bool operator != (const MyInputIterator& it) const { return m_it != it.m_it; }
129 vector_iterator m_it;
132 #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR)
134 inline std::input_iterator_tag iterator_category(const MyInputIterator&) {
135 return std::input_iterator_tag();
137 inline int* value_type(const MyInputIterator&) { return 0; }
138 inline ptrdiff_t* distance_type(const MyInputIterator&) { return 0; }
140 #endif // #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR)
142 using boost::unit_test::test_suite;
143 using namespace boost;
146 #endif // #if !defined(BOOST_CIRCULAR_BUFFER_TEST_HPP)