diff --git a/utilite/test/test_umutex.cpp b/utilite/test/test_umutex.cpp index 49d4e09a..74b9b57b 100644 --- a/utilite/test/test_umutex.cpp +++ b/utilite/test/test_umutex.cpp @@ -202,6 +202,21 @@ TEST(UMutexTest, UScopeMutexDeferredLock) t.join(); } +TEST(UMutexTest, UScopeMutexLockWhenHeld) +{ + UMutex mutex; + { + UScopeMutex scopeMutex(mutex); // locked by the constructor + EXPECT_EQ(scopeMutex.lock(), 0); // Already held: not locked a second time + EXPECT_TRUE(scopeMutex.isLocked()); + } + std::thread t([&mutex]() { + EXPECT_EQ(mutex.lockTry(), 0); // Unlocked once by the destructor, and free + mutex.unlock(); + }); + t.join(); +} + TEST(UMutexTest, UScopeMutexLockTrySucceeds) { UMutex mutex;