diff --git a/WORKSPACE b/WORKSPACE index 27eed2836526e5b300878170e13accfbf6331bcc..338350cbf17527d82906726c102b70a04b7761cf 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 5f24207e81762c2a66cc8d5a576e54c701b62266..2466ab37b270170968b440567fd60d5c98ca49f0 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 8609c3f4b4ad20075990f3f04a4db65066d1e00c..15e87bf16be66b227692b72b5b06d9bf59568c5f 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 f4b933f736cfa864f18acc7f0bbe6de23fc32d75..55feb6da4afa54d7ecefba5d245079adcd9d4f0a 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 d53fa19e08872f1d3ed2550486f37d0240c86be1..8c9e0869fcf166f456049e25ff1638865443b906 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 e6a3bfebadc5fcdb7c3876bcb2cd28ee3d38b7f0..c0c2bc6685c031b36712aa7fc52d1819ddc76c03 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 dd4603191ce797f37467ec62980a45cae623a1b6..87b47ca360156ab0808fb2473359250e663cdfb8 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 aa384f035a66d47d97936281a3d5410babbac0aa..f972172b589b5d021d61b3f59c60c7825adf9f4e 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 bd0de5290134ef38f8d0e09a1b60cd7f380552da..e8a22ee436d63d736f1edb6a66320c14daac53e5 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 b2f27b72c1601d3c8d52c535745a30a5c48f4e8c..efc968def3ca5275c16cc0b5876851b5851d92ca 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 4dde034b852a7780e19a684ea4542cdd9e85c7c4..7987fdeaefa7f5479cc612c979a648745ded5a5f 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 7705bf0088aff422786fa023166775e47ab4f91d..835a77f895e6cd85be2603cdf2738dfb320982ca 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 4b7e221976ba75f717b0546f76ab83e447ac448b..98ee3695eb85619140343c81bb05e1e9f523b22c 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 2dc289a9a57527f8caba3e0d729f841ec192069d..9cfd48822ca18d4252f3281037b8ec8e60f83563 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 5ad7c4c938cb31b3e8ccab292d1be3eb81af3c31..7677cb966c04dce1d9441dae587330d2d2c6cd06 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 ffa335a332a146df85f33a354550ebca4700bcef..9896569e9d8ac070d7047dde274c0d6e4914e840 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 e8b273dd9403c3bd5f647a9472e9cbc877434788..afc89ad72789e6881c2cc890d567cfce2b4ba883 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 6cf57a80cce2d84d174559dce21e2e0aa4aa5d89..6c072da7461ddda32cdfb71993103db66bdeac04 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 40d785c3718cddbc0b7fe7022879fb5ed94b0b57..5bdb334b62a83264644df1003f38a55d18d1e3cb 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 686cd00fc94058b2c90875ce7e431cc231ecd35d..c1e878deb4078d0336a3e354bc3aaadf524b59dc 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 87c97bb47aff5e8b646dd2f186f629871478611f..2a38263784259244c338d47647ef481952881427 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 3c21b0e5f147d96ae4723b2c3ac3fc09830a7bde..074e69046280d84cf8383ac432f4d5e79fbd3a73 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 29af52541016a051e118fd79cfa66bd0b956861c..baf57592609518b70f13464ceb75cef21d7eee35 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 7eafec2c55d75172210bdeb0c245eedcd6075f81..0000000000000000000000000000000000000000 --- 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"], -)