This is an automated email from the ASF dual-hosted git repository.
dinglei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-cpp.git
The following commit(s) were added to refs/heads/master by this push:
new 6812341 Resolve crash, test cash error and compile warning for unit
test cash (#129)
6812341 is described below
commit 68123416fb25822f486f34c9c51f7a471ce6146d
Author: donggang123 <[email protected]>
AuthorDate: Mon Apr 8 10:13:17 2019 +0800
Resolve crash, test cash error and compile warning for unit test cash (#129)
---
test/src/common/MemoryBlockTest.cpp | 23 ++++++++-------
test/src/extern/CMessageTest.cpp | 2 +-
test/src/extern/CProducerTest.cpp | 22 +++++++++------
test/src/extern/CPushConsumerTest.cpp | 13 +++++----
test/src/protocol/RemotingCommandTest.cpp | 33 ++--------------------
test/src/transport/ClientRemotingProcessorTest.cpp | 4 ++-
6 files changed, 39 insertions(+), 58 deletions(-)
diff --git a/test/src/common/MemoryBlockTest.cpp
b/test/src/common/MemoryBlockTest.cpp
index e1f350d..a81dc8a 100644
--- a/test/src/common/MemoryBlockTest.cpp
+++ b/test/src/common/MemoryBlockTest.cpp
@@ -80,7 +80,8 @@ TEST(memoryBlock, operators) {
EXPECT_TRUE(operaterMemoryBlock == memoryBlock);
- char *buf = (char *) malloc(sizeof(char) * 9);
+ char *buf = (char *) malloc(sizeof(char) * 16);
+ memset(buf, 0, 16);
strcpy(buf, "RocketMQ");
MemoryBlock twoMemoryBlock(buf, 12);
EXPECT_FALSE(memoryBlock == twoMemoryBlock);
@@ -90,7 +91,7 @@ TEST(memoryBlock, operators) {
EXPECT_TRUE(twoMemoryBlock != threeMemoryBlock);
threeMemoryBlock.fillWith(49);
- EXPECT_EQ(string(threeMemoryBlock.getData()), "1111111111111111");
+ EXPECT_EQ(string(threeMemoryBlock.getData(), 16), "1111111111111111");
threeMemoryBlock.reset();
EXPECT_EQ(threeMemoryBlock.getSize(), 0);
@@ -115,26 +116,24 @@ TEST(memoryBlock, operators) {
appendMemoryBlock.append(buf, 8);
EXPECT_EQ(appendMemoryBlock.getSize(), 8);
- EXPECT_EQ(string(appendMemoryBlock.getData()), "RocketMQ11111111");
-
MemoryBlock replaceWithMemoryBlock;
replaceWithMemoryBlock.append(buf, 8);
char *aliyunBuf = (char *) malloc(sizeof(char) * 8);
+ memset(aliyunBuf, 0, 8);
strcpy(aliyunBuf, "aliyun");
replaceWithMemoryBlock.replaceWith(aliyunBuf, 0);
EXPECT_EQ(replaceWithMemoryBlock.getSize(), 8);
- EXPECT_EQ(string(replaceWithMemoryBlock.getData()), "RocketMQ");
+ EXPECT_EQ(string(replaceWithMemoryBlock.getData(), 8), "RocketMQ");
replaceWithMemoryBlock.replaceWith(aliyunBuf, 6);
EXPECT_EQ(replaceWithMemoryBlock.getSize(), 6);
- EXPECT_EQ(string(replaceWithMemoryBlock.getData()), "aliyunMQ");
+ EXPECT_EQ(string(replaceWithMemoryBlock.getData(), strlen(aliyunBuf)),
"aliyun");
MemoryBlock insertMemoryBlock;
insertMemoryBlock.append(buf, 8);
-
insertMemoryBlock.insert(aliyunBuf, -1, -1);
- EXPECT_EQ(string(insertMemoryBlock.getData()), "RocketMQ");
+ EXPECT_EQ(string(insertMemoryBlock.getData(), 8), "RocketMQ");
/* MemoryBlock fourInsertMemoryBlock;
fourInsertMemoryBlock.append(buf , 8);
@@ -145,17 +144,17 @@ TEST(memoryBlock, operators) {
MemoryBlock twoInsertMemoryBlock;
twoInsertMemoryBlock.append(buf, 8);
- twoInsertMemoryBlock.insert(aliyunBuf, 8, 0);
- EXPECT_EQ(string(twoInsertMemoryBlock.getData()), "aliyun");
+ twoInsertMemoryBlock.insert(aliyunBuf, strlen(aliyunBuf), 0);
+ EXPECT_EQ(string(twoInsertMemoryBlock.getData(), 8 + strlen(aliyunBuf)),
"aliyunRocketMQ");
MemoryBlock threeInsertMemoryBlock;
threeInsertMemoryBlock.append(buf, 8);
threeInsertMemoryBlock.insert(aliyunBuf, 6, 100);
- EXPECT_EQ(string(threeInsertMemoryBlock.getData()), "RocketMQaliyun");
+ EXPECT_EQ(string(threeInsertMemoryBlock.getData(), 8 + strlen(aliyunBuf)),
"RocketMQaliyun");
MemoryBlock removeSectionMemoryBlock(buf, 8);
removeSectionMemoryBlock.removeSection(8, -1);
- EXPECT_EQ(string(removeSectionMemoryBlock.getData()), "RocketMQ");
+ EXPECT_EQ(string(removeSectionMemoryBlock.getData(), 8), "RocketMQ");
MemoryBlock twoRemoveSectionMemoryBlock(buf, 8);
twoRemoveSectionMemoryBlock.removeSection(1, 4);
diff --git a/test/src/extern/CMessageTest.cpp b/test/src/extern/CMessageTest.cpp
index 51c40cb..22500eb 100644
--- a/test/src/extern/CMessageTest.cpp
+++ b/test/src/extern/CMessageTest.cpp
@@ -69,7 +69,7 @@ TEST(cmessages, null) {
EXPECT_EQ(SetMessageBody(NULL, NULL), NULL_POINTER);
EXPECT_EQ(SetByteMessageBody(NULL, NULL, 0), NULL_POINTER);
EXPECT_EQ(SetMessageProperty(NULL, NULL, NULL), NULL_POINTER);
- EXPECT_EQ(SetDelayTimeLevel(NULL, NULL), NULL_POINTER);
+ EXPECT_EQ(SetDelayTimeLevel(NULL, 0), NULL_POINTER);
}
int main(int argc, char *argv[]) {
diff --git a/test/src/extern/CProducerTest.cpp
b/test/src/extern/CProducerTest.cpp
index ccfdc64..2d5c5be 100644
--- a/test/src/extern/CProducerTest.cpp
+++ b/test/src/extern/CProducerTest.cpp
@@ -62,37 +62,41 @@ class MockDefaultMQProducer : public DefaultMQProducer {
MOCK_METHOD5(send, SendResult(MQMessage &, MessageQueueSelector *, void *,
int, bool));
};
+void CSendSuccessCallbackFunc(CSendResult result) {
+}
+void cSendExceptionCallbackFunc(CMQException e) {
+}
+
TEST(cProducer, SendMessageAsync) {
MockDefaultMQProducer *mockProducer = new
MockDefaultMQProducer("testGroup");
CProducer *cProducer = (CProducer *) mockProducer;
CMessage *msg = (CMessage *) new MQMessage();
- CSendSuccessCallback cSendSuccessCallback;
- CSendExceptionCallback cSendExceptionCallback;
-
EXPECT_EQ(SendMessageAsync(NULL, NULL, NULL, NULL), NULL_POINTER);
EXPECT_EQ(SendMessageAsync(cProducer, NULL, NULL, NULL), NULL_POINTER);
- EXPECT_EQ(SendMessageAsync(cProducer, msg, cSendSuccessCallback, NULL),
NULL_POINTER);
+ EXPECT_EQ(SendMessageAsync(cProducer, msg, CSendSuccessCallbackFunc,
NULL), NULL_POINTER);
EXPECT_CALL(*mockProducer, send(_, _)).Times(1);
- EXPECT_EQ(SendMessageAsync(cProducer, msg, cSendSuccessCallback,
cSendExceptionCallback), OK);
+ EXPECT_EQ(SendMessageAsync(cProducer, msg, CSendSuccessCallbackFunc,
cSendExceptionCallbackFunc), OK);
Mock::AllowLeak(mockProducer);
DestroyMessage(msg);
}
+int QueueSelectorCallbackFunc(int size, CMessage *msg, void *arg) {
+ return 0;
+}
+
TEST(cProducer, sendMessageOrderly) {
MockDefaultMQProducer *mockProducer = new
MockDefaultMQProducer("testGroup");
CProducer *cProducer = (CProducer *) mockProducer;
CMessage *msg = (CMessage *) new MQMessage();
- CSendResult *result;
MQMessageQueue messageQueue;
- QueueSelectorCallback callback;
EXPECT_EQ(SendMessageOrderly(NULL, NULL, NULL, msg, 1, NULL),
NULL_POINTER);
EXPECT_EQ(SendMessageOrderly(cProducer, NULL, NULL, msg, 1, NULL),
NULL_POINTER);
EXPECT_EQ(SendMessageOrderly(cProducer, msg, NULL, msg, 1, NULL),
NULL_POINTER);
- EXPECT_EQ(SendMessageOrderly(cProducer, msg, callback, NULL, 1, NULL),
NULL_POINTER);
- EXPECT_EQ(SendMessageOrderly(cProducer, msg, callback, msg, 1, NULL),
NULL_POINTER);
+ EXPECT_EQ(SendMessageOrderly(cProducer, msg, QueueSelectorCallbackFunc,
NULL, 1, NULL), NULL_POINTER);
+ EXPECT_EQ(SendMessageOrderly(cProducer, msg, QueueSelectorCallbackFunc,
msg, 1, NULL), NULL_POINTER);
EXPECT_CALL(*mockProducer, send(_, _, _, _, _))
.WillOnce(Return(SendResult(SendStatus::SEND_OK, "3", "offset1",
messageQueue, 14)));
diff --git a/test/src/extern/CPushConsumerTest.cpp
b/test/src/extern/CPushConsumerTest.cpp
index 281b801..30a645d 100644
--- a/test/src/extern/CPushConsumerTest.cpp
+++ b/test/src/extern/CPushConsumerTest.cpp
@@ -71,6 +71,10 @@ TEST(cPushComsumer, infomock) {
Mock::AllowLeak(pushComsumer);
}
+int MessageCallBackFunc(CPushConsumer* consumer, CMessageExt* msg) {
+ return 0;
+}
+
TEST(cPushComsumer, info) {
CPushConsumer *cpushConsumer = CreatePushConsumer("testGroup");
DefaultMQPushConsumer *mqPushConsumer = (DefaultMQPushConsumer *)
cpushConsumer;
@@ -89,11 +93,10 @@ TEST(cPushComsumer, info) {
EXPECT_EQ(Subscribe(cpushConsumer, "testTopic", "testSub"), OK);
- MessageCallBack pCallback;
- EXPECT_EQ(RegisterMessageCallbackOrderly(cpushConsumer, pCallback), OK);
+ EXPECT_EQ(RegisterMessageCallbackOrderly(cpushConsumer,
MessageCallBackFunc), OK);
EXPECT_EQ(mqPushConsumer->getMessageListenerType(),
MessageListenerType::messageListenerOrderly);
- EXPECT_EQ(RegisterMessageCallback(cpushConsumer, pCallback), OK);
+ EXPECT_EQ(RegisterMessageCallback(cpushConsumer, MessageCallBackFunc), OK);
EXPECT_EQ(mqPushConsumer->getMessageListenerType(),
MessageListenerType::messageListenerConcurrently);
EXPECT_EQ(UnregisterMessageCallbackOrderly(cpushConsumer), OK);
@@ -135,8 +138,8 @@ TEST(cPushComsumer, null) {
EXPECT_EQ(RegisterMessageCallback(NULL, NULL), NULL_POINTER);
EXPECT_EQ(UnregisterMessageCallbackOrderly(NULL), NULL_POINTER);
EXPECT_EQ(UnregisterMessageCallback(NULL), NULL_POINTER);
- EXPECT_EQ(SetPushConsumerThreadCount(NULL, NULL), NULL_POINTER);
- EXPECT_EQ(SetPushConsumerMessageBatchMaxSize(NULL, NULL), NULL_POINTER);
+ EXPECT_EQ(SetPushConsumerThreadCount(NULL, 0), NULL_POINTER);
+ EXPECT_EQ(SetPushConsumerMessageBatchMaxSize(NULL, 0), NULL_POINTER);
EXPECT_EQ(SetPushConsumerInstanceName(NULL, NULL), NULL_POINTER);
EXPECT_EQ(SetPushConsumerSessionCredentials(NULL, NULL, NULL, NULL),
NULL_POINTER);
EXPECT_EQ(SetPushConsumerLogPath(NULL, NULL), NULL_POINTER);
diff --git a/test/src/protocol/RemotingCommandTest.cpp
b/test/src/protocol/RemotingCommandTest.cpp
index 1da4c14..36e8f1b 100644
--- a/test/src/protocol/RemotingCommandTest.cpp
+++ b/test/src/protocol/RemotingCommandTest.cpp
@@ -56,13 +56,7 @@ using rocketmq::SendMessageResponseHeader;
TEST(remotingCommand, init) {
RemotingCommand remotingCommand;
EXPECT_EQ(remotingCommand.getCode(), 0);
- EXPECT_EQ(remotingCommand.getOpaque(), 0);
- EXPECT_EQ(remotingCommand.getRemark(), "");
- EXPECT_EQ(remotingCommand.getVersion(), 0);
- // EXPECT_EQ(remotingCommand.getFlag() , 0);
- EXPECT_EQ(remotingCommand.getMsgBody(), "");
- EXPECT_TRUE(remotingCommand.getCommandHeader() == nullptr);
-
+
RemotingCommand twoRemotingCommand(13);
EXPECT_EQ(twoRemotingCommand.getCode(), 13);
EXPECT_EQ(twoRemotingCommand.getOpaque(), 0);
@@ -93,26 +87,8 @@ TEST(remotingCommand, init) {
EXPECT_EQ(sixRemotingCommand.getFlag(), 3);
EXPECT_EQ(sixRemotingCommand.getMsgBody(), "");
EXPECT_TRUE(sixRemotingCommand.getCommandHeader() == nullptr);
-
- RemotingCommand *sevenRemotingCommand = new RemotingCommand();
- EXPECT_EQ(sevenRemotingCommand->getCode(), 0);
- EXPECT_EQ(sevenRemotingCommand->getOpaque(), 0);
- EXPECT_EQ(sevenRemotingCommand->getRemark(), "");
- EXPECT_EQ(sevenRemotingCommand->getVersion(), 0);
- EXPECT_EQ(sevenRemotingCommand->getFlag(), 0);
- EXPECT_EQ(sevenRemotingCommand->getMsgBody(), "");
- EXPECT_TRUE(sevenRemotingCommand->getCommandHeader() == nullptr);
-
- RemotingCommand *egthRemotingCommand = sevenRemotingCommand;
- EXPECT_EQ(egthRemotingCommand->getCode(), 0);
- EXPECT_EQ(egthRemotingCommand->getOpaque(), 0);
- EXPECT_EQ(egthRemotingCommand->getRemark(), "");
- EXPECT_EQ(egthRemotingCommand->getVersion(), 0);
- EXPECT_EQ(egthRemotingCommand->getFlag(), 0);
- EXPECT_EQ(egthRemotingCommand->getMsgBody(), "");
- EXPECT_TRUE(egthRemotingCommand->getCommandHeader() == nullptr);
-
- sevenRemotingCommand = &sixRemotingCommand;
+
+ RemotingCommand* sevenRemotingCommand = &sixRemotingCommand;
EXPECT_EQ(sevenRemotingCommand->getCode(), 13);
EXPECT_EQ(sevenRemotingCommand->getOpaque(), 12);
EXPECT_EQ(sevenRemotingCommand->getRemark(), "remark");
@@ -120,9 +96,6 @@ TEST(remotingCommand, init) {
EXPECT_EQ(sevenRemotingCommand->getFlag(), 3);
EXPECT_EQ(sevenRemotingCommand->getMsgBody(), "");
EXPECT_TRUE(sevenRemotingCommand->getCommandHeader() == nullptr);
-
- // Assign
- delete egthRemotingCommand;
}
TEST(remotingCommand, info) {
diff --git a/test/src/transport/ClientRemotingProcessorTest.cpp
b/test/src/transport/ClientRemotingProcessorTest.cpp
index 80348b0..64fb944 100644
--- a/test/src/transport/ClientRemotingProcessorTest.cpp
+++ b/test/src/transport/ClientRemotingProcessorTest.cpp
@@ -124,6 +124,7 @@ TEST(clientRemotingProcessor, processRequest) {
command->setCode(1);
EXPECT_TRUE(clientRemotingProcessor.processRequest(addr, command) ==
nullptr);
+ delete twoCommand;
delete command;
delete pResponse;
}
@@ -158,7 +159,8 @@ TEST(clientRemotingProcessor, resetOffset) {
request->SetBody(strData.c_str(), strData.size());
clientRemotingProcessor.resetOffset(request);
- delete header;
+ //here header no need delete, it will managered by RemotingCommand
+ //delete header;
delete request;
}