Add tests for random-access handles.

This commit is contained in:
chris_kohlhoff 2008-06-11 08:22:08 +00:00
parent f743a4c3b2
commit 59512bccaf
7 changed files with 190 additions and 0 deletions

View File

@ -58,7 +58,10 @@ noinst_PROGRAMS = \
tests/unit/thread \
tests/unit/time_traits \
tests/unit/windows/basic_handle \
tests/unit/windows/basic_random_access_handle \
tests/unit/windows/basic_stream_handle \
tests/unit/windows/random_access_handle \
tests/unit/windows/random_access_handle_service \
tests/unit/windows/stream_handle \
tests/unit/windows/stream_handle_service \
tests/unit/write \
@ -176,7 +179,10 @@ TESTS = \
tests/unit/thread \
tests/unit/time_traits \
tests/unit/windows/basic_handle \
tests/unit/windows/basic_random_access_handle \
tests/unit/windows/basic_stream_handle \
tests/unit/windows/random_access_handle \
tests/unit/windows/random_access_handle_service \
tests/unit/windows/stream_handle \
tests/unit/windows/stream_handle_service \
tests/unit/write
@ -261,7 +267,10 @@ tests_unit_stream_socket_service_SOURCES = tests/unit/stream_socket_service.cpp
tests_unit_thread_SOURCES = tests/unit/thread.cpp
tests_unit_time_traits_SOURCES = tests/unit/time_traits.cpp
tests_unit_windows_basic_handle_SOURCES = tests/unit/windows/basic_handle.cpp
tests_unit_windows_basic_random_access_handle_SOURCES = tests/unit/windows/basic_random_access_handle.cpp
tests_unit_windows_basic_stream_handle_SOURCES = tests/unit/windows/basic_stream_handle.cpp
tests_unit_windows_random_access_handle_SOURCES = tests/unit/windows/random_access_handle.cpp
tests_unit_windows_random_access_handle_service_SOURCES = tests/unit/windows/random_access_handle_service.cpp
tests_unit_windows_stream_handle_SOURCES = tests/unit/windows/stream_handle.cpp
tests_unit_windows_stream_handle_service_SOURCES = tests/unit/windows/stream_handle_service.cpp
tests_unit_write_SOURCES = tests/unit/write.cpp

View File

@ -57,7 +57,10 @@ UNIT_TEST_EXES = \
tests\unit\thread.exe \
tests\unit\time_traits.exe \
tests\unit\windows\basic_handle.exe \
tests\unit\windows\basic_random_access_handle.exe \
tests\unit\windows\basic_stream_handle.exe \
tests\unit\windows\random_access_handle.exe \
tests\unit\windows\random_access_handle_service.exe \
tests\unit\windows\stream_handle.exe \
tests\unit\windows\stream_handle_service.exe \
tests\unit\write.exe

View File

@ -58,7 +58,10 @@ UNIT_TEST_EXES = \
tests/unit/thread.exe \
tests/unit/time_traits.exe \
tests/unit/windows/basic_handle.exe \
tests/unit/windows/basic_random_access_handle.exe \
tests/unit/windows/basic_stream_handle.exe \
tests/unit/windows/random_access_handle.exe \
tests/unit/windows/random_access_handle_service.exe \
tests/unit/windows/stream_handle.exe \
tests/unit/windows/stream_handle_service.exe \
tests/unit/write.exe

View File

@ -109,7 +109,10 @@ UNIT_TEST_EXES = \
tests\unit\thread.exe \
tests\unit\time_traits.exe \
tests\unit\windows\basic_handle.exe \
tests\unit\windows\basic_random_access_handle.exe \
tests\unit\windows\basic_stream_handle.exe \
tests\unit\windows\random_access_handle.exe \
tests\unit\windows\random_access_handle_service.exe \
tests\unit\windows\stream_handle.exe \
tests\unit\windows\stream_handle_service.exe \
tests\unit\write.exe

View File

@ -0,0 +1,27 @@
//
// basic_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 "asio/windows/basic_random_access_handle.hpp"
#include "asio.hpp"
#include "../unit_test.hpp"
test_suite* init_unit_test_suite(int, char*[])
{
test_suite* test = BOOST_TEST_SUITE("windows/basic_random_access_handle");
test->add(BOOST_TEST_CASE(&null_test));
return test;
}

View File

@ -0,0 +1,118 @@
//
// 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 "asio/windows/random_access_handle.hpp"
#include "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 asio::error_code&, std::size_t)
{
}
void read_some_handler(const asio::error_code&, std::size_t)
{
}
void test()
{
#if defined(ASIO_HAS_WINDOWS_STREAM_HANDLE)
using namespace asio;
namespace win = asio::windows;
try
{
io_service ios;
char mutable_char_buffer[128] = "";
const char const_char_buffer[128] = "";
boost::uint64_t offset = 0;
asio::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;
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(ASIO_HAS_WINDOWS_STREAM_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;
}

View File

@ -0,0 +1,27 @@
//
// random_access_handle_service.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 "asio/windows/random_access_handle_service.hpp"
#include "asio.hpp"
#include "../unit_test.hpp"
test_suite* init_unit_test_suite(int, char*[])
{
test_suite* test = BOOST_TEST_SUITE("windows/random_access_handle_service");
test->add(BOOST_TEST_CASE(&null_test));
return test;
}