00001 00008 /************************************************************************** 00009 00010 begin : Thu Dec 26 2002 00011 copyright : (C) 2002-2010 by Ewald Arnold 00012 email : mockpp at ewald-arnold dot de 00013 00014 This program is free software; you can redistribute it and/or modify 00015 it under the terms of the GNU Lesser General Public License as 00016 published by the Free Software Foundation; either version 2 of the License, 00017 or (at your option) any later version. 00018 00019 This program is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU Lesser General Public License 00025 along with this program; if not, write to the Free Software 00026 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00027 00028 **/ 00029 00030 #ifndef MOCKPP_EXPECTATIONMAP_H 00031 #define MOCKPP_EXPECTATIONMAP_H 00032 00033 #include <mockpp/mockpp.h> // always first 00034 00035 #include MOCKPP_ALGORITHM_H 00036 #include MOCKPP_MAP_H 00037 00038 #include <mockpp/ExpectationSet.h> 00039 00040 00041 MOCKPP_NS_START 00042 00043 00048 template <class Key, class Value> 00049 class ExpectationMap : private ExpectationSet<Key> 00050 { 00051 public: 00052 00057 ExpectationMap(const String &name, VerifiableList *parent = 0) 00058 : ExpectationSet<Key>(name, parent) 00059 { 00060 } 00061 00062 00067 ExpectationMap& addExpected(const MOCKPP_STL::pair<const Key, const Value> &pair) 00068 { 00069 ExpectationSet<Key>::addExpected(pair.first); 00070 myEntries.insert(pair); 00071 return *this; 00072 } 00073 00074 00080 template <class I> 00081 ExpectationMap& addExpected(I items, I end) 00082 { 00083 for ( /* -- */; items != end; ++items) 00084 addExpected(*items); 00085 return *this; 00086 } 00087 00088 00094 ExpectationMap& addExpected(const Key &key, const Value &value) 00095 { 00096 ExpectationSet<Key>::addExpected(key); 00097 myEntries.insert(MOCKPP_STL::make_pair(key, value)); 00098 return *this; 00099 } 00100 00101 00107 ExpectationMap& addExpectedMissing(const Key &key) 00108 { 00109 ExpectationSet<Key>::addExpected(key); 00110 return *this; 00111 } 00112 00113 00118 Value get(const Key &key) 00119 { 00120 addActual(key); 00121 return (*myEntries.find(key)).second; 00122 } 00123 00124 00125 // move from private to public 00126 ExpectationSet<Key>::setExpectNothing; 00127 ExpectationSet<Key>::addActual; 00128 ExpectationSet<Key>::clearActual; 00129 ExpectationSet<Key>::reset; 00130 ExpectationSet<Key>::hasExpectations; 00131 ExpectationSet<Key>::setFailOnVerify; 00132 ExpectationSet<Key>::verify; 00133 ExpectationSet<Key>::getVerifiableName; 00134 00135 private: 00136 00137 MOCKPP_STL::map<Key, Value> myEntries; 00138 }; 00139 00140 00141 MOCKPP_NS_END 00142 00143 00144 #endif // MOCKPP_EXPECTATIONMAP_H