blob: 18a393ee0056625b65aa8ffe09a6f5954e9d619a [file] [log] [blame]
Ben Craig1684c422015-04-24 08:52:44 -05001/*
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>
cyy316723a2019-01-05 16:35:14 +080023#include <memory>
Ben Craig1684c422015-04-24 08:52:44 -050024
25using apache::thrift::transport::TServerTransport;
26using apache::thrift::transport::TTransport;
27using apache::thrift::transport::TTransportException;
cyy316723a2019-01-05 16:35:14 +080028using std::shared_ptr;
Ben Craig1684c422015-04-24 08:52:44 -050029
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020030BOOST_AUTO_TEST_SUITE(TServerTransportTest)
Ben Craig1684c422015-04-24 08:52:44 -050031
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020032class TestTTransport : public TTransport {};
Ben Craig1684c422015-04-24 08:52:44 -050033
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020034class TestTServerTransport : public TServerTransport {
Ben Craig1684c422015-04-24 08:52:44 -050035public:
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020036 TestTServerTransport() : valid_(true) {}
Sebastian Zenker042580f2019-01-29 15:48:12 +010037 void close() override {}
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020038 bool valid_;
39
Ben Craig1684c422015-04-24 08:52:44 -050040protected:
Sebastian Zenker042580f2019-01-29 15:48:12 +010041 shared_ptr<TTransport> acceptImpl() override {
cyy64750162019-02-08 13:40:59 +080042 return valid_ ? std::make_shared<TestTTransport>()
James E. King, III82ae9572017-08-05 12:23:54 -040043 : shared_ptr<TestTTransport>();
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020044 }
Ben Craig1684c422015-04-24 08:52:44 -050045};
46
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020047BOOST_AUTO_TEST_CASE(test_positive_accept) {
48 TestTServerTransport uut;
49 BOOST_CHECK(uut.accept());
Ben Craig1684c422015-04-24 08:52:44 -050050}
51
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020052BOOST_AUTO_TEST_CASE(test_negative_accept) {
53 TestTServerTransport uut;
54 uut.valid_ = false;
55 BOOST_CHECK_THROW(uut.accept(), TTransportException);
Ben Craig1684c422015-04-24 08:52:44 -050056}
57
58BOOST_AUTO_TEST_SUITE_END()