Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | * or more contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. The ASF licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | #include <boost/test/auto_unit_test.hpp> |
| 21 | #include <thrift/transport/TSocket.h> |
| 22 | #include <thrift/transport/TServerTransport.h> |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 23 | #include <memory> |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 24 | |
| 25 | using apache::thrift::transport::TServerTransport; |
| 26 | using apache::thrift::transport::TTransport; |
| 27 | using apache::thrift::transport::TTransportException; |
cyy | 316723a | 2019-01-05 16:35:14 +0800 | [diff] [blame] | 28 | using std::shared_ptr; |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 29 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 30 | BOOST_AUTO_TEST_SUITE(TServerTransportTest) |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 31 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 32 | class TestTTransport : public TTransport {}; |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 33 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 34 | class TestTServerTransport : public TServerTransport { |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 35 | public: |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 36 | TestTServerTransport() : valid_(true) {} |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 37 | void close() override {} |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 38 | bool valid_; |
| 39 | |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 40 | protected: |
Sebastian Zenker | 042580f | 2019-01-29 15:48:12 +0100 | [diff] [blame] | 41 | shared_ptr<TTransport> acceptImpl() override { |
cyy | 6475016 | 2019-02-08 13:40:59 +0800 | [diff] [blame] | 42 | return valid_ ? std::make_shared<TestTTransport>() |
James E. King, III | 82ae957 | 2017-08-05 12:23:54 -0400 | [diff] [blame] | 43 | : shared_ptr<TestTTransport>(); |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 44 | } |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 45 | }; |
| 46 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 47 | BOOST_AUTO_TEST_CASE(test_positive_accept) { |
| 48 | TestTServerTransport uut; |
| 49 | BOOST_CHECK(uut.accept()); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 50 | } |
| 51 | |
Konrad Grochowski | 1f6e380 | 2015-05-18 18:10:06 +0200 | [diff] [blame] | 52 | BOOST_AUTO_TEST_CASE(test_negative_accept) { |
| 53 | TestTServerTransport uut; |
| 54 | uut.valid_ = false; |
| 55 | BOOST_CHECK_THROW(uut.accept(), TTransportException); |
Ben Craig | 1684c42 | 2015-04-24 08:52:44 -0500 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | BOOST_AUTO_TEST_SUITE_END() |