Files
pip/src_concurrent/test/ConditionLockIntegrationTest.cpp
Фоменко Степан Владимирович a34bf861ab Removed hard unit tests for executor && fixed another tests
git-svn-id: svn://db.shs.com.ru/pip@890 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
2020-02-28 12:49:58 +00:00

57 lines
1.2 KiB
C++

//
// Created by fomenko on 26.09.2019.
//
#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 = true;
createThread([&](){
m->lock();
isProtect = false;
});
ASSERT_TRUE(isProtect);
}
TEST_F(ConditionLock, unlock_is_release) {
m->lock();
volatile bool isReleased = false;
m->unlock();
createThread([&](){
m->lock();
isReleased = true;
m->unlock();
});
EXPECT_TRUE(thread->waitForFinish(WAIT_THREAD_TIME_MS));
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());
}