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 #include <grpcpp/test/client_context_test_peer.h>
24 #include <grpcpp/impl/grpc_library.h>
25 #include <gtest/gtest.h>
30 static internal::GrpcLibraryInitializer g_initializer;
32 const char key1[] = "metadata-key1";
33 const char key2[] = "metadata-key2";
34 const char val1[] = "metadata-val1";
35 const char val2[] = "metadata-val2";
37 bool ServerInitialMetadataContains(const ClientContext& context,
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();
43 if (iter->first == key && iter->second == value) {
50 TEST(ClientContextTestPeerTest, AddServerInitialMetadata) {
51 ClientContext context;
52 ClientContextTestPeer peer(&context);
54 peer.AddServerInitialMetadata(key1, val1);
55 ASSERT_TRUE(ServerInitialMetadataContains(context, key1, val1));
56 peer.AddServerInitialMetadata(key2, val2);
57 ASSERT_TRUE(ServerInitialMetadataContains(context, key1, val1));
58 ASSERT_TRUE(ServerInitialMetadataContains(context, key2, val2));
61 TEST(ClientContextTestPeerTest, GetSendInitialMetadata) {
62 ClientContext context;
63 ClientContextTestPeer peer(&context);
64 std::multimap<std::string, std::string> metadata;
66 context.AddMetadata(key1, val1);
67 metadata.insert(std::pair<std::string, std::string>(key1, val1));
68 ASSERT_EQ(metadata, peer.GetSendInitialMetadata());
70 context.AddMetadata(key2, val2);
71 metadata.insert(std::pair<std::string, std::string>(key2, val2));
72 ASSERT_EQ(metadata, peer.GetSendInitialMetadata());
75 } // namespace testing
78 int main(int argc, char** argv) {
79 ::testing::InitGoogleTest(&argc, argv);
80 return RUN_ALL_TESTS();