/***mockcpp is a C/C++ mock framework.Copyright [2008] [Darwin Yuan <darwin.yuan@gmail.com>]Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.***/#include <mockcpp/MockObjectBase.h>#include <mockcpp/IndexInvokableGetter.h>#include <mockcpp/Invokable.h>#include <mockcpp/VirtualTable.h>#include <mockcpp/ChainableMockMethodCore.h>#include <mockcpp/ChainableMockMethodIndexKey.h>#include <mockcpp/ChainableMockMethodContainer.h>#include <mockcpp/InvocationMockBuilderGetter.h>MOCKCPP_NS_STARTstruct MockObjectBaseImpl : public IndexInvokableGetter{MockObjectBaseImpl( unsigned int numberOfVptr, ChainableMockMethodContainer* c, ObjectNameGetter* nameGetter, const std::type_info& info);~MockObjectBaseImpl();Invokable* getInvokable(unsigned int vptrIndex, unsigned int vtblIndex) const;ChainableMockMethodCore*getMethod(const std::string& name, void* addr, \unsigned int vptrIndex, unsigned int vtblIndex, \InvocationMockerNamespace* ns);VirtualTable* vtbl;ChainableMockMethodContainer* container;void reset();private:ChainableMockMethodCore*createMethod(const std::string& name, void* addr, \unsigned int vptrIndex, unsigned int vtblIndex, \InvocationMockerNamespace* ns);};////////////////////////////////////////////////////////////////////////MockObjectBaseImpl::MockObjectBaseImpl( unsigned int numberOfVptr, ChainableMockMethodContainer* c, ObjectNameGetter* nameGetter, const std::type_info& info): container(c){vtbl = new VirtualTable(this, nameGetter, numberOfVptr, info);}////////////////////////////////////////////////////////////////////////MockObjectBaseImpl::~MockObjectBaseImpl(){delete vtbl;}////////////////////////////////////////////////////////////////////////void MockObjectBaseImpl::reset(){vtbl->reset();container->reset();}////////////////////////////////////////////////////////////////////////Invokable*MockObjectBaseImpl::getInvokable(unsigned int vptrIndex, unsigned int vtblIndex) const{ChainableMockMethodIndexKey key(vptrIndex, vtblIndex);return container->getMethod(&key);}////////////////////////////////////////////////////////////////////////ChainableMockMethodCore*MockObjectBaseImpl::createMethod(const std::string& name, void* addr, \unsigned int vptrIndex, unsigned int vtblIndex, \InvocationMockerNamespace* ns){ChainableMockMethodIndexKey* key = \new ChainableMockMethodIndexKey(vptrIndex, vtblIndex);ChainableMockMethodCore* method = \new ChainableMockMethodCore(name, ns);container->addMethod(key, method);vtbl->addMethod(addr, vtblIndex, vptrIndex);return method;}////////////////////////////////////////////////////////////////////////ChainableMockMethodCore*MockObjectBaseImpl::getMethod(const std::string& name, void* addr, \unsigned int vptrIndex, unsigned int vtblIndex, \InvocationMockerNamespace* ns){ChainableMockMethodIndexKey key(vptrIndex, vtblIndex);ChainableMockMethodCore* method = container->getMethod(&key);if(method != 0){return method;}return createMethod(name, addr, vptrIndex, vtblIndex, ns);}////////////////////////////////////////////////////////////////////////MockObjectBase::MockObjectBase( const std::string& objName, unsigned int numberOfVptr, const std::type_info& info): ChainableMockObjectBase(objName){This = new MockObjectBaseImpl(numberOfVptr, this->getMethodContainer(), this, info);}////////////////////////////////////////////////////////////////////////MockObjectBase::MockObjectBase( const MockObjectBase& obj): ChainableMockObjectBase(obj), This(obj.This){}////////////////////////////////////////////////////////////////////////MockObjectBase::~MockObjectBase(){if(!shared){delete This;}}////////////////////////////////////////////////////////////////////////InvocationMockBuilderGetterMockObjectBase::createInvocationMockerBuilderGetter(const std::string& name, \void* addr, unsigned int vptrIndex, unsigned int vtblIndex){ChainableMockMethodCore* method = \This->getMethod(name, addr, vptrIndex, vtblIndex, this);return InvocationMockBuilderGetter(method, method);}////////////////////////////////////////////////////////////////////////void*MockObjectBase::toPointerToInterface() const{return This->vtbl->toPointerToInterface();}////////////////////////////////////////////////////////////////////////void MockObjectBase::setDestructor(unsigned int vptrIndex, unsigned int vtblIndex){This->vtbl->setDestructor(vptrIndex, vtblIndex);}////////////////////////////////////////////////////////////////////////void MockObjectBase::expectsBeingDeleted(){This->vtbl->expectsBeingDeleted();}////////////////////////////////////////////////////////////////////////void MockObjectBase::expectsKeepAlive(){This->vtbl->expectsKeepAlive();}////////////////////////////////////////////////////////////////////////voidMockObjectBase::reset(){This->reset();}////////////////////////////////////////////////////////////////////////voidMockObjectBase::verify(){ChainableMockObjectBase::verify();This->vtbl->verify();}////////////////////////////////////////////////////////////////////////MOCKCPP_NS_END
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。