ExpectationsList.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef UTILS__CALITKO_MOCKS__EXPECTATIONS_LIST_H
00024 #define UTILS__CALITKO_MOCKS__EXPECTATIONS_LIST_H
00025
00026 #include "Imports.h"
00027 #include "BasicTypes.h"
00028
00029 namespace Utils {
00030 namespace CalitkoMocks {
00031
00033
00058 template <typename Function>
00059 class ExpectationsList
00060 {
00061 public:
00062 ExpectationsList()
00063 : added(), taken()
00064 {
00065 }
00066
00067 ~ExpectationsList()
00068 {
00069 while (!added.empty()) {
00070 delete added.front();
00071 added.pop_front();
00072 }
00073 while (!taken.empty()) {
00074 delete taken.front();
00075 taken.pop_front();
00076 }
00077 }
00078
00079 bool empty()
00080 {
00081 return added.empty();
00082 }
00083
00084 Function & add (auto_ptr <Function> foo)
00085 {
00086 added.push_back (foo.get());
00087 foo.release();
00088 return *foo;
00089 }
00090
00091
00092 Function & take()
00093 {
00094 Function * f = added.front();
00095
00096
00097
00098 while (f->wasVerified()) {
00099 taken.push_back (f);
00100 added.pop_front();
00101 f = added.front();
00102 }
00103
00104 if (f->isLastExpectedCall()) {
00105 taken.push_back (f);
00106 added.pop_front();
00107 }
00108 return *f;
00109 }
00110
00111 private:
00112
00113 ExpectationsList (const ExpectationsList &);
00114 ExpectationsList & operator= (const ExpectationsList &);
00115
00116 std::list <Function *> added;
00117 std::list <Function *> taken;
00118 };
00119
00121
00148 template <typename Foo>
00149 struct ExpectationPair
00150 {
00151 ExpectationsList <Foo> &list;
00152 mutable auto_ptr <Foo> function;
00153
00154 ExpectationPair (ExpectationsList <Foo> &l, auto_ptr <Foo> f)
00155 : list (l), function (f) {}
00156 ExpectationPair (const ExpectationPair &other)
00157 : list (other.list), function (other.function) {}
00158 };
00159
00160 }
00161 }
00162
00163 #endif // UTILS__CALITKO_MOCKS__EXPECTATIONS_LIST_H