diff options
Diffstat (limited to 'src/boost/libs/contract/test/detail')
-rw-r--r-- | src/boost/libs/contract/test/detail/counter.hpp | 56 | ||||
-rw-r--r-- | src/boost/libs/contract/test/detail/oteststream.hpp | 82 | ||||
-rw-r--r-- | src/boost/libs/contract/test/detail/out.hpp | 23 | ||||
-rw-r--r-- | src/boost/libs/contract/test/detail/out_inlined.hpp | 33 | ||||
-rw-r--r-- | src/boost/libs/contract/test/detail/unprotected_commas.hpp | 27 |
5 files changed, 221 insertions, 0 deletions
diff --git a/src/boost/libs/contract/test/detail/counter.hpp b/src/boost/libs/contract/test/detail/counter.hpp new file mode 100644 index 00000000..ab40dfcd --- /dev/null +++ b/src/boost/libs/contract/test/detail/counter.hpp @@ -0,0 +1,56 @@ + +#ifndef BOOST_CONTRACT_TEST_DETAIL_COUNTER_HPP_ +#define BOOST_CONTRACT_TEST_DETAIL_COUNTER_HPP_ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +namespace boost { namespace contract { namespace test { namespace detail { + +// Helper to count copies and evaluations of type (e.g., for old values). +template<class Tag, typename T> +struct counter { + T value; + + counter() : value() { ++ctors_; } + static unsigned ctors() { return ctors_; } + + ~counter() { ++dtors_; } + static unsigned dtors() { return dtors_; } + + /* implicit */ counter(counter const& other) : value(other.value) { + ++ctor_copies_; + ++ctors_; + } + + counter& operator=(counter const& other) { + value = other.value; + ++op_copies_; + return *this; + } + + static unsigned copies() { return ctor_copies_ + op_copies_; } + + static counter const& eval(counter const& me) { ++me.evals_; return me; } + static unsigned evals() { return evals_; } + +private: + static unsigned ctors_; // Total constructions (including copies). + static unsigned dtors_; + static unsigned ctor_copies_; + static unsigned op_copies_; + static unsigned evals_; +}; + +template<class Tag, typename T> unsigned counter<Tag, T>::ctors_ = 0; +template<class Tag, typename T> unsigned counter<Tag, T>::dtors_ = 0; +template<class Tag, typename T> unsigned counter<Tag, T>::ctor_copies_ = 0; +template<class Tag, typename T> unsigned counter<Tag, T>::op_copies_ = 0; +template<class Tag, typename T> unsigned counter<Tag, T>::evals_ = 0; + +} } } } // namespace + +#endif // #include guard + diff --git a/src/boost/libs/contract/test/detail/oteststream.hpp b/src/boost/libs/contract/test/detail/oteststream.hpp new file mode 100644 index 00000000..5bf5a031 --- /dev/null +++ b/src/boost/libs/contract/test/detail/oteststream.hpp @@ -0,0 +1,82 @@ + +#ifndef BOOST_CONTRACT_TEST_DETAIL_OTESTSTREAM_HPP_ +#define BOOST_CONTRACT_TEST_DETAIL_OTESTSTREAM_HPP_ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include <boost/iostreams/tee.hpp> +#include <boost/iostreams/stream.hpp> +#include <string> +#include <sstream> +#include <iostream> +#include <algorithm> + +namespace boost { namespace contract { namespace test { namespace detail { + +namespace oteststream_ { + struct oss_base { // Wrap oss data member for proper initialization order. + protected: + std::ostringstream oss_; + }; +} + +// Print to clog plus build internal string (using ostringstream) for checking. +struct oteststream : + private oteststream_::oss_base, + public boost::iostreams::stream<boost::iostreams::tee_device<std::ostream, + std::ostringstream> > +{ + oteststream() : + oteststream_::oss_base(), + boost::iostreams::stream<boost::iostreams::tee_device< + std::ostream, std::ostringstream> >( + boost::iostreams::tee_device<std::ostream, std::ostringstream>( + std::clog, oss_) + ) + {} + + std::string str() const { return oss_.str(); } + void str(std::string const& s) { oss_.str(s); } + + bool eq(std::string const& s) { return eq(str(), s); } + + // Also display mismatching characters. + static bool eq(std::string const& r, std::string const& s) { + std::string::size_type i = 0; + for(; i < r.size() && i < s.size(); ++i) if(r[i] != s[i]) break; + if(i < r.size() || i < s.size()) { + std::cout << std::endl; + std::cout << + "Error: Following strings differ at position " << i << + ", because '" << r[i] << "' != '" << s[i] << "':" << std::endl + ; + std::cout << std::endl; + std::cout + << r.substr(0, i) + << "(((" << r[i] << ")))" + // Extra () to avoid clashes with MSVC min macro. + << r.substr((std::min)(i + 1, r.size()), r.size()) + << std::endl + ; + std::cout << std::endl; + std::cout + << s.substr(0, i) + << "(((" << s[i] << ")))" + // Extra () to avoid clashes with MSVC min macro. + << s.substr((std::min)(i + 1, s.size()), s.size()) + << std::endl + ; + std::cout << std::endl; + return false; + } + return true; + } +}; + +} } } } // namespace + +#endif // #include guard + diff --git a/src/boost/libs/contract/test/detail/out.hpp b/src/boost/libs/contract/test/detail/out.hpp new file mode 100644 index 00000000..fd9cd4c5 --- /dev/null +++ b/src/boost/libs/contract/test/detail/out.hpp @@ -0,0 +1,23 @@ + +#ifndef BOOST_CONTRACT_TEST_DETAIL_OUT_HPP_ +#define BOOST_CONTRACT_TEST_DETAIL_OUT_HPP_ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +// To declare test string functions across shared libraries. + +#include <string> + +namespace boost { namespace contract { namespace test { namespace detail { + +std::string BOOST_CONTRACT_TEST_DETAIL_OUT_DECLSPEC out(); + +void BOOST_CONTRACT_TEST_DETAIL_OUT_DECLSPEC out(std::string const& text); + +} } } } + +#endif // #include guard + diff --git a/src/boost/libs/contract/test/detail/out_inlined.hpp b/src/boost/libs/contract/test/detail/out_inlined.hpp new file mode 100644 index 00000000..954088f3 --- /dev/null +++ b/src/boost/libs/contract/test/detail/out_inlined.hpp @@ -0,0 +1,33 @@ + +#ifndef BOOST_CONTRACT_TEST_OUT_INLINED_HPP_ +#define BOOST_CONTRACT_TEST_OUT_INLINED_HPP_ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +#include "out.hpp" +#include <iostream> + +namespace boost { namespace contract { namespace test { namespace detail { + +namespace out_ { + std::string out; +} + +std::string out() { return out_::out; } + +void out(std::string const& text) { + if(text == "") out_::out = ""; + else { + out_::out = out_::out + text; + std::clog << text; + std::clog.flush(); + } +} + +} } } } + +#endif // #include guard + diff --git a/src/boost/libs/contract/test/detail/unprotected_commas.hpp b/src/boost/libs/contract/test/detail/unprotected_commas.hpp new file mode 100644 index 00000000..c20dd404 --- /dev/null +++ b/src/boost/libs/contract/test/detail/unprotected_commas.hpp @@ -0,0 +1,27 @@ + +#ifndef BOOST_CONTRACT_TEST_DETAIL_UNPROTECTED_COMMAS_HPP_ +#define BOOST_CONTRACT_TEST_DETAIL_UNPROTECTED_COMMAS_HPP_ + +// Copyright (C) 2008-2018 Lorenzo Caminiti +// Distributed under the Boost Software License, Version 1.0 (see accompanying +// file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt). +// See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html + +namespace boost { namespace contract { namespace test { namespace detail { + +// Used to test passing unprotected commas into macro parameters. +template<typename T1, typename Unused2, typename Unused3> +struct unprotected_commas { + typedef T1 type1; // For type macro parameters. + + static void call() {} // For code block macro parameters. + + // For value macro parameters. + template<typename U> static U& same(U& x) { return x; } + template<typename U> static U* same(U* x) { return x; } +}; + +} } } } // namespace + +#endif // #include guard + |