rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ding...@apache.org
Subject [rocketmq-client-cpp] branch master updated: unit-test-common-1 (#115)
Date Thu, 04 Apr 2019 07:08:46 GMT
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 6780adf  unit-test-common-1 (#115)
6780adf is described below

commit 6780adfbbf35791849b093184dcc780bb2e6bce4
Author: githublaohu <2372554140@qq.com>
AuthorDate: Thu Apr 4 15:08:42 2019 +0800

    unit-test-common-1 (#115)
---
 test/src/common/TopicConfigTest.cpp    | 93 ++++++++++++++++++++++++++++++++++
 test/src/common/ValidatorsTest.cpp     | 82 ++++++++++++++++++++++++++++++
 test/src/common/VirtualEnvUtilTest.cpp | 51 +++++++++++++++++++
 3 files changed, 226 insertions(+)

diff --git a/test/src/common/TopicConfigTest.cpp b/test/src/common/TopicConfigTest.cpp
new file mode 100644
index 0000000..d435ba6
--- /dev/null
+++ b/test/src/common/TopicConfigTest.cpp
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "string.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include "PermName.h"
+#include "TopicConfig.h"
+#include "TopicFilterType.h"
+
+using std::string;
+
+using ::testing::InitGoogleMock;
+using ::testing::InitGoogleTest;
+using testing::Return;
+
+using rocketmq::PermName;
+using rocketmq::TopicConfig;
+using rocketmq::TopicFilterType;
+
+TEST(topicConfig, encodeAndDecode) {
+    TopicConfig topicConfig("testTopic", 4, 4, PermName::PERM_READ);
+    string str = topicConfig.encode();
+
+    TopicConfig topicDecodeConfig;
+    topicDecodeConfig.decode(str);
+    EXPECT_EQ(str, topicDecodeConfig.encode());
+}
+
+TEST(topicConfig, info) {
+    TopicConfig topicConfig;
+
+    topicConfig.setTopicName("testTopic");
+    EXPECT_EQ(topicConfig.getTopicName(), "testTopic");
+
+    topicConfig.setReadQueueNums(4);
+    EXPECT_EQ(topicConfig.getReadQueueNums(), 4);
+
+    topicConfig.setWriteQueueNums(4);
+    EXPECT_EQ(topicConfig.getWriteQueueNums(), 4);
+
+    topicConfig.setPerm(PermName::PERM_READ);
+    EXPECT_EQ(topicConfig.getPerm(), PermName::PERM_READ);
+
+    topicConfig.setTopicFilterType(TopicFilterType::MULTI_TAG);
+    EXPECT_EQ(topicConfig.getTopicFilterType(), TopicFilterType::MULTI_TAG);
+}
+
+TEST(topicConfig, init) {
+    TopicConfig topicConfig;
+    EXPECT_TRUE(topicConfig.getTopicName() == "");
+    EXPECT_EQ(topicConfig.getReadQueueNums(), TopicConfig::DefaultReadQueueNums);
+    EXPECT_EQ(topicConfig.getWriteQueueNums(), TopicConfig::DefaultWriteQueueNums);
+    EXPECT_EQ(topicConfig.getPerm(), PermName::PERM_READ | PermName::PERM_WRITE);
+    EXPECT_EQ(topicConfig.getTopicFilterType(), TopicFilterType::SINGLE_TAG);
+
+    TopicConfig twoTopicConfig("testTopic");
+    EXPECT_EQ(twoTopicConfig.getTopicName(), "testTopic");
+    EXPECT_EQ(twoTopicConfig.getReadQueueNums(), TopicConfig::DefaultReadQueueNums);
+    EXPECT_EQ(twoTopicConfig.getWriteQueueNums(), TopicConfig::DefaultWriteQueueNums);
+    EXPECT_EQ(twoTopicConfig.getPerm(), PermName::PERM_READ | PermName::PERM_WRITE);
+    EXPECT_EQ(twoTopicConfig.getTopicFilterType(), TopicFilterType::SINGLE_TAG);
+
+    TopicConfig threeTopicConfig("testTopic", 4, 4, PermName::PERM_READ);
+    EXPECT_EQ(threeTopicConfig.getTopicName(), "testTopic");
+    EXPECT_EQ(threeTopicConfig.getReadQueueNums(), 4);
+    EXPECT_EQ(threeTopicConfig.getWriteQueueNums(), 4);
+    EXPECT_EQ(threeTopicConfig.getPerm(), PermName::PERM_READ);
+    EXPECT_EQ(threeTopicConfig.getTopicFilterType(), TopicFilterType::SINGLE_TAG);
+}
+
+int main(int argc, char *argv[]) {
+    InitGoogleMock(&argc, argv);
+    testing::GTEST_FLAG(throw_on_failure) = true;
+    testing::GTEST_FLAG(filter) = "topicConfig.*";
+    int itestts = RUN_ALL_TESTS();
+    return itestts;
+}
diff --git a/test/src/common/ValidatorsTest.cpp b/test/src/common/ValidatorsTest.cpp
new file mode 100644
index 0000000..807ab38
--- /dev/null
+++ b/test/src/common/ValidatorsTest.cpp
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "string.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include "MQClientException.h"
+#include "MQMessage.h"
+#include "Validators.h"
+
+using std::string;
+
+using ::testing::InitGoogleMock;
+using ::testing::InitGoogleTest;
+using testing::Return;
+
+using rocketmq::MQClientException;
+using rocketmq::MQMessage;
+using rocketmq::Validators;
+
+TEST(validators, regularExpressionMatcher) {
+    EXPECT_FALSE(Validators::regularExpressionMatcher(string(), string()));
+
+    EXPECT_TRUE(Validators::regularExpressionMatcher(string("123456"), string()));
+
+    EXPECT_TRUE(Validators::regularExpressionMatcher(string("123456"), string("123")));
+}
+
+TEST(validators, getGroupWithRegularExpression) {
+    EXPECT_EQ(Validators::getGroupWithRegularExpression(string(), string()), "");
+}
+
+TEST(validators, checkTopic) {
+    EXPECT_THROW(Validators::checkTopic(string()), MQClientException);
+    string exceptionTopic = "1234567890";
+    for (int i = 0; i < 25; i++) {
+        exceptionTopic.append("1234567890");
+    }
+    EXPECT_THROW(Validators::checkTopic(exceptionTopic), MQClientException);
+
+    EXPECT_THROW(Validators::checkTopic("TBW102"), MQClientException);
+}
+
+TEST(validators, checkGroup) {
+    EXPECT_THROW(Validators::checkGroup(string()), MQClientException);
+    string exceptionTopic = "1234567890";
+    for (int i = 0; i < 25; i++) {
+        exceptionTopic.append("1234567890");
+    }
+    EXPECT_THROW(Validators::checkGroup(exceptionTopic), MQClientException);
+}
+
+TEST(validators, checkMessage) {
+    MQMessage message("testTopic", string());
+
+    EXPECT_THROW(Validators::checkMessage(MQMessage("testTopic", string()), 1), MQClientException);
+
+    EXPECT_THROW(Validators::checkMessage(MQMessage("testTopic", string("123")), 2), MQClientException);
+}
+
+int main(int argc, char *argv[]) {
+    InitGoogleMock(&argc, argv);
+    testing::GTEST_FLAG(throw_on_failure) = true;
+    testing::GTEST_FLAG(filter) = "validators.*";
+    int itestts = RUN_ALL_TESTS();
+    return itestts;
+}
diff --git a/test/src/common/VirtualEnvUtilTest.cpp b/test/src/common/VirtualEnvUtilTest.cpp
new file mode 100644
index 0000000..305b0cd
--- /dev/null
+++ b/test/src/common/VirtualEnvUtilTest.cpp
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "string.h"
+
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include "VirtualEnvUtil.h"
+
+using std::string;
+
+using ::testing::InitGoogleMock;
+using ::testing::InitGoogleTest;
+using testing::Return;
+
+using rocketmq::VirtualEnvUtil;
+
+VirtualEnvUtil virtualEnvUtil;
+
+TEST(virtualEnvUtil, buildWithProjectGroup) {
+    string origin = "origin";
+    string projectGroup;
+    EXPECT_EQ(virtualEnvUtil.buildWithProjectGroup(origin, string()), origin);
+
+    EXPECT_EQ(virtualEnvUtil.buildWithProjectGroup(origin, string("123")), origin);
+}
+
+TEST(virtualEnvUtil, clearProjectGroup) {}
+
+int main(int argc, char *argv[]) {
+    InitGoogleMock(&argc, argv);
+
+    testing::GTEST_FLAG(throw_on_failure) = true;
+    testing::GTEST_FLAG(filter) = "messageExt.init";
+    int itestts = RUN_ALL_TESTS();
+    return itestts;
+}


Mime
View raw message