Skip to content

Commit

Permalink
Merge test from PR #402
Browse files Browse the repository at this point in the history
  • Loading branch information
karzhenkov committed Jul 3, 2019
2 parents fb247ee + efb1114 commit bf716ee
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
2 changes: 2 additions & 0 deletions asio/src/Makefile.mgw
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ UNIT_TEST_EXES = \
tests/unit/ip/udp.exe \
tests/unit/ip/unicast.exe \
tests/unit/ip/v6_only.exe \
tests/unit/is_buffer_sequence.exe \
tests/unit/is_buffer_sequence_no_decltype.exe \
tests/unit/is_read_buffered.exe \
tests/unit/is_write_buffered.exe \
tests/unit/placeholders.exe \
Expand Down
2 changes: 2 additions & 0 deletions asio/src/Makefile.msc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ UNIT_TEST_EXES = \
tests\unit\ip\udp.exe \
tests\unit\ip\unicast.exe \
tests\unit\ip\v6_only.exe \
tests\unit\is_buffer_sequence.exe \
tests\unit\is_buffer_sequence_no_decltype.exe \
tests\unit\is_read_buffered.exe \
tests\unit\is_write_buffered.exe \
tests\unit\packaged_task.exe \
Expand Down
6 changes: 6 additions & 0 deletions asio/src/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ check_PROGRAMS = \
unit/ip/udp \
unit/ip/unicast \
unit/ip/v6_only \
unit/is_buffer_sequence \
unit/is_buffer_sequence_no_decltype \
unit/is_read_buffered \
unit/is_write_buffered \
unit/local/basic_endpoint \
Expand Down Expand Up @@ -208,6 +210,8 @@ TESTS = \
unit/ip/udp \
unit/ip/unicast \
unit/ip/v6_only \
unit/is_buffer_sequence \
unit/is_buffer_sequence_no_decltype \
unit/is_read_buffered \
unit/is_write_buffered \
unit/local/basic_endpoint \
Expand Down Expand Up @@ -352,6 +356,8 @@ unit_ip_tcp_SOURCES = unit/ip/tcp.cpp
unit_ip_udp_SOURCES = unit/ip/udp.cpp
unit_ip_unicast_SOURCES = unit/ip/unicast.cpp
unit_ip_v6_only_SOURCES = unit/ip/v6_only.cpp
unit_is_buffer_sequence_SOURCES = unit/is_buffer_sequence.cpp
unit_is_buffer_sequence_no_decltype_SOURCES = unit/is_buffer_sequence_no_decltype.cpp
unit_is_read_buffered_SOURCES = unit/is_read_buffered.cpp
unit_is_write_buffered_SOURCES = unit/is_write_buffered.cpp
unit_local_basic_endpoint_SOURCES = unit/local/basic_endpoint.cpp
Expand Down
119 changes: 119 additions & 0 deletions asio/src/tests/unit/is_buffer_sequence.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// is_buffer_sequence.cpp
// ~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2019 Alexander Karzhenkov
//
// 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)
//

#include <vector>
#include "asio/buffer.hpp"
#include "unit_test.hpp"

#ifdef ASIO_HAS_DECLTYPE
# define ASIO_HAS_DECLTYPE_MSG "ASIO_HAS_DECLTYPE is defined"
# define ASIO_HAS_DECLTYPE_FLAG true
#else
# define ASIO_HAS_DECLTYPE_MSG "ASIO_HAS_DECLTYPE is not defined"
# define ASIO_HAS_DECLTYPE_FLAG false
#endif

using namespace asio;

namespace {

struct A1
{
mutable_buffer* begin();

// no "value_type" type
// no "const_iterator" type
// no "end" member function
};

struct B1
{
typedef mutable_buffer value_type;

// bad "const_iterator" type
typedef void const_iterator;

// no "begin" member function
// no "end" member function
};

struct X1
{
typedef mutable_buffer value_type;
typedef const mutable_buffer* const_iterator;

const mutable_buffer* begin() const;
const mutable_buffer* end() const;
};

struct B2
{
typedef mutable_buffer value_type;
typedef void const_iterator; // (!)

const mutable_buffer* begin() const;
const mutable_buffer* end() const;
};

struct B3
{
typedef mutable_buffer value_type;
typedef const mutable_buffer* const_iterator;

int begin; // (!)
const mutable_buffer* end() const;
};

struct C1
{
typedef mutable_buffer value_type;
typedef const mutable_buffer* const_iterator;

const mutable_buffer* begin() const;
int end() const; // (!)
};

void run()
{
ASIO_TEST_IOSTREAM << ASIO_HAS_DECLTYPE_MSG << std::endl;

ASIO_CHECK(!is_mutable_buffer_sequence<A1>::value);
ASIO_CHECK(!is_mutable_buffer_sequence<B1>::value);
ASIO_CHECK( is_mutable_buffer_sequence<X1>::value);
ASIO_CHECK( is_mutable_buffer_sequence<B2>::value == ASIO_HAS_DECLTYPE_FLAG);
ASIO_CHECK(!is_mutable_buffer_sequence<B3>::value);
ASIO_CHECK(!is_mutable_buffer_sequence<C1>::value);

ASIO_CHECK(!is_mutable_buffer_sequence<void>::value);
ASIO_CHECK(!is_const_buffer_sequence<void>::value);

ASIO_CHECK(!is_mutable_buffer_sequence<int>::value);
ASIO_CHECK(!is_const_buffer_sequence<int>::value);

ASIO_CHECK( is_mutable_buffer_sequence<mutable_buffer>::value);
ASIO_CHECK( is_const_buffer_sequence<mutable_buffer>::value);

ASIO_CHECK(!is_mutable_buffer_sequence<const_buffer>::value);
ASIO_CHECK( is_const_buffer_sequence<const_buffer>::value);

ASIO_CHECK( is_mutable_buffer_sequence<std::vector<mutable_buffer> >::value);
ASIO_CHECK( is_const_buffer_sequence<std::vector<mutable_buffer> >::value);

ASIO_CHECK(!is_mutable_buffer_sequence<std::vector<const_buffer> >::value);
ASIO_CHECK( is_const_buffer_sequence<std::vector<const_buffer> >::value);
}

} // namespace

ASIO_TEST_SUITE
(
"is_buffer_sequence",
ASIO_TEST_CASE(run)
)
12 changes: 12 additions & 0 deletions asio/src/tests/unit/is_buffer_sequence_no_decltype.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// is_buffer_sequence_no_decltype.cpp
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
// Copyright (c) 2019 Alexander Karzhenkov
//
// 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)
//

#define ASIO_DISABLE_DECLTYPE
#include "is_buffer_sequence.cpp"

0 comments on commit bf716ee

Please sign in to comment.