IObject* SimpleDynamicLoader::createObject() { IObject* obj; obj = factory(); if(obj) obj->addRef(); return obj; }
IObject* GenericFactory::createObject() { IObject* obj; obj = factory(); if(obj) obj->addRef(); return obj; }
void test006() { IServiceManager* servmgr; IStaticServiceHandler* handler; IMonikerService* monikers; IObject* testobj; IObject* obj; servmgr = XPLC_getServiceManager(); ASSERT(servmgr != 0, "could not obtain service manager"); obj = servmgr->getObject(XPLC::staticServiceHandler); ASSERT(obj != 0, "could not obtain static service handler"); handler = mutate<IStaticServiceHandler>(obj); ASSERT(handler != 0, "static service handler does not have the IStaticServiceHandler interface"); testobj = new TestObject; ASSERT(testobj != 0, "could not create TestObject"); testobj->addRef(); handler->addObject(TestObject_CID, testobj); VERIFY(servmgr->getObject(TestObject_CID) == testobj, "adding the test object did not work"); VERIFY(testobj->release() == 2, "incorrect refcount on test object"); obj = servmgr->getObject(XPLC::monikers); ASSERT(obj != 0, "could not obtain moniker component"); monikers = mutate<IMonikerService>(obj); ASSERT(monikers != 0, "moniker service does not have the IMoniker interface"); monikers->registerObject("moniker", XPLC::monikers); monikers->registerObject("testobject", TestObject_CID); obj = monikers->resolve("testobject"); ASSERT(obj != 0, "resolving the test object returned nothing"); ASSERT(obj == testobj, "the testobject moniker resolved to something else than the test object"); VERIFY(obj->release() == 2, "refcount is wrong on the test object"); obj = monikers->resolve("moniker:testobject"); ASSERT(obj != 0, "resolving the test object indirectly returned nothing"); ASSERT(obj == testobj, "the testobject moniker indirectly resolved to something else than the test object"); VERIFY(obj->release() == 2, "refcount is wrong on the test object"); obj = monikers->resolve("moniker:"); VERIFY(obj == 0, "resolving an empty sub-moniker returned something"); VERIFY(monikers->release() == 1, "incorrect refcount on moniker service"); VERIFY(handler->release() == 2, "incorrect refcount on static service handler"); VERIFY(servmgr->release() == 0, "service manager has non-zero refcount after release"); VERIFY(testobj->release() == 0, "refcount is wrong on the test object"); delete testobj; }
UUID_MAP_END IObject* XPLC_getInterface_real(void* self, const UUID& uuid, const UUID_Info* uuidlist) { IObject* rv; while(uuidlist->iid) { if(uuidlist->iid->equals(uuid)) { rv = reinterpret_cast<IObject*> (reinterpret_cast<ptrdiff_t>(self) + uuidlist->delta); rv->addRef(); return rv; } uuidlist++; } return 0; }
void test() { MyTestObject* test = 0; IObject* iobj = 0; IFoo* ifoo = 0; IBar* ibar = 0; test = MyTestObject::create(); ASSERT(test, "could not instantiate test object"); iobj = static_cast<IFoo*>(test)->getInterface(IObject::IID); VERIFY(iobj, "getInterface(IObject::IID) failed on test object"); VERIFY(reinterpret_cast<void*>(iobj) == reinterpret_cast<void*>(test), "identity test failed"); ifoo = get<IFoo>(iobj); VERIFY(ifoo, "get<IFoo> failed on test object"); ibar = get<IBar>(ifoo); VERIFY(ibar, "get<IBar> failed on test object"); ifoo->setFoo(10); ibar->setBar(20); VERIFY(ifoo->getFoo() == 10, "test object has unexpected behavior"); VERIFY(ibar->getBar() == 20, "test object has unexpected behavior"); VERIFY(iobj->addRef() == 4, "incorrect refcount"); VERIFY(ifoo->addRef() == 5, "incorrect refcount"); VERIFY(ibar->addRef() == 6, "incorrect refcount"); VERIFY(iobj->release() == 5, "incorrect refcount"); VERIFY(ifoo->release() == 4, "incorrect refcount"); VERIFY(ibar->release() == 3, "incorrect refcount"); VERIFY(iobj->release() == 2, "incorrect refcount"); VERIFY(ifoo->release() == 1, "incorrect refcount"); VERIFY(ibar->release() == 0, "incorrect refcount"); }