blob: a5546226926cd2e4181e1d58945dde6d15307454 [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>
Ben Craig1684c422015-04-24 08:52:44 -050023
24using apache::thrift::transport::TServerTransport;
25using apache::thrift::transport::TTransport;
26using apache::thrift::transport::TTransportException;
27
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020028BOOST_AUTO_TEST_SUITE(TServerTransportTest)
Ben Craig1684c422015-04-24 08:52:44 -050029
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020030class TestTTransport : public TTransport {};
Ben Craig1684c422015-04-24 08:52:44 -050031
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020032class TestTServerTransport : public TServerTransport {
Ben Craig1684c422015-04-24 08:52:44 -050033public:
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020034 TestTServerTransport() : valid_(true) {}
35 void close() {}
36 bool valid_;
37
Ben Craig1684c422015-04-24 08:52:44 -050038protected:
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020039 boost::shared_ptr<TTransport> acceptImpl() {
40 return valid_ ? boost::shared_ptr<TestTTransport>(new TestTTransport)
41 : boost::shared_ptr<TestTTransport>();
42 }
Ben Craig1684c422015-04-24 08:52:44 -050043};
44
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020045BOOST_AUTO_TEST_CASE(test_positive_accept) {
46 TestTServerTransport uut;
47 BOOST_CHECK(uut.accept());
Ben Craig1684c422015-04-24 08:52:44 -050048}
49
Konrad Grochowski1f6e3802015-05-18 18:10:06 +020050BOOST_AUTO_TEST_CASE(test_negative_accept) {
51 TestTServerTransport uut;
52 uut.valid_ = false;
53 BOOST_CHECK_THROW(uut.accept(), TTransportException);
Ben Craig1684c422015-04-24 08:52:44 -050054}
55
56BOOST_AUTO_TEST_SUITE_END()