提交 d436082a 编写于 作者: H Hanqing Wu 提交者: Hanqing Wu

upgrade googletest to v1.12.1

Signed-off-by: NHanqing Wu <wuhanqing@corp.netease.com>
上级 6e00652b
......@@ -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(
......
......@@ -34,6 +34,7 @@ namespace curvefs {
namespace client {
using ::testing::SetArgPointee;
using ::testing::DoAll;
using rpcclient::MockMetaServerClient;
using rpcclient::MockMdsClient;
......
......@@ -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 {
......
......@@ -21,8 +21,6 @@
*/
#include <gmock/gmock-generated-actions.h>
#include <gmock/gmock-more-actions.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -23,7 +23,6 @@
#ifndef CURVEFS_TEST_MDS_MOCK_MOCK_METASERVER_CLIENT_H_
#define CURVEFS_TEST_MDS_MOCK_MOCK_METASERVER_CLIENT_H_
#include <gmock/gmock-generated-function-mockers.h>
#include <gmock/gmock.h>
#include <set>
#include <string>
......
......@@ -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 {
......
......@@ -20,8 +20,6 @@
* @Author: chenwei
*/
#include <gmock/gmock-generated-matchers.h>
#include <gmock/gmock-spec-builders.h>
#include <gmock/gmock.h>
#include <google/protobuf/util/message_differencer.h>
#include <gtest/gtest.h>
......
......@@ -23,7 +23,6 @@
#ifndef CURVEFS_TEST_METASERVER_MOCK_MOCK_KV_STORAGE_H_
#define CURVEFS_TEST_METASERVER_MOCK_MOCK_KV_STORAGE_H_
#include <gmock/gmock-generated-function-mockers.h>
#include <gmock/gmock.h>
#include <memory>
......
......@@ -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类
......
......@@ -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
......
......@@ -23,8 +23,6 @@
#include <gtest/gtest.h>
#include <unistd.h>
#include <brpc/server.h>
#include <gmock/gmock-more-actions.h>
#include <gmock/gmock-generated-function-mockers.h>
#include <memory>
#include <cstdio>
......
......@@ -24,8 +24,6 @@
#define TEST_CHUNKSERVER_MOCK_NODE_H_
#include <gmock/gmock.h>
#include <gmock/gmock-generated-function-mockers.h>
#include <gmock/internal/gmock-generated-internal-utils.h>
#include <braft/raft.h>
#include <string>
......
......@@ -24,8 +24,6 @@
#define TEST_CHUNKSERVER_RAFTSNAPSHOT_MOCK_FILE_READER_H_
#include <gmock/gmock.h>
#include <gmock/gmock-generated-function-mockers.h>
#include <gmock/internal/gmock-generated-internal-utils.h>
#include <string>
#include <vector>
#include "src/chunkserver/raftsnapshot/curve_snapshot_file_reader.h"
......
......@@ -24,8 +24,6 @@
#define TEST_CHUNKSERVER_RAFTSNAPSHOT_MOCK_SNAPSHOT_ATTACHMENT_H_
#include <gmock/gmock.h>
#include <gmock/gmock-generated-function-mockers.h>
#include <gmock/internal/gmock-generated-internal-utils.h>
#include <string>
#include <vector>
#include "src/chunkserver/raftsnapshot/curve_snapshot_attachment.h"
......
......@@ -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
......@@ -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
......@@ -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
......@@ -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;
......
......@@ -38,6 +38,7 @@ using ::testing::_;
using ::testing::AnyOf;
using ::testing::SetArgPointee;
using ::testing::Invoke;
using ::testing::DoAll;
class TestTopologyMetric : public ::testing::Test {
public:
......
......@@ -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;
......
......@@ -39,6 +39,7 @@ using ::testing::_;
using ::testing::AnyOf;
using ::testing::SetArgPointee;
using ::testing::Invoke;
using ::testing::DoAll;
class TestTopologyStat : public ::testing::Test {
public:
......
#
# 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"],
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册