]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Header file for the test of the circular buffer library. |
2 | ||
3 | // Copyright (c) 2003-2008 Jan Gaspar | |
4 | ||
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) | |
8 | ||
9 | #if !defined(BOOST_CIRCULAR_BUFFER_TEST_HPP) | |
10 | #define BOOST_CIRCULAR_BUFFER_TEST_HPP | |
11 | ||
12 | #if defined(_MSC_VER) && _MSC_VER >= 1200 | |
13 | #pragma once | |
14 | #endif | |
15 | ||
16 | #define BOOST_CB_TEST | |
17 | ||
18 | #include <boost/circular_buffer.hpp> | |
92f5a8d4 | 19 | #include <boost/core/lightweight_test.hpp> |
7c673cae FG |
20 | #include <iterator> |
21 | #include <numeric> | |
22 | #include <vector> | |
23 | #if !defined(BOOST_NO_EXCEPTIONS) | |
24 | #include <exception> | |
25 | #endif | |
26 | ||
27 | // Integer (substitute for int) - more appropriate for testing | |
28 | class MyInteger { | |
29 | private: | |
30 | int* m_pValue; | |
31 | static int ms_exception_trigger; | |
32 | void check_exception() { | |
33 | if (ms_exception_trigger > 0) { | |
34 | if (--ms_exception_trigger == 0) { | |
35 | delete m_pValue; | |
36 | m_pValue = 0; | |
37 | #if !defined(BOOST_NO_EXCEPTIONS) | |
38 | throw std::exception(); | |
39 | #endif | |
40 | } | |
41 | } | |
42 | } | |
43 | public: | |
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) { | |
49 | if (this == &src) | |
50 | return *this; | |
51 | check_exception(); | |
52 | delete m_pValue; | |
53 | m_pValue = new int(src); | |
54 | return *this; | |
55 | } | |
56 | operator int () const { return *m_pValue; } | |
57 | static void set_exception_trigger(int n) { ms_exception_trigger = n; } | |
58 | }; | |
59 | ||
60 | // default constructible class | |
61 | class MyDefaultConstructible | |
62 | { | |
63 | public: | |
64 | MyDefaultConstructible() : m_n(1) {} | |
65 | MyDefaultConstructible(int n) : m_n(n) {} | |
66 | int m_n; | |
67 | }; | |
68 | ||
69 | // class counting instances of self | |
70 | class InstanceCounter { | |
71 | public: | |
72 | InstanceCounter() { increment(); } | |
73 | InstanceCounter(const InstanceCounter& y) { y.increment(); } | |
74 | ~InstanceCounter() { decrement(); } | |
75 | static int count() { return ms_count; } | |
76 | private: | |
77 | void increment() const { ++ms_count; } | |
78 | void decrement() const { --ms_count; } | |
79 | static int ms_count; | |
80 | }; | |
81 | ||
82 | // dummy class suitable for iterator referencing test | |
83 | class Dummy { | |
84 | public: | |
85 | enum DummyEnum { | |
86 | eVar, | |
87 | eFnc, | |
88 | eConst, | |
89 | eVirtual | |
90 | }; | |
91 | Dummy() : m_n(eVar) {} | |
92f5a8d4 | 92 | virtual ~Dummy() {} |
7c673cae FG |
93 | DummyEnum fnc() { return eFnc; } |
94 | DummyEnum const_fnc() const { return eConst; } | |
95 | virtual DummyEnum virtual_fnc() { return eVirtual; } | |
96 | DummyEnum m_n; | |
97 | }; | |
98 | ||
99 | // simulator of an input iterator | |
92f5a8d4 | 100 | struct MyInputIterator { |
7c673cae | 101 | typedef std::vector<int>::iterator vector_iterator; |
92f5a8d4 | 102 | typedef std::input_iterator_tag iterator_category; |
7c673cae FG |
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) { | |
110 | if (this == &it) | |
111 | return *this; | |
112 | m_it = it.m_it; | |
113 | return *this; | |
114 | } | |
115 | reference operator * () const { return *m_it; } | |
116 | pointer operator -> () const { return &(operator*()); } | |
117 | MyInputIterator& operator ++ () { | |
118 | ++m_it; | |
119 | return *this; | |
120 | } | |
121 | MyInputIterator operator ++ (int) { | |
122 | MyInputIterator tmp = *this; | |
123 | ++*this; | |
124 | return tmp; | |
125 | } | |
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; } | |
128 | private: | |
129 | vector_iterator m_it; | |
130 | }; | |
131 | ||
132 | #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) | |
133 | ||
134 | inline std::input_iterator_tag iterator_category(const MyInputIterator&) { | |
135 | return std::input_iterator_tag(); | |
136 | } | |
137 | inline int* value_type(const MyInputIterator&) { return 0; } | |
138 | inline ptrdiff_t* distance_type(const MyInputIterator&) { return 0; } | |
139 | ||
140 | #endif // #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) | |
141 | ||
7c673cae FG |
142 | using namespace boost; |
143 | using namespace std; | |
144 | ||
145 | #endif // #if !defined(BOOST_CIRCULAR_BUFFER_TEST_HPP) |