/*** mockcpp is a generic C/C++ mock framework. Copyright (C) <2009> This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ***/ #ifndef __MOCKCPP_GNU_METHOD_INFO_READER_H #define __MOCKCPP_GNU_METHOD_INFO_READER_H #include #include #include #include #include #include MOCKCPP_NS_START /////////////////////////////////////////////////////////// struct GnuMethodDescription { union { void* addr; int index; }u; int delta; }; /////////////////////////////////////////////////////////// template union MethodDescriptionUnion { GnuMethodDescription desc; Method method; }; /////////////////////////////////////////////////////////// template void* getAddrOfMethod(Method input) { MethodDescriptionUnion m; m.method = input; oss_t oss; oss << "Method address should be even, please make sure the method " << TypeString::value() << " is NOT a virtual method"; MOCKCPP_ASSERT_TRUE( oss.str(), !(m.desc.u.index%2)); return m.desc.u.addr; } /////////////////////////////////////////////////////////// template GnuMethodDescription getGnuDescOfVirtualMethod(Method input) { typedef typename MethodTypeTraits::MethodType ExpectedMethodType; MethodDescriptionUnion m; m.method = input; oss_t oss; oss << "Virtual method address should be odd, please make sure the method " << TypeString::value() << " is a virtual method"; MOCKCPP_ASSERT_TRUE( oss.str(), (m.desc.u.index%2)); return m.desc; } /////////////////////////////////////////////////////////// template unsigned int getIndexOfMethod(Method method) { return (getGnuDescOfVirtualMethod(method).u.index - 1)/sizeof(void*); } /////////////////////////////////////////////////////////// template unsigned int getDeltaOfMethod(Method method) { return getGnuDescOfVirtualMethod(method).delta/sizeof(void*); } MOCKCPP_NS_END #endif