Debian Codegraph @

test/core/surface/server_chttp2_test.cc

raw
1 /*
2 *
3 * Copyright 2015 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 <string>
20
21 #include "gtest/gtest.h"
22
23 #include <grpc/grpc.h>
24 #include <grpc/grpc_security.h>
25 #include <grpc/support/time.h>
26
27 #include "src/core/lib/channel/channel_args.h"
28 #include "src/core/lib/gprpp/host_port.h"
29 #include "src/core/lib/security/credentials/fake/fake_credentials.h"
30 #include "test/core/util/port.h"
31 #include "test/core/util/test_config.h"
32
33 TEST(ServerChttp2, UnparseableTarget) {
34 grpc_channel_args args = {0, nullptr};
35 grpc_server* server = grpc_server_create(&args, nullptr);
36 grpc_server_credentials* server_creds =
37 grpc_insecure_server_credentials_create();
38 int port = grpc_server_add_http2_port(server, "[", server_creds);
39 grpc_server_credentials_release(server_creds);
40 EXPECT_EQ(port, 0);
41 grpc_server_destroy(server);
42 }
43
44 TEST(ServerChttp2, AddSamePortTwice) {
45 grpc_arg a = grpc_channel_arg_integer_create(
46 const_cast<char*>(GRPC_ARG_ALLOW_REUSEPORT), 0);
47 grpc_channel_args args = {1, &a};
48
49 int port = grpc_pick_unused_port_or_die();
50 grpc_completion_queue* cq = grpc_completion_queue_create_for_pluck(nullptr);
51 grpc_server* server = grpc_server_create(&args, nullptr);
52 grpc_server_credentials* fake_creds =
53 grpc_fake_transport_security_server_credentials_create();
54 std::string addr = grpc_core::JoinHostPort("localhost", port);
55 EXPECT_EQ(grpc_server_add_http2_port(server, addr.c_str(), fake_creds), port);
56 EXPECT_EQ(grpc_server_add_http2_port(server, addr.c_str(), fake_creds), 0);
57
58 grpc_server_credentials_release(fake_creds);
59 grpc_server_shutdown_and_notify(server, cq, nullptr);
60 grpc_completion_queue_pluck(cq, nullptr, gpr_inf_future(GPR_CLOCK_REALTIME),
61 nullptr);
62 grpc_server_destroy(server);
63 grpc_completion_queue_destroy(cq);
64 }
65
66 int main(int argc, char** argv) {
67 grpc::testing::TestEnvironment env(&argc, argv);
68 ::testing::InitGoogleTest(&argc, argv);
69 grpc_init();
70 int ret = RUN_ALL_TESTS();
71 grpc_shutdown();
72 return ret;
73 }