This is an automated email from the ASF dual-hosted git repository. ifplusor pushed a commit to branch re_dev in repository https://gitbox.apache.org/repos/asf/rocketmq-client-cpp.git
commit 44b846ed14ab6833c5625449ea54685c6a32acce Author: James Yin <[email protected]> AuthorDate: Wed Mar 24 16:47:24 2021 +0800 fix: test --- test/CMakeLists.txt | 7 +++---- test/src/message/MQMessageExtTest.cpp | 14 ++++++-------- test/src/message/MessageDecoderTest.cpp | 22 ++++++++++++---------- test/src/message/MessageIdTest.cpp | 13 +++++++------ test/src/protocol/ConsumerRunningInfoTest.cpp | 4 ++-- test/src/protocol/ProcessQueueInfoTest.cpp | 3 ++- test/src/transport/ClientRemotingProcessorTest.cpp | 11 ++++++----- test/src/transport/ResponseFutureTest.cpp | 7 ++++--- test/src/transport/SocketUtilTest.cpp | 10 +++++----- 9 files changed, 47 insertions(+), 44 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 41cff82..d6e56eb 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -22,9 +22,8 @@ set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin) set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};${CMAKE_SOURCE_DIR}/bin/lib64/cmake;${CMAKE_SOURCE_DIR}/bin/lib/cmake") # Find dependencies -if (CMAKE_VERSION VERSION_LESS "3.0") - find_package(GTest 1.10.0 REQUIRED CONFIG) -else () +#find_package(GTest REQUIRED CONFIG) +if (NOT GTest_FOUND) include_directories("${CMAKE_SOURCE_DIR}/bin/include") if (EXISTS "${CMAKE_SOURCE_DIR}/bin/lib64/libgtest.a") @@ -55,7 +54,7 @@ function(config_test file) endif() endif() - if (CMAKE_VERSION VERSION_LESS "3.0") + if (GTest_FOUND) if (BUILD_ROCKETMQ_SHARED) target_link_libraries(${basename} rocketmq_shared GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main) diff --git a/test/src/message/MQMessageExtTest.cpp b/test/src/message/MQMessageExtTest.cpp index b889aa8..702233c 100644 --- a/test/src/message/MQMessageExtTest.cpp +++ b/test/src/message/MQMessageExtTest.cpp @@ -89,18 +89,19 @@ TEST(MessageExtTest, MessageClientExtImpl) { messageClientExt.set_store_timestamp(2222); EXPECT_EQ(messageClientExt.store_timestamp(), 2222); - messageClientExt.set_born_host(rocketmq::string2SocketAddress("127.0.0.1:10091")); + messageClientExt.set_born_host(rocketmq::StringToSockaddr("127.0.0.1:10091")); EXPECT_EQ(messageClientExt.born_host_string(), "127.0.0.1:10091"); - messageClientExt.set_store_host(rocketmq::string2SocketAddress("127.0.0.2:10092")); + messageClientExt.set_store_host(rocketmq::StringToSockaddr("127.0.0.2:10092")); EXPECT_EQ(messageClientExt.store_host_string(), "127.0.0.2:10092"); } TEST(MessageExtTest, MessageExt) { - struct sockaddr* bronHost = rocketmq::copySocketAddress(nullptr, rocketmq::string2SocketAddress("127.0.0.1:10091")); - struct sockaddr* storeHost = rocketmq::copySocketAddress(nullptr, rocketmq::string2SocketAddress("127.0.0.2:10092")); + auto bronHost = rocketmq::SockaddrToStorage(rocketmq::StringToSockaddr("127.0.0.1:10091")); + auto storeHost = rocketmq::SockaddrToStorage(rocketmq::StringToSockaddr("127.0.0.2:10092")); - MQMessageExt messageExt(2, 1024, bronHost, 2048, storeHost, "msgId"); + MQMessageExt messageExt(2, 1024, reinterpret_cast<sockaddr*>(bronHost.get()), 2048, + reinterpret_cast<sockaddr*>(storeHost.get()), "msgId"); EXPECT_EQ(messageExt.queue_offset(), 0); EXPECT_EQ(messageExt.commit_log_offset(), 0); EXPECT_EQ(messageExt.born_timestamp(), 1024); @@ -113,9 +114,6 @@ TEST(MessageExtTest, MessageExt) { EXPECT_EQ(messageExt.msg_id(), "msgId"); EXPECT_EQ(messageExt.born_host_string(), "127.0.0.1:10091"); EXPECT_EQ(messageExt.store_host_string(), "127.0.0.2:10092"); - - free(bronHost); - free(storeHost); } TEST(MessageExtTest, ParseTopicFilterType) { diff --git a/test/src/message/MessageDecoderTest.cpp b/test/src/message/MessageDecoderTest.cpp index d602d80..74e55ce 100644 --- a/test/src/message/MessageDecoderTest.cpp +++ b/test/src/message/MessageDecoderTest.cpp @@ -14,16 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include <gmock/gmock.h> -#include <gtest/gtest.h> +#include "MessageDecoder.h" #include <string> #include <vector> +#include <arpa/inet.h> + +#include <gmock/gmock.h> +#include <gtest/gtest.h> + #include "ByteArray.h" #include "ByteBuffer.hpp" -#include "MessageDecoder.h" #include "MQMessage.h" #include "MQMessageConst.h" #include "MQMessageExt.h" @@ -39,12 +41,12 @@ using testing::Return; using rocketmq::ByteArray; using rocketmq::ByteBuffer; -using rocketmq::MessageSysFlag; using rocketmq::MessageDecoder; +using rocketmq::MessageId; +using rocketmq::MessageSysFlag; using rocketmq::MQMessage; using rocketmq::MQMessageConst; using rocketmq::MQMessageExt; -using rocketmq::MessageId; using rocketmq::RemotingCommand; using rocketmq::SendMessageRequestHeader; using rocketmq::stoba; @@ -52,13 +54,13 @@ using rocketmq::UtilAll; // TODO TEST(MessageDecoderTest, MessageId) { - std::string strMsgId = MessageDecoder::createMessageId(rocketmq::string2SocketAddress("127.0.0.1:10091"), 1024LL); + std::string strMsgId = MessageDecoder::createMessageId(rocketmq::StringToSockaddr("127.0.0.1:10091"), 1024LL); EXPECT_EQ(strMsgId, "7F0000010000276B0000000000000400"); MessageId msgId = MessageDecoder::decodeMessageId(strMsgId); EXPECT_EQ(msgId.getOffset(), 1024LL); - std::string strMsgId2 = MessageDecoder::createMessageId(rocketmq::string2SocketAddress("/172.16.2.114:0"), 123456LL); + std::string strMsgId2 = MessageDecoder::createMessageId(rocketmq::StringToSockaddr("/172.16.2.114:0"), 123456LL); EXPECT_EQ(strMsgId2, "AC10027200000000000000000001E240"); MessageId msgId2 = MessageDecoder::decodeMessageId(strMsgId2); @@ -107,7 +109,7 @@ TEST(MessageDecoderTest, Decode) { // 10 BORNHOST 56=48+4+4 byteBuffer->putInt(ntohl(inet_addr("127.0.0.1"))); byteBuffer->putInt(10091); - msgExt.set_born_host(rocketmq::string2SocketAddress("127.0.0.1:10091")); + msgExt.set_born_host(rocketmq::StringToSockaddr("127.0.0.1:10091")); // 11 STORETIMESTAMP 64=56+8 byteBuffer->putLong(4096LL); @@ -116,7 +118,7 @@ TEST(MessageDecoderTest, Decode) { // 12 STOREHOST 72=64+4+4 byteBuffer->putInt(ntohl(inet_addr("127.0.0.2"))); byteBuffer->putInt(10092); - msgExt.set_store_host(rocketmq::string2SocketAddress("127.0.0.2:10092")); + msgExt.set_store_host(rocketmq::StringToSockaddr("127.0.0.2:10092")); // 13 RECONSUMETIMES 76=72+4 byteBuffer->putInt(18); diff --git a/test/src/message/MessageIdTest.cpp b/test/src/message/MessageIdTest.cpp index aa09006..19efbf4 100644 --- a/test/src/message/MessageIdTest.cpp +++ b/test/src/message/MessageIdTest.cpp @@ -14,11 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "MessageId.h" +#include "SocketUtil.h" + #include <gmock/gmock.h> #include <gtest/gtest.h> -#include "MessageId.h" - using namespace std; using testing::InitGoogleMock; using testing::InitGoogleTest; @@ -27,12 +28,12 @@ using testing::Return; using rocketmq::MessageId; TEST(MessageIdTest, MessageId) { - MessageId msgId(rocketmq::string2SocketAddress("127.0.0.1:10091"), 1024); - EXPECT_EQ(rocketmq::socketAddress2String(msgId.getAddress()), "127.0.0.1:10091"); + MessageId msgId(rocketmq::StringToSockaddr("127.0.0.1:10091"), 1024); + EXPECT_EQ(rocketmq::SockaddrToString(msgId.getAddress()), "127.0.0.1:10091"); EXPECT_EQ(msgId.getOffset(), 1024); - msgId.setAddress(rocketmq::string2SocketAddress("127.0.0.2:10092")); - EXPECT_EQ(rocketmq::socketAddress2String(msgId.getAddress()), "127.0.0.2:10092"); + msgId.setAddress(rocketmq::StringToSockaddr("127.0.0.2:10092")); + EXPECT_EQ(rocketmq::SockaddrToString(msgId.getAddress()), "127.0.0.2:10092"); msgId.setOffset(2048); EXPECT_EQ(msgId.getOffset(), 2048); diff --git a/test/src/protocol/ConsumerRunningInfoTest.cpp b/test/src/protocol/ConsumerRunningInfoTest.cpp index 7c3dc8f..74c21aa 100644 --- a/test/src/protocol/ConsumerRunningInfoTest.cpp +++ b/test/src/protocol/ConsumerRunningInfoTest.cpp @@ -14,6 +14,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "protocol/body/ConsumerRunningInfo.h" + #include <gmock/gmock.h> #include <gtest/gtest.h> #include <json/reader.h> @@ -23,8 +25,6 @@ #include <map> #include <string> -#include "ConsumerRunningInfo.h" - using std::map; using std::string; diff --git a/test/src/protocol/ProcessQueueInfoTest.cpp b/test/src/protocol/ProcessQueueInfoTest.cpp index cfd1a56..dcb544a 100644 --- a/test/src/protocol/ProcessQueueInfoTest.cpp +++ b/test/src/protocol/ProcessQueueInfoTest.cpp @@ -14,11 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "protocol/body/ProcessQueueInfo.hpp" + #include <gmock/gmock.h> #include <gtest/gtest.h> #include "MQMessageExt.h" -#include "ProcessQueueInfo.h" using testing::InitGoogleMock; using testing::InitGoogleTest; diff --git a/test/src/transport/ClientRemotingProcessorTest.cpp b/test/src/transport/ClientRemotingProcessorTest.cpp index 1a840d9..e751a14 100644 --- a/test/src/transport/ClientRemotingProcessorTest.cpp +++ b/test/src/transport/ClientRemotingProcessorTest.cpp @@ -14,18 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "ClientRemotingProcessor.h" + +#include <map> +#include <memory> + #include <gmock/gmock.h> #include <gtest/gtest.h> #include <json/value.h> #include <json/writer.h> -#include <map> -#include <memory> - #include "ByteArray.h" #include "ClientRPCHook.h" -#include "ClientRemotingProcessor.h" -#include "ConsumerRunningInfo.h" #include "MQClientConfigImpl.hpp" #include "MQClientInstance.h" #include "MQMessageQueue.h" @@ -34,6 +34,7 @@ #include "SessionCredentials.h" #include "TcpTransport.h" #include "UtilAll.h" +#include "protocol/body/ConsumerRunningInfo.h" #include "protocol/body/ResetOffsetBody.hpp" #include "protocol/header/CommandHeader.h" diff --git a/test/src/transport/ResponseFutureTest.cpp b/test/src/transport/ResponseFutureTest.cpp index 9826c82..15680d9 100644 --- a/test/src/transport/ResponseFutureTest.cpp +++ b/test/src/transport/ResponseFutureTest.cpp @@ -14,12 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "ResponseFuture.h" + #include <gmock/gmock.h> #include <gtest/gtest.h> #include "InvokeCallback.h" #include "RemotingCommand.h" -#include "ResponseFuture.h" #include "UtilAll.h" #include "protocol/RequestCode.h" @@ -48,8 +49,8 @@ TEST(ResponseFutureTest, Init) { EXPECT_FALSE(responseFuture.hasInvokeCallback()); // ~ResponseFuture delete callback - auto* callback = new MockInvokeCallback(); - ResponseFuture twoResponseFuture(MQRequestCode::QUERY_BROKER_OFFSET, 4, 1000, callback); + ResponseFuture twoResponseFuture(MQRequestCode::QUERY_BROKER_OFFSET, 4, 1000, + std::unique_ptr<InvokeCallback>(new MockInvokeCallback())); EXPECT_TRUE(twoResponseFuture.hasInvokeCallback()); } diff --git a/test/src/transport/SocketUtilTest.cpp b/test/src/transport/SocketUtilTest.cpp index e7b8a70..985d826 100644 --- a/test/src/transport/SocketUtilTest.cpp +++ b/test/src/transport/SocketUtilTest.cpp @@ -14,11 +14,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include "SocketUtil.h" + #include <gmock/gmock.h> #include <gtest/gtest.h> -#include "SocketUtil.h" - using testing::InitGoogleMock; using testing::InitGoogleTest; using testing::Return; @@ -29,14 +29,14 @@ using namespace rocketmq; TEST(SocketUtilTest, Convert) { char ip[] = {0x7F, 0x00, 0x00, 0x01}; - struct sockaddr* sa = ipPort2SocketAddress(ByteArray(ip, sizeof(ip)), 0x276B); + struct sockaddr* sa = IPPortToSockaddr(ByteArray(ip, sizeof(ip)), 0x276B); struct sockaddr_in* sin = (struct sockaddr_in*)sa; EXPECT_EQ(sin->sin_addr.s_addr, 0x0100007F); EXPECT_EQ(sin->sin_port, 0x6B27); - EXPECT_EQ(socketAddress2String(sa), "127.0.0.1:10091"); + EXPECT_EQ(SockaddrToString(sa), "127.0.0.1:10091"); - sa = string2SocketAddress("127.0.0.1:10091"); + sa = StringToSockaddr("127.0.0.1:10091"); sin = (struct sockaddr_in*)sa; EXPECT_EQ(sin->sin_addr.s_addr, 0x0100007F); EXPECT_EQ(sin->sin_port, 0x6B27);
