From d436082a0fa79319b039da9e2d431fdcf7d537db Mon Sep 17 00:00:00 2001 From: Hanqing Wu Date: Sun, 25 Jun 2023 15:14:04 +0800 Subject: [PATCH] upgrade googletest to v1.12.1 Signed-off-by: Hanqing Wu --- WORKSPACE | 11 ++-- curvefs/test/client/client_operator_test.cpp | 1 + .../test/client/lease/lease_executor_test.cpp | 2 +- curvefs/test/client/test_fuse_s3_client.cpp | 3 +- .../test/client/test_fuse_volume_client.cpp | 1 + curvefs/test/mds/fs_manager_test2.cpp | 1 + .../test/mds/mock/mock_metaserver_client.h | 1 - curvefs/test/mds/topology/test_topology.cpp | 1 + .../test/metaserver/inode_storage_test.cpp | 2 - .../test/metaserver/mock/mock_kv_storage.h | 1 - docs/cn/gmock.md | 31 +++++------ replace-curve-repo.sh | 3 -- test/chunkserver/copyset_node_test.cpp | 2 - test/chunkserver/mock_node.h | 2 - .../raftsnapshot/mock_file_reader.h | 2 - .../raftsnapshot/mock_snapshot_attachment.h | 2 - .../test_chunkserver_client.cpp | 3 +- .../chunkserverclient/test_copyset_client.cpp | 6 +-- .../test_snapshotclone_client.cpp | 2 +- test/mds/topology/test_topology.cpp | 1 + test/mds/topology/test_topology_metric.cpp | 1 + .../test_topology_service_manager.cpp | 1 + test/mds/topology/test_topology_stat.cpp | 1 + thirdparties/gmock.BUILD | 52 ------------------- 24 files changed, 38 insertions(+), 95 deletions(-) delete mode 100644 thirdparties/gmock.BUILD diff --git a/WORKSPACE b/WORKSPACE index 27eed283..338350cb 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -75,11 +75,14 @@ bind( ) #import the gtest files. -new_git_repository( +http_archive( name = "com_google_googletest", - build_file = "//:thirdparties/gmock.BUILD", - remote = "https://github.com/google/googletest", - tag = "release-1.8.0", + urls = [ + "https://curve-build.nos-eastchina1.126.net/googletest-release-1.12.1.tar.gz", + "https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz", + ], + sha256 = "81964fe578e9bd7c94dfdb09c8e4d6e6759e19967e397dbea48d1c10e45d0df2", + strip_prefix = "googletest-release-1.12.1", ) bind( diff --git a/curvefs/test/client/client_operator_test.cpp b/curvefs/test/client/client_operator_test.cpp index 5f24207e..2466ab37 100644 --- a/curvefs/test/client/client_operator_test.cpp +++ b/curvefs/test/client/client_operator_test.cpp @@ -34,6 +34,7 @@ namespace curvefs { namespace client { using ::testing::SetArgPointee; +using ::testing::DoAll; using rpcclient::MockMetaServerClient; using rpcclient::MockMdsClient; diff --git a/curvefs/test/client/lease/lease_executor_test.cpp b/curvefs/test/client/lease/lease_executor_test.cpp index 8609c3f4..15e87bf1 100644 --- a/curvefs/test/client/lease/lease_executor_test.cpp +++ b/curvefs/test/client/lease/lease_executor_test.cpp @@ -36,7 +36,7 @@ using curvefs::mds::topology::PartitionTxId; using ::testing::AtLeast; using ::testing::Return; using ::testing::SetArgPointee; - +using ::testing::DoAll; namespace curvefs { namespace client { diff --git a/curvefs/test/client/test_fuse_s3_client.cpp b/curvefs/test/client/test_fuse_s3_client.cpp index f4b933f7..55feb6da 100644 --- a/curvefs/test/client/test_fuse_s3_client.cpp +++ b/curvefs/test/client/test_fuse_s3_client.cpp @@ -21,8 +21,6 @@ */ -#include -#include #include #include @@ -75,6 +73,7 @@ namespace client { using ::curve::common::Configuration; using ::curvefs::mds::topology::PartitionTxId; using ::testing::_; +using ::testing::DoAll; using ::testing::AtLeast; using ::testing::Contains; using ::testing::Invoke; diff --git a/curvefs/test/client/test_fuse_volume_client.cpp b/curvefs/test/client/test_fuse_volume_client.cpp index d53fa19e..8c9e0869 100644 --- a/curvefs/test/client/test_fuse_volume_client.cpp +++ b/curvefs/test/client/test_fuse_volume_client.cpp @@ -56,6 +56,7 @@ namespace client { using ::curve::common::Configuration; using ::curvefs::mds::topology::PartitionTxId; using ::testing::_; +using ::testing::DoAll; using ::testing::Contains; using ::testing::Invoke; using ::testing::Return; diff --git a/curvefs/test/mds/fs_manager_test2.cpp b/curvefs/test/mds/fs_manager_test2.cpp index e6a3bfeb..c0c2bc66 100644 --- a/curvefs/test/mds/fs_manager_test2.cpp +++ b/curvefs/test/mds/fs_manager_test2.cpp @@ -69,6 +69,7 @@ using ::testing::_; using ::testing::Invoke; using ::testing::Matcher; using ::testing::Return; +using ::testing::DoAll; using ::testing::SaveArg; using ::testing::SetArgPointee; using ::curvefs::common::S3Info; diff --git a/curvefs/test/mds/mock/mock_metaserver_client.h b/curvefs/test/mds/mock/mock_metaserver_client.h index dd460319..87b47ca3 100644 --- a/curvefs/test/mds/mock/mock_metaserver_client.h +++ b/curvefs/test/mds/mock/mock_metaserver_client.h @@ -23,7 +23,6 @@ #ifndef CURVEFS_TEST_MDS_MOCK_MOCK_METASERVER_CLIENT_H_ #define CURVEFS_TEST_MDS_MOCK_MOCK_METASERVER_CLIENT_H_ -#include #include #include #include diff --git a/curvefs/test/mds/topology/test_topology.cpp b/curvefs/test/mds/topology/test_topology.cpp index aa384f03..f972172b 100644 --- a/curvefs/test/mds/topology/test_topology.cpp +++ b/curvefs/test/mds/topology/test_topology.cpp @@ -36,6 +36,7 @@ using ::testing::_; using ::testing::AnyOf; using ::testing::Contains; using ::testing::SetArgPointee; +using ::testing::DoAll; using ::curve::common::Configuration; class TestTopology : public ::testing::Test { diff --git a/curvefs/test/metaserver/inode_storage_test.cpp b/curvefs/test/metaserver/inode_storage_test.cpp index bd0de529..e8a22ee4 100644 --- a/curvefs/test/metaserver/inode_storage_test.cpp +++ b/curvefs/test/metaserver/inode_storage_test.cpp @@ -20,8 +20,6 @@ * @Author: chenwei */ -#include -#include #include #include #include diff --git a/curvefs/test/metaserver/mock/mock_kv_storage.h b/curvefs/test/metaserver/mock/mock_kv_storage.h index b2f27b72..efc968de 100644 --- a/curvefs/test/metaserver/mock/mock_kv_storage.h +++ b/curvefs/test/metaserver/mock/mock_kv_storage.h @@ -23,7 +23,6 @@ #ifndef CURVEFS_TEST_METASERVER_MOCK_MOCK_KV_STORAGE_H_ #define CURVEFS_TEST_METASERVER_MOCK_MOCK_KV_STORAGE_H_ -#include #include #include diff --git a/docs/cn/gmock.md b/docs/cn/gmock.md index 4dde034b..7987fdea 100644 --- a/docs/cn/gmock.md +++ b/docs/cn/gmock.md @@ -23,23 +23,24 @@ 1. 从Turtle派生一个类MockTurtle。 2. 使用Turtle的虚函数,计算它有多少参数。 -3. 在子类的public:部分,写MOCK_METHODn(); (或MOCK_CONST_METHODn();如果你是一个const方法),其中n是参数的数量;如果你计数错误,产生一个一个编译器错误。 -4. 使用函数名作为宏的第一个参数,第二个参数是函数的类型。 +3. 在子类的public:部分,使用 `MOCK_METHOD` 创建 mock 函数 例: - - #include "gmock/gmock.h" // Brings in Google Mock. - class MockTurtle : public Turtle { - public: - ... - MOCK_METHOD0(PenUp, void()); - MOCK_METHOD0(PenDown, void()); - MOCK_METHOD1(Forward, void(int distance)); - MOCK_METHOD1(Turn, void(int degrees)); - MOCK_METHOD2(GoTo, void(int x, int y)); - MOCK_CONST_METHOD0(GetX, int()); - MOCK_CONST_METHOD0(GetY, int()); - }; +```cpp +#include "gmock/gmock.h" // Brings in Google Mock. + +class MockTurtle : public Turtle { + public: + // ... + MOCK_METHOD(void, PenUp, (), (override)); + MOCK_METHOD(void, PenDown, (), (override)); + MOCK_METHOD(void, Forward, (int), (override)); + MOCK_METHOD(void, Turn, (int), (override)); + MOCK_METHOD(void, GoTo, (int, int), (override)); + MOCK_METHOD(int, GetX, (), (const, override)); + MOCK_METHOD(int, GetY, (), (const, override)); +}; +``` ### 在测试中使用mock类 diff --git a/replace-curve-repo.sh b/replace-curve-repo.sh index 7705bf00..835a77f8 100755 --- a/replace-curve-repo.sh +++ b/replace-curve-repo.sh @@ -14,9 +14,6 @@ sed -i "s;https://zlib.net/zlib-1.2.11.tar.gz;https://curve-build.nos-eastchina1 # protobuf sed -i "s;https://github.com/google/protobuf/archive/v3.6.1.3.zip;https://curve-build.nos-eastchina1.126.net/protobuf-3.6.1.3.zip;g" WORKSPACE -# googletest -sed -i "s;https://github.com/google/googletest;https://gitee.com/mirrors/googletest;g" WORKSPACE - # gflags sed -i "s;https://github.com/gflags/gflags/archive/v2.2.2.tar.gz;https://curve-build.nos-eastchina1.126.net/gflags-2.2.2.tar.gz;g" WORKSPACE diff --git a/test/chunkserver/copyset_node_test.cpp b/test/chunkserver/copyset_node_test.cpp index 4b7e2219..98ee3695 100644 --- a/test/chunkserver/copyset_node_test.cpp +++ b/test/chunkserver/copyset_node_test.cpp @@ -23,8 +23,6 @@ #include #include #include -#include -#include #include #include diff --git a/test/chunkserver/mock_node.h b/test/chunkserver/mock_node.h index 2dc289a9..9cfd4882 100644 --- a/test/chunkserver/mock_node.h +++ b/test/chunkserver/mock_node.h @@ -24,8 +24,6 @@ #define TEST_CHUNKSERVER_MOCK_NODE_H_ #include -#include -#include #include #include diff --git a/test/chunkserver/raftsnapshot/mock_file_reader.h b/test/chunkserver/raftsnapshot/mock_file_reader.h index 5ad7c4c9..7677cb96 100644 --- a/test/chunkserver/raftsnapshot/mock_file_reader.h +++ b/test/chunkserver/raftsnapshot/mock_file_reader.h @@ -24,8 +24,6 @@ #define TEST_CHUNKSERVER_RAFTSNAPSHOT_MOCK_FILE_READER_H_ #include -#include -#include #include #include #include "src/chunkserver/raftsnapshot/curve_snapshot_file_reader.h" diff --git a/test/chunkserver/raftsnapshot/mock_snapshot_attachment.h b/test/chunkserver/raftsnapshot/mock_snapshot_attachment.h index ffa335a3..9896569e 100644 --- a/test/chunkserver/raftsnapshot/mock_snapshot_attachment.h +++ b/test/chunkserver/raftsnapshot/mock_snapshot_attachment.h @@ -24,8 +24,6 @@ #define TEST_CHUNKSERVER_RAFTSNAPSHOT_MOCK_SNAPSHOT_ATTACHMENT_H_ #include -#include -#include #include #include #include "src/chunkserver/raftsnapshot/curve_snapshot_attachment.h" diff --git a/test/mds/chunkserverclient/test_chunkserver_client.cpp b/test/mds/chunkserverclient/test_chunkserver_client.cpp index e8b273dd..afc89ad7 100644 --- a/test/mds/chunkserverclient/test_chunkserver_client.cpp +++ b/test/mds/chunkserverclient/test_chunkserver_client.cpp @@ -69,6 +69,8 @@ namespace curve { namespace mds { namespace chunkserverclient { +using ::testing::DoAll; + class TestChunkServerClient : public ::testing::Test { protected: TestChunkServerClient() {} @@ -796,4 +798,3 @@ TEST_F(TestChunkServerClient, TestDeleteChunkReturnNotLeader) { } // namespace chunkserverclient } // namespace mds } // namespace curve - diff --git a/test/mds/chunkserverclient/test_copyset_client.cpp b/test/mds/chunkserverclient/test_copyset_client.cpp index 6cf57a80..6c072da7 100644 --- a/test/mds/chunkserverclient/test_copyset_client.cpp +++ b/test/mds/chunkserverclient/test_copyset_client.cpp @@ -66,6 +66,8 @@ namespace curve { namespace mds { namespace chunkserverclient { +using ::testing::DoAll; + class TestCopysetClient : public ::testing::Test { protected: TestCopysetClient() {} @@ -404,7 +406,3 @@ TEST_F(TestCopysetClient, TestDeleteChunkRedirectFail) { } // namespace chunkserverclient } // namespace mds } // namespace curve - - - - diff --git a/test/mds/snapshotcloneclient/test_snapshotclone_client.cpp b/test/mds/snapshotcloneclient/test_snapshotclone_client.cpp index 40d785c3..5bdb334b 100644 --- a/test/mds/snapshotcloneclient/test_snapshotclone_client.cpp +++ b/test/mds/snapshotcloneclient/test_snapshotclone_client.cpp @@ -46,6 +46,7 @@ using ::testing::Return; using ::testing::_; using ::testing::SetArgPointee; using ::testing::Invoke; +using ::testing::DoAll; namespace curve { namespace mds { @@ -351,4 +352,3 @@ TEST_F(TestSnapshotCloneClient, TestGetCloneRefStatusSuccessNeedCheck) { } // namespace snapshotcloneclient } // namespace mds } // namespace curve - diff --git a/test/mds/topology/test_topology.cpp b/test/mds/topology/test_topology.cpp index 686cd00f..c1e878de 100644 --- a/test/mds/topology/test_topology.cpp +++ b/test/mds/topology/test_topology.cpp @@ -37,6 +37,7 @@ using ::testing::_; using ::testing::Contains; using ::testing::SetArgPointee; using ::testing::SaveArg; +using ::testing::DoAll; using ::curve::common::Configuration; using ::curve::common::kDefaultPoolsetId; using ::curve::common::kDefaultPoolsetName; diff --git a/test/mds/topology/test_topology_metric.cpp b/test/mds/topology/test_topology_metric.cpp index 87c97bb4..2a382637 100644 --- a/test/mds/topology/test_topology_metric.cpp +++ b/test/mds/topology/test_topology_metric.cpp @@ -38,6 +38,7 @@ using ::testing::_; using ::testing::AnyOf; using ::testing::SetArgPointee; using ::testing::Invoke; +using ::testing::DoAll; class TestTopologyMetric : public ::testing::Test { public: diff --git a/test/mds/topology/test_topology_service_manager.cpp b/test/mds/topology/test_topology_service_manager.cpp index 3c21b0e5..074e6904 100644 --- a/test/mds/topology/test_topology_service_manager.cpp +++ b/test/mds/topology/test_topology_service_manager.cpp @@ -41,6 +41,7 @@ using ::testing::_; using ::testing::AnyOf; using ::testing::SetArgPointee; using ::testing::Invoke; +using ::testing::DoAll; using ::curve::chunkserver::MockCopysetServiceImpl; using ::curve::chunkserver::CopysetResponse2; diff --git a/test/mds/topology/test_topology_stat.cpp b/test/mds/topology/test_topology_stat.cpp index 29af5254..baf57592 100644 --- a/test/mds/topology/test_topology_stat.cpp +++ b/test/mds/topology/test_topology_stat.cpp @@ -39,6 +39,7 @@ using ::testing::_; using ::testing::AnyOf; using ::testing::SetArgPointee; using ::testing::Invoke; +using ::testing::DoAll; class TestTopologyStat : public ::testing::Test { public: diff --git a/thirdparties/gmock.BUILD b/thirdparties/gmock.BUILD deleted file mode 100644 index 7eafec2c..00000000 --- a/thirdparties/gmock.BUILD +++ /dev/null @@ -1,52 +0,0 @@ -# -# Copyright (c) 2020 NetEase Inc. -# -# Licensed 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. -# - -package(default_visibility = ["//visibility:public"]) - -cc_library( - name = "gtest_prod", - hdrs = ["googletest/include/gtest/gtest_prod.h"], - includes = ["googletest/include"], -) - -cc_library( - name = "gtest", - srcs = [ - "googletest/src/gtest-all.cc", - "googlemock/src/gmock-all.cc", - ], - hdrs = glob([ - "**/*.h", - "googletest/src/*.cc", - "googlemock/src/*.cc", - ]), - includes = [ - "googlemock", - "googletest", - "googletest/include", - "googlemock/include", - ], - linkopts = ["-pthread"], - visibility = ["//visibility:public"], - ) - -cc_library( - name = "gtest_main", - srcs = ["googlemock/src/gmock_main.cc"], - linkopts = ["-pthread"], - visibility = ["//visibility:public"], - deps = [":gtest"], -) -- GitLab