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/core/lightweight_test.hpp>
23 #if !defined(BOOST_NO_EXCEPTIONS)
27 // Integer (substitute for int) - more appropriate for testing
31 static int ms_exception_trigger;
32 void check_exception() {
33 if (ms_exception_trigger > 0) {
34 if (--ms_exception_trigger == 0) {
37 #if !defined(BOOST_NO_EXCEPTIONS)
38 throw std::exception();
44 MyInteger() : m_pValue(new int(0)) { check_exception(); }
45 MyInteger(int i) : m_pValue(new int(i)) { check_exception(); }
46 MyInteger(const MyInteger& src) : m_pValue(new int(src)) { check_exception(); }
47 ~MyInteger() { delete m_pValue; }
48 MyInteger& operator = (const MyInteger& src) {
53 m_pValue = new int(src);
56 operator int () const { return *m_pValue; }
57 static void set_exception_trigger(int n) { ms_exception_trigger = n; }
60 // default constructible class
61 class MyDefaultConstructible
64 MyDefaultConstructible() : m_n(1) {}
65 MyDefaultConstructible(int n) : m_n(n) {}
69 // class counting instances of self
70 class InstanceCounter {
72 InstanceCounter() { increment(); }
73 InstanceCounter(const InstanceCounter& y) { y.increment(); }
74 ~InstanceCounter() { decrement(); }
75 static int count() { return ms_count; }
77 void increment() const { ++ms_count; }
78 void decrement() const { --ms_count; }
82 // dummy class suitable for iterator referencing test
91 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 typedef std::vector<int>::iterator vector_iterator;
102 typedef std::input_iterator_tag iterator_category;
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 namespace boost;
145 #endif // #if !defined(BOOST_CIRCULAR_BUFFER_TEST_HPP)