Add UnitTest file for CXX11_shared_spin_lock
All checks were successful
Publish doxygen documentation to seodisparate.com / doxygen-gen-and-publish (push) Successful in 0s

This commit is contained in:
Stephen Seo 2024-01-12 13:55:28 +09:00
parent 56ee5c3aed
commit 3f2c49572b
2 changed files with 19 additions and 0 deletions

View file

@ -67,6 +67,7 @@ if(CMAKE_BUILD_TYPE MATCHES "Debug")
src/test/UDPC_UnitTest.cpp
src/test/TestTSLQueue.cpp
src/test/TestUDPC.cpp
src/test/TestSharedSpinLock.cpp
)
add_executable(UnitTest ${UDPC_UnitTest_SOURCES})
target_compile_features(UnitTest PUBLIC cxx_std_11)

View file

@ -0,0 +1,18 @@
#include <gtest/gtest.h>
#include "CXX11_shared_spin_lock.hpp"
TEST(CXX11_shared_spin_lock, simple) {
UDPC::SharedSpinLock::Ptr spinLockPtr = UDPC::SharedSpinLock::newInstance();
auto readLock = spinLockPtr->spin_read_lock();
EXPECT_TRUE(readLock.isValid());
EXPECT_TRUE(spinLockPtr->spin_read_lock().isValid());
EXPECT_FALSE(spinLockPtr->try_spin_write_lock().isValid());
auto writeLock = spinLockPtr->trade_read_for_write_lock(readLock);
EXPECT_TRUE(writeLock.isValid());
EXPECT_FALSE(readLock.isValid());
EXPECT_FALSE(spinLockPtr->try_spin_read_lock().isValid());
EXPECT_FALSE(spinLockPtr->try_spin_write_lock().isValid());
}