3 * Copyright 2021 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #ifndef GRPCPP_TEST_CLIENT_CONTEXT_TEST_PEER_H
20 #define GRPCPP_TEST_CLIENT_CONTEXT_TEST_PEER_H
24 #include <grpcpp/client_context.h>
29 /// A test-only class to access private members and methods of ClientContext.
30 class ClientContextTestPeer {
32 explicit ClientContextTestPeer(ClientContext* const ctx) : ctx_(ctx) {}
34 /// Inject metadata to the ClientContext for the test. The test peer
35 /// must be alive when a ClientContext::GetServerInitialMetadata is called.
36 void AddServerInitialMetadata(const std::string& key,
37 const std::string& value) {
38 server_initial_metadata_storage_.insert(
39 std::pair<std::string, std::string>(key, value));
40 ctx_->initial_metadata_received_ = true;
41 ctx_->recv_initial_metadata_.map()->clear();
42 for (const auto& item : server_initial_metadata_storage_) {
43 ctx_->recv_initial_metadata_.map()->insert(
44 std::pair<grpc::string_ref, grpc::string_ref>(
46 grpc::string_ref(item.second.data(), item.second.size())));
50 std::multimap<std::string, std::string> GetSendInitialMetadata() const {
51 return ctx_->send_initial_metadata_;
55 ClientContext* const ctx_; // not owned
56 std::multimap<std::string, std::string> server_initial_metadata_storage_;
59 } // namespace testing
62 #endif // GRPCPP_TEST_CLIENT_CONTEXT_TEST_PEER_H