Roger Meier | 0114455 | 2015-04-04 16:14:08 +0200 | [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/TServerSocket.h> |
| 23 | #include "TestPortFixture.h" |
| 24 | |
| 25 | using apache::thrift::transport::TServerSocket; |
| 26 | using apache::thrift::transport::TSocket; |
| 27 | using apache::thrift::transport::TTransport; |
| 28 | using apache::thrift::transport::TTransportException; |
| 29 | |
| 30 | BOOST_FIXTURE_TEST_SUITE ( TServerSocketTest, TestPortFixture ) |
| 31 | |
| 32 | class TestTServerSocket : public TServerSocket |
| 33 | { |
| 34 | public: |
| 35 | TestTServerSocket(const std::string& address, int port) : TServerSocket(address, port) { } |
| 36 | using TServerSocket::acceptImpl; |
| 37 | }; |
| 38 | |
| 39 | BOOST_AUTO_TEST_CASE( test_bind_to_address ) |
| 40 | { |
| 41 | TestTServerSocket sock1("localhost", m_serverPort); |
| 42 | sock1.listen(); |
| 43 | TSocket clientSock("localhost", m_serverPort); |
| 44 | clientSock.open(); |
| 45 | boost::shared_ptr<TTransport> accepted = sock1.acceptImpl(); |
| 46 | accepted->close(); |
| 47 | sock1.close(); |
| 48 | |
| 49 | TServerSocket sock2("this.is.truly.an.unrecognizable.address.", m_serverPort); |
| 50 | BOOST_CHECK_THROW(sock2.listen(), TTransportException); |
| 51 | sock2.close(); |
| 52 | } |
| 53 | |
| 54 | BOOST_AUTO_TEST_CASE( test_close_before_listen ) |
| 55 | { |
| 56 | TServerSocket sock1("localhost", m_serverPort); |
| 57 | sock1.close(); |
| 58 | } |
| 59 | |
| 60 | BOOST_AUTO_TEST_CASE( test_get_port ) |
| 61 | { |
| 62 | TServerSocket sock1("localHost", 888); |
| 63 | BOOST_CHECK_EQUAL(888, sock1.getPort()); |
| 64 | } |
| 65 | |
| 66 | BOOST_AUTO_TEST_SUITE_END() |
| 67 | |