Ticket #5475: foreach_add_new_tests.patch

File foreach_add_new_tests.patch, 20.7 KB (added by Michel Morin <mimomorin@…>, 11 years ago)

A patch (against trunk) that adds tests for gcc bugs and C++11 lambdas. This patch also adds tests for noncopyable rvalue collections.

  • libs/foreach/test/cxx11_lambda.cpp

     
     1//  (C) Copyright Eric Niebler 2005.
     2//  Use, modification and distribution are subject to the
     3//  Boost Software License, Version 1.0. (See accompanying file
     4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6/*
     7  Revision history:
     8  25 August 2005 : Initial version.
     9*/
     10
     11#include <vector>
     12#include <boost/config.hpp>
     13#include <boost/test/minimal.hpp>
     14#include <boost/foreach.hpp>
     15
     16#ifdef BOOST_NO_LAMBDAS
     17int test_main( int, char*[] )
     18{
     19    return 0;
     20}
     21#else
     22
     23///////////////////////////////////////////////////////////////////////////////
     24// test_main
     25//   
     26int test_main( int, char*[] )
     27{
     28    int counter = 0;
     29
     30    BOOST_FOREACH(int i, [](){ return std::vector<int>(4, 4); }())
     31    {
     32        counter += i;
     33    }
     34
     35    BOOST_CHECK(16 == counter);
     36
     37    return 0;
     38}
     39
     40#endif
  • libs/foreach/test/pair_byval_r.cpp

     
    3333//   
    3434int test_main( int, char*[] )
    3535{
     36#if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND)
    3637    boost::mpl::true_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_pair);
    3738    (void)p;
    38 
     39#endif
    3940    // non-const containers by value
    4041    BOOST_CHECK(sequence_equal_byval_n_r(my_pair, "\5\4\3\2\1"));
    4142
  • libs/foreach/test/array_byval.cpp

     
    3232//   
    3333int test_main( int, char*[] )
    3434{
     35#if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND)
    3536    boost::mpl::false_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_array);
    3637    (void)p;
     38#endif
    3739    // non-const containers by value
    3840    BOOST_CHECK(sequence_equal_byval_n(my_array, "\1\2\3\4\5"));
    3941
  • libs/foreach/test/stl_byval_r.cpp

     
    4848//   
    4949int test_main( int, char*[] )
    5050{
     51#if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND)
    5152    boost::mpl::false_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_list);
    5253    (void)p;
    53 
     54#endif
    5455    // non-const containers by value
    5556    BOOST_CHECK(sequence_equal_byval_n_r(my_list, "\5\4\3\2\1"));
    5657
  • libs/foreach/test/pair_byval.cpp

     
    3333//   
    3434int test_main( int, char*[] )
    3535{
     36#if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND)
    3637    boost::mpl::true_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_pair);
    3738    (void)p;
    38 
     39#endif
    3940    // non-const containers by value
    4041    BOOST_CHECK(sequence_equal_byval_n(my_pair, "\1\2\3\4\5"));
    4142
  • libs/foreach/test/cstr_byval_r.cpp

     
    3333//   
    3434int test_main( int, char*[] )
    3535{
     36#if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND)
    3637    boost::mpl::true_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_ntcs);
    3738    (void)p;
    38 
     39#endif
    3940    // non-const containers by value
    4041    BOOST_CHECK(sequence_equal_byval_n_r(my_ntcs, "\5\4\3\2\1"));
    4142
  • libs/foreach/test/noncopyable_rvalue_nonconst_r.cpp

     
     1//  (C) Copyright Eric Niebler 2005.
     2//  Use, modification and distribution are subject to the
     3//  Boost Software License, Version 1.0. (See accompanying file
     4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6/*
     7  Revision history:
     8  25 August 2005 : Initial version.
     9*/
     10
     11#include <boost/test/minimal.hpp>
     12#include <boost/foreach.hpp>
     13
     14#if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND)
     15# error Expected failure : non-copyable rvalues disallowed
     16#else
     17
     18class my_container
     19{
     20public:
     21    my_container()
     22    {
     23        array_[0] = 1;
     24        array_[1] = 2;
     25        array_[2] = 3;
     26        array_[3] = 4;
     27        array_[4] = 5;
     28    }
     29
     30    typedef int* iterator;
     31    typedef int const* const_iterator;
     32
     33    iterator begin() { return array_; }
     34    const_iterator begin() const { return array_; }
     35
     36    iterator end() { return array_ + 5; }
     37    const_iterator end() const { return array_ + 5; }
     38
     39private:
     40    int array_[5];
     41
     42    // non-copyable
     43    my_container(my_container const &);
     44    my_container &operator =(my_container const &);
     45
     46    // non-movable
     47    my_container(my_container &&);
     48    my_container &operator =(my_container &&);
     49};
     50
     51///////////////////////////////////////////////////////////////////////////////
     52// test_main
     53//   
     54int test_main( int, char*[] )
     55{
     56    int counter = 0;
     57
     58    BOOST_REVERSE_FOREACH(int i, my_container())
     59    {
     60        counter += i;
     61    }
     62
     63    BOOST_CHECK(15 == counter);
     64
     65    return 0;
     66}
     67
     68#endif
  • libs/foreach/test/rvalue_nonconst_access_fail.cpp

     
     1//  (C) Copyright Eric Niebler 2005.
     2//  Use, modification and distribution are subject to the
     3//  Boost Software License, Version 1.0. (See accompanying file
     4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6/*
     7  Revision history:
     8  25 August 2005 : Initial version.
     9*/
     10
     11#include <vector>
     12#include <boost/test/minimal.hpp>
     13#include <boost/foreach.hpp>
     14
     15#ifdef BOOST_FOREACH_NO_RVALUE_DETECTION
     16# error Expected failure : rvalues disallowed
     17#else
     18
     19///////////////////////////////////////////////////////////////////////////////
     20// test_main
     21//   
     22int test_main( int, char*[] )
     23{
     24    BOOST_FOREACH(int &i, std::vector<int>(4, 4))
     25    {
     26        (void)i;
     27    }
     28
     29    return 0;
     30}
     31
     32#endif
  • libs/foreach/test/stl_byval.cpp

     
    4848//   
    4949int test_main( int, char*[] )
    5050{
     51#if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND)
    5152    boost::mpl::false_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_list);
    5253    (void)p;
    53 
     54#endif
    5455    // non-const containers by value
    5556    BOOST_CHECK(sequence_equal_byval_n(my_list, "\1\2\3\4\5"));
    5657
  • libs/foreach/test/char_array_fail.cpp

     
     1//  noncopyable.cpp
     2///
     3//  (C) Copyright Eric Niebler 2004.
     4//  Use, modification and distribution are subject to the
     5//  Boost Software License, Version 1.0. (See accompanying file
     6//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     7
     8/*
     9 Revision history:
     10   21 December 2005 : Initial version.
     11*/
     12
     13#include <boost/foreach.hpp>
     14
     15///////////////////////////////////////////////////////////////////////////////
     16// main
     17//   
     18int main( int, char*[] )
     19{
     20    char ar[] = "\1\2\3\4\5";
     21    BOOST_FOREACH( char ch, ar )
     22    {
     23        (void)ch;
     24    }
     25
     26    return 0;
     27}
  • libs/foreach/test/cstr_byval.cpp

     
    3333//   
    3434int test_main( int, char*[] )
    3535{
     36#if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND)
    3637    boost::mpl::true_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_ntcs);
    3738    (void)p;
    38 
     39#endif
    3940    // non-const containers by value
    4041    BOOST_CHECK(sequence_equal_byval_n(my_ntcs, "\1\2\3\4\5"));
    4142
  • libs/foreach/test/noncopyable_rvalue_nonconst.cpp

     
     1//  (C) Copyright Eric Niebler 2005.
     2//  Use, modification and distribution are subject to the
     3//  Boost Software License, Version 1.0. (See accompanying file
     4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6/*
     7  Revision history:
     8  25 August 2005 : Initial version.
     9*/
     10
     11#include <boost/test/minimal.hpp>
     12#include <boost/foreach.hpp>
     13
     14#if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND)
     15# error Expected failure : non-copyable rvalues disallowed
     16#else
     17
     18class my_container
     19{
     20public:
     21    my_container()
     22    {
     23        array_[0] = 1;
     24        array_[1] = 2;
     25        array_[2] = 3;
     26        array_[3] = 4;
     27        array_[4] = 5;
     28    }
     29
     30    typedef int* iterator;
     31    typedef int const* const_iterator;
     32
     33    iterator begin() { return array_; }
     34    const_iterator begin() const { return array_; }
     35
     36    iterator end() { return array_ + 5; }
     37    const_iterator end() const { return array_ + 5; }
     38
     39private:
     40    int array_[5];
     41
     42    // non-copyable
     43    my_container(my_container const &);
     44    my_container &operator =(my_container const &);
     45
     46    // non-movable
     47    my_container(my_container &&);
     48    my_container &operator =(my_container &&);
     49};
     50
     51///////////////////////////////////////////////////////////////////////////////
     52// test_main
     53//   
     54int test_main( int, char*[] )
     55{
     56    int counter = 0;
     57
     58    BOOST_FOREACH(int i, my_container())
     59    {
     60        counter += i;
     61    }
     62
     63    BOOST_CHECK(15 == counter);
     64
     65    return 0;
     66}
     67
     68#endif
  • libs/foreach/test/rvalue_nonconst_access_r_fail.cpp

     
     1//  (C) Copyright Eric Niebler 2005.
     2//  Use, modification and distribution are subject to the
     3//  Boost Software License, Version 1.0. (See accompanying file
     4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6/*
     7  Revision history:
     8  25 August 2005 : Initial version.
     9*/
     10
     11#include <vector>
     12#include <boost/test/minimal.hpp>
     13#include <boost/foreach.hpp>
     14
     15#ifdef BOOST_FOREACH_NO_RVALUE_DETECTION
     16# error Expected failure : rvalues disallowed
     17#else
     18
     19///////////////////////////////////////////////////////////////////////////////
     20// test_main
     21//   
     22int test_main( int, char*[] )
     23{
     24    BOOST_REVERSE_FOREACH(int &i, std::vector<int>(4, 4))
     25    {
     26        (void)i;
     27    }
     28
     29    return 0;
     30}
     31
     32#endif
  • libs/foreach/test/Jamfile.v2

     
    3333      [ run dependent_type.cpp ]
    3434      [ run misc.cpp ]
    3535      [ compile noncopyable.cpp ]
     36      [ run noncopyable_rvalue_const.cpp ]
     37      [ run noncopyable_rvalue_nonconst.cpp ]
     38      [ run noncopyable_rvalue_const_r.cpp ]
     39      [ run noncopyable_rvalue_nonconst_r.cpp ]
     40      [ run cxx11_gcc_workaround.cpp ]
     41      [ run cxx11_gcc_workaround_r.cpp ]
     42      [ run cxx11_lambda.cpp ]
     43      [ run cxx11_lambda_r.cpp ]
     44      [ compile-fail char_array_fail.cpp ]
     45      [ compile-fail char_array_r_fail.cpp ]
     46      [ compile-fail rvalue_nonconst_access_fail.cpp ]
     47      [ compile-fail rvalue_nonconst_access_r_fail.cpp ]
    3648    ;
  • libs/foreach/test/cxx11_gcc_workaround_r.cpp

     
     1//  (C) Copyright Eric Niebler 2005.
     2//  Use, modification and distribution are subject to the
     3//  Boost Software License, Version 1.0. (See accompanying file
     4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6/*
     7  Revision history:
     8  25 August 2005 : Initial version.
     9*/
     10
     11#include <vector>
     12#include <boost/config.hpp>
     13#include <boost/test/minimal.hpp>
     14#include <boost/foreach.hpp>
     15
     16#ifdef BOOST_NO_RVALUE_REFERENCES
     17int test_main( int, char*[] )
     18{
     19    return 0;
     20}
     21#else
     22
     23template <typename T>
     24T const add_const_if_rvalue(T&& t)
     25{
     26    return t;
     27}
     28
     29template <typename T>
     30void f()
     31{
     32    int counter = 0;
     33
     34    BOOST_FOREACH(int i, add_const_if_rvalue(std::vector<int>(4, 4)))
     35    {
     36        counter += i;
     37    }
     38
     39    BOOST_CHECK(16 == counter);
     40}
     41
     42///////////////////////////////////////////////////////////////////////////////
     43// test_main
     44//   
     45int test_main( int, char*[] )
     46{
     47    f<void>();
     48
     49    return 0;
     50}
     51
     52#endif
  • libs/foreach/test/noncopyable_rvalue_const_r.cpp

     
     1//  (C) Copyright Eric Niebler 2005.
     2//  Use, modification and distribution are subject to the
     3//  Boost Software License, Version 1.0. (See accompanying file
     4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6/*
     7  Revision history:
     8  25 August 2005 : Initial version.
     9*/
     10
     11#include <boost/test/minimal.hpp>
     12#include <boost/foreach.hpp>
     13
     14#if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND)
     15# error Expected failure : non-copyable rvalues disallowed
     16#else
     17
     18class my_container
     19{
     20public:
     21    my_container()
     22    {
     23        array_[0] = 1;
     24        array_[1] = 2;
     25        array_[2] = 3;
     26        array_[3] = 4;
     27        array_[4] = 5;
     28    }
     29
     30    typedef int* iterator;
     31    typedef int const* const_iterator;
     32
     33    iterator begin() { return array_; }
     34    const_iterator begin() const { return array_; }
     35
     36    iterator end() { return array_ + 5; }
     37    const_iterator end() const { return array_ + 5; }
     38
     39private:
     40    int array_[5];
     41
     42    // non-copyable
     43    my_container(my_container const &);
     44    my_container &operator =(my_container const &);
     45
     46    // non-movable
     47    my_container(my_container &&);
     48    my_container &operator =(my_container &&);
     49};
     50
     51typedef my_container const const_my_container;
     52
     53///////////////////////////////////////////////////////////////////////////////
     54// test_main
     55//   
     56int test_main( int, char*[] )
     57{
     58    int counter = 0;
     59
     60    BOOST_REVERSE_FOREACH(int i, const_my_container())
     61    {
     62        counter += i;
     63    }
     64
     65    BOOST_CHECK(15 == counter);
     66
     67    return 0;
     68}
     69
     70#endif
  • libs/foreach/test/cxx11_lambda_r.cpp

     
     1//  (C) Copyright Eric Niebler 2005.
     2//  Use, modification and distribution are subject to the
     3//  Boost Software License, Version 1.0. (See accompanying file
     4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6/*
     7  Revision history:
     8  25 August 2005 : Initial version.
     9*/
     10
     11#include <vector>
     12#include <boost/config.hpp>
     13#include <boost/test/minimal.hpp>
     14#include <boost/foreach.hpp>
     15
     16#ifdef BOOST_NO_LAMBDAS
     17int test_main( int, char*[] )
     18{
     19    return 0;
     20}
     21#else
     22
     23///////////////////////////////////////////////////////////////////////////////
     24// test_main
     25//   
     26int test_main( int, char*[] )
     27{
     28    int counter = 0;
     29
     30    BOOST_REVERSE_FOREACH(int i, [](){ return std::vector<int>(4, 4); }())
     31    {
     32        counter += i;
     33    }
     34
     35    BOOST_CHECK(16 == counter);
     36
     37    return 0;
     38}
     39
     40#endif
  • libs/foreach/test/char_array_r_fail.cpp

     
     1//  noncopyable.cpp
     2///
     3//  (C) Copyright Eric Niebler 2004.
     4//  Use, modification and distribution are subject to the
     5//  Boost Software License, Version 1.0. (See accompanying file
     6//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     7
     8/*
     9 Revision history:
     10   21 December 2005 : Initial version.
     11*/
     12
     13#include <boost/foreach.hpp>
     14
     15///////////////////////////////////////////////////////////////////////////////
     16// main
     17//   
     18int main( int, char*[] )
     19{
     20    char ar[] = "\1\2\3\4\5";
     21    BOOST_REVERSE_FOREACH( char ch, ar )
     22    {
     23        (void)ch;
     24    }
     25
     26    return 0;
     27}
  • libs/foreach/test/cxx11_gcc_workaround.cpp

     
     1//  (C) Copyright Eric Niebler 2005.
     2//  Use, modification and distribution are subject to the
     3//  Boost Software License, Version 1.0. (See accompanying file
     4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6/*
     7  Revision history:
     8  25 August 2005 : Initial version.
     9*/
     10
     11#include <vector>
     12#include <boost/config.hpp>
     13#include <boost/test/minimal.hpp>
     14#include <boost/foreach.hpp>
     15
     16#ifdef BOOST_NO_RVALUE_REFERENCES
     17int test_main( int, char*[] )
     18{
     19    return 0;
     20}
     21#else
     22
     23template <typename T>
     24T const add_const_if_rvalue(T&& t)
     25{
     26    return t;
     27}
     28
     29template <typename T>
     30void f()
     31{
     32    int counter = 0;
     33
     34    BOOST_FOREACH(int i, add_const_if_rvalue(std::vector<int>(4, 4)))
     35    {
     36        counter += i;
     37    }
     38
     39    BOOST_CHECK(16 == counter);
     40}
     41
     42///////////////////////////////////////////////////////////////////////////////
     43// test_main
     44//   
     45int test_main( int, char*[] )
     46{
     47    f<void>();
     48
     49    return 0;
     50}
     51
     52#endif
  • libs/foreach/test/array_byval_r.cpp

     
    3232//   
    3333int test_main( int, char*[] )
    3434{
     35#if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND)
    3536    boost::mpl::false_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_array);
    3637    (void)p;
    37 
     38#endif
    3839    // non-const containers by value
    3940    BOOST_CHECK(sequence_equal_byval_n_r(my_array, "\5\4\3\2\1"));
    4041
  • libs/foreach/test/noncopyable_rvalue_const.cpp

     
     1//  (C) Copyright Eric Niebler 2005.
     2//  Use, modification and distribution are subject to the
     3//  Boost Software License, Version 1.0. (See accompanying file
     4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
     5
     6/*
     7  Revision history:
     8  25 August 2005 : Initial version.
     9*/
     10
     11#include <boost/test/minimal.hpp>
     12#include <boost/foreach.hpp>
     13
     14#if !defined(BOOST_FOREACH_USE_CXX11) && !defined(BOOST_FOREACH_USE_CXX11_GCC_WORKAROUND)
     15# error Expected failure : non-copyable rvalues disallowed
     16#else
     17
     18class my_container
     19{
     20public:
     21    my_container()
     22    {
     23        array_[0] = 1;
     24        array_[1] = 2;
     25        array_[2] = 3;
     26        array_[3] = 4;
     27        array_[4] = 5;
     28    }
     29
     30    typedef int* iterator;
     31    typedef int const* const_iterator;
     32
     33    iterator begin() { return array_; }
     34    const_iterator begin() const { return array_; }
     35
     36    iterator end() { return array_ + 5; }
     37    const_iterator end() const { return array_ + 5; }
     38
     39private:
     40    int array_[5];
     41
     42    // non-copyable
     43    my_container(my_container const &);
     44    my_container &operator =(my_container const &);
     45
     46    // non-movable
     47    my_container(my_container &&);
     48    my_container &operator =(my_container &&);
     49};
     50
     51typedef my_container const const_my_container;
     52
     53///////////////////////////////////////////////////////////////////////////////
     54// test_main
     55//   
     56int test_main( int, char*[] )
     57{
     58    int counter = 0;
     59
     60    BOOST_FOREACH(int i, const_my_container())
     61    {
     62        counter += i;
     63    }
     64
     65    BOOST_CHECK(15 == counter);
     66
     67    return 0;
     68}
     69
     70#endif