2
0
mirror of https://github.com/boostorg/asio.git synced 2026-01-28 06:42:08 +00:00
Files
asio/test/windows/random_access_handle.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

124 lines
3.5 KiB
C++

//
// random_access_handle.cpp
// ~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot 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/windows/random_access_handle.hpp>
#include <boost/asio.hpp>
#include "../unit_test.hpp"
//------------------------------------------------------------------------------
// windows_random_access_handle_compile test
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// The following test checks that all public member functions on the class
// windows::random_access_handle compile and link correctly. Runtime failures
// are ignored.
namespace windows_random_access_handle_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_WINDOWS_RANDOM_ACCESS_HANDLE)
using namespace boost::asio;
namespace win = boost::asio::windows;
try
{
io_service ios;
char mutable_char_buffer[128] = "";
const char const_char_buffer[128] = "";
boost::uint64_t offset = 0;
boost::system::error_code ec;
// basic_random_access_handle constructors.
win::random_access_handle handle1(ios);
HANDLE native_handle1 = INVALID_HANDLE_VALUE;
win::random_access_handle handle2(ios, native_handle1);
// basic_io_object functions.
io_service& ios_ref = handle1.io_service();
(void)ios_ref;
// basic_handle functions.
win::random_access_handle::lowest_layer_type& lowest_layer
= handle1.lowest_layer();
(void)lowest_layer;
const win::random_access_handle& handle3 = handle1;
const win::random_access_handle::lowest_layer_type& lowest_layer2
= handle3.lowest_layer();
(void)lowest_layer2;
HANDLE native_handle2 = INVALID_HANDLE_VALUE;
handle1.assign(native_handle2);
bool is_open = handle1.is_open();
(void)is_open;
handle1.close();
handle1.close(ec);
win::random_access_handle::native_type native_handle3 = handle1.native();
(void)native_handle3;
handle1.cancel();
handle1.cancel(ec);
// basic_random_access_handle functions.
handle1.write_some_at(offset, buffer(mutable_char_buffer));
handle1.write_some_at(offset, buffer(const_char_buffer));
handle1.write_some_at(offset, buffer(mutable_char_buffer), ec);
handle1.write_some_at(offset, buffer(const_char_buffer), ec);
handle1.async_write_some_at(offset,
buffer(mutable_char_buffer), write_some_handler);
handle1.async_write_some_at(offset,
buffer(const_char_buffer), write_some_handler);
handle1.read_some_at(offset, buffer(mutable_char_buffer));
handle1.read_some_at(offset, buffer(mutable_char_buffer), ec);
handle1.async_read_some_at(offset,
buffer(mutable_char_buffer), read_some_handler);
}
catch (std::exception&)
{
}
#endif // defined(BOOST_ASIO_HAS_WINDOWS_RANDOM_ACCESS_HANDLE)
}
} // namespace windows_random_access_handle_compile
//------------------------------------------------------------------------------
test_suite* init_unit_test_suite(int, char*[])
{
test_suite* test = BOOST_TEST_SUITE("windows/random_access_handle");
test->add(BOOST_TEST_CASE(&windows_random_access_handle_compile::test));
return test;
}