From 90e5a21b3621826388a43952edcb65f71d91b126 Mon Sep 17 00:00:00 2001 From: matlabbe Date: Sun, 27 Sep 2026 18:18:17 -0700 Subject: [PATCH] fixing test coverage --- utilite/test/test_umutex.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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;