diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2015-04-08 03:09:47 +0000 |
---|---|---|
committer | <> | 2015-05-05 14:37:32 +0000 |
commit | f2541bb90af059680aa7036f315f052175999355 (patch) | |
tree | a5b214744b256f07e1dc2bd7273035a7808c659f /libs/atomic/test/api_test_helpers.hpp | |
parent | ed232fdd34968697a68783b3195b1da4226915b5 (diff) | |
download | boost-tarball-master.tar.gz |
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_58_0.tar.bz2.HEADboost_1_58_0master
Diffstat (limited to 'libs/atomic/test/api_test_helpers.hpp')
-rw-r--r-- | libs/atomic/test/api_test_helpers.hpp | 115 |
1 files changed, 60 insertions, 55 deletions
diff --git a/libs/atomic/test/api_test_helpers.hpp b/libs/atomic/test/api_test_helpers.hpp index 107e7d7d1..1db8c1fb8 100644 --- a/libs/atomic/test/api_test_helpers.hpp +++ b/libs/atomic/test/api_test_helpers.hpp @@ -7,6 +7,11 @@ #ifndef BOOST_ATOMIC_API_TEST_HELPERS_HPP #define BOOST_ATOMIC_API_TEST_HELPERS_HPP +#include <cstring> +#include <boost/config.hpp> +#include <boost/core/lightweight_test.hpp> +#include <boost/atomic.hpp> + /* provide helpers that exercise whether the API functions of "boost::atomic" provide the correct operational semantic in the case of sequential @@ -21,10 +26,10 @@ test_flag_api(void) boost::atomic_flag f; #endif - BOOST_CHECK( !f.test_and_set() ); - BOOST_CHECK( f.test_and_set() ); + BOOST_TEST( !f.test_and_set() ); + BOOST_TEST( f.test_and_set() ); f.clear(); - BOOST_CHECK( !f.test_and_set() ); + BOOST_TEST( !f.test_and_set() ); } template<typename T> @@ -33,48 +38,48 @@ void test_base_operators(T value1, T value2, T value3) /* explicit load/store */ { boost::atomic<T> a(value1); - BOOST_CHECK( a.load() == value1 ); + BOOST_TEST( a.load() == value1 ); } { boost::atomic<T> a(value1); a.store(value2); - BOOST_CHECK( a.load() == value2 ); + BOOST_TEST( a.load() == value2 ); } /* overloaded assignment/conversion */ { boost::atomic<T> a(value1); - BOOST_CHECK( value1 == a ); + BOOST_TEST( value1 == a ); } { boost::atomic<T> a; a = value2; - BOOST_CHECK( value2 == a ); + BOOST_TEST( value2 == a ); } /* exchange-type operators */ { boost::atomic<T> a(value1); T n = a.exchange(value2); - BOOST_CHECK( a.load() == value2 && n == value1 ); + BOOST_TEST( a.load() == value2 && n == value1 ); } { boost::atomic<T> a(value1); T expected = value1; bool success = a.compare_exchange_strong(expected, value3); - BOOST_CHECK( success ); - BOOST_CHECK( a.load() == value3 && expected == value1 ); + BOOST_TEST( success ); + BOOST_TEST( a.load() == value3 && expected == value1 ); } { boost::atomic<T> a(value1); T expected = value2; bool success = a.compare_exchange_strong(expected, value3); - BOOST_CHECK( !success ); - BOOST_CHECK( a.load() == value1 && expected == value1 ); + BOOST_TEST( !success ); + BOOST_TEST( a.load() == value1 && expected == value1 ); } { @@ -85,8 +90,8 @@ void test_base_operators(T value1, T value2, T value3) expected = value1; success = a.compare_exchange_weak(expected, value3); } while(!success); - BOOST_CHECK( success ); - BOOST_CHECK( a.load() == value3 && expected == value1 ); + BOOST_TEST( success ); + BOOST_TEST( a.load() == value3 && expected == value1 ); } { @@ -99,8 +104,8 @@ void test_base_operators(T value1, T value2, T value3) if (expected != value2) break; } while(!success); - BOOST_CHECK( !success ); - BOOST_CHECK( a.load() == value1 && expected == value1 ); + BOOST_TEST( !success ); + BOOST_TEST( a.load() == value1 && expected == value1 ); } } @@ -111,7 +116,7 @@ void test_constexpr_ctor() #ifndef BOOST_NO_CXX11_CONSTEXPR const T value(0); const boost::atomic<T> tester(value); - BOOST_CHECK( tester == value ); + BOOST_TEST( tester == value ); #endif } @@ -126,59 +131,59 @@ void test_additive_operators_with_type(T value, D delta) { boost::atomic<T> a(value); T n = a.fetch_add(delta); - BOOST_CHECK( a.load() == T((AddType)value + delta) ); - BOOST_CHECK( n == value ); + BOOST_TEST( a.load() == T((AddType)value + delta) ); + BOOST_TEST( n == value ); } { boost::atomic<T> a(value); T n = a.fetch_sub(delta); - BOOST_CHECK( a.load() == T((AddType)value - delta) ); - BOOST_CHECK( n == value ); + BOOST_TEST( a.load() == T((AddType)value - delta) ); + BOOST_TEST( n == value ); } /* overloaded modify/assign*/ { boost::atomic<T> a(value); T n = (a += delta); - BOOST_CHECK( a.load() == T((AddType)value + delta) ); - BOOST_CHECK( n == T((AddType)value + delta) ); + BOOST_TEST( a.load() == T((AddType)value + delta) ); + BOOST_TEST( n == T((AddType)value + delta) ); } { boost::atomic<T> a(value); T n = (a -= delta); - BOOST_CHECK( a.load() == T((AddType)value - delta) ); - BOOST_CHECK( n == T((AddType)value - delta) ); + BOOST_TEST( a.load() == T((AddType)value - delta) ); + BOOST_TEST( n == T((AddType)value - delta) ); } /* overloaded increment/decrement */ { boost::atomic<T> a(value); T n = a++; - BOOST_CHECK( a.load() == T((AddType)value + 1) ); - BOOST_CHECK( n == value ); + BOOST_TEST( a.load() == T((AddType)value + 1) ); + BOOST_TEST( n == value ); } { boost::atomic<T> a(value); T n = ++a; - BOOST_CHECK( a.load() == T((AddType)value + 1) ); - BOOST_CHECK( n == T((AddType)value + 1) ); + BOOST_TEST( a.load() == T((AddType)value + 1) ); + BOOST_TEST( n == T((AddType)value + 1) ); } { boost::atomic<T> a(value); T n = a--; - BOOST_CHECK( a.load() == T((AddType)value - 1) ); - BOOST_CHECK( n == value ); + BOOST_TEST( a.load() == T((AddType)value - 1) ); + BOOST_TEST( n == value ); } { boost::atomic<T> a(value); T n = --a; - BOOST_CHECK( a.load() == T((AddType)value - 1) ); - BOOST_CHECK( n == T((AddType)value - 1) ); + BOOST_TEST( a.load() == T((AddType)value - 1) ); + BOOST_TEST( n == T((AddType)value - 1) ); } } @@ -194,12 +199,12 @@ void test_additive_wrap(T value) { boost::atomic<T> a(value); T n = a.fetch_add(1) + 1; - BOOST_CHECK( a.compare_exchange_strong(n, n) ); + BOOST_TEST( a.compare_exchange_strong(n, n) ); } { boost::atomic<T> a(value); T n = a.fetch_sub(1) - 1; - BOOST_CHECK( a.compare_exchange_strong(n, n) ); + BOOST_TEST( a.compare_exchange_strong(n, n) ); } } @@ -210,51 +215,51 @@ void test_bit_operators(T value, T delta) { boost::atomic<T> a(value); T n = a.fetch_and(delta); - BOOST_CHECK( a.load() == T(value & delta) ); - BOOST_CHECK( n == value ); + BOOST_TEST( a.load() == T(value & delta) ); + BOOST_TEST( n == value ); } { boost::atomic<T> a(value); T n = a.fetch_or(delta); - BOOST_CHECK( a.load() == T(value | delta) ); - BOOST_CHECK( n == value ); + BOOST_TEST( a.load() == T(value | delta) ); + BOOST_TEST( n == value ); } { boost::atomic<T> a(value); T n = a.fetch_xor(delta); - BOOST_CHECK( a.load() == T(value ^ delta) ); - BOOST_CHECK( n == value ); + BOOST_TEST( a.load() == T(value ^ delta) ); + BOOST_TEST( n == value ); } /* overloaded modify/assign */ { boost::atomic<T> a(value); T n = (a &= delta); - BOOST_CHECK( a.load() == T(value & delta) ); - BOOST_CHECK( n == T(value & delta) ); + BOOST_TEST( a.load() == T(value & delta) ); + BOOST_TEST( n == T(value & delta) ); } { boost::atomic<T> a(value); T n = (a |= delta); - BOOST_CHECK( a.load() == T(value | delta) ); - BOOST_CHECK( n == T(value | delta) ); + BOOST_TEST( a.load() == T(value | delta) ); + BOOST_TEST( n == T(value | delta) ); } { boost::atomic<T> a(value); T n = (a ^= delta); - BOOST_CHECK( a.load() == T(value ^ delta) ); - BOOST_CHECK( n == T(value ^ delta) ); + BOOST_TEST( a.load() == T(value ^ delta) ); + BOOST_TEST( n == T(value ^ delta) ); } } template<typename T> void test_integral_api(void) { - BOOST_CHECK( sizeof(boost::atomic<T>) >= sizeof(T)); + BOOST_TEST( sizeof(boost::atomic<T>) >= sizeof(T)); test_base_operators<T>(42, 43, 44); test_additive_operators<T, T>(42, 17); @@ -276,8 +281,8 @@ void test_integral_api(void) template<typename T> void test_pointer_api(void) { - BOOST_CHECK( sizeof(boost::atomic<T *>) >= sizeof(T *)); - BOOST_CHECK( sizeof(boost::atomic<void *>) >= sizeof(T *)); + BOOST_TEST( sizeof(boost::atomic<T *>) >= sizeof(T *)); + BOOST_TEST( sizeof(boost::atomic<void *>) >= sizeof(T *)); T values[3]; @@ -289,7 +294,7 @@ void test_pointer_api(void) boost::atomic<void *> ptr; boost::atomic<intptr_t> integral; - BOOST_CHECK( ptr.is_lock_free() == integral.is_lock_free() ); + BOOST_TEST( ptr.is_lock_free() == integral.is_lock_free() ); } enum test_enum { @@ -321,7 +326,7 @@ test_struct_api(void) { boost::atomic<T> sa; boost::atomic<typename T::value_type> si; - BOOST_CHECK( sa.is_lock_free() == si.is_lock_free() ); + BOOST_TEST( sa.is_lock_free() == si.is_lock_free() ); } } struct large_struct { @@ -329,11 +334,11 @@ struct large_struct { inline bool operator==(const large_struct & c) const { - return memcmp(data, &c.data, sizeof(data)) == 0; + return std::memcmp(data, &c.data, sizeof(data)) == 0; } inline bool operator!=(const large_struct & c) const { - return memcmp(data, &c.data, sizeof(data)) != 0; + return std::memcmp(data, &c.data, sizeof(data)) != 0; } }; @@ -359,7 +364,7 @@ test_struct_with_ctor_api(void) test_struct_with_ctor s; boost::atomic<test_struct_with_ctor> sa; // Check that the default constructor was called - BOOST_CHECK( sa.load() == s ); + BOOST_TEST( sa.load() == s ); } test_struct_with_ctor a, b, c; |