blob: 09b2c59da6a96c95f54051a9ada275e144c6cebf [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>
23#include "TestPortFixture.h"
24
25using apache::thrift::transport::TServerTransport;
26using apache::thrift::transport::TTransport;
27using apache::thrift::transport::TTransportException;
28
29BOOST_AUTO_TEST_SUITE ( TServerTransportTest )
30
31class TestTTransport : public TTransport
32{
33};
34
35class TestTServerTransport : public TServerTransport
36{
37public:
38 TestTServerTransport() : valid_(true) {}
39 void close() {}
40 bool valid_;
41protected:
42 boost::shared_ptr<TTransport> acceptImpl()
43 {
44 return valid_ ? boost::shared_ptr<TestTTransport>(new TestTTransport) : boost::shared_ptr<TestTTransport>();
45 }
46};
47
48BOOST_AUTO_TEST_CASE( test_positive_accept )
49{
50 TestTServerTransport uut;
51 BOOST_CHECK(uut.accept());
52}
53
54BOOST_AUTO_TEST_CASE( test_negative_accept )
55{
56 TestTServerTransport uut;
57 uut.valid_ = false;
58 BOOST_CHECK_THROW(uut.accept(), TTransportException);
59}
60
61BOOST_AUTO_TEST_SUITE_END()
62