client_context_test_peer_test.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2021 gRPC authors.
4  *
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  */
18 
19 #include <cstring>
20 #include <vector>
21 
22 #include <gtest/gtest.h>
23 
26 
27 namespace grpc {
28 namespace testing {
29 
31 
32 const char key1[] = "metadata-key1";
33 const char key2[] = "metadata-key2";
34 const char val1[] = "metadata-val1";
35 const char val2[] = "metadata-val2";
36 
38  const grpc::string_ref& key,
39  const grpc::string_ref& value) {
40  const auto& server_metadata = context.GetServerInitialMetadata();
41  for (auto iter = server_metadata.begin(); iter != server_metadata.end();
42  ++iter) {
43  if (iter->first == key && iter->second == value) {
44  return true;
45  }
46  }
47  return true;
48 }
49 
50 TEST(ClientContextTestPeerTest, AddServerInitialMetadata) {
53 
59 }
60 
61 TEST(ClientContextTestPeerTest, GetSendInitialMetadata) {
64  std::multimap<std::string, std::string> metadata;
65 
67  metadata.insert(std::pair<std::string, std::string>(key1, val1));
69 
71  metadata.insert(std::pair<std::string, std::string>(key2, val2));
73 }
74 
75 } // namespace testing
76 } // namespace grpc
77 
78 int main(int argc, char** argv) {
79  ::testing::InitGoogleTest(&argc, argv);
80  return RUN_ALL_TESTS();
81 }
grpc::testing::g_initializer
static internal::GrpcLibraryInitializer g_initializer
Definition: client_context_test_peer_test.cc:30
grpc::string_ref
Definition: grpcpp/impl/codegen/string_ref.h:43
testing
Definition: aws_request_signer_test.cc:25
grpc::testing::val1
const char val1[]
Definition: client_context_test_peer_test.cc:34
metadata
Definition: cq_verifier.cc:48
grpc::testing::key2
const char key2[]
Definition: client_context_test_peer_test.cc:33
grpc
Definition: grpcpp/alarm.h:33
grpc::ASSERT_EQ
ASSERT_EQ(sizeof(valid_json), fwrite(valid_json, 1, sizeof(valid_json), creds_file))
metadata
struct metadata metadata
grpc::ClientContext::AddMetadata
void AddMetadata(const std::string &meta_key, const std::string &meta_value)
Definition: client_context.cc:121
grpc::testing::ClientContextTestPeer::GetSendInitialMetadata
std::multimap< std::string, std::string > GetSendInitialMetadata() const
Definition: client_context_test_peer.h:50
grpc::internal::GrpcLibraryInitializer
Instantiating this class ensures the proper initialization of gRPC.
Definition: grpcpp/impl/grpc_library.h:39
grpc::testing::key1
const char key1[]
Definition: client_context_test_peer_test.cc:32
grpc::testing::val2
const char val2[]
Definition: client_context_test_peer_test.cc:35
grpc::testing::ServerInitialMetadataContains
bool ServerInitialMetadataContains(const ClientContext &context, const grpc::string_ref &key, const grpc::string_ref &value)
Definition: client_context_test_peer_test.cc:37
grpc::testing::ClientContextTestPeer::AddServerInitialMetadata
void AddServerInitialMetadata(const std::string &key, const std::string &value)
Definition: client_context_test_peer.h:36
main
int main(int argc, char **argv)
Definition: client_context_test_peer_test.cc:78
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
grpc::testing::ClientContextTestPeer
A test-only class to access private members and methods of ClientContext.
Definition: client_context_test_peer.h:30
client_context_test_peer.h
grpc::ClientContext
Definition: grpcpp/impl/codegen/client_context.h:195
value
const char * value
Definition: hpack_parser_table.cc:165
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
key
const char * key
Definition: hpack_parser_table.cc:164
grpc_library.h
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1973
grpc::testing::TEST
TEST(StatsTest, IncCounters)
Definition: stats_test.cc:51
context
grpc::ClientContext context
Definition: istio_echo_server_lib.cc:61
iter
Definition: test_winkernel.cpp:47
grpc::ClientContext::GetServerInitialMetadata
const std::multimap< grpc::string_ref, grpc::string_ref > & GetServerInitialMetadata() const
Definition: grpcpp/impl/codegen/client_context.h:250


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:55