void testRLIwithAccountNumberAndPassword() { RliMessageHandler rlihandler(protocol_); VnocMessageSocketHandler<MockTcpConnection> handler(conn_); handler.setProtocol(protocol_); handler.start(); MSG_RLI rliMessage; unsigned char tmp[16] = {0}; srand((unsigned int)time(0)); for(int i = 0; i < 16; ++i) { tmp[i] = rand() % 256; } rliMessage.SetAccountNumber(tmp, 16); for(int i = 0; i < 16; ++i) { tmp[i] = rand() % 256; } rliMessage.SetPassword(tmp, 16); PackMessage packer; int len = packer.GetMessageLen(&rliMessage); char *buf = new char[len]; packer.Pack(&rliMessage, (byte *)buf, len); conn_->setRecv(buf, len); char *sendBuf = (char*)conn_->getSendBuf(); //return an ALI message with login-success CMessageParser parser; CMessage *msg = parser.Parse((byte*)sendBuf, conn_->getSendLen()); CPPUNIT_ASSERT(msg->GetMessageType() == MSG_ALI_TYPE); CPPUNIT_ASSERT(((MSG_ALI*)msg)->GetLoginResult() == 0); delete msg; delete buf; }
void MSGAPSParseTest() { byte testParamO [] = {0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02}; byte testParamT [] = {0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03}; byte testParamS [] = {0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04}; byte testAPS [] = {0x56, 0x00, 0x00,0x01, 0x00,0x00,0x00,0x35, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x19, 0x00,0x00,0x00,0x00, 0x01, 0x00,0x00,0x00,0x10, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x00,0x00, 0x43}; byte testPackAPS[100] = {0}; //APS CMessageParser msgParser; CMessage* msgAPS = msgParser.Parse(testAPS,sizeof(testAPS)); CPPUNIT_ASSERT(msgAPS->GetMessageType() == MSG_APS_TYPE);//验证消息类型是RPS MSG_APS* msg_aps = (MSG_APS *)msgAPS; CPPUNIT_ASSERT(msg_aps->GetSerial() == 1); CPPUNIT_ASSERT(memcmp(msg_aps->GetGUID(),testParamO,sizeof(byte) * 16) == 0); CPPUNIT_ASSERT(memcmp(msg_aps->GetMessageSynchro(),testParamO,sizeof(byte) * 16) == 0); delete msg_aps; }
void MSGRVCParseTest() { byte testParamO [] = {0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02}; byte testParamT [] = {0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03}; byte testParamS [] = {0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04}; byte testRVC [] = {0x56, 0x00, 0x00,0x01, 0x00,0x00,0x00,0x35, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x14, 0x00,0x00,0x00,0x00, 0x01, 0x00,0x00,0x00,0x10, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x00,0x00, 0x43}; byte testPackRVC[53] = {0}; CMessageParser msgParser; CMessage* msgRVC = msgParser.Parse(testRVC,sizeof(testRVC)); CPPUNIT_ASSERT(msgRVC->GetMessageType() == MSG_RVC_TYPE);//验证消息类型是RVC MSG_RVC* msg_rvc = (MSG_RVC *)msgRVC; CPPUNIT_ASSERT(msg_rvc->GetSerial() == 1); CPPUNIT_ASSERT(memcmp(msg_rvc->GetGUID(),testParamO,sizeof(byte) * 16) == 0); CPPUNIT_ASSERT(memcmp(msg_rvc->GetMachineAddress(),testParamO,16) == 0); delete msg_rvc; }
void testRVC() { RvcMessageHandler rvchandler(protocol_); VnocMessageSocketHandler<MockTcpConnection> handler(conn_); handler.setProtocol(protocol_); handler.start(); MSG_RVC rvcMessage; PackMessage packer; int len = packer.GetMessageLen(&rvcMessage); char *buf = new char[len]; packer.Pack(&rvcMessage, (byte *)buf, len); conn_->setRecv(buf, len); const char *sendBuf = conn_->getSendBuf(); //return an AVC message CMessageParser parser; CMessage *msg = parser.Parse((byte*)sendBuf, conn_->getSendLen()); CPPUNIT_ASSERT(msg->GetMessageType() == MSG_AVC_TYPE); delete msg; delete buf; }
void testRLIdefault() { RliMessageHandler rlihandler(protocol_); VnocMessageSocketHandler<MockTcpConnection> handler(conn_); handler.setProtocol(protocol_); handler.start(); MSG_RLI rliMessage; PackMessage packer; int len = packer.GetMessageLen(&rliMessage); char *buf = new char[len]; packer.Pack(&rliMessage, (byte *)buf, len); conn_->setRecv(buf, len); char *sendBuf = (char*)conn_->getSendBuf(); //return an ALI message with login-failure. CMessageParser parser; CMessage *msg = parser.Parse((byte*)sendBuf, conn_->getSendLen()); CPPUNIT_ASSERT(msg->GetMessageType() == MSG_ALI_TYPE); CPPUNIT_ASSERT(((MSG_ALI*)msg)->GetLoginResult() == 1); delete msg; delete buf; }
void MSGALIParseTest() { byte testParamO [] = {0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02}; byte testParamT [] = {0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03}; byte testParamS [] = {0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04}; byte testALI [] = {0x56, 0x00, 0x00,0x01, 0x00,0x00,0x00,0x4E, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x17, 0x00,0x00,0x00,0x00, 0x03, 0x00,0x00,0x00,0x01, 0x00,0x00,0x00,0x10, 0x00,0x00,0x00,0x10, 0x1e, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x00,0x00, 0x43}; byte testPackALI[100] = {0}; CMessageParser msgParser; CMessage* msgALI = msgParser.Parse(testALI,sizeof(testALI)); CPPUNIT_ASSERT(msgALI->GetMessageType() == MSG_ALI_TYPE);//验证消息类型是ALI MSG_ALI* msg_ali = (MSG_ALI *)msgALI; CPPUNIT_ASSERT(msg_ali->GetSerial() == 1); CPPUNIT_ASSERT(memcmp(msg_ali->GetGUID(),testParamO,sizeof(byte) * 16) == 0); CPPUNIT_ASSERT(msg_ali->GetLoginResult() == 0x1E); CPPUNIT_ASSERT(memcmp(msg_ali->GetATLGUID(),testParamT,sizeof(byte) * 16) == 0); delete msg_ali; }
void MSGRPSParseTest() { byte testParamO [] = {0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02}; byte testParamT [] = {0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03}; byte testParamS [] = {0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04}; byte testRPS [] = {0x56, 0x00, 0x00,0x01, 0x00,0x00,0x00,0x67, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x18, 0x00,0x00,0x00,0x00, 0x05, 0x00,0x00,0x00,0x01, 0x00,0x00,0x00,0x10, 0x00,0x00,0x00,0x10, 0x00,0x00,0x00,0x01, 0x00,0x00,0x00,0x10, 0x01, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 'A', 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x00,0x00, 0x43}; byte testPackRPS[120] = {0}; //RPS CMessageParser msgParser; CMessage* msgRPS = msgParser.Parse(testRPS,sizeof(testRPS)); CPPUNIT_ASSERT(msgRPS->GetMessageType() == MSG_RPS_TYPE);//验证消息类型是RPS MSG_RPS* msg_rps = (MSG_RPS *)msgRPS; CPPUNIT_ASSERT(msg_rps->GetSerial() == 1); CPPUNIT_ASSERT(memcmp(msg_rps->GetGUID(),testParamO,sizeof(byte) * 16) == 0); CPPUNIT_ASSERT(msg_rps->GetRank() == 0x01); CPPUNIT_ASSERT(memcmp(msg_rps->GetNickname(),testParamO,sizeof(byte) * 16) == 0); CPPUNIT_ASSERT(memcmp(msg_rps->GetAutograph(),testParamT,sizeof(byte) * 16) == 0); CPPUNIT_ASSERT(msg_rps->GetHeadForm() == 'A'); CPPUNIT_ASSERT(memcmp(msg_rps->GetHeadPortrait(),testParamS,sizeof(byte) * 16) == 0); delete msg_rps; }
void MSGRLIParseTest() { byte testParamO [] = {0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02}; byte testParamT [] = {0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03}; byte testParamS [] = {0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04}; byte testRLI [] = {0x56, 0x00, 0x00,0x01, 0x00,0x00,0x00,0x5D, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x16, 0x00,0x00,0x00,0x00, 0x03, 0x00,0x00,0x00,0x10, 0x00,0x00,0x00,0x10, 0x00,0x00,0x00,0x10, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x00,0x00, 0x43}; byte testPackRLI[100] = {0}; //RLI CMessageParser msgParser; CMessage* msgRLI = msgParser.Parse(testRLI,sizeof(testRLI)); CPPUNIT_ASSERT(msgRLI->GetMessageType() == MSG_RLI_TYPE);//验证消息类型是RLI MSG_RLI* msg_rli = (MSG_RLI *)msgRLI; CPPUNIT_ASSERT(msg_rli->GetSerial() == 1); CPPUNIT_ASSERT(memcmp(msg_rli->GetGUID(),testParamO,sizeof(byte) * 16) == 0); CPPUNIT_ASSERT(memcmp(msg_rli->GetVerificationCode(),testParamO,sizeof(byte) * 16) == 0); CPPUNIT_ASSERT(memcmp(msg_rli->GetAccountNumber(),testParamT,16) == 0); CPPUNIT_ASSERT(memcmp(msg_rli->GetPassword(),testParamS,16) == 0); delete msg_rli; }
void MSGAVCParseTest() { byte testParamO [] = {0x01,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02}; byte testParamT [] = {0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03, 0x03,0x03,0x03,0x03}; byte testParamS [] = {0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04, 0x04,0x04,0x04,0x04}; byte testAVC [] = {0x56, 0x00, 0x00,0x01, 0x00,0x00,0x00,0x3F, 0x01,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x15, 0x00,0x00,0x00,0x00, 0x03, 0x00,0x00,0x00,0x01, 0x00,0x00,0x00,0x01, 0x00,0x00,0x00,0x10, 0x1e, 0x1e, 0x01,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x02,0x02,0x02,0x02, 0x00,0x00, 0x43}; byte testPackAVC[63] = {0}; //AVC CMessageParser msgParser; CMessage* msgAVC = msgParser.Parse(testAVC,sizeof(testAVC)); CPPUNIT_ASSERT(msgAVC->GetMessageType() == MSG_AVC_TYPE);//验证消息类型是AVC MSG_AVC* msg_avc = (MSG_AVC *)msgAVC; CPPUNIT_ASSERT(msg_avc->GetSerial() == 1); CPPUNIT_ASSERT(memcmp(msg_avc->GetGUID(),testParamO,sizeof(byte) * 16) == 0); CPPUNIT_ASSERT(memcmp(msg_avc->GetCaptcha(),testParamO,16) == 0); CPPUNIT_ASSERT(msg_avc->GetLoginTag() == 0x1e); CPPUNIT_ASSERT(msg_avc->GetCaptchaType() == 0x1e); delete msg_avc; }