server_context_test_spouse_test.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 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& client_metadata = context.client_metadata();
41  for (auto iter = client_metadata.begin(); iter != client_metadata.end();
42  ++iter) {
43  if (iter->first == key && iter->second == value) {
44  return true;
45  }
46  }
47  return false;
48 }
49 
50 TEST(ServerContextTestSpouseTest, ClientMetadataHandle) {
53 
54  spouse.AddClientMetadata(key1, val1);
56 
57  spouse.AddClientMetadata(key2, val2);
60 }
61 
62 TEST(ServerContextTestSpouseTest, InitialMetadata) {
65  std::multimap<std::string, std::string> metadata;
66 
67  context.AddInitialMetadata(key1, val1);
68  metadata.insert(std::pair<std::string, std::string>(key1, val1));
70 
71  context.AddInitialMetadata(key2, val2);
72  metadata.insert(std::pair<std::string, std::string>(key2, val2));
74 }
75 
76 TEST(ServerContextTestSpouseTest, ServerMetadataHandle) {
79  std::multimap<std::string, std::string> metadata;
80 
81  context.AddTrailingMetadata(key1, val1);
82  metadata.insert(std::pair<std::string, std::string>(key1, val1));
84 
85  context.AddTrailingMetadata(key2, val2);
86  metadata.insert(std::pair<std::string, std::string>(key2, val2));
88 }
89 
90 } // namespace testing
91 } // namespace grpc
92 
93 int main(int argc, char** argv) {
94  ::testing::InitGoogleTest(&argc, argv);
95  return RUN_ALL_TESTS();
96 }
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
grpc::ServerContext
Definition: grpcpp/impl/codegen/server_context.h:566
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
main
int main(int argc, char **argv)
Definition: server_context_test_spouse_test.cc:93
grpc::testing::ServerContextTestSpouse::AddClientMetadata
void AddClientMetadata(const std::string &key, const std::string &value)
Definition: grpcpp/test/server_context_test_spouse.h:36
grpc::ASSERT_EQ
ASSERT_EQ(sizeof(valid_json), fwrite(valid_json, 1, sizeof(valid_json), creds_file))
metadata
struct metadata metadata
grpc_core::ServerMetadataHandle
MetadataHandle< ServerMetadata > ServerMetadataHandle
Definition: transport.h:141
grpc::internal::GrpcLibraryInitializer
Instantiating this class ensures the proper initialization of gRPC.
Definition: grpcpp/impl/grpc_library.h:39
server_context_test_spouse.h
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::ClientMetadataContains
bool ClientMetadataContains(const ServerContext &context, const grpc::string_ref &key, const grpc::string_ref &value)
Definition: server_context_test_spouse_test.cc:37
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
grpc::testing::ServerContextTestSpouse::GetInitialMetadata
std::multimap< std::string, std::string > GetInitialMetadata() const
Definition: grpcpp/test/server_context_test_spouse.h:48
grpc::testing::ServerContextTestSpouse
A test-only class to access private members and methods of ServerContext.
Definition: grpcpp/test/server_context_test_spouse.h:30
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_core::ClientMetadataHandle
MetadataHandle< ClientMetadata > ClientMetadataHandle
Definition: transport.h:153
grpc::testing::ServerContextTestSpouse::GetTrailingMetadata
std::multimap< std::string, std::string > GetTrailingMetadata() const
Definition: grpcpp/test/server_context_test_spouse.h:52


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:11