00001 /* 00002 00003 Copyright (C) 2006-2007 by Peter Dimov. 00004 00005 This file is part of Calitko (http://www.calitko.org). 00006 00007 Calitko is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation; either version 2 of the License, or 00010 (at your option) any later version. 00011 00012 Calitko is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with Calitko; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 00021 */ 00022 00023 #ifndef UTILS__CALITKO_MOCKS__BASIC_TYPES_H 00024 #define UTILS__CALITKO_MOCKS__BASIC_TYPES_H 00025 00026 #include "Imports.h" 00027 00028 namespace Utils { 00029 namespace CalitkoMocks { 00030 00032 00038 template <typename T> 00039 struct BoundArgumentStorageType 00040 { 00041 typedef T type; 00042 }; 00043 00045 00072 template <typename T> 00073 struct BoundArgumentStorageType <T &> 00074 { 00075 typedef T &type; 00076 }; 00077 00079 00087 template <typename T> 00088 struct BoundArgumentStorageType <const T &> 00089 { 00090 typedef T type; 00091 }; 00092 00093 template <typename T> 00094 struct ReturnTypeWrapper 00095 { 00096 ReturnTypeWrapper (T v = T()) : value (v) {} 00097 // Facitlitate the conversion ClassMock & to Class * or Class & 00098 template <typename U> 00099 ReturnTypeWrapper (U &u) : value (u) {} 00100 operator T() { return value; } 00101 T value; 00102 }; 00103 00104 template<> 00105 struct ReturnTypeWrapper <void> 00106 { 00107 }; 00108 00109 // \todo seems to not quite work... check it! 00110 template <typename T> 00111 struct ReturnTypeWrapper <std::auto_ptr <T> > 00112 { 00113 //ReturnTypeWrapper (T v = T()) : value (v) {} 00114 ReturnTypeWrapper (const ReturnTypeWrapper &o) { value = o.value; } 00115 //operator std::auto_ptr <T> () { return value; } 00116 //operator std::auto_ptr <T> () const { return value; } 00117 mutable std::auto_ptr <T> value; 00118 }; 00119 00120 template <typename T> 00121 struct DefaultValue 00122 { 00123 static T value; 00124 }; 00125 00126 template <typename T> 00127 T DefaultValue <T>::value = T(); 00128 00129 // This hack could be fixed by defining an interface for an ExpectedFunction, 00130 // or even better, an expectation. 00131 template <typename T> 00132 struct DefaultValue <T &> 00133 { 00134 static T &value; 00135 }; 00136 00137 template <typename T> 00138 T & DefaultValue <T &>::value = *reinterpret_cast <T *> (0); // HACK!!! 00139 00140 template <typename T> 00141 struct DefaultValue <const T &> 00142 { 00143 static const T value; 00144 }; 00145 00146 template <typename T> 00147 const T DefaultValue <const T &>::value = T(); 00148 00149 00150 template <typename T, typename U> 00151 struct IsSameType 00152 { 00153 enum { value = false }; 00154 }; 00155 00156 template <typename T> 00157 struct IsSameType<T,T> 00158 { 00159 enum { value = true }; 00160 }; 00161 00162 template <typename T> 00163 struct IsSameValue 00164 { 00165 static bool check (T expected, T actual) 00166 { return expected == actual; } 00167 }; 00168 00169 template <typename T> 00170 struct IsSameValue <T &> 00171 { 00172 static bool check (T &expected, T &actual) 00173 { return &expected == &actual; } 00174 }; 00175 00176 template <typename T> 00177 struct IsSameValue <const T &> 00178 { 00179 static bool check (const T &expected, const T &actual) 00180 { return expected == actual; } 00181 }; 00182 00183 } // namespace CalitkoMocks 00184 } // namespace Utils 00185 00186 #endif // UTILS__CALITKO_MOCKS__BASIC_TYPES_H