Added mock_stream_test (#25103)

pull/25821/head
Esun Kim 4 years ago committed by GitHub
parent b55fba3382
commit 10b17f3739
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 49
      CMakeLists.txt
  2. 13
      build_autogenerated.yaml
  3. 7
      include/grpcpp/test/mock_stream.h
  4. 17
      test/cpp/test/BUILD
  5. 60
      test/cpp/test/mock_stream_test.cc
  6. 24
      tools/run_tests/generated/tests.json

@ -888,6 +888,7 @@ if(gRPC_BUILD_TESTS)
add_dependencies(buildtests_cxx log_test)
add_dependencies(buildtests_cxx matchers_test)
add_dependencies(buildtests_cxx message_allocator_end2end_test)
add_dependencies(buildtests_cxx mock_stream_test)
add_dependencies(buildtests_cxx mock_test)
add_dependencies(buildtests_cxx nonblocking_test)
add_dependencies(buildtests_cxx noop-benchmark)
@ -12087,6 +12088,54 @@ target_link_libraries(message_allocator_end2end_test
)
endif()
if(gRPC_BUILD_TESTS)
add_executable(mock_stream_test
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.grpc.pb.cc
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.pb.h
${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/simple_messages.grpc.pb.h
test/cpp/test/mock_stream_test.cc
third_party/googletest/googletest/src/gtest-all.cc
third_party/googletest/googlemock/src/gmock-all.cc
)
target_include_directories(mock_stream_test
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}
${_gRPC_RE2_INCLUDE_DIR}
${_gRPC_SSL_INCLUDE_DIR}
${_gRPC_UPB_GENERATED_DIR}
${_gRPC_UPB_GRPC_GENERATED_DIR}
${_gRPC_UPB_INCLUDE_DIR}
${_gRPC_XXHASH_INCLUDE_DIR}
${_gRPC_ZLIB_INCLUDE_DIR}
third_party/googletest/googletest/include
third_party/googletest/googletest
third_party/googletest/googlemock/include
third_party/googletest/googlemock
${_gRPC_PROTO_GENS_DIR}
)
target_link_libraries(mock_stream_test
${_gRPC_PROTOBUF_LIBRARIES}
${_gRPC_ALLTARGETS_LIBRARIES}
grpc++_test
grpc++_test_util
)
endif()
if(gRPC_BUILD_TESTS)

@ -5638,6 +5638,19 @@ targets:
- test/cpp/end2end/test_service_impl.cc
deps:
- grpc++_test_util
- name: mock_stream_test
gtest: true
build: test
language: c++
headers: []
src:
- src/proto/grpc/testing/echo.proto
- src/proto/grpc/testing/echo_messages.proto
- src/proto/grpc/testing/simple_messages.proto
- test/cpp/test/mock_stream_test.cc
deps:
- grpc++_test
- grpc++_test_util
- name: mock_test
gtest: true
build: test

@ -90,6 +90,8 @@ class MockClientAsyncResponseReader
public:
MockClientAsyncResponseReader() = default;
/// ClientAsyncResponseReaderInterface
MOCK_METHOD0_T(StartCall, void());
MOCK_METHOD1_T(ReadInitialMetadata, void(void*));
MOCK_METHOD3_T(Finish, void(R*, Status*, void*));
};
@ -100,6 +102,7 @@ class MockClientAsyncReader : public ClientAsyncReaderInterface<R> {
MockClientAsyncReader() = default;
/// ClientAsyncStreamingInterface
MOCK_METHOD1_T(StartCall, void(void*));
MOCK_METHOD1_T(ReadInitialMetadata, void(void*));
MOCK_METHOD2_T(Finish, void(Status*, void*));
@ -113,11 +116,13 @@ class MockClientAsyncWriter : public ::grpc::ClientAsyncWriterInterface<W> {
MockClientAsyncWriter() = default;
/// ClientAsyncStreamingInterface
MOCK_METHOD1_T(StartCall, void(void*));
MOCK_METHOD1_T(ReadInitialMetadata, void(void*));
MOCK_METHOD2_T(Finish, void(Status*, void*));
/// AsyncWriterInterface
MOCK_METHOD2_T(Write, void(const W&, void*));
MOCK_METHOD3_T(Write, void(const W&, ::grpc::WriteOptions, void*));
/// ClientAsyncWriterInterface
MOCK_METHOD1_T(WritesDone, void(void*));
@ -130,11 +135,13 @@ class MockClientAsyncReaderWriter
MockClientAsyncReaderWriter() = default;
/// ClientAsyncStreamingInterface
MOCK_METHOD1_T(StartCall, void(void*));
MOCK_METHOD1_T(ReadInitialMetadata, void(void*));
MOCK_METHOD2_T(Finish, void(Status*, void*));
/// AsyncWriterInterface
MOCK_METHOD2_T(Write, void(const W&, void*));
MOCK_METHOD3_T(Write, void(const W&, ::grpc::WriteOptions, void*));
/// AsyncReaderInterface
MOCK_METHOD2_T(Read, void(R*, void*));

@ -21,6 +21,23 @@ grpc_package(
visibility = "public",
)
grpc_cc_test(
name = "mock_stream_test",
srcs = ["mock_stream_test.cc"],
external_deps = [
"gtest",
],
deps = [
"//:gpr",
"//:grpc",
"//:grpc++",
"//:grpc++_test",
"//src/proto/grpc/testing:echo_proto",
"//test/core/util:grpc_test_util",
"//test/cpp/util:test_util",
],
)
grpc_cc_test(
name = "server_context_test_spouse_test",
srcs = ["server_context_test_spouse_test.cc"],

@ -0,0 +1,60 @@
/*
*
* Copyright 2020 the gRPC authors.
*
* 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.
*
*/
#include <grpcpp/test/mock_stream.h>
#include <gtest/gtest.h>
#include "absl/memory/memory.h"
#include "src/proto/grpc/testing/echo.grpc.pb.h"
using grpc::testing::EchoRequest;
using grpc::testing::EchoResponse;
TEST(MockStreamTest, Basic) {
auto cr = absl::make_unique<grpc::testing::MockClientReader<EchoResponse>>();
ASSERT_NE(cr, nullptr);
auto cw = absl::make_unique<grpc::testing::MockClientWriter<EchoResponse>>();
ASSERT_NE(cw, nullptr);
auto crw = absl::make_unique<
grpc::testing::MockClientReaderWriter<EchoResponse, EchoResponse>>();
ASSERT_NE(crw, nullptr);
auto carr = absl::make_unique<
grpc::testing::MockClientAsyncResponseReader<EchoResponse>>();
ASSERT_NE(carr, nullptr);
auto car =
absl::make_unique<grpc::testing::MockClientAsyncReader<EchoResponse>>();
ASSERT_NE(car, nullptr);
auto caw =
absl::make_unique<grpc::testing::MockClientAsyncWriter<EchoResponse>>();
ASSERT_NE(caw, nullptr);
auto carw = absl::make_unique<
grpc::testing::MockClientAsyncReaderWriter<EchoRequest, EchoResponse>>();
ASSERT_NE(carw, nullptr);
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

@ -5151,6 +5151,30 @@
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,
"ci_platforms": [
"linux",
"mac",
"posix",
"windows"
],
"cpu_cost": 1.0,
"exclude_configs": [],
"exclude_iomgrs": [],
"flaky": false,
"gtest": true,
"language": "c++",
"name": "mock_stream_test",
"platforms": [
"linux",
"mac",
"posix",
"windows"
],
"uses_polling": true
},
{
"args": [],
"benchmark": false,

Loading…
Cancel
Save