2
0
mirror of https://github.com/boostorg/asio.git synced 2026-01-28 18:52:09 +00:00
Files
asio/test/serial_port.cpp
Christopher Kohlhoff 8e413b0ece Merge from trunk.
........
  r48414 | chris_kohlhoff | 2008-08-28 22:03:46 +1000 (Thu, 28 Aug 2008) | 2 lines
  
  Fix uninitialised event handles in asio::detail::thread in external mode.
........
  r48415 | chris_kohlhoff | 2008-08-28 22:04:21 +1000 (Thu, 28 Aug 2008) | 2 lines
  
  Fix duplicate variable warning.
........
  r48416 | chris_kohlhoff | 2008-08-28 22:06:42 +1000 (Thu, 28 Aug 2008) | 3 lines
  
  Fix duplicate variable warning. Use get_io_service() rather than
  deprecated io_service() function.
........
  r48417 | chris_kohlhoff | 2008-08-28 22:09:09 +1000 (Thu, 28 Aug 2008) | 2 lines
  
  Use get_io_service() rather than deprecated io_service() function.
........
  r48418 | chris_kohlhoff | 2008-08-28 22:11:47 +1000 (Thu, 28 Aug 2008) | 9 lines
  
  Change the CompletionCondition concept so that:
  - It is now evaluated before the first call to the underlying
    *_some() operation, as well as after every operation.
  - The return value is a number of bytes, which indicates the maximum
    length to be transferred on the subsequent *_some() operation. If
    the return value is 0 then the composed operation completes.
  
  Add missing unit tests for read_at and write_at.
........
  r48490 | chris_kohlhoff | 2008-08-31 18:58:49 +1000 (Sun, 31 Aug 2008) | 2 lines
  
  Don't build serial port test code when serial ports are not available.
........
  r48491 | chris_kohlhoff | 2008-08-31 19:01:59 +1000 (Sun, 31 Aug 2008) | 3 lines
  
  Refactor reactive socket implementation so that synchronous read, write,
  accept and connect operations don't modify data associated with the socket.
........
  r48495 | chris_kohlhoff | 2008-08-31 21:38:52 +1000 (Sun, 31 Aug 2008) | 2 lines
  
  Add class to allow use of arbitrary Windows overlapped I/O operations.
........
  r48524 | chris_kohlhoff | 2008-09-02 09:04:35 +1000 (Tue, 02 Sep 2008) | 3 lines
  
  Add support for using an eventfd descriptor on linux to interrupt a blocked
  epoll/select reactor.
........
  r48525 | chris_kohlhoff | 2008-09-02 09:05:05 +1000 (Tue, 02 Sep 2008) | 3 lines
  
  Use templates to handle iovec structures that have an iov_base member of
  type char*.
........
  r48526 | chris_kohlhoff | 2008-09-02 09:07:29 +1000 (Tue, 02 Sep 2008) | 2 lines
  
  Fix error in comment.
........
  r48527 | chris_kohlhoff | 2008-09-02 18:46:46 +1000 (Tue, 02 Sep 2008) | 2 lines
  
  Fix to compile with MSVC 7.1.
........
  r48535 | chris_kohlhoff | 2008-09-02 21:34:18 +1000 (Tue, 02 Sep 2008) | 2 lines
  
  Add const overloads of the lowest_layer member functions.
........
  r48558 | chris_kohlhoff | 2008-09-03 18:56:43 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Oops, changeset 48535 accidentally reverted 48527's fix.
........
  r48559 | chris_kohlhoff | 2008-09-03 18:57:48 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Add a workaround for a possible gcc 4.3 optimiser bug.
........
  r48560 | chris_kohlhoff | 2008-09-03 19:06:10 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Explicitly specify return type with bind to keep some compilers happy.
........
  r48561 | chris_kohlhoff | 2008-09-03 19:08:04 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Update completion_condition documentation to match new signature.
........
  r48562 | chris_kohlhoff | 2008-09-03 21:36:43 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Add windows/transmit_file example.
........
  r48563 | chris_kohlhoff | 2008-09-03 21:46:02 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Document BOOST_ASIO_DISABLE_EVENTFD macro.
........
  r48564 | chris_kohlhoff | 2008-09-03 21:54:06 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Add windows::overlapped_ptr to the reference index page.
........
  r48565 | chris_kohlhoff | 2008-09-03 22:28:07 +1000 (Wed, 03 Sep 2008) | 2 lines
  
  Regenerate documentation.
........
  r48683 | chris_kohlhoff | 2008-09-09 22:59:43 +1000 (Tue, 09 Sep 2008) | 2 lines
  
  Add windows example directory.
........
  r48684 | chris_kohlhoff | 2008-09-09 23:00:07 +1000 (Tue, 09 Sep 2008) | 2 lines
  
  Remove generated tags file.
........
  r48685 | chris_kohlhoff | 2008-09-09 23:01:16 +1000 (Tue, 09 Sep 2008) | 2 lines
  
  Version bump.
........
  r48686 | chris_kohlhoff | 2008-09-09 23:02:22 +1000 (Tue, 09 Sep 2008) | 2 lines
  
  Handle SSL library errors.
........
  r48715 | chris_kohlhoff | 2008-09-11 10:05:57 +1000 (Thu, 11 Sep 2008) | 2 lines
  
  Clarify which resolve functions perform forward or reverse resolution.
........


[SVN r49194]
2008-10-09 05:41:50 +00:00

132 lines
3.5 KiB
C++

//
// serial_port.cpp
// ~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
// Copyright (c) 2008 Rep Invariant Systems, Inc. (info@repinvariant.com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Disable autolinking for unit tests.
#if !defined(BOOST_ALL_NO_LIB)
#define BOOST_ALL_NO_LIB 1
#endif // !defined(BOOST_ALL_NO_LIB)
// Test that header file is self-contained.
#include <boost/asio/serial_port.hpp>
#include <boost/asio.hpp>
#include "unit_test.hpp"
//------------------------------------------------------------------------------
// serial_port_compile test
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
// The following test checks that all public member functions on the class
// serial_port compile and link correctly. Runtime failures are ignored.
namespace serial_port_compile {
void write_some_handler(const boost::system::error_code&, std::size_t)
{
}
void read_some_handler(const boost::system::error_code&, std::size_t)
{
}
void test()
{
#if defined(BOOST_ASIO_HAS_SERIAL_PORT)
using namespace boost::asio;
try
{
io_service ios;
char mutable_char_buffer[128] = "";
const char const_char_buffer[128] = "";
serial_port::baud_rate serial_port_option;
boost::system::error_code ec;
// basic_serial_port constructors.
serial_port port1(ios);
serial_port port2(ios, "null");
serial_port::native_type native_port1 = port1.native();
serial_port port3(ios, native_port1);
// basic_io_object functions.
io_service& ios_ref = port1.io_service();
(void)ios_ref;
// basic_serial_port functions.
serial_port::lowest_layer_type& lowest_layer = port1.lowest_layer();
(void)lowest_layer;
const serial_port& port4 = port1;
const serial_port::lowest_layer_type& lowest_layer2 = port4.lowest_layer();
(void)lowest_layer2;
port1.open("null");
port1.open("null", ec);
serial_port::native_type native_port2 = port1.native();
port1.assign(native_port2);
serial_port::native_type native_port3 = port1.native();
port1.assign(native_port3, ec);
bool is_open = port1.is_open();
(void)is_open;
port1.close();
port1.close(ec);
serial_port::native_type native_port4 = port1.native();
(void)native_port4;
port1.cancel();
port1.cancel(ec);
port1.set_option(serial_port_option);
port1.set_option(serial_port_option, ec);
port1.get_option(serial_port_option);
port1.get_option(serial_port_option, ec);
port1.send_break();
port1.send_break(ec);
port1.write_some(buffer(mutable_char_buffer));
port1.write_some(buffer(const_char_buffer));
port1.write_some(buffer(mutable_char_buffer), ec);
port1.write_some(buffer(const_char_buffer), ec);
port1.async_write_some(buffer(mutable_char_buffer), write_some_handler);
port1.async_write_some(buffer(const_char_buffer), write_some_handler);
port1.read_some(buffer(mutable_char_buffer));
port1.read_some(buffer(mutable_char_buffer), ec);
port1.async_read_some(buffer(mutable_char_buffer), read_some_handler);
}
catch (std::exception&)
{
}
#endif // defined(BOOST_ASIO_HAS_SERIAL_PORT)
}
} // namespace serial_port_compile
//------------------------------------------------------------------------------
test_suite* init_unit_test_suite(int, char*[])
{
test_suite* test = BOOST_TEST_SUITE("serial_port");
test->add(BOOST_TEST_CASE(&serial_port_compile::test));
return test;
}