summaryrefslogtreecommitdiff
path: root/test/atomictest.cc
diff options
context:
space:
mode:
authorChristian Glöckner <cgloeckner@freenet.de>2016-03-31 08:29:09 +0200
committerChristian Glöckner <cgloeckner@freenet.de>2016-03-31 08:29:09 +0200
commit7cbf182eb1f99997915fe203a24b97aa22e5be70 (patch)
tree95b84919fca71e9b7134d467ad10527cad9d04f7 /test/atomictest.cc
parent357bfe71e62970752bf32029f506b2e96967b1d1 (diff)
Added Atomic Tests about being lock free
Diffstat (limited to 'test/atomictest.cc')
-rw-r--r--test/atomictest.cc56
1 files changed, 38 insertions, 18 deletions
diff --git a/test/atomictest.cc b/test/atomictest.cc
index d73695e..1718b33 100644
--- a/test/atomictest.cc
+++ b/test/atomictest.cc
@@ -32,41 +32,38 @@ class AtomicTest
: public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(AtomicTest);
- CPPUNIT_TEST(atomicIntUsesStandardImpl);
- CPPUNIT_TEST(atomicFloatUsesStandardImpl);
- CPPUNIT_TEST(atomicBoolUsesStandardImpl);
- CPPUNIT_TEST(atomicStringCanBeUsed);
+ CPPUNIT_TEST(podAtomicsUseStandardImpl);
+ CPPUNIT_TEST(nonPodAtomicsUseOwnImpl);
CPPUNIT_TEST(podAtomicCanBeDefaultInitialized);
CPPUNIT_TEST(nonPodAtomicCanBeDefaultInitialized);
CPPUNIT_TEST(podAtomicCanBeValueInitialized);
CPPUNIT_TEST(nonPodAtomicCanBeValueInitialized);
CPPUNIT_TEST(podAtomicCanBeValueAssigned);
CPPUNIT_TEST(nonPodAtomicCanBeValueAssigned);
+ CPPUNIT_TEST(podAtomicsAreLockFree);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
- void atomicIntUsesStandardImpl() {
+ void podAtomicsUseStandardImpl() {
+ CPPUNIT_ASSERT(isUsingStandardImpl<bool>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<unsigned short int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<short int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<unsigned int>());
CPPUNIT_ASSERT(isUsingStandardImpl<int>());
- }
-
- void atomicFloatUsesStandardImpl() {
+ CPPUNIT_ASSERT(isUsingStandardImpl<unsigned long int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<long int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<unsigned long long int>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<long long int>());
CPPUNIT_ASSERT(isUsingStandardImpl<float>());
- }
-
- void atomicBoolUsesStandardImpl() {
- CPPUNIT_ASSERT(isUsingStandardImpl<bool>());
- }
-
- void atomicDoubleUsesStandardImpl() {
CPPUNIT_ASSERT(isUsingStandardImpl<double>());
+ CPPUNIT_ASSERT(isUsingStandardImpl<long double>());
}
- void atomicStringCanBeUsed() {
- // note: if it couldn't be used, the compiler would complain
- Atomic<std::string> tmp;
+ void nonPodAtomicsUseOwnImpl() {
+ CPPUNIT_ASSERT(!isUsingStandardImpl<std::string>());
}
void podAtomicCanBeDefaultInitialized() {
@@ -101,6 +98,23 @@ class AtomicTest
CPPUNIT_ASSERT_EQUAL(s.load(), std::string{"hello world"});
}
+ void podAtomicsAreLockFree() {
+ CPPUNIT_ASSERT(isLockFree<bool>());
+ CPPUNIT_ASSERT(isLockFree<unsigned short int>());
+ CPPUNIT_ASSERT(isLockFree<short int>());
+ CPPUNIT_ASSERT(isLockFree<unsigned int>());
+ CPPUNIT_ASSERT(isLockFree<int>());
+ CPPUNIT_ASSERT(isLockFree<unsigned long int>());
+ CPPUNIT_ASSERT(isLockFree<long int>());
+ CPPUNIT_ASSERT(isLockFree<unsigned long long int>());
+ CPPUNIT_ASSERT(isLockFree<long long int>());
+ CPPUNIT_ASSERT(isLockFree<float>());
+ CPPUNIT_ASSERT(isLockFree<double>());
+
+ // compile error: undefined reference to `__atomic_is_lock_free'
+ //CPPUNIT_ASSERT(isLockFree<long double>());
+ }
+
// todo: further testing
private:
@@ -108,6 +122,12 @@ class AtomicTest
bool isUsingStandardImpl() {
return std::is_base_of<std::atomic<T>, Atomic<T>>::value;
}
+
+ template <typename T>
+ bool isLockFree() {
+ Atomic<T> a;
+ return a.is_lock_free();
+ }
};
// Registers the fixture into the 'registry'