Provide a way to use custom search path for gmock.h

pull/13871/head
yang-g 7 years ago
parent e33d0272fd
commit eb64fadfce
  1. 15
      src/compiler/cpp_generator.cc
  2. 4
      src/compiler/cpp_generator.h
  3. 2
      src/compiler/cpp_plugin.cc
  4. 2
      test/cpp/end2end/mock_test.cc

@ -1568,11 +1568,24 @@ grpc::string GetMockIncludes(grpc_generator::File* file,
static const char* headers_strs[] = {
"grpc++/impl/codegen/async_stream.h",
"grpc++/impl/codegen/sync_stream.h",
"gmock/gmock.h",
};
std::vector<grpc::string> headers(headers_strs, array_end(headers_strs));
PrintIncludes(printer.get(), headers, params);
std::vector<grpc::string> gmock_header;
if (params.gmock_search_path.empty()) {
gmock_header.push_back("gmock/gmock.h");
PrintIncludes(printer.get(), gmock_header, params);
} else {
gmock_header.push_back("gmock.h");
// Copy a params to generate gmock header.
Parameters gmock_params(params);
// We use local includes when a gmock_search_path is given
gmock_params.use_system_headers = false;
gmock_params.grpc_search_path = params.gmock_search_path;
PrintIncludes(printer.get(), gmock_header, gmock_params);
}
if (!file->package().empty()) {
std::vector<grpc::string> parts = file->package_parts();

@ -50,8 +50,10 @@ struct Parameters {
bool use_system_headers;
// Prefix to any grpc include
grpc::string grpc_search_path;
// Generate GMOCK code to facilitate unit testing.
// Generate Google Mock code to facilitate unit testing.
bool generate_mock_code;
// Google Mock search path, when non-empty, local includes will be used.
grpc::string gmock_search_path;
};
// Return the prologue of the generated header file.

@ -78,6 +78,8 @@ class CppGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
*error = grpc::string("Invalid parameter: ") + *parameter_string;
return false;
}
} else if (param[0] == "gmock_search_path") {
generator_parameters.gmock_search_path = param[1];
} else {
*error = grpc::string("Unknown parameter: ") + *parameter_string;
return false;

@ -43,7 +43,6 @@
#include <iostream>
using namespace std;
using ::testing::AtLeast;
using ::testing::DoAll;
using ::testing::Invoke;
@ -57,6 +56,7 @@ using grpc::testing::EchoResponse;
using grpc::testing::EchoTestService;
using grpc::testing::MockClientReaderWriter;
using std::chrono::system_clock;
using std::vector;
namespace grpc {
namespace testing {

Loading…
Cancel
Save