TEST(CLExecutiveNameServer, ReleaseCommunicationPtr) { CLExecutiveNameServer *p = CLExecutiveNameServer::GetInstance(); EXPECT_NE(p, (CLExecutiveNameServer *)0); EXPECT_FALSE(p->ReleaseCommunicationPtr(0).IsSuccess()); EXPECT_FALSE(p->ReleaseCommunicationPtr("").IsSuccess()); CLLogger::WriteLogMsg("The Following bug is produced on purpose", 0); EXPECT_FALSE(p->ReleaseCommunicationPtr("1").IsSuccess()); }
CLStatus CLMsgLoopManagerForSTLqueue::Uninitialize() { CLExecutiveNameServer *pNameServer = CLExecutiveNameServer::GetInstance(); if(pNameServer == 0) { CLLogger::WriteLogMsg("In CLMsgLoopManagerForMsgQueue::Uninitialize(), CLExecutiveNameServer::GetInstance error", 0); return CLStatus(-1, 0); } return pNameServer->ReleaseCommunicationPtr(m_strThreadName.c_str()); }
CLStatus CLExecutiveNameServer::PostExecutiveMessage(const char* pstrExecutiveName, CLMessage* pMessage){ if(pMessage == 0) return CLStatus(-1, 0); if((pstrExecutiveName == 0) || (strlen(pstrExecutiveName) == 0)){ delete pMessage; return CLStatus(-1, 0); } CLExecutiveNameServer* pNameServer = CLExecutiveNameServer::GetInstance(); if(pNameServer == NULL){ CLLogger::WriteLogMsg("In CLExecutiveNameServer::PostExecutiveMessage(), CLExecutiveNameServer::GetInstance error", 0); delete pMessage; return CLStatus(-1,0); } CLExecutiveCommunication* pComm = pNameServer->GetCommunicationPtr(pstrExecutiveName); if(pComm == NULL){ CLLogger::WriteLogMsg("In CLExecutiveNameServer::PostExecutiveMessage(), pNameServer->GetCommunicationPtr error", 0); delete pMessage; return CLStatus(-1,0); } CLStatus s = pComm->PostExecutiveMessage(pMessage); if(!s.IsSuccess()){ CLLogger::WriteLogMsg("In CLExecutiveNameServer::PostExecutiveMessage(), pComm->PostExecutiveMessage error", 0); CLStatus s = pNameServer->ReleaseCommunicationPtr(pstrExecutiveName); if(!s.IsSuccess()) CLLogger::WriteLogMsg("In CLExecutiveNameServer::PostExecutiveMessage(), pNameServer->ReleaseCommunicationPtr error", 0); return CLStatus(-1,0); } CLStatus s2 = pNameServer->ReleaseCommunicationPtr(pstrExecutiveName); if(!s2.IsSuccess()) CLLogger::WriteLogMsg("In CLExecutiveNameServer::PostExecutiveMessage(), pNameServer->ReleaseCommunicationPtr error", 0); return CLStatus(0, 0); }
TEST(CLExecutiveNameServer, GetCommunicationPtr) { CLExecutiveNameServer *p = CLExecutiveNameServer::GetInstance(); EXPECT_NE(p, (CLExecutiveNameServer *)0); EXPECT_EQ(p->GetCommunicationPtr(0), (CLMessagePoster *)0); EXPECT_EQ(p->GetCommunicationPtr(""), (CLMessagePoster *)0); CLLogger::WriteLogMsg("The Following bug is produced on purpose", 0); EXPECT_EQ(p->GetCommunicationPtr("3423"), (CLMessagePoster *)0); const char *strPipeName = "/tmp/NamedPipe_For_CLExecutiveNameServer_Test"; CLNamedPipe np(strPipeName, true); CLMessagePoster *mp = new CLMessagePoster(new CLMsgToPointerSerializer, 0, new CLDataPostChannelByNamedPipeMaintainer(strPipeName), 0); EXPECT_TRUE(mp->Initialize(new CLInitialDataPostChannelNotifier, 0).IsSuccess()); EXPECT_TRUE(p->Register("SDFdfd", mp).IsSuccess()); CLMessagePoster *qq = p->GetCommunicationPtr("SDFdfd"); EXPECT_TRUE(qq == mp); EXPECT_TRUE(p->ReleaseCommunicationPtr("SDFdfd").IsSuccess()); EXPECT_TRUE(p->ReleaseCommunicationPtr("SDFdfd").IsSuccess()); }
CLStatus CLMsgLoopManagerForPipeQueue::Uninitialize() { CLPrivateMsgQueuebyNamedPipe *pQueue = dynamic_cast<CLPrivateMsgQueuebyNamedPipe *>(m_pMsgQueue); if(pQueue == 0) return CLStatus(0, 0); CLExecutiveNameServer *pNameServer = CLExecutiveNameServer::GetInstance(); if(pNameServer == 0) { CLLogger::WriteLogMsg("In CLMsgLoopManagerForPipeQueue::Uninitialize(), CLExecutiveNameServer::GetInstance error", 0); return CLStatus(-1, 0); } return pNameServer->ReleaseCommunicationPtr(m_strThreadName.c_str()); }
CLStatus On_2(CLMessage *pm) { CLMsg2ForCLNonThreadForMsgLoopTest *p = dynamic_cast<CLMsg2ForCLNonThreadForMsgLoopTest*>(pm); EXPECT_TRUE(p != 0); g_for_on2++; if(g_for_on2 == count) { EXPECT_TRUE(CLExecutiveNameServer::PostExecutiveMessage(test1_pipe_name, new CLMsg2ForCLNonThreadForMsgLoopTest, true).IsSuccess()); CLExecutiveNameServer *pNameServer = CLExecutiveNameServer::GetInstance(); EXPECT_TRUE(pNameServer != 0); pNameServer->ReleaseCommunicationPtr(test1_pipe_name); return CLStatus(QUIT_MESSAGE_LOOP, 0); } return CLStatus(0, 0); }
TEST(CLExecutiveNameServer, MsgReceiver_Features_Test) { const char *strPipeName = "/tmp/NamedPipe_For_CLExecutiveNameServer_Test"; CLMessageReceiver *mr = new CLMessageReceiver(new CLBufferManager(), new CLDataReceiverByNamedPipe(strPipeName), new CLPointerToMsgDeserializer(), new CLProtocolDecapsulatorBySplitPointer); CLMessagePoster *mp = new CLMessagePoster(new CLMsgToPointerSerializer, 0, new CLDataPostChannelByNamedPipeMaintainer(strPipeName), 0); EXPECT_TRUE(mp->Initialize(new CLInitialDataPostChannelNotifier, 0).IsSuccess()); CLExecutiveNameServer *p = CLExecutiveNameServer::GetInstance(); EXPECT_NE(p, (CLExecutiveNameServer *)0); EXPECT_TRUE(p->Register("SDFdfd1", mp, mr).IsSuccess()); for(int i = 1; i < 40960 / 8; i++) { EXPECT_TRUE(CLExecutiveNameServer::PostExecutiveMessage("SDFdfd1", new CLMessage(i)).IsSuccess()); } EXPECT_TRUE(p->ReleaseCommunicationPtr("SDFdfd1").IsSuccess()); }
TEST(CLExecutiveNameServer, PostExecutiveMessage_Features_Test) { const char *strPipeName = "/tmp/NamedPipe_For_CLExecutiveNameServer_Test"; CLNamedPipe np(strPipeName, true); CLMessagePoster *mp = new CLMessagePoster(new CLMsgToPointerSerializer, 0, new CLDataPostChannelByNamedPipeMaintainer(strPipeName), 0); CLExecutiveNameServer *p = CLExecutiveNameServer::GetInstance(); EXPECT_NE(p, (CLExecutiveNameServer *)0); EXPECT_TRUE(mp->Initialize(new CLInitialDataPostChannelNotifier, 0).IsSuccess()); EXPECT_TRUE(p->Register("SDFdfd1", mp).IsSuccess()); CLMessage *pmsg1 = new CLMessage(1); EXPECT_TRUE(CLExecutiveNameServer::PostExecutiveMessage("SDFdfd1", pmsg1, true).IsSuccess()); CLIOVectors iov; long j; EXPECT_TRUE(iov.PushBack((char *)(&j), 8).IsSuccess()); EXPECT_TRUE(np.Read(iov).IsSuccess()); EXPECT_EQ(j, (long)pmsg1); EXPECT_TRUE(p->ReleaseCommunicationPtr("SDFdfd1").IsSuccess()); }