]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/circular_buffer/test/test.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / circular_buffer / test / test.hpp
CommitLineData
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
28class MyInteger {
29private:
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 }
43public:
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
61class MyDefaultConstructible
62{
63public:
64 MyDefaultConstructible() : m_n(1) {}
65 MyDefaultConstructible(int n) : m_n(n) {}
66 int m_n;
67};
68
69// class counting instances of self
70class InstanceCounter {
71public:
72 InstanceCounter() { increment(); }
73 InstanceCounter(const InstanceCounter& y) { y.increment(); }
74 ~InstanceCounter() { decrement(); }
75 static int count() { return ms_count; }
76private:
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
83class Dummy {
84public:
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 100struct 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; }
128private:
129 vector_iterator m_it;
130};
131
132#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR)
133
134inline std::input_iterator_tag iterator_category(const MyInputIterator&) {
135 return std::input_iterator_tag();
136}
137inline int* value_type(const MyInputIterator&) { return 0; }
138inline 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
142using namespace boost;
143using namespace std;
144
145#endif // #if !defined(BOOST_CIRCULAR_BUFFER_TEST_HPP)