early-access version 3088

This commit is contained in:
pineappleEA
2022-11-05 15:35:56 +01:00
parent 4e4fc25ce3
commit b601909c6d
35519 changed files with 5996896 additions and 860 deletions

View File

@@ -0,0 +1,232 @@
// (C) Copyright Raffi Enficiaud 2018
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// @brief tests the access to the master test suite from the datasets, trac 12953
// ***************************************************************************
#define BOOST_TEST_MODULE "Access master test suite arguments from datasets"
#include <boost/test/included/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <iostream>
class dataset_loader
{
public:
static const int arity = 1;
// this constructor access the master test suite
dataset_loader();
dataset_loader(std::initializer_list<std::string> init_list)
: m_input_extension(init_list)
{}
dataset_loader(std::string s1, std::string s2)
{
m_input_extension.push_back(s1);
m_input_extension.push_back(s2);
}
struct iterator {
iterator(std::vector<std::string>::const_iterator const& v_iterator)
: m_iterator(v_iterator)
{}
// bug in joins, see 13380, can safely be changed to std::string once fixed
const std::string& operator*() const { return *m_iterator; }
void operator++()
{
++m_iterator;
}
private:
std::vector<std::string>::const_iterator m_iterator;
};
boost::unit_test::data::size_t size() const {
return m_input_extension.size();
}
// iterator
iterator begin() const { return iterator(m_input_extension.begin()); }
private:
std::vector<std::string> m_input_extension;
};
dataset_loader::dataset_loader()
{
BOOST_TEST_INFO("dataset_loader");
int argc = boost::unit_test::framework::master_test_suite().argc;
char** argv = boost::unit_test::framework::master_test_suite().argv;
// not taking into account the name of the program (first argument)
for(unsigned i = 1; i != argc; i++) {
m_input_extension.push_back(argv[i]);
}
}
//------------------------------------------------------------------------------
namespace boost { namespace unit_test { namespace data {
namespace monomorphic {
template <>
struct is_dataset<dataset_loader> : boost::mpl::true_ {};
}
}}}
BOOST_AUTO_TEST_SUITE( concrete_testsuite )
// parameters passed on the command line
char const* expected[] = {"--param1=1", "--param2=2"};
BOOST_DATA_TEST_CASE(master_access_zips,
boost::unit_test::data::make_delayed<dataset_loader>( ) ^ boost::unit_test::data::make(expected),
input, expect)
{
// ...
BOOST_TEST(input == expect);
}
BOOST_DATA_TEST_CASE(master_access_zips_flip,
boost::unit_test::data::make_delayed<dataset_loader>( ) ^ dataset_loader({"--param1=1", "--param2=2"}),
input, expect)
{
BOOST_TEST(input == expect);
}
// checking the forward of the arguments
BOOST_DATA_TEST_CASE(master_access_zips_args_forward,
boost::unit_test::data::make_delayed<dataset_loader>( "--param1=1", "--param2=2" ) ^ boost::unit_test::data::make_delayed<dataset_loader>( ),
input, expect)
{
BOOST_TEST(input == expect);
}
BOOST_DATA_TEST_CASE(master_access_grid,
boost::unit_test::data::make_delayed<dataset_loader>( ) * dataset_loader({"--param1=1", "--param2=2"}),
input, expect)
{
BOOST_TEST((input == expect || input == "--param1=1" || expect == "--param1=1" ));
}
BOOST_DATA_TEST_CASE(master_access_grid_flip,
dataset_loader({"--param1=1", "--param2=2"}) * boost::unit_test::data::make_delayed<dataset_loader>( ),
input, expect)
{
BOOST_TEST((input == expect || input == "--param1=1" || expect == "--param1=1" ));
}
int counter4 = 0;
BOOST_DATA_TEST_CASE(master_access_joins,
boost::unit_test::data::make_delayed<dataset_loader>( ) + dataset_loader({"--param1=1", "--param2=2"}),
input)
{
static const std::string values[] = {"--param1=1", "--param2=2", "--param1=1", "--param2=2"};
BOOST_TEST(input == values[counter4++]);
}
int counter41 = 0;
BOOST_DATA_TEST_CASE(master_access_joins_flip,
dataset_loader({"--param2=2", "--param1=1"}) + boost::unit_test::data::make_delayed<dataset_loader>( ),
input)
{
static const std::string values[] = {"--param2=2", "--param1=1", "--param1=1", "--param2=2"};
BOOST_TEST(input == values[counter41++]);
}
BOOST_AUTO_TEST_SUITE_END()
class dataset_loader_arity3
{
public:
typedef std::vector<std::string> data_type;
data_type m_expected;
data_type m_input;
static const int arity = 3;
public:
dataset_loader_arity3(std::string some_additional) : m_some_additional(some_additional)
{
int argc = boost::unit_test::framework::master_test_suite().argc;
char** argv = boost::unit_test::framework::master_test_suite().argv;
for(unsigned i = 1; i != argc; i++) {
std::string current(argv[i]);
std::cout << "current " << current << std::endl;
if(current.find("--param1") != std::string::npos) {
m_expected.push_back(current);
}
else {
m_input.push_back(current);
}
}
}
struct iterator {
iterator(
data_type::const_iterator v_expected,
data_type::const_iterator v_input,
std::string additional)
: m_input(v_input)
, m_expected(v_expected)
, m_additional(additional)
{}
// bug in joins, see 13380. We should return a non temporary
std::tuple<std::string, std::string, std::string> operator*() const {
return std::tuple<std::string, std::string, std::string>(*m_input, *m_expected, *m_input + " -" + m_additional + "- " + *m_expected);
}
void operator++()
{
++m_input;
++m_expected;
}
private:
data_type::const_iterator m_input, m_expected;
std::string m_additional;
};
boost::unit_test::data::size_t size() const {
using namespace boost;
BOOST_TEST_I_ASSRT( m_expected.size() == m_input.size(), "Lists of strings of different size" );
return m_input.size();
}
// iterator
iterator begin() const {
using namespace boost;
BOOST_TEST_I_ASSRT( m_expected.size() == m_input.size(), "Lists of strings of different size" );
return iterator(m_expected.begin(), m_input.begin(), m_some_additional); }
private:
std::string m_some_additional;
};
namespace boost { namespace unit_test { namespace data {
namespace monomorphic {
template <>
struct is_dataset<dataset_loader_arity3> : boost::mpl::true_ {};
}
}}}
BOOST_DATA_TEST_CASE(master_access_make_ds_with_arity,
boost::unit_test::data::make_delayed<dataset_loader_arity3>( "something-in-the-middle"),
input, expected, additional)
{
std::cout << "input: " << input << " -- expected: " << expected << " -- additional: " << additional << std::endl;
BOOST_TEST(true);
}

View File

@@ -0,0 +1,139 @@
// (C) Copyright Raffi Enficiaud 2016.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// Tests the variadic sample element support and the respect of move semantics
/// for the datasets definitions
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MODULE test movable return type on datasets test
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic/singleton.hpp>
#include <boost/test/data/monomorphic/collection.hpp>
#include <boost/test/data/for_each_sample.hpp>
namespace utf=boost::unit_test;
namespace bdata=utf::data;
#include <vector>
#include <list>
class non_copyable_type
{
public:
static int nb_rvalue_construct;
static int nb_rvalue_assignment;
static int nb_destructs;
non_copyable_type(const non_copyable_type&) = delete;
non_copyable_type& operator=(const non_copyable_type&) = delete;
~non_copyable_type() {
nb_destructs++;
}
non_copyable_type(non_copyable_type&& rhs)
{
value_ = rhs.value_;
rhs.value_ = -1;
nb_rvalue_construct++;
}
non_copyable_type& operator=(non_copyable_type&& rhs) {
value_ = rhs.value_;
rhs.value_ = -1;
nb_rvalue_assignment++;
return *this;
}
explicit non_copyable_type(const int value)
{
value_ = value;
}
friend std::ostream& operator<<(std::ostream& ost, const non_copyable_type& rhs)
{
ost << "non_copyable_type: " << rhs.value_ << std::endl;
return ost;
}
int get() const {
return value_;
}
private:
int value_;
};
int non_copyable_type::nb_rvalue_construct = 0;
int non_copyable_type::nb_rvalue_assignment = 0;
int non_copyable_type::nb_destructs = 0;
// Dataset generating a Fibonacci sequence
// The return type is either a regular int or a non-movable type
template <class return_t = int>
class fibonacci_dataset {
public:
static const int arity = 1;
struct iterator {
iterator() : a(1), b(1) {}
return_t operator*() const { return return_t(b); }
void operator++()
{
a = a + b;
std::swap(a, b);
}
private:
int a;
int b; // b is the output
};
fibonacci_dataset() {}
// size is infinite
bdata::size_t size() const { return bdata::BOOST_TEST_DS_INFINITE_SIZE; }
// iterator
iterator begin() const { return iterator(); }
};
namespace boost { namespace unit_test { namespace data { namespace monomorphic {
// registering fibonacci_dataset as a proper dataset
template <>
struct is_dataset< fibonacci_dataset<int> > : boost::mpl::true_ {};
template <>
struct is_dataset< fibonacci_dataset<non_copyable_type> > : boost::mpl::true_ {};
}}}}
// Creating a test-driven dataset
BOOST_DATA_TEST_CASE(
test1,
fibonacci_dataset<int>() ^ bdata::make( { 1, 2, 3, 5, 8, 13, 21, 34, 55 } ),
fib_sample, exp)
{
BOOST_TEST(fib_sample == exp);
}
BOOST_DATA_TEST_CASE(
test2,
fibonacci_dataset<non_copyable_type>() ^ bdata::make( { 1, 2, 3, 5, 8, 13, 21, 34, 55 } ),
fib_sample, exp)
{
BOOST_TEST(fib_sample.get() == exp);
}
//____________________________________________________________________________//
// EOF

View File

@@ -0,0 +1,81 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// Tests C array based dataset
// ***************************************************************************
// Boost.Test
#include <boost/test/unit_test.hpp>
#include <boost/test/data/monomorphic/array.hpp>
#include <boost/test/data/for_each_sample.hpp>
namespace data=boost::unit_test::data;
#include "datasets-test.hpp"
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_array )
{
int arr1[] = {1,2,3};
BOOST_TEST( data::make( arr1 ).size() == 3 );
double const arr2[] = {7.4,3.2};
BOOST_TEST( data::make( arr2 ).size() == 2 );
bool arr3[] = {true, true, false};
BOOST_TEST( data::make( arr3 ).size() == 3 );
typedef bool (arr_type)[3];
arr_type const& arr3_ref = arr3;
BOOST_TEST( data::make( arr3_ref ).size() == 3 );
int arr4[] = {7,11,13,17};
data::for_each_sample( data::make( arr4 ), check_arg_type<int>() );
int c = 0;
int* ptr4 = arr4;
data::for_each_sample( data::make( arr4 ), [&c,ptr4](int i) {
BOOST_TEST( i == ptr4[c++] );
});
data::for_each_sample( data::make( arr4 ), expected_call_count{ 4 } );
data::for_each_sample( data::make( arr4 ), expected_call_count{ 2 }, 2 );
data::for_each_sample( data::make( arr4 ), expected_call_count{ 0 }, 0 );
copy_count::value() = 0;
copy_count arr5[] = { copy_count(), copy_count() };
data::for_each_sample( data::make( arr5 ), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
copy_count const arr6[] = { copy_count(), copy_count() };
data::for_each_sample( data::make( arr6 ), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_array_make_type )
{
int arr1[] = {1,2,3};
typedef int (&arr_t)[3];
BOOST_STATIC_ASSERT(( boost::is_array< boost::remove_reference<arr_t>::type >::value ) );
typedef data::result_of::make<int (&)[3]>::type dataset_array_type;
dataset_array_type res = data::make( arr1 );
BOOST_TEST( res.size() == 3 );
double const arr2[] = {7.4,3.2};
typedef data::result_of::make<double const (&)[2]>::type dataset_array_double_type;
dataset_array_double_type res2 = data::make( arr2 );
BOOST_TEST( res2.size() == 2 );
}
// EOF

View File

@@ -0,0 +1,159 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : tests stl collection based dataset
// ***************************************************************************
// Boost.Test
#include <boost/test/data/monomorphic/singleton.hpp>
#include <boost/test/data/monomorphic/collection.hpp>
#include <boost/test/data/for_each_sample.hpp>
#include <boost/test/unit_test.hpp>
namespace utf=boost::unit_test;
namespace data=utf::data;
#include "datasets-test.hpp"
#include <vector>
#include <list>
//____________________________________________________________________________//
template <typename>
struct forwarded_to_collection : std::false_type {};
template <typename T>
struct forwarded_to_collection< data::monomorphic::collection<T> > : std::true_type {};
BOOST_AUTO_TEST_CASE( test_forwarded_to_collection)
{
{
std::vector<int> samples1;
BOOST_TEST(boost::unit_test::is_container_forward_iterable<decltype(samples1)>::value, "forward iterable");
BOOST_TEST((forwarded_to_collection<decltype(data::make( samples1 ))>::value),
"not properly forwarded to a collection");
}
{
int samples1(0);
boost::ignore_unused( samples1 );
BOOST_TEST(!boost::unit_test::is_container_forward_iterable<decltype(samples1)>::value, "forward iterable");
BOOST_TEST(!(forwarded_to_collection<decltype(data::make( samples1 ))>::value),
"not properly forwarded to a collection");
}
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_collection_sizes )
{
BOOST_TEST( data::make( std::vector<int>() ).size() == 0 );
BOOST_TEST( data::make( std::vector<int>( 3 ) ).size() == 3 );
BOOST_TEST( data::make( std::list<double>() ).size() == 0 );
BOOST_TEST( data::make( std::list<double>( 2 ) ).size() == 2 );
data::for_each_sample( data::make( std::vector<int>( 3 ) ), check_arg_type<int>() );
data::for_each_sample( data::make( std::list<double>( 2 ) ), check_arg_type<double>() );
invocation_count ic;
ic.m_value = 0;
data::for_each_sample( data::make( std::vector<int>( 3 ) ), ic );
BOOST_TEST( ic.m_value == 3 );
ic.m_value = 0;
data::for_each_sample( data::make( std::list<double>( 2 ) ), ic, 4 );
BOOST_TEST( ic.m_value == 2 );
ic.m_value = 0;
data::for_each_sample( data::make( std::vector<int>( 3 ) ), ic, 1 );
BOOST_TEST( ic.m_value == 1 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_collection )
{
std::vector<int> samples1;
samples1.push_back(5);
samples1.push_back(567);
samples1.push_back(13);
int c = 0;
data::for_each_sample( data::make( samples1 ), [&c,samples1](int i) {
BOOST_TEST( i == samples1[c++] );
});
std::list<char const*> samples2;
samples2.push_back("sd");
samples2.push_back("bg");
samples2.push_back( "we3eq3" );
auto it = samples2.begin();
data::for_each_sample( data::make( samples2 ), [&it](char const* str ) {
BOOST_TEST( str == *it++ );
});
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_collection_copies )
{
// number of copies due to the dataset make
int exp_copy_count = 0;
// number of copies due to the vector constructor
copy_count::value() = 0;
int std_vector_constructor_count = 0;
{
std::vector<copy_count> v(2); // we cannot do better than std::vector constructor
std_vector_constructor_count = copy_count::value()/2;
}
copy_count::value() = 0;
int std_list_constructor_count = 0;
{
std::list<copy_count> v(2); // we cannot do better than std::vector constructor
std_list_constructor_count = copy_count::value()/2;
}
copy_count::value() = 0;
data::for_each_sample( data::make( std::vector<copy_count>( 2 ) ), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == (exp_copy_count + std_vector_constructor_count) * 2);
copy_count::value() = 0;
std::vector<copy_count> samples3( 2 );
data::for_each_sample( data::make( samples3 ), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == (exp_copy_count + std_vector_constructor_count) * 2);
copy_count::value() = 0;
std::vector<copy_count> const samples4( 2 );
data::for_each_sample( data::make( samples4 ), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == (exp_copy_count + std_vector_constructor_count) * 2);
copy_count::value() = 0;
auto ds1 = data::make( make_copy_count_collection() );
BOOST_TEST( ds1.size() == 3 );
BOOST_TEST( copy_count::value() == (exp_copy_count + std_vector_constructor_count) * 3);
data::for_each_sample( ds1, check_arg_type<copy_count>() );
copy_count::value() = 0;
auto ds2 = data::make( make_copy_count_const_collection() );
BOOST_TEST( ds2.size() == 3 );
data::for_each_sample( ds2, check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == (exp_copy_count + std_list_constructor_count + 1) * 3 ); // no rvalue constructor for the dataset
}
//____________________________________________________________________________//
// EOF

View File

@@ -0,0 +1,207 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : datasets test helpers
// ***************************************************************************
#ifndef BOOST_TEST_TEST_DATASETS_HPP
#define BOOST_TEST_TEST_DATASETS_HPP
// Boost
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_convertible.hpp>
#include <iostream>
#include <vector>
#include <list>
//____________________________________________________________________________//
class copy_count {
public:
copy_count() {}
copy_count( copy_count const& ) {
value()++;
}
copy_count( copy_count&& ) BOOST_NOEXCEPT_OR_NOTHROW {} // noexcept is important indeed
copy_count( copy_count const&& ) {}
// ~copy_count() { std::cout << "~copy_count" << std::endl; }
static int& value() { static int s_value; return s_value; };
static copy_count make() { return copy_count(); }
static copy_count const make_const() { return copy_count(); }
};
//____________________________________________________________________________//
template<typename T>
struct check_arg_type {
template<typename S>
void operator()( S const& ) const
{
BOOST_CHECK_MESSAGE( (boost::is_same<S,T>::value), "Sample type does not match expected" );
}
};
//____________________________________________________________________________//
template<typename T1, typename T2>
struct check_arg_type<std::tuple<T1,T2>> {
template<typename S1, typename S2>
void operator()( S1 const&, S2 const& ) const
{
BOOST_CHECK_MESSAGE( (boost::is_same<S1,T1>::value), "S1 type does not match expected" );
BOOST_CHECK_MESSAGE( (boost::is_same<S2,T2>::value), "S2 type does not match expected" );
}
};
//____________________________________________________________________________//
template<typename T1, typename T2, typename T3>
struct check_arg_type<std::tuple<T1,T2,T3>> {
template<typename S1, typename S2, typename S3>
void operator()( S1 const&, S2 const&, S3 const& ) const
{
BOOST_CHECK_MESSAGE( (boost::is_same<S1,T1>::value), "S1 type does not match expected" );
BOOST_CHECK_MESSAGE( (boost::is_same<S2,T2>::value), "S2 type does not match expected" );
BOOST_CHECK_MESSAGE( (boost::is_same<S3,T3>::value), "S3 type does not match expected" );
}
};
//____________________________________________________________________________//
template<typename T>
struct check_arg_type_like {
template<typename S>
void operator()( S const& ) const
{
BOOST_CHECK_MESSAGE( (boost::is_convertible<S,T>::value), "Sample type does not match expected" );
}
};
//____________________________________________________________________________//
template<typename T1, typename T2>
struct check_arg_type_like<std::tuple<T1,T2>> {
template<typename S1, typename S2>
void operator()( S1 const&, S2 const& ) const
{
BOOST_CHECK_MESSAGE( (boost::is_convertible<S1,T1>::value), "S1 type does not match expected" );
BOOST_CHECK_MESSAGE( (boost::is_convertible<S2,T2>::value), "S2 type does not match expected" );
}
};
//____________________________________________________________________________//
template<typename T1, typename T2, typename T3>
struct check_arg_type_like<std::tuple<T1,T2,T3>> {
template<typename S1, typename S2, typename S3>
void operator()( S1 const&, S2 const&, S3 const& ) const
{
BOOST_CHECK_MESSAGE( (boost::is_convertible<S1,T1>::value), "S1 type does not match expected" );
BOOST_CHECK_MESSAGE( (boost::is_convertible<S2,T2>::value), "S2 type does not match expected" );
BOOST_CHECK_MESSAGE( (boost::is_convertible<S3,T3>::value), "S3 type does not match expected" );
}
};
//____________________________________________________________________________//
struct invocation_count {
invocation_count() : m_value( 0 ) {}
template<typename S>
void operator()( S const& ) const
{
m_value++;
}
template<typename S1,typename S2>
void operator()( S1 const&, S2 const& ) const
{
m_value++;
}
template<typename S1,typename S2,typename S3>
void operator()( S1 const&, S2 const&, S3 const& ) const
{
m_value++;
}
mutable int m_value;
private:
invocation_count(invocation_count const&);
};
//____________________________________________________________________________//
struct expected_call_count {
explicit expected_call_count( int exp_count )
: m_call_count( 0 )
, m_exp_count( exp_count )
{}
expected_call_count(expected_call_count const&) = delete;
void operator=(expected_call_count const&) = delete;
~expected_call_count()
{
BOOST_TEST( m_exp_count == m_call_count );
}
template<typename S>
void operator()( S const& ) const
{
m_call_count++;
}
template<typename S1,typename S2>
void operator()( S1 const&, S2 const& ) const
{
m_call_count++;
}
template<typename S1,typename S2,typename S3>
void operator()( S1 const&, S2 const&, S3 const& ) const
{
m_call_count++;
}
mutable int m_call_count;
int m_exp_count;
};
//____________________________________________________________________________//
struct print_sample {
template<typename T>
void operator()( T const& sample ) const
{
std::cout << "S has type: " << typeid(T).name() << " and value " << sample << std::endl;
}
};
//____________________________________________________________________________//
inline std::vector<copy_count>
make_copy_count_collection()
{
return std::vector<copy_count>( 3 );
}
//____________________________________________________________________________//
inline std::list<copy_count> const
make_copy_count_const_collection()
{
return std::list<copy_count>( 3 );
}
//____________________________________________________________________________//
#endif // BOOST_TEST_TEST_DATASETS_HPP

View File

@@ -0,0 +1,82 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : tests implicit interfaces
// ***************************************************************************
// Boost.Test
#include <boost/test/unit_test.hpp>
#include <boost/test/data/monomorphic.hpp>
#include <boost/test/data/for_each_sample.hpp>
namespace data=boost::unit_test::data;
#include "datasets-test.hpp"
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_implicit_for_each )
{
data::for_each_sample( 2, check_arg_type<int>() );
data::for_each_sample( "ch", check_arg_type<char const*>() );
data::for_each_sample( 2., check_arg_type<double>() );
data::for_each_sample( std::vector<int>( 3 ), check_arg_type<int>() );
data::for_each_sample( std::list<double>( 2 ), check_arg_type<double>() );
invocation_count ic;
ic.m_value = 0;
data::for_each_sample( std::vector<int>( 3 ), ic );
BOOST_TEST( ic.m_value == 3 );
ic.m_value = 0;
data::for_each_sample( std::list<double>( 2 ), ic, 1 );
BOOST_TEST( ic.m_value == 1 );
std::vector<copy_count> samples1( 2 );
copy_count::value() = 0; // we do not test the construction of the vector
data::for_each_sample( samples1, check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
copy_count samples2[] = { copy_count(), copy_count() };
data::for_each_sample( samples2, check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_implicit_join )
{
auto ds = data::make( 5 );
BOOST_TEST( (1 + ds).size() == 2 );
BOOST_TEST( (ds + 1).size() == 2 );
BOOST_TEST( (1 + data::make( 5 )).size() == 2 );
BOOST_TEST( (data::make( 5 ) + 1).size() == 2 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_implicit_zip )
{
auto ds = data::make( 5 );
BOOST_TEST( (1 ^ ds).size() == 1 );
BOOST_TEST( (ds ^ 1).size() == 1 );
BOOST_TEST( (1 ^ data::make( 5 )).size() == 1 );
BOOST_TEST( (data::make( 5 ) ^ 1).size() == 1 );
}
//____________________________________________________________________________//
// EOF

View File

@@ -0,0 +1,76 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// Tests C array based dataset
// ***************************************************************************
// Boost.Test
#include <boost/test/unit_test.hpp>
#include <boost/test/data/monomorphic/initializer_list.hpp>
#include <boost/test/data/monomorphic/singleton.hpp>
#include <boost/test/data/for_each_sample.hpp>
namespace data=boost::unit_test::data;
#include "datasets-test.hpp"
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_initializer_list )
{
BOOST_TEST( data::make( {1,2,3} ).size() == 3 );
BOOST_TEST( data::make( {7.4,3.2} ).size() == 2 );
BOOST_TEST( data::make( {true, true, false} ).size() == 3 );
data::for_each_sample( data::make( {7,11,13,17} ), check_arg_type<int>() );
int c = 0;
int exp[] = {7,11,13,17};
data::for_each_sample( data::make( {7,11,13,17} ), [&c,&exp](int i) {
BOOST_TEST( i == exp[c++] );
});
data::for_each_sample( data::make( {1,2,3,4} ), expected_call_count{ 4 } );
data::for_each_sample( data::make( {1,2,3,4} ), expected_call_count{ 2 }, 2 );
data::for_each_sample( data::make( {1,2,3,4} ), expected_call_count{ 0 }, 0 );
copy_count::value() = 0;
data::for_each_sample( data::make( { copy_count(), copy_count() } ), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 2 ); // this is copied in this case, because of the initializer_list
}
#ifndef BOOST_TEST_ERRONEOUS_INIT_LIST
BOOST_AUTO_TEST_CASE( test_initializer_list_variadic_template )
{
BOOST_TEST( data::make( 1,2,3 ).size() == 3 );
BOOST_TEST( data::make( 7.4,3.2 ).size() == 2 );
BOOST_TEST( data::make( true, true, false ).size() == 3 );
data::for_each_sample( data::make( 7,11,13,17 ), check_arg_type<int>() );
int c = 0;
int exp[] = {7,11,13,17};
data::for_each_sample( data::make( 7,11,13,17 ), [&c,&exp](int i) {
BOOST_TEST( i == exp[c++] );
});
data::for_each_sample( data::make( 1,2,3,4 ), expected_call_count{ 4 } );
data::for_each_sample( data::make( 1,2,3,4 ), expected_call_count{ 2 }, 2 );
data::for_each_sample( data::make( 1,2,3,4 ), expected_call_count{ 0 }, 0 );
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count(), copy_count() ), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
}
#endif
// EOF

View File

@@ -0,0 +1,187 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// @brief tests monomorphic grid
// ***************************************************************************
// Boost.Test
#include <boost/test/unit_test.hpp>
#include <boost/test/data/monomorphic/grid.hpp>
#include <boost/test/data/monomorphic/singleton.hpp>
#include <boost/test/data/monomorphic/array.hpp>
#include <boost/test/data/monomorphic/collection.hpp>
#include <boost/test/data/monomorphic/generators/xrange.hpp>
#include <boost/test/data/for_each_sample.hpp>
namespace data = boost::unit_test::data;
#include "datasets-test.hpp"
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_mono_grid_size_and_composition )
{
BOOST_TEST( (data::make( 1 ) * data::make( 5 )).size() == 1 );
BOOST_TEST( (data::make( std::vector<int>(2) ) * data::make( std::list<float>(2) )).size() == 4 );
BOOST_TEST( (data::make( std::vector<int>(2) ) * data::make( 5. )).size() == 2 );
BOOST_TEST( (data::make( std::vector<int>(3) ) * data::make( std::list<int>(1) )).size() == 3 );
BOOST_TEST( (data::make( std::vector<int>(3) ) * data::make( std::list<std::string>(3) ) * data::make( 5 )).size() == 9 );
BOOST_TEST( (data::make( std::vector<int>(1) ) * data::make( std::list<int>(3) ) * data::make( 5 )).size() == 3 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_mono_grid_with_xrange )
{
auto ds1 = data::make(1);
auto ds2 = data::xrange(5);
BOOST_TEST( (ds1 * ds2).size() == 5 );
BOOST_TEST( (ds1 * ds2).size() == 5 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_mono_grid_cpp11_features )
{
int arr1[] = {1,2};
char const* arr2[] = {"a","b"};
int* exp1 = arr1;
char const** exp2 = arr2;
invocation_count ic;
auto samples1 = data::make( arr1 ) * data::make( arr2 );
BOOST_TEST( samples1.size() == 4 );
ic.m_value = 0;
data::for_each_sample( samples1, ic );
BOOST_TEST( ic.m_value == 4 );
data::for_each_sample( samples1, check_arg_type_like<std::tuple<int,char const*>>() );
int c = 0;
data::for_each_sample( samples1, [&c,exp1,exp2](int i,char const* s) {
BOOST_TEST( i == exp1[c/2] );
BOOST_TEST( s == exp2[c%2] );
++c;
});
std::vector<double> vec1;
vec1.push_back(2.1);
vec1.push_back(3.2);
vec1.push_back(4.7);
int arr3[] = {4,2,1};
auto samples2 = data::make( vec1 ) * data::make( "qqq" ) * data::make( arr3 );
BOOST_TEST( samples2.size() == 9 );
ic.m_value = 0;
data::for_each_sample( samples2, ic );
BOOST_TEST( ic.m_value == 9 );
data::for_each_sample( samples2, check_arg_type_like<std::tuple<double,char const*,int>>() );
int* exp3 = arr3;
c = 0;
data::for_each_sample( samples2, [&c,&vec1,exp3](double a1,char const* a2,int a3) {
BOOST_TEST( a1 == vec1[c/3] );
BOOST_TEST( a2 == "qqq" );
BOOST_TEST( a3 == exp3[c%3] );
++c;
});
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_mono_grid_number_of_copies )
{
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count() ) * data::make( copy_count() ), check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count() ) * data::make( copy_count() ) * data::make( copy_count() ),
check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count() ) * (data::make( copy_count() ) * data::make( copy_count() )),
check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_mono_grid_number_of_copies_auto )
{
auto ds1 = data::make( copy_count() );
auto const ds2 = data::make( copy_count() );
copy_count::value() = 0;
data::for_each_sample( ds1 * ds1, check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( ds2 * ds2, check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( ds1 * ds2, check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
auto zp1 = ds1 * data::make( copy_count() );
BOOST_TEST( zp1.size() == 1 );
data::for_each_sample( zp1, check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count() ) * ds1, check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( ds1 * ds2 * ds1, check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( ds1 * (ds1 * ds2), check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
int std_vector_constructor_count = 0;
{
std::vector<copy_count> v(2); // we cannot do better than std::vector constructor
std_vector_constructor_count = copy_count::value()/2;
}
copy_count::value() = 0;
auto ds3 = data::make( make_copy_count_collection() ) * data::make( make_copy_count_collection() );
BOOST_TEST( ds3.size() == 9 );
data::for_each_sample( ds3, check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == std_vector_constructor_count *2 *3);
}
BOOST_AUTO_TEST_CASE( test_mono_grid_variadic_dimension )
{
// tests that the grid dimension can be > 3
BOOST_TEST( (data::make( 1 ) * data::make( 5 ) * data::make( 1 )).size() == 1 );
BOOST_TEST( (data::make( 1 ) * data::make( 5 ) * data::make( 1 ) * data::make( 1 )).size() == 1 );
BOOST_TEST( (data::xrange(2) * data::xrange(2) * data::xrange(2) * data::xrange(2)).size() == (1 << 4));
}
//____________________________________________________________________________//
// EOF

View File

@@ -0,0 +1,158 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// @brief tests monomorphic join
// ***************************************************************************
// Boost.Test
#include <boost/test/unit_test.hpp>
#include <boost/test/data/monomorphic/join.hpp>
#include <boost/test/data/monomorphic/singleton.hpp>
#include <boost/test/data/monomorphic/array.hpp>
#include <boost/test/data/monomorphic/collection.hpp>
#include <boost/test/data/monomorphic/fwd.hpp>
#include <boost/test/data/for_each_sample.hpp>
namespace data=boost::unit_test::data;
#include <boost/test/data/test_case.hpp>
#include "datasets-test.hpp"
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_mono_join )
{
BOOST_TEST( (data::make( 1 ) + data::make( 5 )).size() == 2 );
BOOST_TEST( (data::make( std::vector<int>(2) ) + data::make( std::list<int>(3) )).size() == 5 );
int arr1[] = {1,2};
int arr2[] = {7,19};
BOOST_TEST( (data::make( arr1 ) + data::make( arr2 )).size() == 4 );
BOOST_TEST( (data::make( 1 ) + data::make( 5 ) + data::make( 19 )).size() == 3 );
BOOST_TEST( (data::make( std::vector<int>(2) ) + data::make( 1 ) + data::make( arr2 ) + data::make( 17 )).size() == 6 );
int expected[] = {1,2,5,7,19,37};
int* exp = expected;
int c = 0;
invocation_count ic;
auto samples1 = data::make( std::vector<int>(arr1,arr1+2) ) + data::make( 5 ) + data::make( arr2 ) + data::make( 37 );
ic.m_value = 0;
data::for_each_sample( samples1, ic );
BOOST_TEST( ic.m_value == 6 );
c = 0;
data::for_each_sample( samples1, [&c,exp](int i) {
BOOST_TEST( i == exp[c++] );
});
auto samples2 = data::make( std::vector<int>(arr1,arr1+2) ) + (data::make( 5 ) + (data::make( arr2 ) + data::make( 37 )));
ic.m_value = 0;
data::for_each_sample( samples2, ic );
BOOST_TEST( ic.m_value == 6 );
c = 0;
data::for_each_sample( samples2, [&c,exp](int i) {
BOOST_TEST( i == exp[c++] );
});
auto samples3 = (data::make( std::vector<int>(arr1,arr1+2) ) + data::make( 5 )) + (data::make( arr2 ) + data::make( 37 ));
ic.m_value = 0;
data::for_each_sample( samples3, ic );
BOOST_TEST( ic.m_value == 6 );
c = 0;
data::for_each_sample( samples3, [&c,exp](int i) {
BOOST_TEST( i == exp[c++] );
});
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count() ) + data::make( copy_count() ), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count() ) + data::make( copy_count() ) + data::make( copy_count() ), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count() ) + (data::make( copy_count() ) + data::make( copy_count() )), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( (data::make( copy_count() ) + data::make( copy_count() )) +
(data::make( copy_count() ) + data::make( copy_count() )), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
auto ds1 = data::make( copy_count() );
auto const ds2 = data::make( copy_count() );
copy_count::value() = 0;
data::for_each_sample( ds1 + ds1, check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( ds2 + ds2, check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( ds1 + ds2, check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
auto jn1 = ds1 + data::make( copy_count() );
data::for_each_sample( jn1, check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count() ) + ds1, check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( ds1 + ds2 + ds1, check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( ds1 + (ds1 + ds2), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( (ds1 + ds1) + (ds2 + ds2), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
int std_vector_constructor_count = 0;
{
std::vector<copy_count> v(2); // we cannot do better than std::vector constructor
std_vector_constructor_count = copy_count::value()/2;
}
copy_count::value() = 0;
auto ds3 = data::make( make_copy_count_collection() ) + data::make( make_copy_count_collection() );
BOOST_TEST( ds3.size() == 6 );
data::for_each_sample( ds3, check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == std_vector_constructor_count * 2 * 3 );
}
//____________________________________________________________________________//
// ticket 13380
// note that the test relies on the fact that the references to temporaries are properly
// escalated as errors. Currently only on clang.
BOOST_DATA_TEST_CASE(
sampleTest,
(data::make(1) ^ data::make(2)) + (data::make(3) ^ data::make(4)),
var1,
var2)
{
std::cout << var1 << "," << var2 << std::endl;
}
// EOF

View File

@@ -0,0 +1,158 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : tests monomorphic zip
// ***************************************************************************
// Boost.Test
#include <boost/test/unit_test.hpp>
#include <boost/test/data/monomorphic/zip.hpp>
#include <boost/test/data/monomorphic/singleton.hpp>
#include <boost/test/data/monomorphic/array.hpp>
#include <boost/test/data/monomorphic/collection.hpp>
#include <boost/test/data/for_each_sample.hpp>
namespace data=boost::unit_test::data;
#include "datasets-test.hpp"
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_mono_zip_sizes )
{
BOOST_TEST( (data::make( 1 ) ^ data::make( 5 )).size() == 1 );
BOOST_TEST( (data::make( std::vector<int>(2) ) ^ data::make( std::list<float>(2) )).size() == 2 );
BOOST_TEST( (data::make( std::vector<int>(2) ) ^ data::make( 5. )).size() == 2 );
BOOST_TEST( (data::make( std::vector<int>(3) ) ^ data::make( std::list<int>(1) )).size() == 3 );
BOOST_TEST( (data::make( std::vector<int>(3) ) ^ data::make( std::list<std::string>(3) ) ^ data::make( 5 )).size() == 3 );
BOOST_TEST( (data::make( std::vector<int>(1) ) ^ data::make( std::list<int>(3) ) ^ data::make( 5 )).size() == 3 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_mono_zip )
{
int arr1[] = {1,2};
char const* arr2[] = {"a","b"};
int* exp1 = arr1;
char const** exp2 = arr2;
int c = 0;
invocation_count ic;
auto samples1 = data::make( arr1 ) ^ data::make( arr2 );
BOOST_TEST( samples1.size() == 2 );
ic.m_value = 0;
data::for_each_sample( samples1, ic );
BOOST_TEST( ic.m_value == 2 );
data::for_each_sample( samples1, check_arg_type_like<std::tuple<int,char const*>>() );
c = 0;
data::for_each_sample( samples1, [&c,exp1,exp2](int i,char const* s) {
BOOST_TEST( i == exp1[c] );
BOOST_TEST( s == exp2[c] );
++c;
});
std::vector<double> vec1;
vec1.push_back(2.1);
vec1.push_back(3.2);
vec1.push_back(4.7);
int arr3[] = {4,2,1};
auto samples2 = data::make( vec1 ) ^ data::make( "qqq" ) ^ data::make( arr3 );
BOOST_TEST( samples2.size() == 3 );
ic.m_value = 0;
data::for_each_sample( samples2, ic );
BOOST_TEST( ic.m_value == 3 );
data::for_each_sample( samples2, check_arg_type_like<std::tuple<double,char const*,int>>() );
c = 0;
int* exp3 = arr3;
data::for_each_sample( samples2, [&c,&vec1,exp3](double a1,char const* a2,int a3) {
BOOST_TEST( a1 == vec1[c] );
BOOST_TEST( a2 == "qqq" );
BOOST_TEST( a3 == exp3[c] );
++c;
});
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count() ) ^ data::make( copy_count() ), check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count() ) ^ data::make( copy_count() ) ^ data::make( copy_count() ),
check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count() ) ^ (data::make( copy_count() ) ^ data::make( copy_count() )),
check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
auto ds1 = data::make( copy_count() );
auto const ds2 = data::make( copy_count() );
copy_count::value() = 0;
data::for_each_sample( ds1 ^ ds1, check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( ds2 ^ ds2, check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( ds1 ^ ds2, check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
auto zp1 = ds1 ^ data::make( copy_count() );
BOOST_TEST( zp1.size() == 1 );
data::for_each_sample( zp1, check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count() ) ^ ds1, check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( ds1 ^ ds2 ^ ds1, check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
data::for_each_sample( ds1 ^ (ds1 ^ ds2), check_arg_type<std::tuple<copy_count,copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == 0 );
copy_count::value() = 0;
int std_vector_constructor_count = 0;
{
std::vector<copy_count> v(2); // we cannot do better than std::vector constructor
std_vector_constructor_count = copy_count::value()/2;
}
copy_count::value() = 0;
auto ds3 = data::make( make_copy_count_collection() ) ^ data::make( make_copy_count_collection() );
BOOST_TEST( ds3.size() == 3 );
data::for_each_sample( ds3, check_arg_type<std::tuple<copy_count,copy_count>>() );
BOOST_TEST( copy_count::value() == std_vector_constructor_count *2 *3 );
}
//____________________________________________________________________________//
// EOF

View File

@@ -0,0 +1,133 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
//! @file
//! @brief tests random dataset
// ***************************************************************************
// Boost.Test
#include <boost/test/unit_test.hpp>
#include <boost/test/data/monomorphic/generators/random.hpp>
#include <boost/test/data/monomorphic/zip.hpp>
#include <boost/test/data/monomorphic/array.hpp>
#include <boost/test/data/monomorphic/grid.hpp>
#include <boost/test/data/for_each_sample.hpp>
namespace data=boost::unit_test::data;
#include "datasets-test.hpp"
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_default )
{
BOOST_TEST( data::random().size() == data::BOOST_TEST_DS_INFINITE_SIZE );
auto ds = data::random();
BOOST_CHECK_THROW( data::for_each_sample( ds, [](double ) {}), std::logic_error );
invocation_count ic;
ic.m_value = 0;
data::for_each_sample( ds, ic, 10 );
BOOST_TEST( ic.m_value == 10 );
ic.m_value = 0;
int arr[] = {1,2,3,4,5};
data::for_each_sample( ds^arr, ic );
BOOST_TEST( ic.m_value == 5 );
BOOST_CHECK_THROW( (ds * arr).size(), std::logic_error );
BOOST_CHECK_THROW( (arr * ds).size(), std::logic_error );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_uniform_range )
{
auto ds1 = data::random(1,5);
data::for_each_sample( ds1, [](int s) {
BOOST_TEST(s>=1);
BOOST_TEST(s<=5);
}, 10);
auto ds2 = data::random(1.,2.);
data::for_each_sample( ds2, [](double s) {
BOOST_TEST(s>=1.);
BOOST_TEST(s<=2.);
}, 100);
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_parameterized_init )
{
auto ds1 = data::random(data::distribution = std::normal_distribution<>(5.,2));
typedef decltype(ds1) DS1;
BOOST_TEST(( std::is_same<DS1::generator_type::distr_type,
std::normal_distribution<>>::value ));
BOOST_TEST(( std::is_same<DS1::generator_type::sample,double>::value ));
BOOST_TEST(( std::is_same<DS1::generator_type::engine_type,
std::default_random_engine>::value ));
auto ds2 = data::random(data::distribution = std::discrete_distribution<>());
typedef decltype(ds2) DS2;
BOOST_TEST(( std::is_same<DS2::generator_type::distr_type,
std::discrete_distribution<>>::value ));
BOOST_TEST(( std::is_same<DS2::generator_type::sample,int>::value ));
BOOST_TEST(( std::is_same<DS2::generator_type::engine_type,
std::default_random_engine>::value ));
auto ds3 = data::random(data::engine = std::minstd_rand());
typedef decltype(ds3) DS3;
BOOST_TEST(( std::is_same<DS3::generator_type::distr_type,
std::uniform_real_distribution<>>::value ));
BOOST_TEST(( std::is_same<DS3::generator_type::sample,double>::value ));
BOOST_TEST(( std::is_same<DS3::generator_type::engine_type,
std::minstd_rand>::value ));
auto ds4 = data::random(data::seed = 100UL);
typedef decltype(ds4) DS4;
BOOST_TEST(( std::is_same<DS4::generator_type::distr_type,
std::uniform_real_distribution<>>::value ));
BOOST_TEST(( std::is_same<DS4::generator_type::sample,double>::value ));
BOOST_TEST(( std::is_same<DS4::generator_type::engine_type,
std::default_random_engine>::value ));
auto ds5 = data::random(data::seed = 100UL);
std::list<double> vals;
data::for_each_sample( ds4, [&vals](double s) {
vals.push_back( s );
}, 10);
data::for_each_sample( ds5, [&vals](double s) {
BOOST_TEST( vals.front() == s );
vals.pop_front();
}, 10);
auto ds6 = data::random(( data::engine = std::minstd_rand(),
data::distribution = std::normal_distribution<>(5.,2),
data::seed = 20UL ));
typedef decltype(ds6) DS6;
BOOST_TEST(( std::is_same<DS6::generator_type::distr_type,
std::normal_distribution<>>::value ));
BOOST_TEST(( std::is_same<DS6::generator_type::sample,double>::value ));
BOOST_TEST(( std::is_same<DS6::generator_type::engine_type,
std::minstd_rand>::value ));
}
//____________________________________________________________________________//
// EOF

View File

@@ -0,0 +1,64 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// Tests C array based dataset
// ***************************************************************************
// Boost.Test
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
namespace data=boost::unit_test::data;
#include "datasets-test.hpp"
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_seed_with_singleton )
{
BOOST_TEST( (data::ds_detail::seed{} ->* 1).size() == 1 );
struct TT {};
BOOST_TEST( (data::ds_detail::seed{} ->* TT{}).size() == 1 );
int arr[] = {1,2,3};
BOOST_TEST( (data::ds_detail::seed{} ->* arr).size() == 3 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_seed_with_zip )
{
int arr[] = {1,2,3};
BOOST_TEST( (data::ds_detail::seed{} ->* 1 ^ arr).size() == 3 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_seed_with_join )
{
int arr[] = {1,2,3};
BOOST_TEST( (data::ds_detail::seed{} ->* 1 + arr).size() == 4 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_seed_with_grid )
{
int arr1[] = {1,2,3};
int arr2[] = {1,2,3};
BOOST_TEST( (data::ds_detail::seed{} ->* arr1 * arr2).size() == 9 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_seed_with_init_list )
{
BOOST_TEST( (data::ds_detail::seed{} ->* data::make({1,2,3})).size() == 3 );
}
// EOF

View File

@@ -0,0 +1,79 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// @brief tests singleton dataset
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/test/data/monomorphic/singleton.hpp>
#include <boost/test/data/for_each_sample.hpp>
namespace data=boost::unit_test::data;
#include "datasets-test.hpp"
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_singleton )
{
BOOST_TEST( data::make( 1 ).size() == 1 );
BOOST_TEST( data::make( 2.3 ).size() == 1 );
BOOST_TEST( data::make( "1" ).size() == 1 );
data::for_each_sample( data::make( 2 ), check_arg_type<int>() );
data::for_each_sample( data::make( "ch" ), check_arg_type<char const*>() );
data::for_each_sample( data::make( 2. ), check_arg_type<double>() );
invocation_count ic;
ic.m_value = 0;
data::for_each_sample( data::make( 2 ), ic );
BOOST_TEST( ic.m_value == 1 );
ic.m_value = 0;
data::for_each_sample( data::make( 2 ), ic, 2 );
BOOST_TEST( ic.m_value == 1 );
ic.m_value = 0;
data::for_each_sample( data::make( 2 ), ic, 0 );
BOOST_TEST( ic.m_value == 0 );
data::for_each_sample( data::make( 2 ), [] (int s) {
BOOST_TEST( s == 2 );
});
int exp_copy_count = 0;
copy_count::value() = 0;
data::for_each_sample( data::make( copy_count() ), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == exp_copy_count );
copy_count::value() = 0;
copy_count cc1;
data::for_each_sample( data::make( cc1 ), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == exp_copy_count );
copy_count::value() = 0;
copy_count const cc2;
data::for_each_sample( data::make( cc2 ), check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == exp_copy_count );
copy_count::value() = 0;
auto ds1 = data::make( copy_count::make() );
data::for_each_sample( ds1, check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == exp_copy_count );
copy_count::value() = 0;
auto ds2 = data::make( copy_count::make_const() );
data::for_each_sample( ds2, check_arg_type<copy_count>() );
BOOST_TEST( copy_count::value() == exp_copy_count );
}
//____________________________________________________________________________//
// EOF

View File

@@ -0,0 +1,215 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : tests singleton dataset
// ***************************************************************************
// Boost.Test
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>
namespace data=boost::unit_test::data;
#include "datasets-test.hpp"
//____________________________________________________________________________//
int samples1[] = {1,2,3};
int index1 = 0;
BOOST_DATA_TEST_CASE( test_case_interface_01, data::make({1,2,3}) )
{
BOOST_TEST( sample == samples1[index1++] );
}
//____________________________________________________________________________//
std::vector<std::string> samples2 = {"qwerty","asdfg"};
int index2 = 0;
BOOST_DATA_TEST_CASE( test_case_interface_02, samples2, str )
{
BOOST_TEST( str == samples2[index2++] );
}
//____________________________________________________________________________//
int samples3[] = {7,9};
int index3 = 0;
BOOST_DATA_TEST_CASE( test_case_interface_03, data::make({1,2,3}) + samples3, val )
{
if( index3 < 3 )
BOOST_TEST( val == samples1[index3] );
else
BOOST_TEST( val == samples3[index3-3] );
++index3;
}
//____________________________________________________________________________//
int index4 = 0;
BOOST_DATA_TEST_CASE( test_case_interface_04, samples2 ^ data::make({7,9}), str, intval )
{
BOOST_TEST( str == samples2[index4] );
BOOST_TEST( intval == samples3[index4] );
++index4;
}
//____________________________________________________________________________//
int index5 = 0;
BOOST_DATA_TEST_CASE( test_case_interface_05, samples1 * samples2, sample0, sample1 )
{
BOOST_TEST( sample0 == samples1[index5/2] );
BOOST_TEST( sample1 == samples2[index5%2] );
++index5;
}
//____________________________________________________________________________//
int index6 = 0;
BOOST_DATA_TEST_CASE( test_case_interface_06, samples1 * samples2 * samples3, intval, str, val2 )
{
BOOST_TEST( intval == samples1[index6/4] );
BOOST_TEST( str == samples2[(index6/2)%2] );
BOOST_TEST( val2 == samples3[index6%2] );
++index6;
}
//____________________________________________________________________________//
// test dataset dim > 3
int index7 = 0;
float samples4[] = {1E3f, 1E-3f, 3.14f};
#define sizeoftable(x) (sizeof(x)/sizeof(x[0]))
BOOST_DATA_TEST_CASE( test_case_interface_07, samples1 * samples2 * samples3 * samples4, intval, str, val2, floatval )
{
BOOST_TEST_CONTEXT("index7 " << index7) {
BOOST_TEST( intval == samples1[index7/(sizeoftable(samples4)*sizeoftable(samples3)*samples2.size())] );
BOOST_TEST( str == samples2[(index7/(sizeoftable(samples4)*sizeoftable(samples3)))%samples2.size()] );
BOOST_TEST( val2 == samples3[(index7/sizeoftable(samples4))%sizeoftable(samples3)] );
BOOST_TEST( floatval == samples4[index7%sizeoftable(samples4)] );
}
++index7;
}
//____________________________________________________________________________//
static int index8 = 1;
struct SharedFixture {
SharedFixture()
: m_expected(index8++)
{
}
int m_expected;
};
BOOST_DATA_TEST_CASE_F( SharedFixture, test_case_interface_08, data::make({1,2,3}) )
{
BOOST_TEST( sample == m_expected );
}
//____________________________________________________________________________//
BOOST_DATA_TEST_CASE(test_case_interface_correct_file_line_declaration, samples2)
{
boost::unit_test::test_case const& current_test_case = boost::unit_test::framework::current_test_case();
BOOST_TEST(current_test_case.p_line_num == 136);
BOOST_TEST(current_test_case.p_file_name == __FILE__);
}
//____________________________________________________________________________//
// ticket 13443
BOOST_DATA_TEST_CASE(
test_arity_above_9,
data::make( { 1, 2, 3, 5 } ) ^
data::make( { 1, 2, 3, 5 } ) ^
data::make( { 1, 2, 3, 5 } ) ^
data::make( { 1, 2, 3, 5 } ) ^
data::make( { 1, 2, 3, 5 } ) ^
data::make( { 1, 2, 3, 5 } ) ^
data::make( { 1, 2, 3, 5 } ) ^
data::make( { 1, 2, 3, 5 } ) ^
data::make( { 1, 2, 3, 5 } ) ^
data::make( { 1, 2, 3, 5 } ),
sample1, sample2, sample3, sample4, sample5, sample6, sample7, sample8, sample9, sample10)
{
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_has_dataset )
{
using t1 = decltype(data::make( 1 ));
BOOST_TEST((data::monomorphic::has_dataset<t1>::value));
BOOST_TEST((data::monomorphic::has_dataset<int, t1>::value));
BOOST_TEST((!data::monomorphic::has_dataset<int, float>::value));
}
//____________________________________________________________________________//
static int index_fixture_setup_teardown = 0;
struct SharedFixtureSetupTeardown {
SharedFixtureSetupTeardown()
: m_expected(1 + index_fixture_setup_teardown)
{}
void setup() {
m_expected *= m_expected;
}
void teardown() {
index_fixture_setup_teardown++;
}
int m_expected;
};
BOOST_DATA_TEST_CASE_F( SharedFixtureSetupTeardown, test_case_interface_setup_teardown, data::make({0,1,2,3}) )
{
BOOST_TEST( sample == index_fixture_setup_teardown );
BOOST_TEST( m_expected == (1+sample)*(1+sample));
}
//____________________________________________________________________________//
// GH-217
#ifndef BOOST_TEST_ERRONEOUS_INIT_LIST
const bool ExpectedValues[] = { false, true, true, true, false, false};
BOOST_DATA_TEST_CASE(BoostDataTest
, boost::unit_test::data::make({ false, true, true, true, false, false }) ^
boost::unit_test::data::make(ExpectedValues)
, value, expectedValue)
{
BOOST_TEST(value == expectedValue);
}
#endif
// EOF

View File

@@ -0,0 +1,88 @@
// (C) Copyright Gennadiy Rozental 2011-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : tests singleton dataset
// ***************************************************************************
// Boost.Test
#include <boost/test/unit_test.hpp>
#include <boost/test/data/monomorphic/generators/xrange.hpp>
#include <boost/test/data/monomorphic/join.hpp>
#include <boost/test/data/for_each_sample.hpp>
namespace data=boost::unit_test::data;
#include "datasets-test.hpp"
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_single_range )
{
BOOST_TEST( data::xrange( 5 ).size() == 5 );
BOOST_TEST( data::xrange( 3. ).size() == 3 );
BOOST_CHECK_THROW( data::xrange( -5 ), std::logic_error );
BOOST_CHECK_THROW( data::xrange( 0 ), std::logic_error );
BOOST_TEST( data::xrange( 1, 5 ).size() == 4 );
BOOST_TEST( data::xrange( -5, 0 ).size() == 5 );
BOOST_TEST( data::xrange( 1., 7.5 ).size() == 7 );
BOOST_CHECK_THROW( data::xrange( 0, 0 ), std::logic_error );
BOOST_CHECK_THROW( data::xrange( 3, 1 ), std::logic_error );
BOOST_TEST( data::xrange( 3, 9, 2 ).size() == 3 );
BOOST_TEST( data::xrange( 5, 0, -1 ).size() == 5 );
BOOST_TEST( data::xrange( 1, 10, 2 ).size() == 5 );
BOOST_TEST( data::xrange( 1, 10, 3 ).size() == 3 );
BOOST_TEST( data::xrange( 1, 10, 8 ).size() == 2 );
BOOST_TEST( data::xrange( 0., 3., 0.4 ).size() == 8 );
BOOST_TEST( data::xrange( 1e-6, 2.e-6, 1e-9 ).size() == 1000 );
BOOST_TEST( data::xrange<int>(( data::begin = 9, data::end = 15 )).size() == 6 );
BOOST_TEST( data::xrange<double>(( data::step = 0.5, data::end = 3 )).size() == 6 );
int c = 0;
data::for_each_sample( data::xrange( 3 ), [&c](int a) {
BOOST_TEST( a == c++ );
});
c = 1;
data::for_each_sample( data::xrange( 1, 10, 2 ), [&c](int a) {
BOOST_TEST( a == c );
c += 2;
});
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_range_join )
{
auto ds = data::xrange( 1, 4 ) + data::xrange( 7, 11 );
BOOST_TEST( ds.size() == 7 );
invocation_count ic;
ic.m_value = 0;
data::for_each_sample( ds, ic );
BOOST_TEST( ic.m_value == 7 );
int arr[] = {1,2,3,7,8,9,10};
int* exp = arr;
int c = 0;
data::for_each_sample( ds, [&c,exp](int a) {
BOOST_TEST( a == exp[c++] );
});
}
//____________________________________________________________________________//
// EOF

View File

@@ -0,0 +1,233 @@
// (C) Copyright Gennadiy Rozental 2002-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// Description : tests parameterized tests
// Note: this file should be compatible with C++03 compilers (features in boost.test v2)
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/test/parameterized_test.hpp>
#include <boost/test/unit_test_log.hpp>
#include <boost/test/results_collector.hpp>
#include <boost/test/utils/nullstream.hpp>
typedef boost::onullstream onullstream_type;
namespace ut = boost::unit_test;
// BOOST
#include <boost/scoped_ptr.hpp>
// STL
#include <list>
#include <iostream>
//____________________________________________________________________________//
void test0( int i )
{
BOOST_TEST( (i%2 == 0) ); // amounts to BOOST_CHECK, for backward compatibility wrt. boost.test v2
}
//____________________________________________________________________________//
void test1( int i )
{
BOOST_TEST( (i%2 == 0) );
if( i%3 == 0 ) {
throw 124;
}
}
//____________________________________________________________________________//
static void
setup_tree( ut::test_suite* master_tu )
{
master_tu->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( master_tu->p_id );
}
//____________________________________________________________________________//
struct logger_guard {
logger_guard(std::ostream& s_out) {
ut::unit_test_log.set_stream( s_out );
}
~logger_guard() {
ut::unit_test_log.set_stream( std::cout );
}
};
BOOST_AUTO_TEST_CASE( test_case1 )
{
// if an exception is thrown in the test, this object is destructed when we reach the logger
// for logging the exception. This happens for instance if the test->add throws:
// - test case aborted, null_output destructed but still refered from the logger
// - exception caught by the framework, and exception content logged
// - reference to a non-existing log stream
onullstream_type null_output;
logger_guard G( null_output );
ut::test_suite* test = BOOST_TEST_SUITE( "" );
int test_data[] = { 2, 2, 2 };
test->add( BOOST_PARAM_TEST_CASE( &test0, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
setup_tree( test );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 0U );
BOOST_TEST( !tr.p_aborted );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_case2 )
{
onullstream_type null_output;
logger_guard G( null_output );
ut::test_suite* test = BOOST_TEST_SUITE( "" );
int test_data[] = { 1, 2, 2 };
test->add( BOOST_PARAM_TEST_CASE( &test0, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
setup_tree( test );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 1U );
BOOST_TEST( !tr.p_aborted );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_case3 )
{
onullstream_type null_output;
logger_guard G( null_output );
ut::test_suite* test = BOOST_TEST_SUITE( "" );
int test_data[] = { 1, 1, 2 };
test->add( BOOST_PARAM_TEST_CASE( &test0, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
setup_tree( test );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 2U );
BOOST_TEST( !tr.p_aborted );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_case4 )
{
onullstream_type null_output;
logger_guard G( null_output );
ut::test_suite* test = BOOST_TEST_SUITE( "" );
int test_data[] = { 1, 1, 1 };
test->add( BOOST_PARAM_TEST_CASE( &test0, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
setup_tree( test );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 3U );
BOOST_TEST( !tr.p_aborted );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_case5 )
{
onullstream_type null_output;
logger_guard G( null_output );
ut::test_suite* test = BOOST_TEST_SUITE( "" );
int test_data[] = { 6, 6, 6 };
test->add( BOOST_PARAM_TEST_CASE( &test1, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
setup_tree( test );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 3U );
BOOST_TEST( !tr.p_aborted );
BOOST_TEST( !tr.passed() );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_case6 )
{
onullstream_type null_output;
logger_guard G( null_output );
ut::test_suite* test = BOOST_TEST_SUITE( "" );
int test_data[] = { 0, 3, 9 };
test->add( BOOST_PARAM_TEST_CASE( &test1, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
setup_tree( test );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 5U );
BOOST_TEST( !tr.p_aborted );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_case7 )
{
onullstream_type null_output;
logger_guard G( null_output );
ut::test_suite* test = BOOST_TEST_SUITE( "" );
int test_data[] = { 2, 3, 9 };
test->add( BOOST_PARAM_TEST_CASE( &test1, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
setup_tree( test );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 4U );
BOOST_TEST( !tr.p_aborted );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test_case8 )
{
onullstream_type null_output;
logger_guard G( null_output );
ut::test_suite* test = BOOST_TEST_SUITE( "" );
int test_data[] = { 3, 2, 6 };
test->add( BOOST_PARAM_TEST_CASE( &test1, (int*)test_data, (int*)test_data + sizeof(test_data)/sizeof(int) ) );
setup_tree( test );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 3U );
BOOST_TEST( !tr.p_aborted );
}
//____________________________________________________________________________//
// EOF

View File

@@ -0,0 +1,329 @@
// (C) Copyright Gennadiy Rozental 2007-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : test tree management unit test
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MODULE test tree management test
#include <boost/test/unit_test.hpp>
using namespace boost::unit_test;
#include <boost/mpl/vector.hpp>
//____________________________________________________________________________//
// some empty test suites/cases
BOOST_AUTO_TEST_SUITE( S1 )
#if BOOST_PP_VARIADICS
BOOST_AUTO_TEST_CASE( tc1, * expected_failures(1) )
#else
BOOST_TEST_DECORATOR(*boost::unit_test::expected_failures(1)) BOOST_AUTO_TEST_CASE( tc1 ) /* on the same line, otherwise some test below should be updated */
#endif
{ BOOST_ERROR(""); }
BOOST_AUTO_TEST_CASE( tc2 ) {}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE( S1 )
void tc3() {}
void tc4() {}
struct myreg {
myreg() {
framework::current_auto_test_suite().add( BOOST_TEST_CASE( &tc3 ) );
framework::current_auto_test_suite().add( BOOST_TEST_CASE( &tc4 ) );
}
} myreg_;
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE( S2 )
BOOST_AUTO_TEST_CASE( tc1 ) {}
BOOST_AUTO_TEST_CASE( tc2 ) {}
BOOST_AUTO_TEST_SUITE( S21 )
#if BOOST_PP_VARIADICS
BOOST_AUTO_TEST_CASE( tc1, * expected_failures(1) )
#else
BOOST_TEST_DECORATOR(*boost::unit_test::expected_failures(1)) BOOST_AUTO_TEST_CASE( tc1 ) /* on the same line, otherwise some test below should be updated (the test is sensitive to line numbers) */
#endif
{ BOOST_ERROR( "" ); }
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE( S3 )
BOOST_AUTO_TEST_SUITE_END()
struct F1 {
F1() { BOOST_TEST_MESSAGE( "In F1" ); }
};
BOOST_AUTO_TEST_SUITE( S4 )
typedef boost::mpl::vector<int,float,char> test_types;
BOOST_FIXTURE_TEST_CASE_TEMPLATE( tctempl, T, test_types, F1 )
{
}
BOOST_AUTO_TEST_SUITE_END()
struct F2 {
F2() { BOOST_TEST_MESSAGE( "In F2" ); }
};
BOOST_FIXTURE_TEST_SUITE( S5, F2 )
typedef boost::mpl::vector<int,float,char,double,short int> test_types;
BOOST_AUTO_TEST_CASE_TEMPLATE( tctempl, T, test_types )
{
}
BOOST_AUTO_TEST_SUITE_END()
//____________________________________________________________________________//
// VC9 defines a function called void empty(); in ivec.h
void empty_() {}
BOOST_AUTO_TEST_CASE( manual_test_case_creation_test )
{
test_case* tc1 = BOOST_TEST_CASE( &empty_ );
BOOST_TEST( tc1->p_type == TUT_CASE );
BOOST_TEST( tc1->p_type_name == const_string( "case" ) );
BOOST_TEST( tc1->p_parent_id == INV_TEST_UNIT_ID );
BOOST_TEST( tc1->p_id != INV_TEST_UNIT_ID );
BOOST_TEST( tc1->p_expected_failures == 0U );
BOOST_TEST( tc1->p_timeout == 0U );
BOOST_TEST( tc1->p_name == const_string( "empty_" ) );
BOOST_TEST( tc1->p_test_func );
BOOST_TEST( tc1->p_default_status == test_unit::RS_INHERIT );
BOOST_TEST( tc1->p_run_status == test_unit::RS_INVALID );
BOOST_TEST( !tc1->is_enabled() );
BOOST_TEST( &framework::get<test_case>( tc1->p_id ) == tc1 );
BOOST_TEST( &framework::get( tc1->p_id, TUT_CASE ) == tc1 );
BOOST_CHECK_THROW( framework::get( tc1->p_id, TUT_SUITE ), framework::internal_error );
test_case* tc2 = make_test_case( &empty_, "my test case", "test_file_name", 1 );
BOOST_TEST( tc2->p_name == const_string( "my test case" ) );
BOOST_TEST( tc2->p_file_name == const_string( "test_file_name" ) );
BOOST_TEST( tc2->p_line_num == 1U );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( manual_test_suite_creation )
{
test_suite* ts1 = BOOST_TEST_SUITE( "TestSuite" );
BOOST_TEST( ts1->p_type == TUT_SUITE );
BOOST_TEST( ts1->p_type_name == const_string( "suite" ) );
BOOST_TEST( ts1->p_parent_id == INV_TEST_UNIT_ID );
BOOST_TEST( ts1->p_id != INV_TEST_UNIT_ID );
const_string fn(ts1->p_file_name);
const_string::size_type pos = fn.rfind( "/" );
if( pos != const_string::npos )
fn.trim_left( pos+1 );
pos = fn.rfind( "\\" );
if( pos != const_string::npos )
fn.trim_left( pos+1 );
BOOST_TEST( fn == const_string( "test-tree-management-test.cpp" ) );
BOOST_TEST( ts1->p_line_num == 138U );
BOOST_TEST( ts1->p_expected_failures == 0U );
BOOST_TEST( ts1->p_timeout == 0U );
BOOST_TEST( ts1->p_name == const_string( "TestSuite" ) );
BOOST_TEST( ts1->p_default_status == test_unit::RS_INHERIT );
BOOST_TEST( ts1->p_run_status == test_unit::RS_INVALID );
BOOST_TEST( !ts1->is_enabled() );
BOOST_TEST( ts1->size() == 0U );
BOOST_TEST( &framework::get<test_suite>( ts1->p_id ) == ts1 );
BOOST_TEST( &framework::get( ts1->p_id, TUT_SUITE ) == ts1 );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( manual_test_unit_registration )
{
test_suite* ts1 = BOOST_TEST_SUITE( "TestSuite" );
std::size_t line_num = 1;
test_case* tc1 = make_test_case( &empty_, "empty1", "file_name", line_num );
ts1->add( tc1, 1, 10U );
BOOST_TEST( ts1->size() == 1U );
BOOST_TEST( tc1->p_expected_failures == 1U );
BOOST_TEST( tc1->p_timeout == 10U );
BOOST_TEST( ts1->p_expected_failures == 1U );
test_case* tc2 = make_test_case( &empty_, "empty2", "file_name", line_num );
ts1->add( tc2, 2U );
BOOST_TEST( ts1->size() == 2U );
BOOST_TEST( tc2->p_expected_failures == 2U );
BOOST_TEST( tc2->p_timeout == 0U );
BOOST_TEST( ts1->p_expected_failures == 3U );
test_suite* ts2 = BOOST_TEST_SUITE( "TestSuite2" );
ts1->add( ts2 );
BOOST_TEST( ts1->size() == 3U );
BOOST_TEST( ts2->p_expected_failures == 0U );
BOOST_TEST( ts1->p_expected_failures == 3U );
BOOST_TEST( ts1->get( "empty1" ) == tc1->p_id );
BOOST_TEST( ts1->get( "empty2" ) == tc2->p_id );
BOOST_TEST( ts1->get( "TestSuite2" ) == ts2->p_id );
BOOST_TEST( ts1->get( "another name" ) == INV_TEST_UNIT_ID );
ts1->remove( tc1->p_id );
BOOST_TEST( ts1->size() == 2U );
BOOST_TEST( ts1->get( "empty1" ) == INV_TEST_UNIT_ID );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( automated_test_units_registration )
{
test_suite& mts = framework::master_test_suite();
BOOST_TEST( mts.size() == 10U );
BOOST_TEST( mts.p_expected_failures == 2U );
BOOST_TEST( framework::get<test_case>( mts.get( "automated_test_units_registration" ) ).p_expected_failures == 0U );
test_suite& S1 = framework::get<test_suite>( mts.get( "S1" ) );
BOOST_TEST( S1.size() == 4U );
BOOST_TEST( S1.p_expected_failures == 1U );
test_suite& S2 = framework::get<test_suite>( mts.get( "S2" ) );
BOOST_TEST( S2.size() == 3U );
BOOST_TEST( S2.p_expected_failures == 1U );
test_suite& S3 = framework::get<test_suite>( mts.get( "S3" ) );
BOOST_TEST( S3.size() == 0U );
BOOST_TEST( S3.p_expected_failures == 0U );
test_suite& S21 = framework::get<test_suite>( S2.get( "S21" ) );
BOOST_TEST( S21.size() == 1U );
BOOST_TEST( S1.p_expected_failures == 1U );
test_suite& S4 = framework::get<test_suite>( mts.get( "S4" ) );
BOOST_TEST( S4.size() == 3U );
test_suite& S5 = framework::get<test_suite>( mts.get( "S5" ) );
BOOST_TEST( S5.size() == 5U );
}
//____________________________________________________________________________//
struct A {
A() : i(0){}
virtual ~A(){}
void test_methodA1() { i++; }
void test_methodA2() { i++; }
int i;
};
struct B : public A {
void test_methodB() { i--; }
};
struct C {
C() : i( 0 ) {}
virtual ~C(){}
void virtual test_method() = 0;
int i;
};
struct D : public C {
void virtual test_method() { i++; }
};
struct E : public C {
void virtual test_method() { i+=2; }
};
BOOST_AUTO_TEST_CASE( user_class_test_case )
{
boost::shared_ptr<A> instA( new A );
test_case* tc1 = BOOST_CLASS_TEST_CASE( &A::test_methodA1, instA );
test_case* tc2 = BOOST_CLASS_TEST_CASE( &A::test_methodA2, instA );
BOOST_TEST( tc1->p_name == const_string( "A__test_methodA1" ) );
BOOST_TEST( tc2->p_name == const_string( "A__test_methodA2" ) );
BOOST_TEST( instA->i == 0 );
tc1->p_test_func.get()();
BOOST_TEST( instA->i == 1 );
tc2->p_test_func.get()();
BOOST_TEST( instA->i == 2 );
boost::shared_ptr<B> instB( new B );
test_case* tc3 = BOOST_CLASS_TEST_CASE( &A::test_methodA1, instB );
test_case* tc4 = BOOST_CLASS_TEST_CASE( &B::test_methodB, instB );
BOOST_TEST( tc3->p_name == const_string( "A__test_methodA1" ) );
BOOST_TEST( tc4->p_name == const_string( "B__test_methodB" ) );
BOOST_TEST( instB->i == 0 );
tc3->p_test_func.get()();
BOOST_TEST( instB->i == 1 );
tc4->p_test_func.get()();
BOOST_TEST( instB->i == 0 );
boost::shared_ptr<C> instC1( new D );
test_case* tc5 = BOOST_CLASS_TEST_CASE( &C::test_method, instC1 );
BOOST_TEST( tc5->p_name == const_string( "C__test_method" ) );
tc5->p_test_func.get()();
BOOST_TEST( instC1->i == 1 );
boost::shared_ptr<C> instC2( new E );
test_case* tc6 = BOOST_CLASS_TEST_CASE( &C::test_method, instC2 );
BOOST_TEST( tc6->p_name == const_string( "C__test_method" ) );
tc6->p_test_func.get()();
BOOST_TEST( instC2->i == 2 );
}
//____________________________________________________________________________//
// EOF

View File

@@ -0,0 +1,23 @@
// (C) Copyright Raffi Enficiaud 2017.
// 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)
// See http://www.boost.org/libs/test for the library home page.
// first file, should be exactly the same as second file except for the test name
BOOST_AUTO_TEST_SUITE(data)
BOOST_AUTO_TEST_SUITE(foo)
BOOST_AUTO_TEST_CASE(test1)
{
BOOST_TEST(true);
}
BOOST_TEST_DECORATOR(* boost::unit_test::description("with description"))
BOOST_AUTO_TEST_CASE(test11)
{
BOOST_TEST(true);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -0,0 +1,23 @@
// (C) Copyright Raffi Enficiaud 2017.
// 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)
// See http://www.boost.org/libs/test for the library home page.
// second file, should be exactly the same as second file except for the test name
BOOST_AUTO_TEST_SUITE(data)
BOOST_AUTO_TEST_SUITE(foo)
BOOST_AUTO_TEST_CASE(test2)
{
BOOST_TEST(true);
}
BOOST_TEST_DECORATOR(* boost::unit_test::description("with description"))
BOOST_AUTO_TEST_CASE(test21)
{
BOOST_TEST(true);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()

View File

@@ -0,0 +1,12 @@
// (C) Copyright Raffi Enficiaud 2017.
// 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)
// See http://www.boost.org/libs/test for the library home page.
#define BOOST_TEST_MODULE several test suite decl
#include <boost/test/unit_test.hpp>
#include "test-tree-several-suite-decl-1.hpp"
#include "test-tree-several-suite-decl-2.hpp"

View File

@@ -0,0 +1,199 @@
// (C) Copyright Gennadiy Rozental 2003-2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : tests function template test case
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_log.hpp>
#include <boost/test/results_collector.hpp>
#include <boost/test/utils/nullstream.hpp>
typedef boost::onullstream onullstream_type;
// BOOST
#include <boost/mpl/range_c.hpp>
#include <boost/mpl/list_c.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/config.hpp>
namespace ut = boost::unit_test;
namespace mpl = boost::mpl;
// STL
#include <iostream>
struct logger_guard {
logger_guard(std::ostream& s_out) {
ut::unit_test_log.set_stream( s_out );
}
~logger_guard() {
ut::unit_test_log.set_stream( std::cout );
}
};
//____________________________________________________________________________//
BOOST_TEST_CASE_TEMPLATE_FUNCTION( test0, Number )
{
BOOST_TEST( 2 == (int)Number::value );
}
//____________________________________________________________________________//
BOOST_TEST_CASE_TEMPLATE_FUNCTION( test1, Number )
{
BOOST_TEST( 6 == (int)Number::value );
BOOST_TEST_REQUIRE( 2 <= (int)Number::value );
BOOST_TEST( 3 == (int)Number::value );
}
//____________________________________________________________________________//
BOOST_TEST_CASE_TEMPLATE_FUNCTION( test2, Number )
{
throw Number();
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test0_only_2 )
{
// if an exception is thrown in the test, this object is destructed when we reach the logger
// for logging the exception. This happens for instance if the test->add throws:
// - test case aborted, null_output destructed but still refered from the logger
// - exception caught by the framework, and exception content logged
// - reference to a non-existing log stream
onullstream_type null_output;
logger_guard G( null_output );
typedef boost::mpl::list_c<int,2> only_2;
ut::test_suite* test = BOOST_TEST_SUITE( "" );
test->add( BOOST_TEST_CASE_TEMPLATE( test0, only_2 ) );
test->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( test->p_id );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 0U );
BOOST_TEST( !tr.p_aborted );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test0_one_to_ten )
{
onullstream_type null_output;
logger_guard G( null_output );
ut::test_suite* test = BOOST_TEST_SUITE( "" );
typedef boost::mpl::range_c<int,0,10> one_to_ten;
test->add( BOOST_TEST_CASE_TEMPLATE( test0, one_to_ten ) );
test->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( test->p_id );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 9U );
BOOST_TEST( !tr.p_aborted );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test1_one_to_five )
{
onullstream_type null_output;
logger_guard G( null_output );
ut::test_suite* test = BOOST_TEST_SUITE( "" );
typedef boost::mpl::range_c<int,1,5> one_to_five;
test->add( BOOST_TEST_CASE_TEMPLATE( test1, one_to_five ) );
test->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( test->p_id );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 7U );
BOOST_TEST( !tr.p_aborted );
}
//____________________________________________________________________________//
BOOST_AUTO_TEST_CASE( test2_one_to_three )
{
onullstream_type null_output;
logger_guard G( null_output );
ut::test_suite* test = BOOST_TEST_SUITE( "" );
typedef boost::mpl::range_c<int,1,3> one_to_three;
test->add( BOOST_TEST_CASE_TEMPLATE( test2, one_to_three ) );
test->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( test->p_id );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 2U );
BOOST_TEST( !tr.p_aborted );
BOOST_TEST( !tr.passed() );
}
//____________________________________________________________________________//
// checks if volatile, const, ... are properly handled
typedef boost::mpl::vector<int,int const, int volatile,int const volatile> test_types_ints_variations;
BOOST_AUTO_TEST_CASE_TEMPLATE( tctempl2, T, test_types_ints_variations )
{
BOOST_TEST( sizeof(T) == sizeof(int) );
}
// checks if references are properly handled
typedef boost::mpl::vector<
int
, int&
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
, int&&
#endif
, int const
, int const&
#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
, int const&&
#endif
> test_types_ints_ref_variations;
BOOST_AUTO_TEST_CASE_TEMPLATE( tctempl3, T, test_types_ints_ref_variations )
{
BOOST_TEST( (sizeof(T) == sizeof(int&) || sizeof(T) == sizeof(int)) );
}
// checks if pointers are properly handled
typedef boost::mpl::vector<int,int*,int const*, int const volatile*, int const*const, int*&> test_types_ints_pointer_variations;
BOOST_AUTO_TEST_CASE_TEMPLATE( tctempl4, T, test_types_ints_pointer_variations )
{
BOOST_TEST( (sizeof(T) == sizeof(int*) || sizeof(T) == sizeof(int)));
}
// EOF

View File

@@ -0,0 +1,148 @@
// (C) Copyright Raffi Enficiaud 2018.
// 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)
// Checks the instanciation of template test cases with tuples instead of mpl::list
// See trac #12092 https://svn.boost.org/trac10/ticket/12092
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MODULE template_test_case_with_tuples
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_log.hpp>
#include <boost/test/results_collector.hpp>
#include <boost/test/utils/nullstream.hpp>
typedef boost::onullstream onullstream_type;
#include <boost/mpl/integral_c.hpp>
#include <tuple>
namespace ut = boost::unit_test;
namespace mpl = boost::mpl;
#include <iostream>
struct logger_guard {
logger_guard(std::ostream& s_out) {
ut::unit_test_log.set_stream( s_out );
}
~logger_guard() {
ut::unit_test_log.set_stream( std::cout );
}
};
//____________________________________________________________________________//
BOOST_TEST_CASE_TEMPLATE_FUNCTION( test0, Number )
{
BOOST_TEST( 2 == (int)Number::value );
}
BOOST_AUTO_TEST_CASE( test0_only_2 )
{
onullstream_type null_output;
logger_guard G(null_output);
typedef std::tuple< mpl::integral_c<int,2> > only_2;
ut::test_suite* test = BOOST_TEST_SUITE( "" );
test->add( BOOST_TEST_CASE_TEMPLATE( test0, only_2 ) );
test->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( test->p_id );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 0U );
BOOST_TEST( !tr.p_aborted );
}
BOOST_AUTO_TEST_CASE( test1_with_9_errors )
{
onullstream_type null_output;
logger_guard G(null_output);
typedef std::tuple<
mpl::integral_c<int,0>,
mpl::integral_c<int,1>,
mpl::integral_c<int,2>,
mpl::integral_c<int,3>,
mpl::integral_c<int,4>,
mpl::integral_c<int,5>,
mpl::integral_c<int,6>,
mpl::integral_c<int,7>,
mpl::integral_c<int,8>,
mpl::integral_c<int,9>
> range_10;
ut::test_suite* test = BOOST_TEST_SUITE( "" );
test->add( BOOST_TEST_CASE_TEMPLATE( test0, range_10 ) );
test->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( test->p_id );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 9U );
BOOST_TEST( !tr.p_aborted );
}
int counter = 0;
BOOST_TEST_CASE_TEMPLATE_FUNCTION( test_counter, Number )
{
BOOST_TEST( counter++ == (int)Number::value );
}
BOOST_AUTO_TEST_CASE( test_left_to_right_evaluation )
{
onullstream_type null_output;
logger_guard G(null_output);
typedef std::tuple<
mpl::integral_c<int,0>,
mpl::integral_c<int,1>,
mpl::integral_c<int,2>,
mpl::integral_c<int,3>,
mpl::integral_c<int,4>,
mpl::integral_c<int,5>,
mpl::integral_c<int,6>,
mpl::integral_c<int,7>,
mpl::integral_c<int,8>,
mpl::integral_c<int,9>
> range_10;
ut::test_suite* test = BOOST_TEST_SUITE( "" );
test->add( BOOST_TEST_CASE_TEMPLATE( test_counter, range_10 ) );
test->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( test->p_id );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 0U );
BOOST_TEST( !tr.p_aborted );
}
typedef std::tuple<
mpl::integral_c<int,1>,
mpl::integral_c<int,3>,
mpl::integral_c<int,5>,
mpl::integral_c<int,6>,
mpl::integral_c<int,7>,
mpl::integral_c<int,8>,
mpl::integral_c<int,9>
> range_special;
BOOST_AUTO_TEST_CASE_TEMPLATE(odd_or_above_5, T, range_special) {
BOOST_TEST( (T::value % 2 || T::value >= 5 ) );
}

View File

@@ -0,0 +1,158 @@
// (C) Copyright Raffi Enficiaud 2019.
// 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)
// Extends #12092 with arbitrary type list
// see https://svn.boost.org/trac10/ticket/13418 and
// https://github.com/boostorg/test/issues/141
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MODULE template_test_case_with_variadic
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_log.hpp>
#include <boost/test/results_collector.hpp>
#include <boost/test/utils/nullstream.hpp>
typedef boost::onullstream onullstream_type;
#include <boost/mpl/integral_c.hpp>
// tuple already done in another test module
// #include <tuple>
namespace ut = boost::unit_test;
namespace mpl = boost::mpl;
#include <iostream>
struct logger_guard {
logger_guard(std::ostream& s_out) {
ut::unit_test_log.set_stream( s_out );
}
~logger_guard() {
ut::unit_test_log.set_stream( std::cout );
}
};
template <class ... T>
struct dummy1 {
};
//____________________________________________________________________________//
BOOST_TEST_CASE_TEMPLATE_FUNCTION( test0, Number )
{
BOOST_TEST( 2 == (int)Number::value );
}
BOOST_AUTO_TEST_CASE( test0_only_2 )
{
onullstream_type null_output;
logger_guard G(null_output);
typedef dummy1< mpl::integral_c<int,2> > only_2;
ut::test_suite* test = BOOST_TEST_SUITE( "" );
test->add( BOOST_TEST_CASE_TEMPLATE( test0, only_2 ) );
test->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( test->p_id );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 0U );
BOOST_TEST( !tr.p_aborted );
}
BOOST_AUTO_TEST_CASE( test1_with_9_errors )
{
onullstream_type null_output;
logger_guard G(null_output);
typedef dummy1<
mpl::integral_c<int,0>,
mpl::integral_c<int,1>,
mpl::integral_c<int,2>,
mpl::integral_c<int,3>,
mpl::integral_c<int,4>,
mpl::integral_c<int,5>,
mpl::integral_c<int,6>,
mpl::integral_c<int,7>,
mpl::integral_c<int,8>,
mpl::integral_c<int,9>
> range_10;
ut::test_suite* test = BOOST_TEST_SUITE( "" );
test->add( BOOST_TEST_CASE_TEMPLATE( test0, range_10 ) );
test->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( test->p_id );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 9U );
BOOST_TEST( !tr.p_aborted );
}
int counter = 0;
BOOST_TEST_CASE_TEMPLATE_FUNCTION( test_counter, Number )
{
BOOST_TEST( counter++ == (int)Number::value );
}
BOOST_AUTO_TEST_CASE( test_left_to_right_evaluation )
{
onullstream_type null_output;
logger_guard G(null_output);
typedef dummy1<
mpl::integral_c<int,0>,
mpl::integral_c<int,1>,
mpl::integral_c<int,2>,
mpl::integral_c<int,3>,
mpl::integral_c<int,4>,
mpl::integral_c<int,5>,
mpl::integral_c<int,6>,
mpl::integral_c<int,7>,
mpl::integral_c<int,8>,
mpl::integral_c<int,9>
> range_10;
ut::test_suite* test = BOOST_TEST_SUITE( "" );
test->add( BOOST_TEST_CASE_TEMPLATE( test_counter, range_10 ) );
test->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( test->p_id );
ut::framework::run( test );
ut::test_results const& tr = ut::results_collector.results( test->p_id );
ut::unit_test_log.set_stream( std::cout );
BOOST_TEST( tr.p_assertions_failed == 0U );
BOOST_TEST( !tr.p_aborted );
}
typedef dummy1<
mpl::integral_c<int,1>,
mpl::integral_c<int,3>,
mpl::integral_c<int,5>,
mpl::integral_c<int,6>,
mpl::integral_c<int,7>,
mpl::integral_c<int,8>,
mpl::integral_c<int,9>
> range_special;
BOOST_AUTO_TEST_CASE_TEMPLATE(odd_or_above_5, T, range_special) {
BOOST_TEST( (T::value % 2 || T::value >= 5 ) );
}

View File

@@ -0,0 +1,84 @@
// (C) Copyright Raffi Enficiaud 2017.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
//! @file
//! checking the nested suites activation, ticket trac #13149
// *****************************************************************************
#define BOOST_TEST_MODULE test_nested_dependency
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_parameters.hpp>
#include <boost/test/tree/test_case_counter.hpp>
#include <boost/test/tree/traverse.hpp>
// initial reproducing snippet on the corresponding ticket
#if 0
BOOST_AUTO_TEST_SUITE(suite1, *boost::unit_test::depends_on("suite2"))
BOOST_AUTO_TEST_SUITE(suite1_nested)
BOOST_AUTO_TEST_CASE(suite1_test1)
{
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE(suite2)
BOOST_AUTO_TEST_CASE(suite2_test2)
{
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_SUITE_END()
#endif
void suite1_test1()
{
BOOST_CHECK(true);
}
void suite2_test2()
{
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_CASE( some_test )
{
using namespace boost::unit_test;
// test tree
test_suite* master_ts = BOOST_TEST_SUITE("local master");
test_suite* t_suite1 = BOOST_TEST_SUITE( "suite1" );
test_suite* t_suite1_nested = BOOST_TEST_SUITE( "suite1_nested" );
t_suite1_nested->add( BOOST_TEST_CASE( suite1_test1 ) );
t_suite1->add(t_suite1_nested);
test_suite* t_suite2 = BOOST_TEST_SUITE( "suite2" );
t_suite2->add( BOOST_TEST_CASE( suite2_test2 ) );
master_ts->add(t_suite1);
master_ts->add(t_suite2);
// dependencies
t_suite1->depends_on( t_suite2 );
// running
char const* argv[] = { "dummy-test-module.exe", "--log_level=all", "--run_test=suite1/suite1_nested"};
int argc = sizeof(argv)/sizeof(argv[0]);
master_ts->p_default_status.value = test_unit::RS_ENABLED;
framework::finalize_setup_phase( master_ts->p_id );
runtime_config::init( argc, (char**)argv );
framework::impl::setup_for_execution( *master_ts );
// no need to run
//framework::run( master_ts );
// we should have 2 test cases enabled with this run parameters
test_case_counter tcc;
traverse_test_tree( master_ts->p_id, tcc );
BOOST_TEST( tcc.p_count == 2 );
}

View File

@@ -0,0 +1,149 @@
// (C) Copyright Raffi Enficiaud 2016.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
/// @file
/// @brief tests order of the running unit tests under shuffling
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MODULE test unit order shuffled test
#include <boost/test/included/unit_test.hpp>
#include <boost/test/unit_test_log.hpp>
#include <boost/test/tree/visitor.hpp>
#include <boost/test/utils/string_cast.hpp>
#include <boost/test/utils/nullstream.hpp>
typedef boost::onullstream onullstream_type;
namespace ut = boost::unit_test;
namespace tt = boost::test_tools;
#include <cstddef>
#include <iostream>
//____________________________________________________________________________//
void some_test() {}
#define TC( name ) \
boost::unit_test::make_test_case( boost::function<void ()>(some_test), \
BOOST_TEST_STRINGIZE( name ), \
__FILE__, __LINE__ )
//____________________________________________________________________________//
struct tu_order_collector : ut::test_observer {
virtual void test_unit_start( ut::test_unit const& tu )
{
//std::cout << "## TU: " << tu.full_name() << std::endl;
m_order.push_back( tu.p_id );
}
std::vector<ut::test_unit_id> m_order;
};
//____________________________________________________________________________//
static tu_order_collector
run_tree( ut::test_suite* master )
{
std::cout << "## TU: START" << std::endl;
tu_order_collector c;
ut::framework::register_observer( c );
master->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( master->p_id );
ut::framework::impl::setup_for_execution( *master );
onullstream_type null_output;
ut::unit_test_log.set_stream( null_output );
ut::framework::run( master );
ut::unit_test_log.set_stream( std::cout );
ut::framework::deregister_observer( c );
return c;
}
//____________________________________________________________________________//
struct test_tree {
test_tree() {
master = BOOST_TEST_SUITE( "master" );
std::size_t nb_ts = (std::max)(3, std::rand() % 17);
std::vector<ut::test_suite*> tsuites(1, master); // master is in there
for(std::size_t s = 0; s < nb_ts; s++)
{
tsuites.push_back(BOOST_TEST_SUITE( "ts1_" + boost::unit_test::utils::string_cast(s)));
master->add( tsuites.back() );
}
std::size_t nb_ts2 = (std::max)(3, std::rand() % 11);
for(std::size_t s = 0; s < nb_ts2; s++)
{
tsuites.push_back(BOOST_TEST_SUITE( "ts2_" + boost::unit_test::utils::string_cast(s)));
tsuites[std::rand() % nb_ts]->add( tsuites.back() ); // picking a random one in the first level
}
// generating N tests units, associating them to an aribtrary test suite
for(std::size_t s = 0; s < 10; s++)
{
ut::test_case* tc = boost::unit_test::make_test_case(
boost::function<void ()>(some_test),
"tc_" + boost::unit_test::utils::string_cast(s),
__FILE__, __LINE__ );
tsuites[std::rand() % tsuites.size()]->add(tc);
}
}
ut::test_suite* master;
};
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_no_seed, test_tree )
{
// no seed set
ut::runtime_config::s_arguments_store.set<unsigned int>(ut::runtime_config::btrt_random_seed, 0);
tu_order_collector res1 = run_tree( master );
tu_order_collector res2 = run_tree( master );
BOOST_TEST( res1.m_order == res2.m_order, tt::per_element() );
}
BOOST_FIXTURE_TEST_CASE( test_seed_to_time, test_tree )
{
// seed = 1 means current time is used.
ut::runtime_config::s_arguments_store.set<unsigned int>(ut::runtime_config::btrt_random_seed, 1);
tu_order_collector res1 = run_tree( master );
tu_order_collector res2 = run_tree( master );
BOOST_TEST( res1.m_order != res2.m_order ); // some elements might be the same, but not the full sequences
}
BOOST_FIXTURE_TEST_CASE( test_seed_identical, test_tree )
{
// seed = 1 means current time is used.
unsigned int seed = static_cast<unsigned int>( std::time( 0 ) );
ut::runtime_config::s_arguments_store.set<unsigned int>(ut::runtime_config::btrt_random_seed, seed);
tu_order_collector res1 = run_tree( master );
ut::runtime_config::s_arguments_store.set<unsigned int>(ut::runtime_config::btrt_random_seed, seed);
tu_order_collector res2 = run_tree( master );
BOOST_TEST( res1.m_order == res2.m_order, tt::per_element() );
// using time seed now
ut::runtime_config::s_arguments_store.set<unsigned int>(ut::runtime_config::btrt_random_seed, 1);
tu_order_collector res3 = run_tree( master );
BOOST_TEST( res1.m_order != res3.m_order ); // some elements might be the same, but not the full sequences
}

View File

@@ -0,0 +1,383 @@
// (C) Copyright Gennadiy Rozental 2015.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
// File : $RCSfile$
//
// Version : $Revision$
//
// Description : tests proper order of test unis in case of various dependencies specifications
// ***************************************************************************
// Boost.Test
#define BOOST_TEST_MODULE test unit order test
#include <boost/test/unit_test.hpp>
#include <boost/test/unit_test_log.hpp>
#include <boost/test/tree/visitor.hpp>
#include <boost/test/utils/nullstream.hpp>
typedef boost::onullstream onullstream_type;
namespace ut = boost::unit_test;
namespace tt = boost::test_tools;
#include <iostream>
//____________________________________________________________________________//
void some_test() {}
#define TC( name ) \
boost::unit_test::make_test_case( boost::function<void ()>(some_test), \
BOOST_TEST_STRINGIZE( name ), \
__FILE__, __LINE__ )
//____________________________________________________________________________//
struct tu_order_collector : ut::test_observer {
virtual void test_unit_start( ut::test_unit const& tu )
{
// std::cout << "## TU: " << tu.full_name() << std::endl;
m_order.push_back( tu.p_id );
}
std::vector<ut::test_unit_id> m_order;
};
//____________________________________________________________________________//
static tu_order_collector
run_tree( ut::test_suite* master )
{
tu_order_collector c;
ut::framework::register_observer( c );
master->p_default_status.value = ut::test_unit::RS_ENABLED;
ut::framework::finalize_setup_phase( master->p_id );
onullstream_type null_output;
ut::unit_test_log.set_stream( null_output );
//hrf_content_reporter reporter( std::cout );
//ut::traverse_test_tree( *master, reporter, true );
ut::framework::run( master );
ut::unit_test_log.set_stream( std::cout );
ut::framework::deregister_observer( c );
return c;
}
//____________________________________________________________________________//
struct _3cases {
_3cases() {
master = BOOST_TEST_SUITE( "master" );
tc1 = TC( test1 );
tc2 = TC( test2 );
tc3 = TC( test3 );
master->add( tc1 );
master->add( tc2 );
master->add( tc3 );
}
void test_run( std::vector<ut::test_unit_id> const& expected_order )
{
tu_order_collector res = run_tree( master );
#ifndef BOOST_TEST_MACRO_LIMITED_SUPPORT
BOOST_TEST( expected_order == res.m_order, tt::per_element() );
#else
BOOST_CHECK_EQUAL_COLLECTIONS(expected_order.begin(), expected_order.end(),
res.m_order.begin(), res.m_order.end());
#endif
}
ut::test_suite* master;
ut::test_case* tc1;
ut::test_case* tc2;
ut::test_case* tc3;
};
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_simple_order, _3cases )
{
ut::test_unit_id order[] = {master->p_id, tc1->p_id, tc2->p_id, tc3->p_id};
std::vector<ut::test_unit_id> expected_order(order, order+4);
test_run( expected_order );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_simple_dep1, _3cases )
{
tc1->depends_on( tc2 );
ut::test_unit_id order[] = {master->p_id, tc2->p_id, tc3->p_id, tc1->p_id};
std::vector<ut::test_unit_id> expected_order(order, order+4);
test_run( expected_order );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_simple_dep2, _3cases )
{
tc1->depends_on( tc2 );
tc2->depends_on( tc3 );
ut::test_unit_id order[] = {master->p_id, tc3->p_id, tc2->p_id, tc1->p_id};
std::vector<ut::test_unit_id> expected_order(order, order+4);
test_run( expected_order );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_simple_loop1, _3cases )
{
tc1->depends_on( tc2 );
tc2->depends_on( tc1 );
master->p_default_status.value = ut::test_unit::RS_ENABLED;
BOOST_CHECK_THROW( ut::framework::finalize_setup_phase( master->p_id ),
ut::framework::setup_error );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_simple_loop2, _3cases )
{
tc1->depends_on( tc2 );
tc2->depends_on( tc3 );
tc3->depends_on( tc1 );
master->p_default_status.value = ut::test_unit::RS_ENABLED;
BOOST_CHECK_THROW( ut::framework::finalize_setup_phase( master->p_id ),
ut::framework::setup_error );
}
//____________________________________________________________________________//
struct _2suites_4_cases {
_2suites_4_cases() {
master = BOOST_TEST_SUITE( "master" );
s1 = BOOST_TEST_SUITE( "s1" );
s2 = BOOST_TEST_SUITE( "s2" );
tc1 = TC( test1 );
tc2 = TC( test2 );
tc3 = TC( test3 );
tc4 = TC( test4 );
s1->add( tc1 );
s1->add( tc2 );
s2->add( tc3 );
s2->add( tc4 );
master->add( s1 );
master->add( s2 );
}
void test_run( std::vector<ut::test_unit_id> const& expected_order )
{
tu_order_collector res = run_tree( master );
#ifndef BOOST_TEST_MACRO_LIMITED_SUPPORT
BOOST_TEST( expected_order == res.m_order, tt::per_element() );
#else
BOOST_CHECK_EQUAL_COLLECTIONS(expected_order.begin(), expected_order.end(),
res.m_order.begin(), res.m_order.end());
#endif
}
ut::test_suite* master;
ut::test_suite* s1;
ut::test_suite* s2;
ut::test_case* tc1;
ut::test_case* tc2;
ut::test_case* tc3;
ut::test_case* tc4;
};
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_suite_normal_order, _2suites_4_cases )
{
ut::test_unit_id order[] = { master->p_id,
s1->p_id, tc1->p_id, tc2->p_id,
s2->p_id, tc3->p_id, tc4->p_id };
std::vector<ut::test_unit_id> expected_order(order, order+7);
test_run( expected_order );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_suite_simple_dep, _2suites_4_cases )
{
tc1->depends_on( tc2 );
tc3->depends_on( tc4 );
ut::test_unit_id order[] = { master->p_id,
s1->p_id, tc2->p_id, tc1->p_id,
s2->p_id, tc4->p_id, tc3->p_id };
std::vector<ut::test_unit_id> expected_order(order, order+7);
test_run( expected_order );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_suite_cross_dep1, _2suites_4_cases )
{
tc1->depends_on( tc3 );
ut::test_unit_id order[] = { master->p_id,
s2->p_id, tc3->p_id, tc4->p_id,
s1->p_id, tc1->p_id, tc2->p_id };
std::vector<ut::test_unit_id> expected_order(order, order+7);
test_run( expected_order );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_suite_cross_dep2, _2suites_4_cases )
{
tc2->depends_on( tc4 );
tc1->depends_on( tc2 );
ut::test_unit_id order[] = { master->p_id,
s2->p_id, tc3->p_id, tc4->p_id,
s1->p_id, tc2->p_id, tc1->p_id};
std::vector<ut::test_unit_id> expected_order(order, order+7);
test_run( expected_order );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_suite_on_suite_dep, _2suites_4_cases )
{
s1->depends_on( s2 );
ut::test_unit_id order[] = { master->p_id,
s2->p_id, tc3->p_id, tc4->p_id,
s1->p_id, tc1->p_id, tc2->p_id };
std::vector<ut::test_unit_id> expected_order(order, order+7);
test_run( expected_order );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_suite_on_case_dep, _2suites_4_cases )
{
s1->depends_on( tc3 );
ut::test_unit_id order[] = { master->p_id,
s2->p_id, tc3->p_id, tc4->p_id,
s1->p_id, tc1->p_id, tc2->p_id };
std::vector<ut::test_unit_id> expected_order(order, order+7);
test_run( expected_order );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_case_on_suite_dep, _2suites_4_cases )
{
tc1->depends_on( s2 );
ut::test_unit_id order[] = { master->p_id,
s2->p_id, tc3->p_id, tc4->p_id,
s1->p_id, tc1->p_id, tc2->p_id };
std::vector<ut::test_unit_id> expected_order(order, order+7);
test_run( expected_order );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_suite_loop1, _2suites_4_cases )
{
tc1->depends_on( tc3 );
tc3->depends_on( tc2 );
master->p_default_status.value = ut::test_unit::RS_ENABLED;
BOOST_CHECK_THROW( ut::framework::finalize_setup_phase( master->p_id ),
ut::framework::setup_error );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_suite_loop2, _2suites_4_cases )
{
tc1->depends_on( tc3 );
tc4->depends_on( tc2 );
master->p_default_status.value = ut::test_unit::RS_ENABLED;
BOOST_CHECK_THROW( ut::framework::finalize_setup_phase( master->p_id ),
ut::framework::setup_error );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_suite_loop3, _2suites_4_cases )
{
s1->depends_on( tc3 );
s2->depends_on( tc2 );
master->p_default_status.value = ut::test_unit::RS_ENABLED;
BOOST_CHECK_THROW( ut::framework::finalize_setup_phase( master->p_id ),
ut::framework::setup_error );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_suite_loop4, _2suites_4_cases )
{
s1->depends_on( tc1 );
master->p_default_status.value = ut::test_unit::RS_ENABLED;
BOOST_CHECK_THROW( ut::framework::finalize_setup_phase( master->p_id ),
ut::framework::setup_error );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_suite_loop5, _2suites_4_cases )
{
tc1->depends_on( s1 );
master->p_default_status.value = ut::test_unit::RS_ENABLED;
BOOST_CHECK_THROW( ut::framework::finalize_setup_phase( master->p_id ),
ut::framework::setup_error );
}
//____________________________________________________________________________//
BOOST_FIXTURE_TEST_CASE( test_suite_loop6, _2suites_4_cases )
{
tc1->depends_on( s2 );
tc3->depends_on( s1 );
master->p_default_status.value = ut::test_unit::RS_ENABLED;
BOOST_CHECK_THROW( ut::framework::finalize_setup_phase( master->p_id ),
ut::framework::setup_error );
}
//____________________________________________________________________________//
// EOF

View File

@@ -0,0 +1,101 @@
// (C) Copyright Raffi Enficiaud 2018.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
//! @file
//! checking the clashing names, ticket trac #12597
// *****************************************************************************
#define BOOST_TEST_MODULE test_clashing_names
#include <boost/test/unit_test.hpp>
#include <boost/test/utils/string_cast.hpp>
#include <boost/mpl/list.hpp>
#include <boost/bind/bind.hpp>
void suite1_test1()
{
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_CASE( test_clashing_suites )
{
using namespace boost::unit_test;
test_suite* master_ts = BOOST_TEST_SUITE("local master");
test_suite* t_suite1 = BOOST_TEST_SUITE( "suite1" );
test_suite* t_suite2 = BOOST_TEST_SUITE( "suite1" );
master_ts->add(t_suite1);
BOOST_CHECK_NO_THROW( master_ts->add(t_suite2) );
master_ts->p_default_status.value = test_unit::RS_ENABLED;
BOOST_CHECK_THROW(framework::finalize_setup_phase( master_ts->p_id ),
boost::unit_test::framework::setup_error );
}
BOOST_AUTO_TEST_CASE( test_clashing_cases )
{
using namespace boost::unit_test;
test_suite* master_ts = BOOST_TEST_SUITE("local master");
test_suite* t_suite1 = BOOST_TEST_SUITE( "suite1" );
test_suite* t_suite2 = BOOST_TEST_SUITE( "suite2" );
master_ts->add(t_suite1);
master_ts->add(t_suite2);
t_suite1->add( BOOST_TEST_CASE( suite1_test1 ) );
BOOST_CHECK_NO_THROW( t_suite1->add( BOOST_TEST_CASE( suite1_test1 ) ) );
BOOST_CHECK_THROW(framework::finalize_setup_phase( master_ts->p_id ),
boost::unit_test::framework::setup_error );
BOOST_CHECK_NO_THROW( t_suite2->add( BOOST_TEST_CASE( suite1_test1 ) ) );
}
BOOST_TEST_CASE_TEMPLATE_FUNCTION( template_test_case, T )
{
BOOST_TEST( sizeof(T) == 4U );
}
BOOST_AUTO_TEST_CASE( test_clashing_cases_template_test_case )
{
using namespace boost::unit_test;
test_suite* master_ts = BOOST_TEST_SUITE("local master");
test_suite* t_suite1 = BOOST_TEST_SUITE( "suite1" );
test_suite* t_suite2 = BOOST_TEST_SUITE( "suite2" );
master_ts->add(t_suite1);
master_ts->add(t_suite2);
typedef boost::mpl::list<int, long, unsigned char> test_types1;
typedef boost::mpl::list<int, long, unsigned char, int> test_types2;
BOOST_CHECK_NO_THROW( t_suite2->add( BOOST_TEST_CASE_TEMPLATE( template_test_case, test_types1 ) ) );
BOOST_CHECK_NO_THROW(framework::finalize_setup_phase( master_ts->p_id ));
BOOST_CHECK_NO_THROW( t_suite1->add( BOOST_TEST_CASE_TEMPLATE( template_test_case, test_types2 ) ) );
BOOST_CHECK_THROW(framework::finalize_setup_phase( master_ts->p_id ),
boost::unit_test::framework::setup_error );
}
void test2(int value)
{
BOOST_TEST(value >= 0);
}
BOOST_AUTO_TEST_CASE( test_clashing_cases_with_name )
{
using namespace boost::unit_test;
test_suite* master_ts = BOOST_TEST_SUITE("local master");
test_suite* t_suite1 = BOOST_TEST_SUITE( "suite1" );
master_ts->add(t_suite1);
t_suite1->add( BOOST_TEST_CASE( suite1_test1 ) );
t_suite1->add( BOOST_TEST_CASE( boost::bind( test2, 0 ) ) );
BOOST_CHECK_NO_THROW( t_suite1->add( BOOST_TEST_CASE( boost::bind( test2, 0 ) ) ) );
BOOST_CHECK_THROW(framework::finalize_setup_phase( master_ts->p_id ),
boost::unit_test::framework::setup_error );
for(int i = 0; i < 10; i++) {
t_suite1->add( BOOST_TEST_CASE_NAME( boost::bind( test2, i ), "test-X-" + boost::unit_test::utils::string_cast(i) ) );
}
}

View File

@@ -0,0 +1,67 @@
// (C) Copyright Raffi Enficiaud 2018.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
//! @file
//! checking the clashing names, ticket trac #12596
// *****************************************************************************
#define BOOST_TEST_MODULE test_name_sanitize
#include <boost/test/unit_test.hpp>
#include <boost/mpl/list.hpp>
void suite1_test1()
{
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_CASE( test_suites_sanitize )
{
using namespace boost::unit_test;
test_suite* master_ts = BOOST_TEST_SUITE("local master");
test_suite* t_suite1 = BOOST_TEST_SUITE( "!suite1" );
master_ts->add(t_suite1);
BOOST_TEST( t_suite1->p_name.value == "_suite1" );
BOOST_TEST( master_ts->get("!suite1") == INV_TEST_UNIT_ID );
BOOST_TEST( master_ts->get("_suite1") != INV_TEST_UNIT_ID );
test_suite* t_suite2 = BOOST_TEST_SUITE( " /suite2/@label" );
master_ts->add(t_suite2);
BOOST_TEST( t_suite2->p_name.value == "_suite2__label" );
BOOST_TEST( master_ts->get(" /suite2/@label") == INV_TEST_UNIT_ID );
BOOST_TEST( master_ts->get("_suite2__label") != INV_TEST_UNIT_ID );
// spaces trimming
test_suite* t_suite3 = BOOST_TEST_SUITE( " /suite3/@label " );
master_ts->add(t_suite3);
BOOST_TEST( t_suite3->p_name.value == "_suite3__label" );
BOOST_TEST( master_ts->get(" /suite3/@label ") == INV_TEST_UNIT_ID );
BOOST_TEST( master_ts->get("/suite3/@label") == INV_TEST_UNIT_ID );
BOOST_TEST( master_ts->get(" _suite3__label ") == INV_TEST_UNIT_ID );
BOOST_TEST( master_ts->get("_suite3__label") != INV_TEST_UNIT_ID );
}
BOOST_AUTO_TEST_CASE( test_case_sanitize )
{
using namespace boost::unit_test;
test_suite* master_ts = BOOST_TEST_SUITE("local master");
test_case* tc1 = make_test_case(suite1_test1, "my@whateve!r test case", __FILE__, __LINE__);
master_ts->add( tc1 );
BOOST_TEST( master_ts->get("my@whateve!r test case") == INV_TEST_UNIT_ID );
BOOST_TEST( master_ts->get("my_whateve_r test case") == tc1->p_id );
test_case* tc2 = make_test_case(suite1_test1, " my@whateve!r test case 2 ", __FILE__, __LINE__);
master_ts->add( tc2 );
BOOST_TEST( master_ts->get("my@whateve!r test case 2") == INV_TEST_UNIT_ID );
BOOST_TEST( master_ts->get(" my_whateve_r test case 2 ") == INV_TEST_UNIT_ID );
BOOST_TEST( master_ts->get("my_whateve_r test case 2") == tc2->p_id );
test_case* tc3 = make_test_case(suite1_test1, " some_type < bla, blabla> ", __FILE__, __LINE__);
master_ts->add( tc3 );
BOOST_TEST( master_ts->get("some_type < bla, blabla>") == INV_TEST_UNIT_ID );
BOOST_TEST( master_ts->get(" some_type < bla, blabla> ") == INV_TEST_UNIT_ID );
BOOST_TEST( master_ts->get("some_type < bla_ blabla>") == tc3->p_id );
}

View File

@@ -0,0 +1,28 @@
// (C) Copyright Raffi Enficiaud 2018.
// 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)
// See http://www.boost.org/libs/test for the library home page.
//
//! @file
//! Allowing for suites with same name, ticket trac #12597
// *****************************************************************************
#define BOOST_TEST_MODULE test_clashing_names_suites_ok
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_SUITE( dummy_suite )
BOOST_AUTO_TEST_CASE( ts1 )
{
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_SUITE( dummy_suite )
BOOST_AUTO_TEST_CASE( ts2 )
{
BOOST_CHECK(true);
}
BOOST_AUTO_TEST_SUITE_END()