Files
pip/lib/concurrent/test/ConditionLockIntegrationTest.cpp
Ivan Pelipenko 42925122cb version 1.22.0
source tree changed
detached PIConsole and PIScreen* in "pip_console" library
2020-06-28 00:18:24 +03:00

53 lines
1.2 KiB
C++

#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "piconditionvar.h"
#include <pithread.h>
#include "testutil.h"
class ConditionLock : public ::testing::Test, public TestUtil {
public:
PIConditionLock* m = new PIConditionLock();
};
TEST_F(ConditionLock, lock_is_protect) {
m->lock();
bool* isProtect = new bool(true);
createThread([&](){
m->lock();
*isProtect = false;
});
EXPECT_FALSE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
ASSERT_TRUE(*isProtect);
}
TEST_F(ConditionLock, unlock_is_release) {
m->lock();
bool* isReleased = new bool(false);
m->unlock();
createThread([&](){
m->lock();
*isReleased = true;
m->unlock();
});
ASSERT_TRUE(*isReleased);
}
TEST_F(ConditionLock, tryLock_is_false_when_locked) {
createThread([&](){
m->lock();
piMSleep(WAIT_THREAD_TIME_MS);
});
ASSERT_FALSE(m->tryLock());
}
TEST_F(ConditionLock, tryLock_is_true_when_unlocked) {
ASSERT_TRUE(m->tryLock());
}
TEST_F(ConditionLock, tryLock_is_recursive_lock_enable) {
m->lock();
ASSERT_TRUE(m->tryLock());
}