Skip to content

Instantly share code, notes, and snippets.

@bkuhns
Created March 12, 2013 12:13
Show Gist options
  • Save bkuhns/5142428 to your computer and use it in GitHub Desktop.
Save bkuhns/5142428 to your computer and use it in GitHub Desktop.
Modifications to HippoMocks. Pulled latest from https://www.assembla.com/code/hippomocks/git/nodes/master/HippoMocks/hippomocks.h on 2013-03-13. Adds support for move-only return types like std::unique_ptr. Also attempted to patch COM support; it builds, but setting expectations is ineffective at runtime.
1133,1135c1133
< case 0x60ff018b:
< case 0x0424448b: // bkuhns: added just for fiddling with COM. Doesn't seem to work...
< return *(unsigned char *)(func + 4) / 4;
---
> case 0x60ff018b: return *(unsigned char *)(func + 4) / 4;
1568d1565
< #if 0
1580,1604d1576
< #else
< // bkuhns: Adding support for move-only types. See: http://stackoverflow.com/questions/15160565/hippomocks-mocking-a-function-that-retuns-a-unique-ptr
< class ReturnValueHolder {
< public:
< virtual ~ReturnValueHolder() {}
< };
<
<
< template <class T>
< class TypedReturnValueHolder : public ReturnValueHolder {
< public:
< virtual T rv() = 0;
< };
<
<
< // ReturnValueWrapper changed to support move-semantics, see SO link above.
< template <class T>
< class ReturnValueWrapper : public TypedReturnValueHolder<T> {
< //typename no_cref<T>::type prv; // bkuhns: Why does hippomocks strip the reference here? It seems unnecessary...
< T prv; // bkuhns: Storing prv as type T directly, so reference types are permitted.
< public:
< ReturnValueWrapper(T rv) : prv(rv) {}
< virtual T rv() { return prv; };
< };
< #endif
4856c4828
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
4860c4832
< funcIndex.first, funcIndex.second,
---
> funcIndex,
4866c4838
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
4880c4852
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
4884c4856
< funcIndex.first, funcIndex.second,
---
> funcIndex,
4890c4862
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
4905c4877
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
4909c4881
< funcIndex.first, funcIndex.second,
---
> funcIndex,
4915c4887
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
4930c4902
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
4934c4906
< funcIndex.first, funcIndex.second,
---
> funcIndex,
4940c4912
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
4955c4927
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
4959c4931
< funcIndex.first, funcIndex.second,
---
> funcIndex,
4965c4937
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
4981c4953
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
4985c4957
< funcIndex.first, funcIndex.second,
---
> funcIndex,
4991c4963
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
5007c4979
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
5011c4983
< funcIndex.first, funcIndex.second,
---
> funcIndex,
5017c4989
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
5033c5005
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
5037c5009
< funcIndex.first, funcIndex.second,
---
> funcIndex,
5043c5015
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
5059c5031
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
5063c5035
< funcIndex.first, funcIndex.second,
---
> funcIndex,
5069c5041
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
5086c5058
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
5090c5062
< funcIndex.first, funcIndex.second,
---
> funcIndex,
5096c5068
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
5113c5085
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
5117c5089
< funcIndex.first, funcIndex.second,
---
> funcIndex,
5123c5095
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
5140c5112
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
5144c5116
< funcIndex.first, funcIndex.second,
---
> funcIndex,
5150c5122
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
5167c5139
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
5171c5143
< funcIndex.first, funcIndex.second,
---
> funcIndex,
5177c5149
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
5195c5167
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
5199c5171
< funcIndex.first, funcIndex.second,
---
> funcIndex,
5205c5177
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
5223c5195
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
5227c5199
< funcIndex.first, funcIndex.second,
---
> funcIndex,
5233c5205
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
5251c5223
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
5255c5227
< funcIndex.first, funcIndex.second,
---
> funcIndex,
5261c5233
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
5280c5252
< std::pair<int, int> funcIndex = virtual_index((Y (Z2::*)())func);
---
> int funcIndex = getFunctionIndex(func);
5284c5256
< funcIndex.first, funcIndex.second,
---
> funcIndex,
5290c5262
< case Any: optionals.push_back(call); break;
---
> case DontCare: optionals.push_back(call); break;
6194,6196c6166
< return ((TypedReturnValueHolder<Z> *)call->retVal)->rv();
< /*if (call->retVal)
< return ((ReturnValueWrapper<Z> *)call->retVal)->rv;*/
---
> return ((ReturnValueWrapper<Z> *)call->retVal)->rv;
6263,6265c6233
< return ((TypedReturnValueHolder<Z> *)call->retVal)->rv();
< /*if (call->retVal)
< return ((ReturnValueWrapper<Z> *)call->retVal)->rv;*/
---
> return ((ReturnValueWrapper<Z> *)call->retVal)->rv;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment