|  | @@ -1407,4 +1407,188 @@ grpc::string GetSourceEpilogue(grpc_generator::File *file,
 | 
	
		
			
				|  |  |    return temp;
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +// TODO(mmukhi): Make sure we need parameters or not.
 | 
	
		
			
				|  |  | +grpc::string GetMockPrologue(File *file, const Parameters & ) {
 | 
	
		
			
				|  |  | +  grpc::string output;
 | 
	
		
			
				|  |  | +  {
 | 
	
		
			
				|  |  | +    // Scope the output stream so it closes and finalizes output to the string.
 | 
	
		
			
				|  |  | +    auto printer = file->CreatePrinter(&output);
 | 
	
		
			
				|  |  | +    std::map<grpc::string, grpc::string> vars;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    vars["filename"] = file->filename();
 | 
	
		
			
				|  |  | +    vars["filename_base"] = file->filename_without_ext();
 | 
	
		
			
				|  |  | +    vars["message_header_ext"] = file->message_header_ext();
 | 
	
		
			
				|  |  | +    vars["service_header_ext"] = file->service_header_ext();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    printer->Print(vars, "// Generated by the gRPC C++ plugin.\n");
 | 
	
		
			
				|  |  | +    printer->Print(vars,
 | 
	
		
			
				|  |  | +                   "// If you make any local change, they will be lost.\n");
 | 
	
		
			
				|  |  | +    printer->Print(vars, "// source: $filename$\n\n");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    printer->Print(vars, "#include \"$filename_base$$message_header_ext$\"\n");
 | 
	
		
			
				|  |  | +    printer->Print(vars, "#include \"$filename_base$$service_header_ext$\"\n");
 | 
	
		
			
				|  |  | +    printer->Print(vars, file->additional_headers().c_str());
 | 
	
		
			
				|  |  | +    printer->Print(vars, "\n");
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  return output;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +// TODO(mmukhi): Add client-stream and completion-queue headers.
 | 
	
		
			
				|  |  | +grpc::string GetMockIncludes(File *file, const Parameters ¶ms) {
 | 
	
		
			
				|  |  | +  grpc::string output;
 | 
	
		
			
				|  |  | +  {
 | 
	
		
			
				|  |  | +    // Scope the output stream so it closes and finalizes output to the string.
 | 
	
		
			
				|  |  | +    auto printer = file->CreatePrinter(&output);
 | 
	
		
			
				|  |  | +    std::map<grpc::string, grpc::string> vars;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    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);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    if (!file->package().empty()) {
 | 
	
		
			
				|  |  | +      std::vector<grpc::string> parts = file->package_parts();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      for(auto part = parts.begin(); part != parts.end(); part++) {
 | 
	
		
			
				|  |  | +        vars["part"] = *part;
 | 
	
		
			
				|  |  | +        printer->Print(vars, "namespace $part$ {\n");
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    printer->Print(vars, "\n");
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  return output;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +void PrintMockClientMethods(
 | 
	
		
			
				|  |  | +    Printer *printer, const Method *method,
 | 
	
		
			
				|  |  | +    std::map<grpc::string, grpc::string> *vars) {
 | 
	
		
			
				|  |  | +  (*vars)["Method"] = method->name();
 | 
	
		
			
				|  |  | +  (*vars)["Request"] = method->input_type_name();
 | 
	
		
			
				|  |  | +  (*vars)["Response"] = method->output_type_name();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  if (method->NoStreaming()) {
 | 
	
		
			
				|  |  | +    printer->Print(
 | 
	
		
			
				|  |  | +        *vars,
 | 
	
		
			
				|  |  | +        "MOCK_METHOD3($Method$, ::grpc::Status(::grpc::ClientContext* context, "
 | 
	
		
			
				|  |  | +        "const $Request$& request, $Response$* response));\n");
 | 
	
		
			
				|  |  | +    printer->Print(
 | 
	
		
			
				|  |  | +        *vars,
 | 
	
		
			
				|  |  | +        "MOCK_METHOD3(Async$Method$Raw, "
 | 
	
		
			
				|  |  | +        "::grpc::ClientAsyncResponseReaderInterface< $Response$>*"
 | 
	
		
			
				|  |  | +        "(::grpc::ClientContext* context, const $Request$& request, "
 | 
	
		
			
				|  |  | +        "::grpc::CompletionQueue* cq));\n");
 | 
	
		
			
				|  |  | +  } else if (method->ClientOnlyStreaming()) {
 | 
	
		
			
				|  |  | +    printer->Print(
 | 
	
		
			
				|  |  | +        *vars,
 | 
	
		
			
				|  |  | +        "MOCK_METHOD2($Method$Raw, "
 | 
	
		
			
				|  |  | +        "::grpc::ClientWriterInterface< $Request$>*"
 | 
	
		
			
				|  |  | +        "(::grpc::ClientContext* context, $Response$* response));\n");
 | 
	
		
			
				|  |  | +    printer->Print(
 | 
	
		
			
				|  |  | +        *vars,
 | 
	
		
			
				|  |  | +        "MOCK_METHOD4(Async$Method$Raw, "
 | 
	
		
			
				|  |  | +        "::grpc::ClientAsyncWriterInterface< $Request$>*"
 | 
	
		
			
				|  |  | +        "(::grpc::ClientContext* context, $Response$* response, "
 | 
	
		
			
				|  |  | +        "::grpc::CompletionQueue* cq, void* tag));\n");
 | 
	
		
			
				|  |  | +  } else if (method->ServerOnlyStreaming()) {
 | 
	
		
			
				|  |  | +    printer->Print(
 | 
	
		
			
				|  |  | +        *vars,
 | 
	
		
			
				|  |  | +        "MOCK_METHOD2($Method$Raw, "
 | 
	
		
			
				|  |  | +        "::grpc::ClientReaderInterface< $Response$>*"
 | 
	
		
			
				|  |  | +        "(::grpc::ClientContext* context, const $Request$& request));\n");
 | 
	
		
			
				|  |  | +    printer->Print(
 | 
	
		
			
				|  |  | +        *vars,
 | 
	
		
			
				|  |  | +        "MOCK_METHOD4(Async$Method$Raw, "
 | 
	
		
			
				|  |  | +        "::grpc::ClientAsyncReaderInterface< $Response$>*"
 | 
	
		
			
				|  |  | +        "(::grpc::ClientContext* context, const $Request$& request, "
 | 
	
		
			
				|  |  | +        "::grpc::CompletionQueue* cq, void* tag));\n");
 | 
	
		
			
				|  |  | +  } else if (method->BidiStreaming()) {
 | 
	
		
			
				|  |  | +    printer->Print(
 | 
	
		
			
				|  |  | +        *vars,
 | 
	
		
			
				|  |  | +        "MOCK_METHOD1($Method$Raw, "
 | 
	
		
			
				|  |  | +        "::grpc::ClientReaderWriterInterface< $Request$, $Response$>*"
 | 
	
		
			
				|  |  | +        "(::grpc::ClientContext* context));\n");
 | 
	
		
			
				|  |  | +    printer->Print(
 | 
	
		
			
				|  |  | +        *vars,
 | 
	
		
			
				|  |  | +        "MOCK_METHOD3(Async$Method$Raw, "
 | 
	
		
			
				|  |  | +        "::grpc::ClientAsyncReaderWriterInterface<$Request$, $Response$>*"
 | 
	
		
			
				|  |  | +        "(::grpc::ClientContext* context, ::grpc::CompletionQueue* cq, "
 | 
	
		
			
				|  |  | +        "void* tag));\n");
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +void PrintMockService(Printer *printer,
 | 
	
		
			
				|  |  | +                              const Service *service,
 | 
	
		
			
				|  |  | +                              std::map<grpc::string, grpc::string> *vars) {
 | 
	
		
			
				|  |  | +  (*vars)["Service"] = service->name();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  printer->Print(service->GetLeadingComments().c_str());
 | 
	
		
			
				|  |  | +  printer->Print(*vars,
 | 
	
		
			
				|  |  | +                 "class Mock$Service$Stub : public $Service$::StubInterface {\n"
 | 
	
		
			
				|  |  | +                 " public:\n");
 | 
	
		
			
				|  |  | +  printer->Indent();
 | 
	
		
			
				|  |  | +  printer->Print(*vars,
 | 
	
		
			
				|  |  | +                 "Mock$Service$Stub(){}\n"
 | 
	
		
			
				|  |  | +                 "~Mock$Service$Stub(){}\n");
 | 
	
		
			
				|  |  | +  for (int i = 0; i < service->method_count(); ++i) {
 | 
	
		
			
				|  |  | +    printer->Print(service->method(i)->GetLeadingComments().c_str());
 | 
	
		
			
				|  |  | +    PrintMockClientMethods(printer, service->method(i).get(), vars);
 | 
	
		
			
				|  |  | +    printer->Print(service->method(i)->GetTrailingComments().c_str());
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  printer->Outdent();
 | 
	
		
			
				|  |  | +  printer->Print("};\n");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +grpc::string GetMockServices(File *file,
 | 
	
		
			
				|  |  | +                             const Parameters ¶ms) {
 | 
	
		
			
				|  |  | +  grpc::string output;
 | 
	
		
			
				|  |  | +  {
 | 
	
		
			
				|  |  | +    // Scope the output stream so it closes and finalizes output to the string.
 | 
	
		
			
				|  |  | +    auto printer = file->CreatePrinter(&output);
 | 
	
		
			
				|  |  | +    std::map<grpc::string, grpc::string> vars;
 | 
	
		
			
				|  |  | +    // Package string is empty or ends with a dot. It is used to fully qualify
 | 
	
		
			
				|  |  | +    // method names.
 | 
	
		
			
				|  |  | +    vars["Package"] = file->package();
 | 
	
		
			
				|  |  | +    if (!file->package().empty()) {
 | 
	
		
			
				|  |  | +      vars["Package"].append(".");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    if(!params.services_namespace.empty()) {
 | 
	
		
			
				|  |  | +      vars["services_namespace"] = params.services_namespace;
 | 
	
		
			
				|  |  | +      printer->Print(vars, "\nnamespace $services_namespace$ {\n\n");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    for (int i =0; i < file->service_count(); i++) {
 | 
	
		
			
				|  |  | +      PrintMockService(printer.get(), file->service(i).get(), &vars);
 | 
	
		
			
				|  |  | +      printer->Print("\n");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    if (!params.services_namespace.empty()) {
 | 
	
		
			
				|  |  | +      printer->Print(vars, "} // namespace $services_namespace$\n\n");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  return output;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +grpc::string GetMockEpilogue(File *file, const Parameters &) {
 | 
	
		
			
				|  |  | +  grpc::string temp;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  if (!file->package().empty()) {
 | 
	
		
			
				|  |  | +    std::vector<grpc::string> parts = file->package_parts();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    for (auto part = parts.begin(); part != parts.end(); part++){
 | 
	
		
			
				|  |  | +      temp.append("} // namespace ");
 | 
	
		
			
				|  |  | +      temp.append(*part);
 | 
	
		
			
				|  |  | +      temp.append("\n");
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    temp.append("\n");
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  return temp;
 | 
	
		
			
				|  |  | +}
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }  // namespace grpc_cpp_generator
 |